Bug 138425 - Adding a menu bar entry given by a PopupMenuController in an extension doesn't work with GTK
Summary: Adding a menu bar entry given by a PopupMenuController in an extension doesn'...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
Version:
(earliest affected)
6.3 all versions
Hardware: All All
: medium normal
Assignee: Thomas Viehmann
URL:
Whiteboard: target:7.2.0 target:7.1.0.0.beta2
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-23 08:37 UTC by Thomas Viehmann
Modified: 2021-03-31 14:06 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Viehmann 2020-11-23 08:37:56 UTC
Description:
I have an extension and want to add a top-level menu (so it's own entry in the menu bar itself), with the menu provided by a PopupMenuController. This works on Windows (last I tested in late 2019) and with the gen VCL plugin on Linux. It does not work with the gtk VCL plugin. For the latter, the menu bar has the extra item, but the menu is unpopulated and the menu controller isn't "fired".

I'm using this in 
https://github.com/lernapparat/lotranslate/
but as this has C extension module dependencies, it is a bit harder to get to run than the BookmarksMenu extension, which shows the same phenomenon:
https://github.com/hanya/BookmarksMenu

I have yet to make sure if it is the top-level aspect specifically or if it is generally with popup menus (although this might not gone unnoticed, given LibreOffice's internal use of popup menus).


Steps to Reproduce:
Install the bookmarks menu extension linked above (it has not been updated recently, but it works on November git libreoffice) and look at the "Bookmarks" heading. Setting with "SAL_USE_VCLPLUGIN=gtk3 ./instdir/program/soffice", the bookmark menu only has the "<no selection possible>" placeholder, with SAL_USE_VCLPLUGIN=gen, the menu appears.

Actual Results:
Depending on the backend, the menu is present or not.

Expected Results:
Always get the menu.


Reproducible: Always


User Profile Reset: Yes



Additional Info:
Debian seems to use the gen backend by default, which works. Windows seems to work, too. A self-built git checkout seems to use gtk by default, which doesn't work, but forcing gen works. I didn't check other backends.
Comment 1 Thomas Viehmann 2020-11-23 19:34:34 UTC
I think I found the root cause of my problem.

VCL GTK (in contrast to X11 and apparently Windows) pre-activates popup menus in GtkSalMenu::UpdateFull by calling GtkSalMenu::ActivateAllSubmenus defined here:

https://git.libreoffice.org/core/+/406e1d123500b1c40a32055c3876ab06e88370e8/vcl/unx/gtk3/gtk3gtksalmenu.cxx#1206

This roughly does (excuse my using of Python as pseudocode):

def activate_all_submenus(self):
  for i in self.menuitems:
    if i.has_submenu:
      activate(i.submenu)
      i.submenu.activate_all_submenus()

but this, called on the main menu, does not activate the main menu itself!

Changing the logic to

def activate_all_submenus(self):
  activate(self)
  for i in self.menuitems:
    if i.has_submenu:
      i.submenu.activate_all_submenus()

makes my usecase work.

I'll submit a patch changing this.

I haven't discovered yet where the VCL tests would live, so I'm not entirely sure how I would design a test case and where I would put it.
Comment 2 Thomas Viehmann 2020-11-23 19:39:47 UTC
A similar update would apply to the VCL Qt5 plugin in Qt5Menu::DoFullMenuUpdate .
Comment 3 Thomas Viehmann 2020-11-23 20:21:43 UTC
My attempt at a fix:
https://gerrit.libreoffice.org/c/core/+/106454
Comment 4 Commit Notification 2020-11-25 09:50:34 UTC
Thomas Viehmann committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/cbc18cc904c652a936c4b68fba4d975bd89b5abd

tdf#138425 vcl/gtk activate main menu in UpdateFull

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2020-11-25 13:57:19 UTC
Thomas Viehmann committed a patch related to this issue.
It has been pushed to "libreoffice-7-1":

https://git.libreoffice.org/core/commit/5270d6901ba69f411b595fa9e2d123169905ab72

tdf#138425 vcl/gtk activate main menu in UpdateFull

It will be available in 7.1.0.0.beta2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Xisco Faulí 2021-03-31 13:47:45 UTC
A polite ping to Thomas Viehmann:
Is this bug fixed? if so, could you please close it as RESOLVED FIXED ?
Otherwise, Could you please explain what's missing?
Thanks
Comment 7 Thomas Viehmann 2021-03-31 14:06:31 UTC
GTK is fixed, I forget if there was some other toolkit also not getting the menus.