Skip to content

Commit

Permalink
globalshortcut-x11: Use XDefaultRootWindow with Qt >= 6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Feb 14, 2022
1 parent 1e0c0a3 commit 488b326
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,17 @@ optional_component(GLOBALSHORTCUTS ON "Global shortcuts"
DEPENDS "D-Bus, X11, Windows or macOS" HAVE_GLOBALSHORTCUTS_SUPPORT
)

if(HAVE_X11EXTRAS OR HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
set(HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H ON)
if(BUILD_WITH_QT6 AND (Qt6Core_VERSION VERSION_EQUAL 6.2.0 OR Qt6Core_VERSION VERSION_GREATER 6.2.0))
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts" DEPENDS "X11" X11_FOUND)
else()
if(HAVE_X11EXTRAS OR HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
set(HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H ON)
endif()
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts"
DEPENDS "X11" X11_FOUND
DEPENDS "Qt >= 6.2, X11Extras or qpa/qplatformnativeinterface.h header" HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H
)
endif()
optional_component(X11_GLOBALSHORTCUTS ON "X11 global shortcuts"
DEPENDS "X11" X11_FOUND
DEPENDS "X11Extras or qpa/qplatformnativeinterface.h header" HAVE_X11EXTRAS_OR_QPA_QPLATFORMNATIVEINTERFACE_H
)

optional_component(AUDIOCD ON "Devices: Audio CD support"
DEPENDS "libcdio" LIBCDIO_FOUND
Expand Down
21 changes: 9 additions & 12 deletions src/globalshortcuts/globalshortcut-x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <QtGlobal>
#include <QApplication>
#include <QGuiApplication>
#include <QMap>
#include <QVector>
#include <QByteArray>
Expand All @@ -37,14 +38,12 @@
#include <xcb/xcb.h>
#include <xcb/xproto.h>

#include <QGuiApplication>

#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
#if defined(HAVE_X11EXTRAS)
# include <QX11Info>
#elif defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
# include <qpa/qplatformnativeinterface.h>
#else
# error "Missing X11Extras or qpa/qplatformnativeinterface.h header."
#endif
#endif

const QVector<quint32> GlobalShortcut::mask_modifiers_ = QVector<quint32>() << 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
Expand All @@ -60,9 +59,7 @@ Display *X11Display() {
if (QNativeInterface::QX11Application *x11_app = qApp->nativeInterface<QNativeInterface::QX11Application>()) {
return x11_app->display();
}
else {
return nullptr;
}
return nullptr;

#elif defined(HAVE_X11EXTRAS) // Qt 5: Use X11Extras

Expand All @@ -87,14 +84,14 @@ Display *X11Display() {

quint32 AppRootWindow() {

#if 0 // 6.2: There currently isn't a way to access rootWindow through QX11Application.
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) // 6.2: Use the new native interface.

if (QNativeInterface::QX11Application *x11_app = qApp->nativeInterface<QNativeInterface::QX11Application>()) {
return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(x11_app->rootWindow()));
}
else {
return 0;
if (x11_app->display()) {
return XDefaultRootWindow(x11_app->display());
}
}
return 0;

#elif defined(HAVE_X11EXTRAS) // Qt 5: Use X11Extras

Expand Down

0 comments on commit 488b326

Please sign in to comment.