Add support for close-request hook

This commit is contained in:
daleclack 2024-03-20 20:07:23 +08:00
parent 0fca3141a4
commit 79af95c7ee
2 changed files with 14 additions and 1 deletions

View File

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

View File

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