Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ elseif(APPLE)
else()
list(APPEND _src
qwindowkit_linux.h
qwindowkit_linux.cpp
)
endif()

Expand Down Expand Up @@ -66,6 +67,15 @@ else()
contexts/qtwindowcontext_p.h
contexts/qtwindowcontext.cpp
)

if(LINUX)
list(APPEND _src
contexts/linuxx11context_p.h
contexts/linuxx11context.cpp
contexts/linuxwaylandcontext_p.h
contexts/linuxwaylandcontext.cpp
)
endif()
endif()
endif()

Expand Down
4 changes: 2 additions & 2 deletions src/core/contexts/abstractwindowcontext.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// SPDX-License-Identifier: Apache-2.0

#include "abstractwindowcontext_p.h"
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace QWK {
return false;
}

for (auto item : m_hitTestVisibleItems) {
for (auto &&item : std::as_const(m_hitTestVisibleItems)) {
if (item && m_delegate->isVisible(item) &&
m_delegate->mapGeometryToScene(item).contains(pos)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/contexts/abstractwindowcontext_p.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// SPDX-License-Identifier: Apache-2.0

#ifndef ABSTRACTWINDOWCONTEXT_P_H
Expand Down
65 changes: 65 additions & 0 deletions src/core/contexts/linuxwaylandcontext.cpp
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);
}
}
}
36 changes: 36 additions & 0 deletions src/core/contexts/linuxwaylandcontext_p.h
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
191 changes: 191 additions & 0 deletions src/core/contexts/linuxx11context.cpp
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;

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);
}
}
}
34 changes: 34 additions & 0 deletions src/core/contexts/linuxx11context_p.h
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

#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
6 changes: 4 additions & 2 deletions src/core/contexts/qtwindowcontext.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// SPDX-License-Identifier: Apache-2.0

#include "qtwindowcontext_p.h"
Expand Down Expand Up @@ -151,7 +151,9 @@ namespace QWK {
break;
}
case Qt::RightButton: {
m_context->showSystemMenu(globalPos);
if (inTitleBar) {
m_context->showSystemMenu(globalPos);
}
break;
}
default:
Expand Down
Loading