diff --git a/Gtk4/gtk160_wayland_test/src/MyTitleBar.cpp b/Gtk4/gtk160_wayland_test/src/MyTitleBar.cpp index 192caba..d51bda9 100644 --- a/Gtk4/gtk160_wayland_test/src/MyTitleBar.cpp +++ b/Gtk4/gtk160_wayland_test/src/MyTitleBar.cpp @@ -15,6 +15,11 @@ static void ctrl_win_hide(MyTitleBar *self) gtk_widget_set_visible(self->ctrl_window, FALSE); } +static void ctrl_win_close(MyTitleBar *self) +{ + gtk_window_close(GTK_WINDOW(self->ctrl_window)); +} + void my_titlebar_set_window(MyTitleBar *self, GtkWidget *window) { gtk_window_set_titlebar(GTK_WINDOW(window), self->header); @@ -50,7 +55,7 @@ static void my_titlebar_init(MyTitleBar *self) GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - g_signal_connect_swapped(self->btn_close, "clicked", G_CALLBACK(ctrl_win_hide), self); + g_signal_connect_swapped(self->btn_close, "clicked", G_CALLBACK(ctrl_win_close), self); g_signal_connect_swapped(self->btn_mini, "clicked", G_CALLBACK(ctrl_win_hide), self); } diff --git a/Gtk4/gtk160_wayland_test/src/TestWin.cpp b/Gtk4/gtk160_wayland_test/src/TestWin.cpp index 728d504..ac0b92a 100644 --- a/Gtk4/gtk160_wayland_test/src/TestWin.cpp +++ b/Gtk4/gtk160_wayland_test/src/TestWin.cpp @@ -9,14 +9,22 @@ struct _TestWin G_DEFINE_TYPE(TestWin, test_win, GTK_TYPE_WINDOW) +static void test_win_closed(GtkWindow *win, TestWin *self) +{ + g_print("window closed!\n"); +} + static void test_win_init(TestWin *self) { // Initalize window gtk_window_set_title(GTK_WINDOW(self), "Test Window 1"); + gtk_window_set_hide_on_close(GTK_WINDOW(self), TRUE); // Add a custom headerbar self->header = my_titlebar_new(); my_titlebar_set_window(self->header, GTK_WIDGET(self)); + + g_signal_connect(self, "close-request", G_CALLBACK(test_win_closed), self); } static void test_win_class_init(TestWinClass *klass)