Popover: Include window shadows in overshoot calcs

.update_position() enforces that non-Wayland platforms must position a
Popover within its parent Window. We use the allocation of the Window
to translate the position and check for overshoot on each of its sides.
Calling Widget.get_allocation() of a CSD Window includes its shadows.

But shadows were not excluded from the area in which we can position.
Thus, Popovers could get positioned in the shadow of CSD windows, where,
at least on X11, no input is received. Therefore, positioning a Popover
over a shadow meant its child widgets within that area became unusable.

Fix by calling Window.get_shadow() and including it in the overshoot on
each side. This adjusts for how the allocation includes shadows, making
overshoots with and without shadows the same. Thus, we avoid considering
shadows as viable for positioning, favouring a side where input works.

https://bugzilla.gnome.org/show_bug.cgi?id=786209
This commit is contained in:
Daniel Boles 2017-08-23 21:44:10 +01:00
parent 3a2c379f3c
commit 947bca195c

View File

@ -1042,6 +1042,7 @@ gtk_popover_update_position (GtkPopover *popover)
GtkPopoverPrivate *priv = popover->priv;
GtkWidget *widget = GTK_WIDGET (popover);
GtkAllocation window_alloc;
GtkBorder window_shadow;
GdkRectangle rect;
GtkRequisition req;
GtkPositionType pos;
@ -1054,6 +1055,7 @@ gtk_popover_update_position (GtkPopover *popover)
gtk_widget_get_preferred_size (widget, NULL, &req);
gtk_widget_get_allocation (GTK_WIDGET (priv->window), &window_alloc);
_gtk_window_get_shadow_width (priv->window, &window_shadow);
priv->final_position = priv->preferred_position;
gtk_popover_get_pointing_to (popover, &rect);
@ -1062,10 +1064,12 @@ gtk_popover_update_position (GtkPopover *popover)
pos = get_effective_position (popover, priv->preferred_position);
overshoot[GTK_POS_TOP] = req.height - rect.y;
overshoot[GTK_POS_BOTTOM] = rect.y + rect.height + req.height - window_alloc.height;
overshoot[GTK_POS_LEFT] = req.width - rect.x;
overshoot[GTK_POS_RIGHT] = rect.x + rect.width + req.width - window_alloc.width;
overshoot[GTK_POS_TOP] = req.height - rect.y + window_shadow.top;
overshoot[GTK_POS_BOTTOM] = rect.y + rect.height + req.height - window_alloc.height
+ window_shadow.bottom;
overshoot[GTK_POS_LEFT] = req.width - rect.x + window_shadow.left;
overshoot[GTK_POS_RIGHT] = rect.x + rect.width + req.width - window_alloc.width
+ window_shadow.right;
#ifdef GDK_WINDOWING_WAYLAND
if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget)) &&