Opened 3 years ago

Closed 2 years ago

#14302 closed defect (fixed)

wxMenuBar UpdateUI doesn't work with Ubuntu Unity

Reported by: bishop Owned by:
Priority: normal Milestone: 2.9.5
Component: wxGTK Version: 2.9.3
Keywords: wxMenuBar UpdateUI ubuntu 12.04 Unity Cc:
Blocked By: Blocking:
Patch: no

Description

The sample from samles/menu build on Ubuntu 12.04 (Unity) don't fire UpdateUI event (EVT_UPDATE_UI). One can build sample and select "File->Clear log". The log will be cleared but menu item will not disabled.

Can anybody confirm such behavior?

wxWidgets build from source as usual ./configure->make->sudo make install

Attachments (1)

ubuntu-menu.diff download (3.7 KB) - added by pcor 2 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 3 years ago by vadz

This seems to be Ubuntu-specific, I can't reproduce the bug under Debian.

I start really, really hating Ubuntu changes to GTK+. Anyhow, this needs to be debugged, together with all the other Ubuntu bugs. Any help would be welcome, as usual.

comment:2 Changed 2 years ago by vadz

  • Status changed from new to confirmed

I do see this under Unity. This is almost certainly related to lack of EVT_MENU_OPEN events (the CLOSE ones are generated however, including on the sample startup, confusingly enough).

No idea how to fix this though...

comment:3 Changed 2 years ago by vadz

  • Priority changed from high to normal
  • Summary changed from wxMenuBar UpdateUI event not fired on ubuntu 12.04, wx2.9.3 to wxMenuBar UpdateUI doesn't work with Ubuntu Unity

Actually it's related to "map" signal but this particular problem is due to "can_activate_accel" one which we don't get neither with Unity menus.

I've created a bug for this problem because I just don't see how could we possibly work around this.

comment:4 Changed 2 years ago by juliansmart

Hi,

Just found this problem and bug report. It still happens on 12.10. The way I've worked around it in wxWidgets 2.8 is as follows: edit include/wx/platform.h and comment out the WXGTK test for wxUSE_IDLEMENUUPDATES.

Obviously this will be slower than updating when menus are opened, but it's better than nothing. Another approach might be to use a wxSystemOption so the application can test whether it's running on Ubrokentu or not, and change the behaviour at run time. Would be better for it to be fixed in the OS of course, but now several versions of the OS have the problem, and presumably won't receive any fix, we need to fix it in our applications.

Julian

/* Choose which method we will use for updating menus

  • - in OnIdle, or when we receive a wxEVT_MENU_OPEN event.
  • Presently, only Windows and GTK+ support wxEVT_MENU_OPEN. */

#ifndef wxUSE_IDLEMENUUPDATES

# if (defined(WXMSW) /*
defined(WXGTK)*/) && !defined(WXUNIVERSAL)

comment:5 Changed 2 years ago by vadz

Yes, I think we need to explicitly test for Ubuntu/Unity HUD and disable "on demand" menu updates in this case. I am not sure how to test for it properly though...

comment:6 Changed 2 years ago by juliansmart

I have just committed r72775 to the 2.8 branch to backport menu update event processing so that using idle-time processing is possible. Otherwise the wrong event source is used and no updates happen.

However, a simpler and arguably better solution is to set UBUNTU_MENUPROXY to 0 in your application before GTK+ initialisation, e.g. in your app class ctor, to switch off the global menu and avoid the bug. It also avoids the bug where the menubar is still available from within modal dialogs - which could easily lead to reentrancy and crashes. Use e.g.

wxSetEnv(wxT("UBUNTU_MENUPROXY"), wxT("0"));

This won't work from OnInit(); it needs to be in the app ctor. Perhaps we need to document or implement this somewhere in wxWidgets because otherwise all wxWidgets applications are broken by default on recent Ubuntus.

(I'm working on 2.8 but this obviously applies to 2.9 too unless something has been done there.)

Changed 2 years ago by pcor

comment:7 follow-up: Changed 2 years ago by pcor

If Ubuntu manages to set _NET_WM_NAME to something useful, like "Unity", we can use something like the attached patch. We just need someone with Ubuntu to find out what gdk_x11_screen_get_window_manager_name() returns.

comment:8 Changed 2 years ago by bishop

On Ubuntu 12.04 gdk_x11_screen_get_window_manager_name returns "Metacity"

GdkScreen * pszStr = gdk_screen_get_default ();
cout << gdk_x11_screen_get_window_manager_name(pszStr) << endl;

comment:9 in reply to: ↑ 7 ; follow-up: Changed 2 years ago by dghart

Replying to pcor:

We just need someone with Ubuntu to find out what gdk_x11_screen_get_window_manager_name() returns.

On ubuntu 12.04: The default WM gives "Compiz" (so, strangely, does GNOME/Openbox). Ubuntu 2D: "Metacity". KDE Plasma Workspace: "Kwin".
On ubuntu 12.10 (quantal): The default WM gives "Compiz". GNOME/Openbox: "Compiz". Ubuntu 2D is no longer available. KDE Plasma Workspace: "Kwin". The other alternatives, and LXDE, give "Openbox".

I tried to test in which of these the 'menu' sample misbehaved in wxGTK-2.8.12, but I couldn't get it to do so anywhere. UpdateUI seems to work: after clearing the log, the 'Standard Items Demo' item is disabled. The 'Clear log' item isn't, but opening the menu itself generates a log item, so that's as I'd expect. It's also the same behaviour as in debian wheezy. What am I misunderstanding?

comment:10 in reply to: ↑ 9 ; follow-up: Changed 2 years ago by bishop

Replying to dghart:

I tried to test in which of these the 'menu' sample misbehaved in wxGTK-2.8.12, but I couldn't get it to do so anywhere. UpdateUI seems to work: after clearing the log, the 'Standard Items Demo' item is disabled. The 'Clear log' item isn't, but opening the menu itself generates a log item, so that's as I'd expect. It's also the same behaviour as in debian wheezy. What am I misunderstanding?

This issue adressed 2.9.x. On 2.8.x everything is ok.

comment:11 in reply to: ↑ 10 Changed 2 years ago by dghart

This issue addressed 2.9.x. On 2.8.x everything is ok.

Ah; I was confused by the earlier mention of the 2.8 branch.

I've now tested in a recent 2.9.5. Of the above, the problem exists only in Ubuntu default and (for 12.04) Ubuntu 2D. So testing for "Metacity" and "Compiz" will catch all the failing WMs, but will also unnecessarily 'fix' GNOME/Openbox.

comment:12 Changed 2 years ago by vadz

  • Milestone set to 2.9.5

Yes, the question is how to distinguish between Unity and everything else. If we test for "Metacity" and "Compiz" we could just as well disable on demand menu updates for wxGTK completely.

And probably this is what would need to be done for 2.9.5, we simply can't leave it broken like this :-(

comment:13 Changed 2 years ago by VZ

(In [73008]) Add wxApp::GTKIsUsingGlobalMenu() helper to wxGTK.

This allows to check whether the global menu is being used and will be mostly
useful for working around various bugs/problems uncovered by it.

See #14302.

comment:14 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [73009]) Use idle time menu updating when using global menu bar in wxGTK.

We don't get wxEVT_MENU_OPEN events when using the global menu bar so don't
rely on them for updating the menu items status and fall back to idle time
menu updating if the global menu bar is used.

This required changing wxUSE_IDLEMENUUPDATES tests from compile- to run-time
ones.

Closes #14302.

Note: See TracTickets for help on using tickets.