Remove use of X11Extras and WinExtras
Modules are deprecated in Qt 6 See: QTBUG-83251
This commit is contained in:
@@ -54,7 +54,6 @@ bool GlobalShortcut::unregisterShortcut(quint32 native_key, quint32 native_mods)
|
||||
return UnregisterHotKey(0, native_mods ^ native_key);
|
||||
}
|
||||
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
bool GlobalShortcut::nativeEventFilter(const QByteArray &eventtype, void *message, qintptr *result) {
|
||||
#else
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QApplication>
|
||||
#include <QMap>
|
||||
#include <QVector>
|
||||
#include <QByteArray>
|
||||
#include <QString>
|
||||
#include <QX11Info>
|
||||
#include <QKeySequence>
|
||||
#include <QFlags>
|
||||
#include <QScreen>
|
||||
|
||||
#include "globalshortcut.h"
|
||||
#include "keymapper_x11.h"
|
||||
@@ -36,8 +37,40 @@
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
|
||||
const QVector<quint32> GlobalShortcut::mask_modifiers_ = QVector<quint32>() << 0 << Mod2Mask << LockMask << (Mod2Mask | LockMask);
|
||||
|
||||
namespace {
|
||||
|
||||
Display *X11Display() {
|
||||
|
||||
if (!qApp) return nullptr;
|
||||
|
||||
QPlatformNativeInterface *native = qApp->platformNativeInterface();
|
||||
if (!native) return nullptr;
|
||||
|
||||
void *display = native->nativeResourceForIntegration("display");
|
||||
return reinterpret_cast<Display*>(display);
|
||||
|
||||
}
|
||||
|
||||
quint32 AppRootWindow() {
|
||||
|
||||
if (!qApp) return 0;
|
||||
|
||||
QPlatformNativeInterface *native = qApp->platformNativeInterface();
|
||||
if (!native) return 0;
|
||||
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
if (!screen) return 0;
|
||||
|
||||
return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen("rootwindow", screen)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
quint32 GlobalShortcut::nativeModifiers(Qt::KeyboardModifiers qt_mods) {
|
||||
|
||||
quint32 native_mods = 0;
|
||||
@@ -51,7 +84,8 @@ quint32 GlobalShortcut::nativeModifiers(Qt::KeyboardModifiers qt_mods) {
|
||||
|
||||
quint32 GlobalShortcut::nativeKeycode(Qt::Key qt_key) {
|
||||
|
||||
if (!QX11Info::display()) return 0;
|
||||
Display *disp = X11Display();
|
||||
if (!disp) return false;
|
||||
|
||||
quint32 keysym = 0;
|
||||
if (KeyMapperX11::keymapper_x11_.contains(qt_key)) {
|
||||
@@ -61,25 +95,32 @@ quint32 GlobalShortcut::nativeKeycode(Qt::Key qt_key) {
|
||||
keysym = XStringToKeysym(QKeySequence(qt_key).toString().toLatin1().data());
|
||||
if (keysym == NoSymbol) return 0;
|
||||
}
|
||||
return XKeysymToKeycode(QX11Info::display(), keysym);
|
||||
return XKeysymToKeycode(disp, keysym);
|
||||
|
||||
}
|
||||
|
||||
bool GlobalShortcut::registerShortcut(quint32 native_key, quint32 native_mods) {
|
||||
if (!QX11Info::display()) return false;
|
||||
|
||||
Display *disp = X11Display();
|
||||
if (!disp) return false;
|
||||
|
||||
for (quint32 mask_mods : mask_modifiers_) {
|
||||
//xcb_grab_key(QX11Info::connection(), 1, QX11Info::appRootWindow(), (native_mods | mask_mods), native_key, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||
XGrabKey(QX11Info::display(), native_key, (native_mods | mask_mods), QX11Info::appRootWindow(), True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(disp, native_key, (native_mods | mask_mods), AppRootWindow(), True, GrabModeAsync, GrabModeAsync);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool GlobalShortcut::unregisterShortcut(quint32 native_key, quint32 native_mods) {
|
||||
if (!QX11Info::display()) return false;
|
||||
|
||||
Display *disp = X11Display();
|
||||
if (!disp) return false;
|
||||
|
||||
for (quint32 mask_mods : mask_modifiers_) {
|
||||
XUngrabKey(QX11Info::display(), native_key, native_mods | mask_mods, QX11Info::appRootWindow());
|
||||
XUngrabKey(disp, native_key, native_mods | mask_mods, AppRootWindow());
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QWidget>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
@@ -32,9 +33,6 @@
|
||||
#ifdef HAVE_DBUS
|
||||
# include <QDBusConnectionInterface>
|
||||
#endif
|
||||
#ifdef HAVE_X11EXTRAS
|
||||
# include <QX11Info>
|
||||
#endif
|
||||
|
||||
#include "globalshortcutsmanager.h"
|
||||
#include "globalshortcutsbackend.h"
|
||||
@@ -43,7 +41,7 @@
|
||||
# include "globalshortcutsbackend-gsd.h"
|
||||
# include "globalshortcutsbackend-kde.h"
|
||||
#endif
|
||||
#if defined(HAVE_X11EXTRAS) || defined(Q_OS_WIN)
|
||||
#if (defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)) || defined(Q_OS_WIN)
|
||||
# include "globalshortcutsbackend-system.h"
|
||||
#endif
|
||||
#ifdef Q_OS_MACOS
|
||||
@@ -99,7 +97,7 @@ GlobalShortcutsManager::GlobalShortcutsManager(QWidget *parent)
|
||||
if (!system_backend_)
|
||||
system_backend_ = new GlobalShortcutsBackendSystem(this);
|
||||
#endif
|
||||
#if defined(HAVE_X11EXTRAS)
|
||||
#if defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
|
||||
if (!system_backend_ && IsX11Available())
|
||||
system_backend_ = new GlobalShortcutsBackendSystem(this);
|
||||
#endif
|
||||
@@ -168,11 +166,7 @@ bool GlobalShortcutsManager::IsKdeAvailable() const {
|
||||
|
||||
bool GlobalShortcutsManager::IsX11Available() const {
|
||||
|
||||
#ifdef HAVE_X11EXTRAS
|
||||
return QX11Info::isPlatformX11();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
return QApplication::platformName() == "xcb";
|
||||
|
||||
}
|
||||
|
||||
@@ -180,12 +174,12 @@ void GlobalShortcutsManager::Register() {
|
||||
|
||||
if (use_gsd_ && gsd_backend_ && gsd_backend_->Register()) return;
|
||||
if (use_kde_ && kde_backend_ && kde_backend_->Register()) return;
|
||||
#ifdef HAVE_X11EXTRAS // If this system has X11, only use the system backend if X11 is enabled in the global shortcut settings
|
||||
#if defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H) // If this system has X11, only use the system backend if X11 is enabled in the global shortcut settings
|
||||
if (use_x11_) {
|
||||
#endif
|
||||
if (system_backend_)
|
||||
system_backend_->Register();
|
||||
#ifdef HAVE_X11EXTRAS
|
||||
#if defined(HAVE_X11) && defined(HAVE_QPA_QPLATFORMNATIVEINTERFACE_H)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user