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));