change X11 event impl

This commit is contained in:
Altair Wei 2021-09-21 10:17:42 +08:00
parent 9b2dc893b6
commit 3a3e39c0c0
2 changed files with 41 additions and 48 deletions

View File

@ -59,10 +59,10 @@ FRAMELESSHELPER_API void updateQtFrameMargins(QWindow *window, const bool enable
#endif #endif
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
FRAMELESSHELPER_API void sendX11ButtonReleaseEvent(QWindow *w, const QPoint &pos); FRAMELESSHELPER_API void sendX11ButtonReleaseEvent(QWindow *w, const QPoint &globalPos);
FRAMELESSHELPER_API void sendX11MoveResizeEvent(QWindow *w, const QPoint &pos, int section); FRAMELESSHELPER_API void sendX11MoveResizeEvent(QWindow *w, const QPoint &globalPos, int section);
FRAMELESSHELPER_API void startX11Moving(QWindow *w, const QPoint &pos); FRAMELESSHELPER_API void startX11Moving(QWindow *w, const QPoint &globalPos);
FRAMELESSHELPER_API void startX11Resizing(QWindow *w, const QPoint &pos, Qt::WindowFrameSection frameSection); FRAMELESSHELPER_API void startX11Resizing(QWindow *w, const QPoint &globalPos, Qt::WindowFrameSection frameSection);
FRAMELESSHELPER_API void setX11CursorShape(QWindow *w, int cursorId); FRAMELESSHELPER_API void setX11CursorShape(QWindow *w, int cursorId);
FRAMELESSHELPER_API void resetX1CursorShape(QWindow *w); FRAMELESSHELPER_API void resetX1CursorShape(QWindow *w);
FRAMELESSHELPER_API unsigned int getX11CursorForFrameSection(Qt::WindowFrameSection frameSection); FRAMELESSHELPER_API unsigned int getX11CursorForFrameSection(Qt::WindowFrameSection frameSection);

View File

@ -149,61 +149,54 @@ bool Utilities::showSystemMenu(const WId winId, const QPointF &pos)
return false; return false;
} }
void Utilities::sendX11ButtonReleaseEvent(QWindow *w, const QPoint &pos) void Utilities::sendX11ButtonReleaseEvent(QWindow *w, const QPoint &globalPos)
{ {
QPoint clientPos = w->mapFromGlobal(pos); const QPoint pos = w->mapFromGlobal(globalPos);
Display *display = QX11Info::display(); const auto display = QX11Info::display();
int screen = QX11Info::appScreen(); const auto screen = QX11Info::appScreen();
unsigned long rootWindow = QX11Info::appRootWindow(screen);
XEvent event; XEvent xevent;
memset(&event, 0, sizeof (event)); memset(&xevent, 0, sizeof(XEvent));
event.xbutton.button = 0; xevent.type = ButtonRelease;
event.xbutton.same_screen = True; xevent.xbutton.button = Button1;
event.xbutton.send_event = True; xevent.xbutton.window = w->winId();
Window window = w->winId(); xevent.xbutton.x = pos.x();
event.xbutton.window = window; xevent.xbutton.y = pos.y();
event.xbutton.root = rootWindow; xevent.xbutton.x_root = globalPos.x();
event.xbutton.x_root = pos.x(); xevent.xbutton.y_root = globalPos.y();
event.xbutton.y_root = pos.y(); xevent.xbutton.display = display;
event.xbutton.x = clientPos.x();
event.xbutton.y = clientPos.y();
event.xbutton.type = ButtonRelease;
event.xbutton.time = CurrentTime;
if (XSendEvent(display, window, True, ButtonReleaseMask, &event) == 0) if (XSendEvent(display, w->winId(), False, ButtonReleaseMask, &xevent) == 0)
qWarning() << "Failed to send ButtonRelease event."; qWarning() << "Failed to send ButtonRelease event.";
XFlush(display); XFlush(display);
} }
void Utilities::sendX11MoveResizeEvent(QWindow *w, const QPoint &pos, int section) void Utilities::sendX11MoveResizeEvent(QWindow *w, const QPoint &globalPos, int section)
{ {
Display *display = QX11Info::display(); const auto display = QX11Info::display();
int screen = QX11Info::appScreen(); const auto winId = w->winId();
unsigned long rootWindow = QX11Info::appRootWindow(screen); const auto screen = QX11Info::appScreen();
static Atom netMoveResize = XInternAtom(display, "_NET_WM_MOVERESIZE", False);
XUngrabPointer(display, CurrentTime); XEvent xev;
const Atom netMoveResize = XInternAtom(display, "_NET_WM_MOVERESIZE", false);
xev.xclient.type = ClientMessage;
xev.xclient.message_type = netMoveResize;
xev.xclient.display = display;
xev.xclient.window = winId;
xev.xclient.format = 32;
XEvent event; xev.xclient.data.l[0] = globalPos.x();
memset(&event, 0x00, sizeof(event)); xev.xclient.data.l[1] = globalPos.y();
event.xclient.type = ClientMessage; xev.xclient.data.l[2] = section;
event.xclient.window = w->winId(); xev.xclient.data.l[3] = Button1;
event.xclient.message_type = netMoveResize; xev.xclient.data.l[4] = 1;
event.xclient.serial = 0; XUngrabPointer(display, QX11Info::appTime());
event.xclient.display = display;
event.xclient.send_event = True; if(XSendEvent(display, QX11Info::appRootWindow(screen),
event.xclient.format = 32; false, SubstructureRedirectMask | SubstructureNotifyMask, &xev) == 0)
event.xclient.data.l[0] = pos.x();
event.xclient.data.l[1] = pos.y();
event.xclient.data.l[2] = section;
event.xclient.data.l[3] = Button1;
event.xclient.data.l[4] = 0;
if (XSendEvent(display, rootWindow,
False, SubstructureRedirectMask | SubstructureNotifyMask, &event) == 0)
qWarning("Failed to send Move or Resize event."); qWarning("Failed to send Move or Resize event.");
XFlush(display); XFlush(display);
} }
void Utilities::startX11Moving(QWindow *w, const QPoint &pos) void Utilities::startX11Moving(QWindow *w, const QPoint &pos)