From 2b5f111fb1fb6a02dc2c4e88720b4e3509cae516 Mon Sep 17 00:00:00 2001 From: s <47981745+sghhhh@users.noreply.github.com> Date: Sat, 3 Jan 2026 18:42:30 +0800 Subject: [PATCH] fix: resolve Linux window close handler to prevent app hang (#1795) - Add delete-event callback that properly quits the application when window is closed --- linux/CMakeLists.txt | 2 +- linux/runner/my_application.cc | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index f215d17ab..c03fcaf61 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -1,6 +1,6 @@ # Project-level configuration. 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 on-disk name of your application. diff --git a/linux/runner/my_application.cc b/linux/runner/my_application.cc index ea7374e03..ecdd386fe 100644 --- a/linux/runner/my_application.cc +++ b/linux/runner/my_application.cc @@ -20,6 +20,18 @@ static void first_frame_cb(MyApplication* self, FlView *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. static void my_application_activate(GApplication* 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); 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)); gtk_widget_grab_focus(GTK_WIDGET(view));