Commit a5d5106f authored by Lars Uebernickel's avatar Lars Uebernickel

gtkmenu: displace popups by their css margin

Without a margin, the pointer is above the first (or last) menu item,
making it easy to accidentally activate that item.

https://bugzilla.gnome.org/show_bug.cgi?id=591258
parent 158cb29e
......@@ -2525,6 +2525,19 @@ get_menu_padding (GtkWidget *widget,
gtk_style_context_get_padding (context, state, padding);
}
static void
get_menu_margin (GtkWidget *widget,
GtkBorder *margin)
{
GtkStyleContext *context;
GtkStateFlags state;
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_margin (context, state, margin);
}
static void
gtk_menu_realize (GtkWidget *widget)
{
......@@ -4494,9 +4507,11 @@ gtk_menu_position (GtkMenu *menu,
gint needed_width;
gint needed_height;
GtkBorder padding;
GtkBorder margin;
gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
get_menu_padding (widget, &padding);
get_menu_margin (widget, &margin);
/* The placement of popup menus horizontally works like this (with
* RTL in parentheses)
......@@ -4537,12 +4552,12 @@ gtk_menu_position (GtkMenu *menu,
(!rtl && needed_width > space_right))
{
/* position left */
x = x + padding.left - requisition.width + 1;
x = x - margin.left + padding.left - requisition.width + 1;
}
else
{
/* position right */
x = x - padding.right;
x = x + margin.right - padding.right;
}
/* x is clamped on-screen further down */
......@@ -4588,9 +4603,9 @@ gtk_menu_position (GtkMenu *menu,
needed_height <= space_below)
{
if (needed_height <= space_below)
y = y - padding.top;
y = y + margin.top - padding.top;
else
y = y + padding.bottom - requisition.height + 1;
y = y - margin.bottom + padding.bottom - requisition.height + 1;
y = CLAMP (y, monitor.y,
monitor.y + monitor.height - requisition.height);
......
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