From c73b48f28a49f5872bf8c03a477686367d33e1b3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 28 Jun 2013 22:19:15 -0400 Subject: [PATCH] Add a gtk_window_close function This is useful when adding close buttons in custom titlebars. --- docs/reference/gtk/gtk3-sections.txt | 1 + gtk/gtkwindow.c | 25 ++++++++++++++++++++----- gtk/gtkwindow.h | 2 ++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 481c101c04..fa1449e5fd 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5560,6 +5560,7 @@ gtk_window_get_default_widget gtk_window_set_default gtk_window_present gtk_window_present_with_time +gtk_window_close gtk_window_iconify gtk_window_deiconify gtk_window_stick diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index f669abd949..4c96e65d61 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -1235,7 +1235,7 @@ gtk_window_title_max_clicked (GtkWidget *widget, gpointer data) static gboolean send_delete_event (gpointer data) { - GtkWidget *window = GTK_WIDGET (data); + GtkWidget *window = data; GdkEvent *event; event = gdk_event_new (GDK_DELETE); @@ -1249,10 +1249,25 @@ send_delete_event (gpointer data) return G_SOURCE_REMOVE; } -static void -gtk_window_title_close_clicked (GtkWidget *button, gpointer data) +/** + * gtk_window_close: + * @window: a #GtkWindow + * + * Requests that the window is closed, similar to what happens + * when a window manager close button is clicked. + * + * This function can be used with close buttons in custom + * titlebars. + * + * Since: 3.10 + */ +void +gtk_window_close (GtkWindow *window) { - gdk_threads_add_idle (send_delete_event, data); + if (!gtk_widget_get_realized (GTK_WIDGET (window))) + return; + + gdk_threads_add_idle (send_delete_event, window); } static void @@ -5157,7 +5172,7 @@ update_window_buttons (GtkWindow *window) gtk_widget_set_can_focus (button, FALSE); gtk_widget_show_all (button); g_signal_connect (button, "clicked", - G_CALLBACK (gtk_window_title_close_clicked), window); + G_CALLBACK (gtk_window_close), window); priv->title_close_button = button; } diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h index a4de027788..4324cb7f5b 100644 --- a/gtk/gtkwindow.h +++ b/gtk/gtkwindow.h @@ -348,6 +348,8 @@ GDK_AVAILABLE_IN_ALL void gtk_window_fullscreen (GtkWindow *window); GDK_AVAILABLE_IN_ALL void gtk_window_unfullscreen (GtkWindow *window); +GDK_AVAILABLE_IN_3_10 +void gtk_window_close (GtkWindow *window); GDK_AVAILABLE_IN_ALL void gtk_window_set_keep_above (GtkWindow *window, gboolean setting); GDK_AVAILABLE_IN_ALL