-
Notifications
You must be signed in to change notification settings - Fork 178
add linux support for ShowSystemMenu #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) | ||
| // Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) | ||
| // Copyright (C) 2025-2027 Wing-summer (wingsummer) | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "linuxwaylandcontext_p.h" | ||
|
|
||
| #include "qwindowkit_linux.h" | ||
|
|
||
| #include <QtGui/qpa/qplatformnativeinterface.h> | ||
|
|
||
| namespace QWK { | ||
| static inline void xdg_toplevel_show_window_menu(struct xdg_toplevel *xdg_toplevel, | ||
| struct wl_seat *seat, uint32_t serial, | ||
| int32_t x, int32_t y) { | ||
| constexpr auto XDG_TOPLEVEL_SHOW_WINDOW_MENU = 4; | ||
| const auto &api = QWK::Private::waylandAPI(); | ||
| Q_ASSERT(api.isValid()); | ||
| api.wl_proxy_marshal_flags( | ||
| reinterpret_cast<struct wl_proxy *>(xdg_toplevel), XDG_TOPLEVEL_SHOW_WINDOW_MENU, | ||
| nullptr, api.wl_proxy_get_version(reinterpret_cast<struct wl_proxy *>(xdg_toplevel)), 0, | ||
| seat, serial, x, y); | ||
| } | ||
|
|
||
| LinuxWaylandContext::LinuxWaylandContext() : QtWindowContext() { | ||
| } | ||
|
|
||
| LinuxWaylandContext::~LinuxWaylandContext() = default; | ||
|
|
||
| QString LinuxWaylandContext::key() const { | ||
| return QStringLiteral("wayland"); | ||
| } | ||
|
|
||
| void LinuxWaylandContext::virtual_hook(int id, void *data) { | ||
| if (id == ShowSystemMenuHook) { | ||
| auto *waylandApp = qApp->nativeInterface<QNativeInterface::QWaylandApplication>(); | ||
| if (!waylandApp) { | ||
| return; | ||
| } | ||
| uint serial = waylandApp->lastInputSerial(); | ||
| wl_seat *seat = waylandApp->lastInputSeat(); | ||
| if (serial == 0 || !seat) { | ||
| return; | ||
| } | ||
|
|
||
| auto toplevel = static_cast<xdg_toplevel *>( | ||
| QGuiApplication::platformNativeInterface()->nativeResourceForWindow( | ||
| "xdg_toplevel", m_windowHandle)); | ||
| if (!toplevel) { | ||
| return; | ||
| } | ||
| auto pos = static_cast<const QPoint *>(data); | ||
| xdg_toplevel_show_window_menu(toplevel, seat, serial, pos->x(), pos->y()); | ||
|
|
||
| wl_display *d = waylandApp->display(); | ||
| if (d) { | ||
| const auto &api = QWK::Private::waylandAPI(); | ||
| Q_ASSERT(api.isValid()); | ||
| api.wl_display_flush(d); | ||
| } | ||
| } else { | ||
| QtWindowContext::virtual_hook(id, data); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) | ||
| // Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) | ||
| // Copyright (C) 2025-2027 Wing-summer (wingsummer) | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| #ifndef LINUXWAYLANDCONTEXT_P_H | ||
| #define LINUXWAYLANDCONTEXT_P_H | ||
|
|
||
| // | ||
| // W A R N I N G !!! | ||
| // ----------------- | ||
| // | ||
| // This file is not part of the QWindowKit API. It is used purely as an | ||
| // implementation detail. This header file may change from version to | ||
| // version without notice, or may even be removed. | ||
| // | ||
|
|
||
|
|
||
| #include "qtwindowcontext_p.h" | ||
|
|
||
| namespace QWK { | ||
|
|
||
| class LinuxWaylandContext : public QtWindowContext { | ||
| Q_OBJECT | ||
| public: | ||
| LinuxWaylandContext(); | ||
| ~LinuxWaylandContext() override; | ||
|
|
||
| QString key() const override; | ||
| void virtual_hook(int id, void *data) override; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif // LINUXWAYLANDCONTEXT_P_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| // Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) | ||
| // Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) | ||
| // Copyright (C) 2025-2027 Wing-summer (wingsummer) | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
|
|
||
| #include "linuxx11context_p.h" | ||
|
|
||
| #include "qwindowkit_linux.h" | ||
|
|
||
| // copy from X11 library and simplify it | ||
| typedef struct _XExtData XExtData; | ||
| struct ScreenFormat; | ||
| struct Depth; | ||
| struct Visual; | ||
| typedef XID Colormap; | ||
| typedef struct { | ||
| XExtData *ext_data; /* hook for extension to hang data */ | ||
| struct _XDisplay *display; /* back pointer to display structure */ | ||
| Window root; /* Root window id. */ | ||
| int width, height; /* width and height of screen */ | ||
| int mwidth, mheight; /* width and height of in millimeters */ | ||
| int ndepths; /* number of depths possible */ | ||
| Depth *depths; /* list of allowable depths on the screen */ | ||
| int root_depth; /* bits per pixel */ | ||
| Visual *root_visual; /* root visual */ | ||
|
|
||
| // typedef struct _XGC | ||
| // #ifdef XLIB_ILLEGAL_ACCESS | ||
| // { | ||
| // XExtData *ext_data; /* hook for extension to hang data */ | ||
| // GContext gid; /* protocol ID for graphics context */ | ||
| // /* there is more to this structure, but it is private to Xlib */ | ||
| // } | ||
| // #endif | ||
| // *GC; | ||
| void * /*GC*/ default_gc; /* GC for the root root visual */ | ||
|
|
||
| Colormap cmap; /* default color map */ | ||
| unsigned long white_pixel; | ||
| unsigned long black_pixel; /* White and Black pixel values */ | ||
| int max_maps, min_maps; /* max and min color maps */ | ||
| int backing_store; /* Never, WhenMapped, Always */ | ||
| Bool save_unders; | ||
| long root_input_mask; /* initial root input mask */ | ||
| } Screen; | ||
| typedef char *XPointer; | ||
| typedef struct { | ||
| XExtData *ext_data; /* hook for extension to hang data */ | ||
| struct _XPrivate *private1; | ||
| int fd; /* Network socket. */ | ||
| int private2; | ||
| int proto_major_version; /* major version of server's X protocol */ | ||
| int proto_minor_version; /* minor version of servers X protocol */ | ||
| char *vendor; /* vendor of the server hardware */ | ||
| XID private3; | ||
| XID private4; | ||
| XID private5; | ||
| int private6; | ||
| XID (*resource_alloc)(/* allocator function */ | ||
| struct _XDisplay *); | ||
| int byte_order; /* screen byte order, LSBFirst, MSBFirst */ | ||
| int bitmap_unit; /* padding and data requirements */ | ||
| int bitmap_pad; /* padding requirements on bitmaps */ | ||
| int bitmap_bit_order; /* LeastSignificant or MostSignificant */ | ||
| int nformats; /* number of pixmap formats in list */ | ||
| ScreenFormat *pixmap_format; /* pixmap format list */ | ||
| int private8; | ||
| int release; /* release of the server */ | ||
| struct _XPrivate *private9, *private10; | ||
| int qlen; /* Length of input event queue */ | ||
| unsigned long last_request_read; /* seq number of last event read */ | ||
| unsigned long request; /* sequence number of last request. */ | ||
| XPointer private11; | ||
| XPointer private12; | ||
| XPointer private13; | ||
| XPointer private14; | ||
| unsigned max_request_size; /* maximum number 32 bit words in request*/ | ||
| struct _XrmHashBucketRec *db; | ||
| int (*private15)(struct _XDisplay *); | ||
| char *display_name; /* "host:display" string used on this connect*/ | ||
| int default_screen; /* default screen for operations */ | ||
| int nscreens; /* number of screens on this server*/ | ||
| Screen *screens; /* pointer to list of screens */ | ||
| unsigned long motion_buffer; /* size of motion buffer */ | ||
| unsigned long private16; | ||
| int min_keycode; /* minimum defined keycode */ | ||
| int max_keycode; /* maximum defined keycode */ | ||
| XPointer private17; | ||
| XPointer private18; | ||
| int private19; | ||
| char *xdefaults; /* contents of defaults from server */ | ||
| /* there is more to this structure, but it is private to Xlib */ | ||
| } *_XPrivDisplay; | ||
|
|
||
| typedef struct { | ||
| int type; | ||
| unsigned long serial; /* # of last request processed by server */ | ||
| Bool send_event; /* true if this came from a SendEvent request */ | ||
| Display *display; /* Display the event was read from */ | ||
| Window window; | ||
| Atom message_type; | ||
| int format; | ||
| union { | ||
| char b[20]; | ||
| short s[10]; | ||
| long l[5]; | ||
| } data; | ||
| } XClientMessageEvent; | ||
|
|
||
| /* | ||
| * this union is defined so Xlib can always use the same sized | ||
| * event structure internally, to avoid memory fragmentation. | ||
| */ | ||
| union _XEvent { | ||
| // delete so many members but size unchanged because of pad | ||
| XClientMessageEvent xclient; | ||
| long pad[24]; | ||
| }; | ||
|
|
||
| #define ScreenOfDisplay(dpy, scr) (&((_XPrivDisplay) (dpy))->screens[scr]) | ||
| #define DefaultScreen(dpy) (((_XPrivDisplay) (dpy))->default_screen) | ||
| #define DefaultRootWindow(dpy) (ScreenOfDisplay(dpy, DefaultScreen(dpy))->root) | ||
|
|
||
| namespace QWK { | ||
|
|
||
| LinuxX11Context::LinuxX11Context() : QtWindowContext() { | ||
| } | ||
|
|
||
| LinuxX11Context::~LinuxX11Context() = default; | ||
|
|
||
| QString LinuxX11Context::key() const { | ||
| return QStringLiteral("xcb"); | ||
| } | ||
|
|
||
| void LinuxX11Context::virtual_hook(int id, void *data) { | ||
| if (id == ShowSystemMenuHook) { | ||
| auto *x11app = qApp->nativeInterface<QNativeInterface::QX11Application>(); | ||
| if (!x11app) { | ||
| return; | ||
| } | ||
|
|
||
| auto display = x11app->display(); | ||
| if (!display) { | ||
| return; | ||
| } | ||
|
|
||
| const auto &api = QWK::Private::x11API(); | ||
| Q_ASSERT(api.isValid()); | ||
|
|
||
| // some marcos to constexpr in X11 | ||
| constexpr auto None = 0L; | ||
| constexpr auto ClientMessage = 33; | ||
| constexpr auto False = 0; | ||
| constexpr auto Button3 = 3; | ||
| constexpr auto SubstructureNotifyMask = 1L << 19; | ||
| constexpr auto SubstructureRedirectMask = 1L << 20; | ||
|
|
||
| // use window id (XID) | ||
| auto xwin = static_cast<Window>(m_windowId); | ||
| Atom atom = api.XInternAtom(display, "_GTK_SHOW_WINDOW_MENU", False); | ||
| if (atom == None) | ||
| return; // WM might not support this atom | ||
| auto pos = static_cast<const QPoint *>(data); | ||
| XEvent ev{}; | ||
| ev.xclient.type = ClientMessage; | ||
| ev.xclient.window = xwin; | ||
| ev.xclient.message_type = atom; | ||
|
|
||
| // The format member is set to 8, 16, or 32 | ||
| // and specifies whether the data should be viewed as | ||
| // a list of bytes, shorts, or longs - typeof(xclient.data). | ||
| ev.xclient.format = 32; | ||
Wing-summer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| qreal dpr = m_windowHandle->devicePixelRatio(); | ||
| int root_x = qRound(pos->x() * dpr); | ||
| int root_y = qRound(pos->y() * dpr); | ||
|
|
||
| ev.xclient.data.l[0] = Button3; // right button | ||
| ev.xclient.data.l[1] = root_x; | ||
| ev.xclient.data.l[2] = root_y; | ||
|
|
||
| Window root = DefaultRootWindow(display); | ||
| api.XSendEvent(display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, | ||
| &ev); | ||
| api.XFlush(display); | ||
| } else { | ||
| QtWindowContext::virtual_hook(id, data); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) | ||
| // Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) | ||
| // Copyright (C) 2025-2027 Wing-summer (wingsummer) | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
Wing-summer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #ifndef LINUXX11CONTEXT_P_H | ||
| #define LINUXX11CONTEXT_P_H | ||
|
|
||
| // | ||
| // W A R N I N G !!! | ||
| // ----------------- | ||
| // | ||
| // This file is not part of the QWindowKit API. It is used purely as an | ||
| // implementation detail. This header file may change from version to | ||
| // version without notice, or may even be removed. | ||
| // | ||
|
|
||
| #include "qtwindowcontext_p.h" | ||
|
|
||
| namespace QWK { | ||
|
|
||
| class LinuxX11Context : public QtWindowContext { | ||
| Q_OBJECT | ||
| public: | ||
| LinuxX11Context(); | ||
| ~LinuxX11Context() override; | ||
|
|
||
| QString key() const override; | ||
| void virtual_hook(int id, void *data) override; | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| #endif // LINUXX11CONTEXT_P_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.