|
| 1 | +// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) |
| 2 | +// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +#include "linuxwaylandcontext_p.h" |
| 6 | + |
| 7 | +#include "linuxdesktopenvapi.h" |
| 8 | + |
| 9 | +#include <QtGui/qpa/qplatformnativeinterface.h> |
| 10 | + |
| 11 | +namespace QWK { |
| 12 | + static inline void xdg_toplevel_show_window_menu(struct xdg_toplevel *xdg_toplevel, |
| 13 | + struct wl_seat *seat, uint32_t serial, |
| 14 | + int32_t x, int32_t y) { |
| 15 | + constexpr auto XDG_TOPLEVEL_SHOW_WINDOW_MENU = 4; |
| 16 | + auto &api = LinuxDesktopEnvAPI::waylandAPI(); |
| 17 | + Q_ASSERT(api.isValid()); |
| 18 | + api.wl_proxy_marshal_flags((struct wl_proxy *) xdg_toplevel, XDG_TOPLEVEL_SHOW_WINDOW_MENU, |
| 19 | + NULL, api.wl_proxy_get_version((struct wl_proxy *) xdg_toplevel), |
| 20 | + 0, seat, serial, x, y); |
| 21 | + } |
| 22 | + |
| 23 | + LinuxWaylandContext::LinuxWaylandContext() : QtWindowContext() { |
| 24 | + } |
| 25 | + |
| 26 | + LinuxWaylandContext::~LinuxWaylandContext() = default; |
| 27 | + |
| 28 | + QString LinuxWaylandContext::key() const { |
| 29 | + return QStringLiteral("wayland"); |
| 30 | + } |
| 31 | + |
| 32 | + void LinuxWaylandContext::virtual_hook(int id, void *data) { |
| 33 | + if (id == ShowSystemMenuHook) { |
| 34 | + auto *native = QGuiApplication::platformNativeInterface(); |
| 35 | + auto *waylandApp = qApp->nativeInterface<QNativeInterface::QWaylandApplication>(); |
| 36 | + if (!waylandApp) { |
| 37 | + return; |
| 38 | + } |
| 39 | + uint serial = waylandApp->lastInputSerial(); |
| 40 | + wl_seat *seat = waylandApp->lastInputSeat(); |
| 41 | + if (serial == 0 || !seat) { |
| 42 | + return; |
| 43 | + } |
| 44 | + void *rawToplevel = native->nativeResourceForWindow("xdg_toplevel", m_windowHandle); |
| 45 | + if (!rawToplevel) { |
| 46 | + return; |
| 47 | + } |
| 48 | + xdg_toplevel *toplevel = static_cast<xdg_toplevel *>(rawToplevel); |
| 49 | + auto pos = static_cast<QPoint *>(data); |
| 50 | + int lx = pos->x(); |
| 51 | + int ly = pos->y(); |
| 52 | + xdg_toplevel_show_window_menu(toplevel, seat, serial, lx, ly); |
| 53 | + |
| 54 | + wl_display *d = waylandApp->display(); |
| 55 | + if (d) { |
| 56 | + auto &api = LinuxDesktopEnvAPI::waylandAPI(); |
| 57 | + Q_ASSERT(api.isValid()); |
| 58 | + api.wl_display_flush(d); |
| 59 | + } |
| 60 | + } else { |
| 61 | + QtWindowContext::virtual_hook(id, data); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments