diff options
author | Matthias Clasen <mclasen@redhat.com> | 2015-12-01 14:56:56 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2015-12-01 17:26:25 -0500 |
commit | e626038467f2d10db56e0c193e293e0108c5a255 (patch) | |
tree | 1d5f302a50fd0b10d75b3505c3b893bd2067b6eb /gtk | |
parent | 5dcf4e10b7769119651151dc8a598f3286064857 (diff) | |
download | gtk+-e626038467f2d10db56e0c193e293e0108c5a255.tar.gz |
popover: Make it possible to constrain to toplevel
Under X11, popovers are always constrained to the toplevel
window. Under Wayland, they aren't. This commit adds a
property that allows to explicitly constrain popovers to
the toplevel, giving them the same behavior under Wayland
as under X11.
https://bugzilla.gnome.org/show_bug.cgi?id=757474
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkenums.h | 19 | ||||
-rw-r--r-- | gtk/gtkpopover.c | 79 | ||||
-rw-r--r-- | gtk/gtkpopover.h | 7 |
3 files changed, 103 insertions, 2 deletions
diff --git a/gtk/gtkenums.h b/gtk/gtkenums.h index d2ada7e8a6..73bc316c42 100644 --- a/gtk/gtkenums.h +++ b/gtk/gtkenums.h @@ -1126,4 +1126,23 @@ typedef enum GTK_PAN_DIRECTION_DOWN } GtkPanDirection; +/** + * GtkPopoverConstraint: + * @GTK_POPOVER_CONSTRAINT_NONE: Don't constrain the popover position + * beyond what is imposed by the implementation + * @GTK_POPOVER_CONSTRAINT_WINDOW: Constrain the popover to the boundaries + * of the window that it is attached to + * + * Describes constraints to positioning of popovers. More values + * may be added to this enumeration in the future. + * + * Since: 3.20 + */ +typedef enum +{ + GTK_POPOVER_CONSTRAINT_NONE, + GTK_POPOVER_CONSTRAINT_WINDOW +} GtkPopoverConstraint; + + #endif /* __GTK_ENUMS_H__ */ diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c index 0506c5a76f..d7f3229935 100644 --- a/gtk/gtkpopover.c +++ b/gtk/gtkpopover.c @@ -125,7 +125,8 @@ enum { PROP_POINTING_TO, PROP_POSITION, PROP_MODAL, - PROP_TRANSITIONS_ENABLED + PROP_TRANSITIONS_ENABLED, + PROP_CONSTRAIN_TO }; enum { @@ -151,6 +152,7 @@ struct _GtkPopoverPrivate GtkAdjustment *vadj; GtkAdjustment *hadj; GdkRectangle pointing_to; + GtkPopoverConstraint constraint; guint prev_focus_unmap_id; guint hierarchy_changed_id; guint size_allocate_id; @@ -199,6 +201,7 @@ gtk_popover_init (GtkPopover *popover) popover->priv->modal = TRUE; popover->priv->tick_id = 0; popover->priv->transitions_enabled = TRUE; + popover->priv->constraint = GTK_POPOVER_CONSTRAINT_WINDOW; context = gtk_widget_get_style_context (GTK_WIDGET (popover)); gtk_style_context_add_class (context, GTK_STYLE_CLASS_BACKGROUND); @@ -232,6 +235,10 @@ gtk_popover_set_property (GObject *object, gtk_popover_set_transitions_enabled (GTK_POPOVER (object), g_value_get_boolean (value)); break; + case PROP_CONSTRAIN_TO: + gtk_popover_set_constrain_to (GTK_POPOVER (object), + g_value_get_enum (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -262,6 +269,9 @@ gtk_popover_get_property (GObject *object, case PROP_TRANSITIONS_ENABLED: g_value_set_boolean (value, priv->transitions_enabled); break; + case PROP_CONSTRAIN_TO: + g_value_set_enum (value, priv->constraint); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -986,7 +996,8 @@ gtk_popover_update_position (GtkPopover *popover) overshoot[GTK_POS_RIGHT] = rect.x + rect.width + req.width - window_alloc.width; #ifdef GDK_WINDOWING_WAYLAND - if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget))) + if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)) && + priv->constraint == GTK_POPOVER_CONSTRAINT_NONE) { priv->final_position = priv->preferred_position; } @@ -1698,6 +1709,20 @@ gtk_popover_class_init (GtkPopoverClass *klass) TRUE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); + /** + * GtkPopover:constrain-to: + * + * Sets a constraint for the popover position. + * + * Since: 3.20 + */ + g_object_class_install_property (object_class, + PROP_CONSTRAIN_TO, + g_param_spec_enum ("constrain-to", + P_("Constraint"), + P_("Constraint for the popover position"), + GTK_TYPE_POPOVER_CONSTRAINT, GTK_POPOVER_CONSTRAINT_WINDOW, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); signals[CLOSED] = g_signal_new (I_("closed"), G_TYPE_FROM_CLASS (object_class), @@ -2482,3 +2507,53 @@ gtk_popover_get_default_widget (GtkPopover *popover) return priv->default_widget; } + +/** + * gtk_popover_set_constrain_to: + * @popover: a #GtkPopover + * @constraint: the new constraint + * + * Sets a constraint for positioning this popover. + * + * Note that not all platforms support placing popovers freely, + * and may already impose constraints. + * + * Since: 3.20 + */ +void +gtk_popover_set_constrain_to (GtkPopover *popover, + GtkPopoverConstraint constraint) +{ + GtkPopoverPrivate *priv = popover->priv; + + g_return_if_fail (GTK_IS_POPOVER (popover)); + + if (priv->constraint == constraint) + return; + + priv->constraint = constraint; + gtk_popover_update_position (popover); + + g_object_notify (G_OBJECT (popover), "constrain-to"); +} + +/** + * gtk_popover_get_constrain_to: + * @popover: a #GtkPopover + * + * Returns the constraint for placing this popover. + * See gtk_popover_set_constrain_to(). + * + * Returns: the constraint for placing this popover. + * + * Since: 3.20 + */ +GtkPopoverConstraint +gtk_popover_get_constrain_to (GtkPopover *popover) +{ + GtkPopoverPrivate *priv = popover->priv; + + g_return_val_if_fail (GTK_IS_POPOVER (popover), GTK_POPOVER_CONSTRAINT_WINDOW); + + return priv->constraint; +} diff --git a/gtk/gtkpopover.h b/gtk/gtkpopover.h index f226bb2d4c..61bcd92703 100644 --- a/gtk/gtkpopover.h +++ b/gtk/gtkpopover.h @@ -109,6 +109,13 @@ void gtk_popover_set_default_widget (GtkPopover *popover, GDK_AVAILABLE_IN_3_18 GtkWidget * gtk_popover_get_default_widget (GtkPopover *popover); +GDK_AVAILABLE_IN_3_20 +void gtk_popover_set_constrain_to (GtkPopover *popover, + GtkPopoverConstraint constraint); + +GDK_AVAILABLE_IN_3_20 +GtkPopoverConstraint gtk_popover_get_constrain_to (GtkPopover *popover); + G_END_DECLS #endif /* __GTK_POPOVER_H__ */ |