Fix shortcuts

This commit is contained in:
Ximi1970
2024-03-31 23:50:52 +02:00
parent d296660b9f
commit 809a36caff
7 changed files with 35 additions and 48 deletions

View File

@@ -19,7 +19,7 @@ include( ../SysTray-X.pri )
# #
# Set the Qt modules # Set the Qt modules
# #
QT += core gui QT += core gui widgets
unix:!macx: { unix:!macx: {
contains(DEFINES,KDE_INTEGRATION) { contains(DEFINES,KDE_INTEGRATION) {
lessThan(QT_MAJOR_VERSION, 6): { lessThan(QT_MAJOR_VERSION, 6): {
@@ -37,8 +37,6 @@ unix:!macx: {
} }
} }
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# #
# Define the target # Define the target
# #
@@ -161,74 +159,54 @@ win32: {
SOURCES += \ SOURCES += \
debugwidget.cpp \
main.cpp \ main.cpp \
nativeeventfilterbase.cpp \
systrayxlink.cpp \ systrayxlink.cpp \
systrayxicon.cpp \ systrayxicon.cpp \
systrayx.cpp \ systrayx.cpp \
debugwidget.cpp \
preferencesdialog.cpp \ preferencesdialog.cpp \
preferences.cpp \ preferences.cpp \
windowctrl.cpp
lessThan(QT_MAJOR_VERSION, 6): {
SOURCES += \
shortcut.cpp \ shortcut.cpp \
nativeeventfilterbase.cpp windowctrl.cpp
}
unix: { unix: {
SOURCES += \ SOURCES += \
windowctrl-unix.cpp nativeeventfilter-x11.cpp \
windowctrl-unix.cpp
contains(DEFINES,KDE_INTEGRATION) { contains(DEFINES,KDE_INTEGRATION) {
SOURCES += \ SOURCES += \
systrayxstatusnotifier.cpp systrayxstatusnotifier.cpp
} }
lessThan(QT_MAJOR_VERSION, 6): {
SOURCES += \
nativeeventfilter-x11.cpp
}
} }
win32: { win32: {
SOURCES += \ SOURCES += \
nativeeventfilter-win.cpp
windowctrl-win.cpp windowctrl-win.cpp
lessThan(QT_MAJOR_VERSION, 6): {
SOURCES += \
nativeeventfilter-win.cpp
}
} }
HEADERS += \ HEADERS += \
debug.h \ debug.h \
debugwidget.h \
nativeeventfilterbase.h \
preferencesdialog.h \
preferences.h \
systrayxlink.h \ systrayxlink.h \
systrayxicon.h \ systrayxicon.h \
systrayx.h \ systrayx.h \
debugwidget.h \
preferencesdialog.h \
preferences.h \
windowctrl.h
lessThan(QT_MAJOR_VERSION, 6): {
HEADERS += \
shortcut.h \ shortcut.h \
nativeeventfilterbase.h windowctrl.h
}
unix: { unix: {
HEADERS += \ HEADERS += \
nativeeventfilter-x11.h \
windowctrl-unix.h windowctrl-unix.h
contains(DEFINES,KDE_INTEGRATION) { contains(DEFINES,KDE_INTEGRATION) {
HEADERS += \ HEADERS += \
systrayxstatusnotifier.h systrayxstatusnotifier.h
} }
lessThan(QT_MAJOR_VERSION, 6): {
HEADERS += \
nativeeventfilter-x11.h
}
} }
win32: { win32: {
HEADERS += \ HEADERS += \

View File

@@ -24,7 +24,12 @@ const int NativeEventFilterX11::m_valid_mods_mask = ShiftMask | ControlMask | Mo
/* /*
* Catch the key press * Catch the key press
*/ */
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool NativeEventFilterX11::nativeEventFilter( const QByteArray& eventType, void* message, long* result ) bool NativeEventFilterX11::nativeEventFilter( const QByteArray& eventType, void* message, long* result )
#else
bool NativeEventFilterX11::nativeEventFilter( const QByteArray& eventType, void* message, qintptr* result )
#endif
{ {
Q_UNUSED( eventType ) Q_UNUSED( eventType )
Q_UNUSED( result ) Q_UNUSED( result )
@@ -50,8 +55,8 @@ bool NativeEventFilterX11::nativeEventFilter( const QByteArray& eventType, void*
*/ */
bool NativeEventFilterX11::connectShortcut( QKeySequence key_seq ) bool NativeEventFilterX11::connectShortcut( QKeySequence key_seq )
{ {
Qt::Key key_code = Qt::Key( key_seq[ 0 ] & static_cast< int >( ~Qt::KeyboardModifierMask ) ); Qt::Key key_code = Qt::Key( key_seq[ 0 ].toCombined() & static_cast< int >( ~Qt::KeyboardModifierMask ) );
Qt::KeyboardModifiers key_modifiers = Qt::KeyboardModifiers( key_seq[ 0 ] & static_cast<int>( Qt::KeyboardModifierMask ) ); Qt::KeyboardModifiers key_modifiers = Qt::KeyboardModifiers( key_seq[ 0 ].toCombined() & static_cast<int>( Qt::KeyboardModifierMask ) );
return connectShortcut( key_code, key_modifiers ); return connectShortcut( key_code, key_modifiers );
} }
@@ -132,7 +137,8 @@ bool NativeEventFilterX11::connectShortcut( Qt::Key key_code, Qt::KeyboardModifi
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Display *display = QX11Info::display(); Display *display = QX11Info::display();
#else #else
Display *display = 0; QNativeInterface::QX11Application *x11App = qApp->nativeInterface<QNativeInterface::QX11Application>();
Display *display = x11App->display();
#endif #endif
/* /*
@@ -162,7 +168,8 @@ bool NativeEventFilterX11::disconnectShortcut()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Display *display = QX11Info::display(); Display *display = QX11Info::display();
#else #else
Display *display = 0; QNativeInterface::QX11Application *x11App = qApp->nativeInterface<QNativeInterface::QX11Application>();
Display *display = x11App->display();
#endif #endif
/* /*

View File

@@ -33,7 +33,11 @@ class NativeEventFilterX11 : public NativeEventFilterBase
* *
* @return Result * @return Result
*/ */
bool nativeEventFilter( const QByteArray& eventType, void* message, long* result ) override; #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
bool nativeEventFilter( const QByteArray& eventType, void* message, long* result ) override;
#else
bool nativeEventFilter( const QByteArray& eventType, void* message, qintptr* result ) override;
#endif
protected: protected:

View File

@@ -12,7 +12,6 @@
/* /*
* Qt includes * Qt includes
*/ */
#include <QCoreApplication>
#include <QAbstractEventDispatcher> #include <QAbstractEventDispatcher>

View File

@@ -15,6 +15,7 @@
#include <QObject> #include <QObject>
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <QGlobalStatic> #include <QGlobalStatic>
#include <QGuiApplication>
/* /*
* Predefines * Predefines

View File

@@ -49,8 +49,8 @@ Shortcut::~Shortcut()
*/ */
bool Shortcut::setShortcut( QKeySequence key_seq ) bool Shortcut::setShortcut( QKeySequence key_seq )
{ {
Qt::Key key_code = Qt::Key( key_seq[ 0 ] & ~Qt::KeyboardModifierMask ); Qt::Key key_code = Qt::Key( key_seq[ 0 ].toCombined() & ~Qt::KeyboardModifierMask );
Qt::KeyboardModifiers key_modifiers = Qt::KeyboardModifiers( key_seq[ 0 ] & Qt::KeyboardModifierMask); Qt::KeyboardModifiers key_modifiers = Qt::KeyboardModifiers( key_seq[ 0 ].toCombined() & Qt::KeyboardModifierMask);
return setShortcut( key_code, key_modifiers ); return setShortcut( key_code, key_modifiers );
} }

View File

@@ -9,7 +9,7 @@
#include "systrayxicon.h" #include "systrayxicon.h"
#include "systrayxstatusnotifier.h" #include "systrayxstatusnotifier.h"
#include "windowctrl.h" #include "windowctrl.h"
//#include "shortcut.h" #include "shortcut.h"
/* /*
* Qt includes * Qt includes
@@ -194,7 +194,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
m_preferences->displayDebug(); m_preferences->displayDebug();
/*
m_preferences->setBrowserVersion( "115.1.0" ); m_preferences->setBrowserVersion( "115.1.0" );
// m_preferences->setBrowserVersion( "102.2.3" ); // m_preferences->setBrowserVersion( "102.2.3" );
@@ -215,7 +215,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
// m_preferences->setStartApp( "/home/maxime/test.sh" ); // m_preferences->setStartApp( "/home/maxime/test.sh" );
// m_preferences->setStartAppArgs( "/home/maxime/startup.txt StartupString" ); // m_preferences->setStartAppArgs( "/home/maxime/startup.txt StartupString" );
// slotStartApp(); // slotStartApp();
*/
} }
@@ -784,7 +784,6 @@ void SysTrayX::slotCloseApp()
void SysTrayX::slotShowHideShortcutChange() void SysTrayX::slotShowHideShortcutChange()
{ {
#ifdef ENABLE_SHORTCUT
if( m_show_hide_shortcut != nullptr ) if( m_show_hide_shortcut != nullptr )
{ {
disconnect( m_show_hide_shortcut, &Shortcut::activated, m_win_ctrl, &WindowCtrl::slotShowHide ); disconnect( m_show_hide_shortcut, &Shortcut::activated, m_win_ctrl, &WindowCtrl::slotShowHide );
@@ -795,5 +794,4 @@ void SysTrayX::slotShowHideShortcutChange()
m_show_hide_shortcut = new Shortcut( m_preferences->getShowHideShortcut(), this ); m_show_hide_shortcut = new Shortcut( m_preferences->getShowHideShortcut(), this );
connect( m_show_hide_shortcut, &Shortcut::activated, m_win_ctrl, &WindowCtrl::slotShowHide ); connect( m_show_hide_shortcut, &Shortcut::activated, m_win_ctrl, &WindowCtrl::slotShowHide );
#endif
} }