fix: resolve Linux window close handler to prevent app hang (#1795)

- Add delete-event callback that properly quits the application when window is closed
This commit is contained in:
s
2026-01-03 18:42:30 +08:00
committed by GitHub
parent 9f5ce5ae37
commit 2b5f111fb1
2 changed files with 16 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
# Project-level configuration. # Project-level configuration.
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(runner LANGUAGES CXX) project(runner LANGUAGES C CXX)
# The name of the executable created for the application. Change this to change # The name of the executable created for the application. Change this to change
# the on-disk name of your application. # the on-disk name of your application.

View File

@@ -20,6 +20,18 @@ static void first_frame_cb(MyApplication* self, FlView *view)
gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view))); gtk_widget_show(gtk_widget_get_toplevel(GTK_WIDGET(view)));
} }
// Called when window is requested to be closed.
static gboolean window_delete_event_cb(GtkWidget *widget, GdkEvent *event,
gpointer data) {
// Get the application and quit it.
GtkApplication *app = gtk_window_get_application(GTK_WINDOW(widget));
if (app != nullptr) {
g_application_quit(G_APPLICATION(app));
}
// Return TRUE to prevent further processing of the delete event.
return TRUE;
}
// Implements GApplication::activate. // Implements GApplication::activate.
static void my_application_activate(GApplication* application) { static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application); MyApplication* self = MY_APPLICATION(application);
@@ -71,6 +83,9 @@ static void my_application_activate(GApplication* application) {
g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb), self); g_signal_connect_swapped(view, "first-frame", G_CALLBACK(first_frame_cb), self);
gtk_widget_realize(GTK_WIDGET(view)); gtk_widget_realize(GTK_WIDGET(view));
// Connect the delete-event signal to handle window close.
g_signal_connect(window, "delete-event", G_CALLBACK(window_delete_event_cb), NULL);
fl_register_plugins(FL_PLUGIN_REGISTRY(view)); fl_register_plugins(FL_PLUGIN_REGISTRY(view));
gtk_widget_grab_focus(GTK_WIDGET(view)); gtk_widget_grab_focus(GTK_WIDGET(view));