Commit 19778574 authored by Cosimo Cecchi's avatar Cosimo Cecchi Committed by Matthias Clasen

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
parent 1691bb74
......@@ -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
......
......@@ -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 ();
......
......@@ -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)
......
......@@ -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__ */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment