[gtk+] window: add an is-maximized property to GtkWindow
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] window: add an is-maximized property to GtkWindow
- Date: Tue, 14 Jan 2014 04:19:06 +0000 (UTC)
commit 197785744b3a74e70086fa91306c824de2c3f54c
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Apr 24 15:45:49 2013 -0400
window: add an is-maximized property to GtkWindow
With proper notifications, plus an accessor method for that state. This
allows client to just listen to notify::is-maximized instead of tracking
window-state-event.
https://bugzilla.gnome.org/show_bug.cgi?id=698786
docs/reference/gtk/gtk3-sections.txt | 1 +
gtk/gtkheaderbar.c | 2 +-
gtk/gtkwindow.c | 39 +++++++++++++++++++++++++++++++--
gtk/gtkwindow.h | 3 ++
gtk/gtkwindowprivate.h | 1 -
5 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index d425a7c..3e35ccc 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5580,6 +5580,7 @@ gtk_window_set_hide_titlebar_when_maximized
gtk_window_set_screen
gtk_window_get_screen
gtk_window_is_active
+gtk_window_is_maximized
gtk_window_has_toplevel_focus
gtk_window_list_toplevels
gtk_window_add_mnemonic
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 3e0f4cd..d1b1c59 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -433,7 +433,7 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
type_hint == GDK_WINDOW_TYPE_HINT_NORMAL)
{
const gchar *icon_name;
- gboolean maximized = _gtk_window_get_maximized (window);
+ gboolean maximized = gtk_window_is_maximized (window);
icon_name = maximized ? "window-restore-symbolic" : "window-maximize-symbolic";
button = gtk_button_new ();
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index dcbe115..f34f943 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -280,6 +280,8 @@ enum {
PROP_MNEMONICS_VISIBLE,
PROP_FOCUS_VISIBLE,
+ PROP_IS_MAXIMIZED,
+
LAST_ARG
};
@@ -1075,6 +1077,14 @@ gtk_window_class_init (GtkWindowClass *klass)
GTK_TYPE_WIDGET,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (gobject_class,
+ PROP_IS_MAXIMIZED,
+ g_param_spec_boolean ("is-maximized",
+ P_("Is maximized"),
+ P_("Whether the window is maximized"),
+ FALSE,
+ GTK_PARAM_READABLE));
+
/* Style properties.
*/
gtk_widget_class_install_style_property (widget_class,
@@ -1233,11 +1243,29 @@ gtk_window_class_init (GtkWindowClass *klass)
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_WINDOW_ACCESSIBLE);
}
+/**
+ * gtk_window_is_maximized:
+ * @window: a #GtkWindow
+ *
+ * Retrieves the current maximized state of @window.
+ *
+ * Note that since maximization is ultimately handled by the window
+ * manager and happens asynchronously to an application request, you
+ * shouldn't assume the return value of this function changing
+ * immediately (or at all), as an effect of calling
+ * gtk_window_maximize() or gtk_window_unmaximize().
+ *
+ * Returns: whether the window has a maximized state.
+ *
+ * Since: 3.12
+ */
gboolean
-_gtk_window_get_maximized (GtkWindow *window)
+gtk_window_is_maximized (GtkWindow *window)
{
GtkWindowPrivate *priv = window->priv;
+ g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
return priv->maximized;
}
@@ -1594,6 +1622,9 @@ gtk_window_get_property (GObject *object,
case PROP_FOCUS_VISIBLE:
g_value_set_boolean (value, priv->focus_visible);
break;
+ case PROP_IS_MAXIMIZED:
+ g_value_set_boolean (value, gtk_window_is_maximized (window));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -6776,6 +6807,7 @@ gtk_window_state_event (GtkWidget *widget,
{
priv->maximized =
(event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED) ? 1 : 0;
+ g_object_notify (G_OBJECT (widget), "is-maximized");
}
if (event->changed_mask & (GDK_WINDOW_STATE_FULLSCREEN | GDK_WINDOW_STATE_MAXIMIZED |
GDK_WINDOW_STATE_TILED))
@@ -9696,8 +9728,9 @@ gtk_window_unstick (GtkWindow *window)
* initially.
*
* You can track maximization via the "window-state-event" signal
- * on #GtkWidget.
- *
+ * on #GtkWidget, or by listening to notifications on the
+ * #GtkWindow:is-maximized property.
+ *
**/
void
gtk_window_maximize (GtkWindow *window)
diff --git a/gtk/gtkwindow.h b/gtk/gtkwindow.h
index 4324cb7..0be0c9f 100644
--- a/gtk/gtkwindow.h
+++ b/gtk/gtkwindow.h
@@ -467,6 +467,9 @@ GDK_AVAILABLE_IN_3_10
void gtk_window_set_titlebar (GtkWindow *window,
GtkWidget *titlebar);
+GDK_AVAILABLE_IN_3_12
+gboolean gtk_window_is_maximized (GtkWindow *window);
+
G_END_DECLS
#endif /* __GTK_WINDOW_H__ */
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index bfe7ecc..d9f9f4d 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -89,7 +89,6 @@ gboolean _gtk_window_titlebar_shows_app_menu (GtkWindow *window);
void _gtk_window_get_shadow_width (GtkWindow *window,
GtkBorder *border);
-gboolean _gtk_window_get_maximized (GtkWindow *window);
void _gtk_window_toggle_maximized (GtkWindow *window);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]