Skip to content

Commit

Permalink
QxtGlobalShortcut/Mac: removed the extra route via QApplication::macE…
Browse files Browse the repository at this point in the history
…ventFilter() - use qxt_mac_handle_hot_key() directly.

--HG--
branch : 0.6
extra : transplant_source : %3D%7B%20%9E%E1%8C%1Ar%DD%9A%89R%1B%5E%13%7CV%E5%BE%D8
  • Loading branch information
jaripenu committed May 10, 2010
1 parent c12717a commit 788b22c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/gui/qxtglobalshortcut.cpp
Expand Up @@ -28,20 +28,26 @@
#include <QtDebug>

bool QxtGlobalShortcutPrivate::error = false;
#ifndef Q_WS_MAC
int QxtGlobalShortcutPrivate::ref = 0;
QAbstractEventDispatcher::EventFilter QxtGlobalShortcutPrivate::prevEventFilter = 0;
#endif // Q_WS_MAC
QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> QxtGlobalShortcutPrivate::shortcuts;

QxtGlobalShortcutPrivate::QxtGlobalShortcutPrivate() : enabled(true), key(Qt::Key(0)), mods(Qt::NoModifier)
{
#ifndef Q_WS_MAC
if (!ref++)
prevEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(eventFilter);
#endif // Q_WS_MAC
}

QxtGlobalShortcutPrivate::~QxtGlobalShortcutPrivate()
{
#ifndef Q_WS_MAC
if (!--ref)
QAbstractEventDispatcher::instance()->setEventFilter(prevEventFilter);
#endif // Q_WS_MAC
}

bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut)
Expand Down
15 changes: 3 additions & 12 deletions src/gui/qxtglobalshortcut_mac.cpp
Expand Up @@ -37,24 +37,16 @@ static bool qxt_mac_handler_installed = false;

OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
{
// pass event to the app event filter
Q_UNUSED(nextHandler);
Q_UNUSED(data);
qApp->macEventFilter(nextHandler, event);
return noErr;
}

bool QxtGlobalShortcutPrivate::eventFilter(void* message)
//bool QxtGlobalShortcutPrivate::macEventFilter(EventHandlerCallRef caller, EventRef event)
{
EventRef event = (EventRef) message;
if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
{
EventHotKeyID keyID;
GetEventParameter(event, kEventParamDirectObject, typeEventHotKeyID, NULL, sizeof(keyID), NULL, &keyID);
Identifier id = keyIDs.key(keyID.id);
activateShortcut(id.second, id.first);
QxtGlobalShortcutPrivate::activateShortcut(id.second, id.first);
}
return false;
return noErr;
}

quint32 QxtGlobalShortcutPrivate::nativeModifiers(Qt::KeyboardModifiers modifiers)
Expand Down Expand Up @@ -192,7 +184,6 @@ bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativ
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);
keyRefs.insert(keyID.id, ref);
}
qDebug() << ref;
return rv;
}

Expand Down
5 changes: 4 additions & 1 deletion src/gui/qxtglobalshortcut_p.h
Expand Up @@ -45,17 +45,20 @@ class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
bool unsetShortcut();

static bool error;
#ifndef Q_WS_MAC
static int ref;
static QAbstractEventDispatcher::EventFilter prevEventFilter;
static bool eventFilter(void* message);
#endif // Q_WS_MAC

static void activateShortcut(quint32 nativeKey, quint32 nativeMods);

private:
static quint32 nativeKeycode(Qt::Key keycode);
static quint32 nativeModifiers(Qt::KeyboardModifiers modifiers);

static bool registerShortcut(quint32 nativeKey, quint32 nativeMods);
static bool unregisterShortcut(quint32 nativeKey, quint32 nativeMods);
static void activateShortcut(quint32 nativeKey, quint32 nativeMods);

static QHash<QPair<quint32, quint32>, QxtGlobalShortcut*> shortcuts;
};
Expand Down

0 comments on commit 788b22c

Please sign in to comment.