Bug 454756 - KWin on X11 doesn't support _GTK_SHOW_WINDOW_MENU hint/message.
Summary: KWin on X11 doesn't support _GTK_SHOW_WINDOW_MENU hint/message.
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-02 16:11 UTC by Emilio Cobos Álvarez (:emilio)
Modified: 2022-06-14 07:14 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Test program which does what I want to do on Firefox (1.85 KB, text/plain)
2022-06-02 16:11 UTC, Emilio Cobos Álvarez (:emilio)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Emilio Cobos Álvarez (:emilio) 2022-06-02 16:11:31 UTC
Created attachment 149407 [details]
Test program which does what I want to do on Firefox

(Please move the component if I got it wrong)

SUMMARY

GTK has a `gdk_window_show_window_menu` API, which is useful to show the context menu on applications that use CSD:

 * https://docs.gtk.org/gdk3/method.Window.show_window_menu.html

On Wayland, this is implemented via `xdg_toplevel::show_window_menu` and it works as expected on KWin: https://wayland.app/protocols/xdg-shell#xdg_toplevel:request:show_window_menu

On X11, however, it's implemented using a WM hint+message called `_GTK_SHOW_WINDOW_MENU`, used like this:

https://gitlab.gnome.org/GNOME/gtk/-/blob/ad5c3168a9f21c3f387df09ce5cd501a9ea1b2d8/gdk/x11/gdksurface-x11.c#L4769-4796

For parity, it'd be great to have it supported on X11 too.

One example where this doesn't work is Firefox's PiP window. Right-clicking there on KWin-on-Wayland, or in GNOME (Wayland or X11), shows the native context-menu to allow to move / position / etc the window.

I wanted to extend this so that we also allow showing the native menu where using CSD / not showing the native titlebar in https://phabricator.services.mozilla.com/D147771. However on Plasma+X11 it doesn't do anything, which is unfortunate.

STEPS TO REPRODUCE
1. `python <test-program>`
2. Right-click on the window area. See a context menu pop up.
3. Click on the context menu item.

OBSERVED RESULT

Nothing

EXPECTED RESULT

A popup, like on Wayland, with the native menu.

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: Trunk
Comment 1 Emilio Cobos Álvarez (:emilio) 2022-06-02 16:12:09 UTC
Happy to try fixing this with some pointers btw.
Comment 2 David Edmundson 2022-06-07 08:03:21 UTC
Find the code for X11 frame extents: 84d75cb5674577098d584c7f3634ea2a81d8b9f2 then it's mostly a c&p job.

that'll show you roughly what's needed:
 - create the right atom in atoms.cpp
 - announce we support it in netinfo.cpp
 - watch for the new X11 event in events.cpp

Then call into the existing code we have for wayland to show a menu
Comment 3 Emilio Cobos Álvarez (:emilio) 2022-06-07 10:27:37 UTC
Thanks! For my own reference, that's https://invent.kde.org/plasma/kwin/-/commit/84d75cb5674577098d584c7f3634ea2a81d8b9f2
Comment 4 Emilio Cobos Álvarez (:emilio) 2022-06-07 11:23:31 UTC
Ok, I think this should do. Works properly with a local build and:

 * https://invent.kde.org/frameworks/kwindowsystem/-/merge_requests/58
 * https://invent.kde.org/plasma/kwin/-/merge_requests/2495

There's a test failure in the former MR which I need to investigate, seems I just need to add the expected atom somewhere.
Comment 5 Emilio Cobos Álvarez (:emilio) 2022-06-07 11:42:10 UTC
(In reply to Emilio Cobos Álvarez (:emilio) from comment #4)
> There's a test failure in the former MR which I need to investigate, seems I
> just need to add the expected atom somewhere.

(This is now fixed)
Comment 6 Emilio Cobos Álvarez (:emilio) 2022-06-10 15:18:23 UTC
Git commit c3fa9cada231ba14f281d1a2fc46e240d0440517 by Emilio Cobos Álvarez.
Committed on 10/06/2022 at 12:55.
Pushed by davidedmundson into branch 'master'.

Implement _GTK_SHOW_WINDOW_MENU.

M  +4    -0    autotests/netrootinfotestwm.cpp
M  +2    -0    src/netwm_def.h
M  +1    -0    src/platforms/xcb/atoms_p.h
M  +31   -0    src/platforms/xcb/netwm.cpp
M  +30   -0    src/platforms/xcb/netwm.h

https://invent.kde.org/frameworks/kwindowsystem/commit/c3fa9cada231ba14f281d1a2fc46e240d0440517
Comment 7 Vlad Zahorodnii 2022-06-14 07:14:43 UTC
Git commit 7e1617c2808b7c9b23a8c786327fc88212e10b32 by Vlad Zahorodnii, on behalf of Emilio Cobos Álvarez.
Committed on 14/06/2022 at 06:55.
Pushed by vladz into branch 'master'.

[x11] Implement _GTK_SHOW_WINDOW_MENU.

M  +10   -1    src/netinfo.cpp
M  +1    -0    src/netinfo.h
M  +7    -0    src/x11window.cpp
M  +1    -0    src/x11window.h

https://invent.kde.org/plasma/kwin/commit/7e1617c2808b7c9b23a8c786327fc88212e10b32