Skip to content

Commit

Permalink
Add isPlatformSupported() (#28)
Browse files Browse the repository at this point in the history
* Add isPlatformSupported()
* Remove extra semicolons
* Add newlines before new methods
  • Loading branch information
Shatur authored and Skycoder42 committed Jan 7, 2020
1 parent 96a0710 commit 9583eaf
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
5 changes: 5 additions & 0 deletions QHotkey/qhotkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ void QHotkey::addGlobalMapping(const QKeySequence &shortcut, const QHotkey::Nati
Q_ARG(QHotkey::NativeShortcut, nativeShortcut));
}

bool QHotkey::isPlatformSupported()
{
return QHotkeyPrivate::isPlatformSupported();
}

QHotkey::QHotkey(QObject *parent) :
QObject(parent),
_keyCode(Qt::Key_unknown),
Expand Down
3 changes: 3 additions & 0 deletions QHotkey/qhotkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class QHOTKEY_SHARED_EXPORT QHotkey : public QObject
//! Adds a global mapping of a key sequence to a replacement native shortcut
static void addGlobalMapping(const QKeySequence &shortcut, const NativeShortcut &nativeShortcut);

//! Checks if global shortcuts are supported by the current platform
static bool isPlatformSupported();

//! Default Constructor
explicit QHotkey(QObject *parent = nullptr);
//! Constructs a hotkey with a shortcut and optionally registers it
Expand Down
11 changes: 8 additions & 3 deletions QHotkey/qhotkey_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ class QHotkeyPrivateMac : public QHotkeyPrivate
};
NATIVE_INSTANCE(QHotkeyPrivateMac)

bool QHotkeyPrivate::isPlatformSupported()
{
return true;
}

bool QHotkeyPrivateMac::isHotkeyHandlerRegistered = false;
QHash<QHotkey::NativeShortcut, EventHotKeyRef> QHotkeyPrivateMac::hotkeyRefs;

bool QHotkeyPrivateMac::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
Q_UNUSED(eventType);
Q_UNUSED(message);
Q_UNUSED(result);
Q_UNUSED(eventType)
Q_UNUSED(message)
Q_UNUSED(result)
return false;
}

Expand Down
1 change: 1 addition & 0 deletions QHotkey/qhotkey_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QHOTKEY_SHARED_EXPORT QHotkeyPrivate : public QObject, public QAbstractNat
~QHotkeyPrivate();

static QHotkeyPrivate *instance();
static bool isPlatformSupported();

QHotkey::NativeShortcut nativeShortcut(Qt::Key keycode, Qt::KeyboardModifiers modifiers);

Expand Down
9 changes: 7 additions & 2 deletions QHotkey/qhotkey_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ class QHotkeyPrivateWin : public QHotkeyPrivate
};
NATIVE_INSTANCE(QHotkeyPrivateWin)

bool QHotkeyPrivate::isPlatformSupported()
{
return true;
}

bool QHotkeyPrivateWin::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
Q_UNUSED(eventType);
Q_UNUSED(result);
Q_UNUSED(eventType)
Q_UNUSED(result)

MSG* msg = static_cast<MSG*>(message);
if(msg->message == WM_HOTKEY)
Expand Down
9 changes: 7 additions & 2 deletions QHotkey/qhotkey_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ class QHotkeyPrivateX11 : public QHotkeyPrivate
};
NATIVE_INSTANCE(QHotkeyPrivateX11)

bool QHotkeyPrivate::isPlatformSupported()
{
return QX11Info::isPlatformX11();
}

const QVector<quint32> QHotkeyPrivateX11::specialModifiers = {0, Mod2Mask, LockMask, (Mod2Mask | LockMask)};
const quint32 QHotkeyPrivateX11::validModsMask = ShiftMask | ControlMask | Mod1Mask | Mod4Mask;

bool QHotkeyPrivateX11::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
Q_UNUSED(eventType);
Q_UNUSED(result);
Q_UNUSED(eventType)
Q_UNUSED(result)

xcb_generic_event_t *genericEvent = static_cast<xcb_generic_event_t *>(message);
if (genericEvent->response_type == XCB_KEY_PRESS) {
Expand Down

0 comments on commit 9583eaf

Please sign in to comment.