[gtk+/wip/matthiasc/kill-event-signals: 6/62] window: Add a hide-on-delete property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/kill-event-signals: 6/62] window: Add a hide-on-delete property
- Date: Tue, 2 Jan 2018 04:52:18 +0000 (UTC)
commit a2a0b43e3a0deb5c06907593aed4111f1e0057b3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Dec 31 10:42:10 2017 -0500
window: Add a hide-on-delete property
This lets us avoid ::delete-event signal handlers for just
this purpose.
gtk/gtkwindow.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkwindow.h | 5 +++
2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 1f31437..900f111 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -264,6 +264,7 @@ struct _GtkWindowPrivate
guint tiled : 1;
guint use_subsurface : 1;
+ guint hide_on_delete : 1;
GdkWindowTypeHint type_hint;
@@ -310,6 +311,7 @@ enum {
PROP_DEFAULT_WIDTH,
PROP_DEFAULT_HEIGHT,
PROP_DESTROY_WITH_PARENT,
+ PROP_HIDE_ON_DELETE,
PROP_ICON,
PROP_ICON_NAME,
PROP_DISPLAY,
@@ -416,6 +418,8 @@ static void gtk_window_size_allocate (GtkWidget *widget,
const GtkAllocation *allocation,
int baseline,
GtkAllocation *out_clip);
+static gboolean gtk_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event);
static gboolean gtk_window_map_event (GtkWidget *widget,
GdkEventAny *event);
static gint gtk_window_configure_event (GtkWidget *widget,
@@ -799,6 +803,7 @@ gtk_window_class_init (GtkWindowClass *klass)
widget_class->realize = gtk_window_realize;
widget_class->unrealize = gtk_window_unrealize;
widget_class->size_allocate = gtk_window_size_allocate;
+ widget_class->delete_event = gtk_window_delete_event;
widget_class->configure_event = gtk_window_configure_event;
widget_class->event = gtk_window_event;
widget_class->key_press_event = gtk_window_key_press_event;
@@ -908,6 +913,14 @@ gtk_window_class_init (GtkWindowClass *klass)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ window_props[PROP_HIDE_ON_DELETE] =
+ g_param_spec_boolean ("hide-on-delete",
+ P_("Hide on Delete"),
+ P_("If this window should be hidden when the user clicks the close button"),
+ FALSE,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
+
window_props[PROP_ICON] =
g_param_spec_object ("icon",
P_("Icon"),
@@ -2043,6 +2056,9 @@ gtk_window_set_property (GObject *object,
case PROP_DESTROY_WITH_PARENT:
gtk_window_set_destroy_with_parent (window, g_value_get_boolean (value));
break;
+ case PROP_HIDE_ON_DELETE:
+ gtk_window_set_hide_on_delete (window, g_value_get_boolean (value));
+ break;
case PROP_ICON:
gtk_window_set_icon (window,
g_value_get_object (value));
@@ -2154,6 +2170,9 @@ gtk_window_get_property (GObject *object,
case PROP_DESTROY_WITH_PARENT:
g_value_set_boolean (value, priv->destroy_with_parent);
break;
+ case PROP_HIDE_ON_DELETE:
+ g_value_set_boolean (value, priv->hide_on_delete);
+ break;
case PROP_ICON:
g_value_set_object (value, gtk_window_get_icon (window));
break;
@@ -4056,6 +4075,50 @@ gtk_window_get_destroy_with_parent (GtkWindow *window)
return window->priv->destroy_with_parent;
}
+/**
+ * gtk_window_set_hide_on_delete:
+ * @window: a #GtkWindow
+ * @setting: whether to hide the window when it is closed
+ *
+ * If @setting is %TRUE, then clicking the close button on the window
+ * will not destroy it, but only hide it.
+ *
+ * Since: 3.94
+ */
+void
+gtk_window_set_hide_on_delete (GtkWindow *window,
+ gboolean setting)
+{
+ GtkWindowPrivate *priv = window->priv;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ if (priv->hide_on_delete == setting)
+ return;
+
+ priv->hide_on_delete = setting;
+
+ g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_HIDE_ON_DELETE]);
+}
+
+/**
+ * gtk_window_get_hide_on_delete:
+ * @window: a #GtkWindow
+ *
+ * Returns whether the window will be hidden when the close button is clicked.
+ *
+ * Returns: %TRUE if the window will be hidden
+ *
+ * Since: 3.94
+ */
+gboolean
+gtk_window_get_hide_on_delete (GtkWindow *window)
+{
+ g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+ return window->priv->hide_on_delete;
+}
+
static GtkWindowGeometryInfo*
gtk_window_get_geometry_info (GtkWindow *window,
gboolean create)
@@ -5904,6 +5967,22 @@ gtk_window_destroy (GtkWidget *widget)
GTK_WIDGET_CLASS (gtk_window_parent_class)->destroy (widget);
}
+static gboolean
+gtk_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event)
+{
+ GtkWindow *window = GTK_WINDOW (widget);
+ GtkWindowPrivate *priv = window->priv;
+
+ if (priv->hide_on_delete)
+ {
+ gtk_widget_hide (widget);
+ return GDK_EVENT_STOP;
+ }
+
+ return GDK_EVENT_PROPAGATE;
+}
+
static void
gtk_window_finalize (GObject *object)
{
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 47f8263..a67c96e 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -227,9 +227,14 @@ void gtk_window_set_destroy_with_parent (GtkWindow *window,
gboolean setting);
GDK_AVAILABLE_IN_ALL
gboolean gtk_window_get_destroy_with_parent (GtkWindow *window);
+GDK_AVAILABLE_IN_3_94
+void gtk_window_set_hide_on_delete (GtkWindow *window,
+ gboolean setting);
GDK_AVAILABLE_IN_ALL
void gtk_window_set_mnemonics_visible (GtkWindow *window,
gboolean setting);
+GDK_AVAILABLE_IN_3_94
+gboolean gtk_window_get_hide_on_delete (GtkWindow *window);
GDK_AVAILABLE_IN_ALL
gboolean gtk_window_get_mnemonics_visible (GtkWindow *window);
GDK_AVAILABLE_IN_3_2
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]