Fix positioning of up menu button popup
Use the menu allocation instead of the request size. https://bugzilla.gnome.org/show_bug.cgi?id=720939
This commit is contained in:
@@ -255,13 +255,12 @@ menu_position_up_down_func (GtkMenu *menu,
|
|||||||
GtkMenuButtonPrivate *priv = menu_button->priv;
|
GtkMenuButtonPrivate *priv = menu_button->priv;
|
||||||
GtkWidget *widget = GTK_WIDGET (menu_button);
|
GtkWidget *widget = GTK_WIDGET (menu_button);
|
||||||
GtkWidget *toplevel;
|
GtkWidget *toplevel;
|
||||||
GtkRequisition menu_req;
|
|
||||||
GtkTextDirection direction;
|
GtkTextDirection direction;
|
||||||
GdkRectangle monitor;
|
GdkRectangle monitor;
|
||||||
gint monitor_num;
|
gint monitor_num;
|
||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
GtkAllocation allocation, arrow_allocation;
|
GtkAllocation menu_allocation, allocation, arrow_allocation;
|
||||||
GtkAlign align;
|
GtkAlign align;
|
||||||
|
|
||||||
/* In the common case the menu button is showing a dropdown menu, set the
|
/* In the common case the menu button is showing a dropdown menu, set the
|
||||||
@@ -274,9 +273,6 @@ menu_position_up_down_func (GtkMenu *menu,
|
|||||||
gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
|
gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_get_preferred_size (GTK_WIDGET (priv->popup),
|
|
||||||
&menu_req, NULL);
|
|
||||||
|
|
||||||
align = gtk_widget_get_halign (GTK_WIDGET (priv->popup));
|
align = gtk_widget_get_halign (GTK_WIDGET (priv->popup));
|
||||||
direction = gtk_widget_get_direction (widget);
|
direction = gtk_widget_get_direction (widget);
|
||||||
window = gtk_widget_get_window (priv->align_widget ? priv->align_widget : widget);
|
window = gtk_widget_get_window (priv->align_widget ? priv->align_widget : widget);
|
||||||
@@ -289,6 +285,7 @@ menu_position_up_down_func (GtkMenu *menu,
|
|||||||
|
|
||||||
gtk_widget_get_allocation (priv->align_widget ? priv->align_widget : widget, &allocation);
|
gtk_widget_get_allocation (priv->align_widget ? priv->align_widget : widget, &allocation);
|
||||||
gtk_widget_get_allocation (widget, &arrow_allocation);
|
gtk_widget_get_allocation (widget, &arrow_allocation);
|
||||||
|
gtk_widget_get_allocation (GTK_WIDGET (priv->popup), &menu_allocation);
|
||||||
|
|
||||||
gdk_window_get_origin (window, x, y);
|
gdk_window_get_origin (window, x, y);
|
||||||
*x += allocation.x;
|
*x += allocation.x;
|
||||||
@@ -299,27 +296,27 @@ menu_position_up_down_func (GtkMenu *menu,
|
|||||||
align = GTK_ALIGN_START;
|
align = GTK_ALIGN_START;
|
||||||
|
|
||||||
if (align == GTK_ALIGN_CENTER)
|
if (align == GTK_ALIGN_CENTER)
|
||||||
*x -= (menu_req.width - allocation.width) / 2;
|
*x -= (menu_allocation.width - allocation.width) / 2;
|
||||||
else if ((align == GTK_ALIGN_START && direction == GTK_TEXT_DIR_LTR) ||
|
else if ((align == GTK_ALIGN_START && direction == GTK_TEXT_DIR_LTR) ||
|
||||||
(align == GTK_ALIGN_END && direction == GTK_TEXT_DIR_RTL))
|
(align == GTK_ALIGN_END && direction == GTK_TEXT_DIR_RTL))
|
||||||
*x += MAX (allocation.width - menu_req.width, 0);
|
*x += MAX (allocation.width - menu_allocation.width, 0);
|
||||||
else if (menu_req.width > allocation.width)
|
else if (menu_allocation.width > allocation.width)
|
||||||
*x -= menu_req.width - allocation.width;
|
*x -= menu_allocation.width - allocation.width;
|
||||||
|
|
||||||
if (priv->arrow_type == GTK_ARROW_UP && *y - menu_req.height >= monitor.y)
|
if (priv->arrow_type == GTK_ARROW_UP && *y - menu_allocation.height >= monitor.y)
|
||||||
{
|
{
|
||||||
*y -= menu_req.height;
|
*y -= menu_allocation.height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height)
|
if ((*y + arrow_allocation.height + menu_allocation.height) <= monitor.y + monitor.height)
|
||||||
*y += arrow_allocation.height;
|
*y += arrow_allocation.height;
|
||||||
else if ((*y - menu_req.height) >= monitor.y)
|
else if ((*y - menu_allocation.height) >= monitor.y)
|
||||||
*y -= menu_req.height;
|
*y -= menu_allocation.height;
|
||||||
else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
|
else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
|
||||||
*y += arrow_allocation.height;
|
*y += arrow_allocation.height;
|
||||||
else
|
else
|
||||||
*y -= menu_req.height;
|
*y -= menu_allocation.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
*push_in = FALSE;
|
*push_in = FALSE;
|
||||||
@@ -334,8 +331,8 @@ menu_position_side_func (GtkMenu *menu,
|
|||||||
{
|
{
|
||||||
GtkMenuButtonPrivate *priv = menu_button->priv;
|
GtkMenuButtonPrivate *priv = menu_button->priv;
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
|
GtkAllocation menu_allocation;
|
||||||
GtkWidget *widget = GTK_WIDGET (menu_button);
|
GtkWidget *widget = GTK_WIDGET (menu_button);
|
||||||
GtkRequisition menu_req;
|
|
||||||
GdkRectangle monitor;
|
GdkRectangle monitor;
|
||||||
gint monitor_num;
|
gint monitor_num;
|
||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
@@ -343,9 +340,6 @@ menu_position_side_func (GtkMenu *menu,
|
|||||||
GtkAlign align;
|
GtkAlign align;
|
||||||
GtkTextDirection direction;
|
GtkTextDirection direction;
|
||||||
|
|
||||||
gtk_widget_get_preferred_size (GTK_WIDGET (priv->popup),
|
|
||||||
&menu_req, NULL);
|
|
||||||
|
|
||||||
window = gtk_widget_get_window (widget);
|
window = gtk_widget_get_window (widget);
|
||||||
|
|
||||||
direction = gtk_widget_get_direction (widget);
|
direction = gtk_widget_get_direction (widget);
|
||||||
@@ -359,20 +353,21 @@ menu_position_side_func (GtkMenu *menu,
|
|||||||
gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (menu_button)), x, y);
|
gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (menu_button)), x, y);
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
gtk_widget_get_allocation (widget, &allocation);
|
||||||
|
gtk_widget_get_allocation (GTK_WIDGET (priv->popup), &menu_allocation);
|
||||||
|
|
||||||
if ((priv->arrow_type == GTK_ARROW_RIGHT && direction == GTK_TEXT_DIR_LTR) ||
|
if ((priv->arrow_type == GTK_ARROW_RIGHT && direction == GTK_TEXT_DIR_LTR) ||
|
||||||
(priv->arrow_type == GTK_ARROW_LEFT && direction == GTK_TEXT_DIR_RTL))
|
(priv->arrow_type == GTK_ARROW_LEFT && direction == GTK_TEXT_DIR_RTL))
|
||||||
|
|
||||||
{
|
{
|
||||||
if (*x + allocation.width + menu_req.width <= monitor.x + monitor.width)
|
if (*x + allocation.width + menu_allocation.width <= monitor.x + monitor.width)
|
||||||
*x += allocation.width;
|
*x += allocation.width;
|
||||||
else
|
else
|
||||||
*x -= menu_req.width;
|
*x -= menu_allocation.width;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (*x - menu_req.width >= monitor.x)
|
if (*x - menu_allocation.width >= monitor.x)
|
||||||
*x -= menu_req.width;
|
*x -= menu_allocation.width;
|
||||||
else
|
else
|
||||||
*x += allocation.width;
|
*x += allocation.width;
|
||||||
}
|
}
|
||||||
@@ -382,9 +377,9 @@ menu_position_side_func (GtkMenu *menu,
|
|||||||
align = GTK_ALIGN_START;
|
align = GTK_ALIGN_START;
|
||||||
|
|
||||||
if (align == GTK_ALIGN_CENTER)
|
if (align == GTK_ALIGN_CENTER)
|
||||||
*y -= (menu_req.height - allocation.height) / 2;
|
*y -= (menu_allocation.height - allocation.height) / 2;
|
||||||
else if (align == GTK_ALIGN_END)
|
else if (align == GTK_ALIGN_END)
|
||||||
*y -= menu_req.height - allocation.height;
|
*y -= menu_allocation.height - allocation.height;
|
||||||
|
|
||||||
*push_in = FALSE;
|
*push_in = FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user