Skip to content

Commit

Permalink
更新linux去边框x11支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 9, 2022
1 parent 2a86e27 commit 95eebe8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion GrayFramelesshelper/GrayFramelesshelper.pri
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ win32 {
$$PWD/qwinregistry.cpp
LIBS += -luser32 -lshell32 -ladvapi32
}
linux*: SOURCES += $$PWD/utilities_linux.cpp
linux* {
QT += x11extras
SOURCES += $$PWD/utilities_linux.cpp
}
macx: SOURCES += $$PWD/utilities_macos.mm

macx {
Expand Down
32 changes: 26 additions & 6 deletions GrayFramelesshelper/framelesshelper.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* MIT License
*
* Copyright (C) 2021 by wangwenx190 (Yuhang Zhao)
Expand All @@ -24,6 +24,14 @@

#include "framelesshelper.h"

#ifdef Q_OS_LINUX
#include <QX11Info>

#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>
#endif

#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))

#include <QDateTime>
Expand Down Expand Up @@ -200,11 +208,23 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
if(m_bLinuxWindowClicked)
{
m_bLinuxWindowClicked = false;
qDebug() << window->flags();
QPoint pos = QPoint(10,10);
QMouseEvent Mouseevent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QGuiApplication::sendEvent(window, &Mouseevent);
window->showNormal();
const auto display = QX11Info::display();
const auto screen = QX11Info::appScreen();

XEvent xevent;
memset(&xevent, 0, sizeof(XEvent));

xevent.type = ButtonRelease;
xevent.xbutton.button = Button1;
xevent.xbutton.window = window->winId();
xevent.xbutton.x = pos.x();
xevent.xbutton.y = pos.y();
xevent.xbutton.x_root = globalPos.x();
xevent.xbutton.y_root = globalPos.y();
xevent.xbutton.display = display;

XSendEvent(display, widget->effectiveWinId(), False, ButtonReleaseMask, &xevent);
XFlush(display);
qDebug() << "LinuxWindow ckicked";
}
#endif
Expand Down

0 comments on commit 95eebe8

Please sign in to comment.