Toolbar popup context menu unexpectedly opens over menubar sub menus

Bug #1184708 reported by André Auzi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Midori Web Browser
Fix Released
Undecided
Unassigned

Bug Description

When I clic with button 3 on menu entries of a sub menu of the menu bar

I expect a popup context menu related to the context of the sub menu
(eg. bookmark popup context menu in bookmarks menu tree)

whatever the sub menu is, I get the toolbar popup context menu.

Related branches

Revision history for this message
André Auzi (aauzi) wrote :
Revision history for this message
André Auzi (aauzi) wrote :

I traced the issue down to the function: midori_browser_menu_button_press_event_cb

It implements a code that relay the 'button-press-event' if the 'button-press-event' is handled by the menubar handler.

    /* GtkMenuBar catches button events on children with submenus,
       so we need to see if the actual widget is the menubar, and if
       it is an item, we forward it to the actual widget. */
    if ((GTK_IS_BOX (toolitem) || GTK_IS_MENU_BAR (toolitem)))
    {
        midori_browser_toolbar_popup_context_menu_cb (
            GTK_IS_BIN (toolitem) && gtk_bin_get_child (GTK_BIN (toolitem)) ?
                gtk_widget_get_parent (toolitem) : toolitem,
            event->x, event->y, event->button, browser);
        return TRUE;
    }
    else if (GTK_IS_MENU_ITEM (toolitem))
    {
        gboolean handled;
        g_signal_emit_by_name (toolitem, "button-press-event", event, &handled);
        return handled;
    }

This code does not work in my environment (See version description previously attached)

I managed to avoid this misbehaviour by checking the inclusion of the 'button-press-event' in the bounding box of the menubar widget.

like this:

      /* GtkMenuBar catches button events on children with submenus,
         so we need to see if the actual widget is the menubar, and if
         it is an item, we forward it to the actual widget. */
      if ((GTK_IS_BOX (toolitem) || GTK_IS_MENU_BAR (toolitem)))
      {
! gboolean event_in_window = TRUE;
! gint ex, ey, x, y, width, height;
!
! gdk_window_get_origin (toolitem->window, &x, &y);
! gdk_drawable_get_size (GDK_DRAWABLE (toolitem->window), &width, &height);
! ex = event->x_root; ey = event->y_root;;
!
! if ((ex < x) || (ey < y)
! || (ex > x+width) || (ey > y+height))
! event_in_window = FALSE;
!
! g_print (" evt: x=%d, y=%d\n", ex, ey);
! g_print (" wnd: x=%d, y=%d, w=%d, h=%d\n", x, y, width, height);
! g_print ("popup: is_box=%d, is_menu_bar=%d,"
! " is_menu_item=%d, is_browser_menubar=%d,"
! " event_in_window=%d\n",
! GTK_IS_BOX (toolitem), GTK_IS_MENU_BAR (toolitem),
! GTK_IS_MENU_ITEM (toolitem),
! toolitem == (GtkWidget*)browser->menubar,
! event_in_window);
!
! if ((ex < x) || (ey < y)
! || (ex > x+width) || (ey > y+height))
! return FALSE;
!
! midori_browser_toolbar_popup_context_menu_cb (

Revision history for this message
Cris Dywan (kalikiana) wrote :

midori_browser_menu_button_press_event_cb is called on both GtkStatusbar and GtkMenuBar thus GTK_IS_BOX and GTK_IS_MENU_BAR.
I'm not certain regarding the GTK_IS_MENU_ITEM case, the callback may have been connected or relyed on a particular menubar implementation (Gtk2, Gtk3, global menubar and Unity menubar indicator all have subtle behavior aspects - this is just a thought, I have no concrete reason to suspect so).

Revision history for this message
gue5t gue5t (gue5t) wrote :

This can probably be simplified by checking the widget's GdkWindow against the GdkEvent's window field rather than comparing bounding boxes w/ x,y values. I'll take a look at it in a bit. This would be a nice thing to have fixed, though.

Revision history for this message
gue5t gue5t (gue5t) wrote :

After having tried a variety of different approaches, I think aauzi's approach is actually about as clean as things are likely to get. GtkMenubar's event stealing really complicates things, and the GdkWindow hierarchy isn't as nice as it could be here.

Donte Greene (flykidd)
Changed in midori:
status: New → In Progress
Cody Garver (codygarver)
Changed in midori:
milestone: none → 0.5.7
Cris Dywan (kalikiana)
Changed in midori:
milestone: 0.5.7 → 0.5.8
Changed in midori:
status: In Progress → Fix Committed
Cris Dywan (kalikiana)
Changed in midori:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.