2009-04-19 21:32:18 +00:00
|
|
|
#ifndef HOTKEYWRAPPER_H
|
|
|
|
#define HOTKEYWRAPPER_H
|
|
|
|
|
|
|
|
#include <QtGui>
|
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
2009-04-21 18:27:26 +00:00
|
|
|
#include <X11/extensions/record.h>
|
2009-04-19 21:32:18 +00:00
|
|
|
#include <QX11Info>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
#include "ex.hh"
|
2009-04-19 21:32:18 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct HotkeyStruct
|
|
|
|
{
|
|
|
|
HotkeyStruct() {};
|
2009-04-21 18:27:26 +00:00
|
|
|
HotkeyStruct( quint32 key, quint32 key2, quint32 modifier, int handle );
|
2009-04-19 21:32:18 +00:00
|
|
|
|
|
|
|
quint32 key, key2;
|
|
|
|
quint32 modifier;
|
2009-04-21 18:27:26 +00:00
|
|
|
int handle;
|
2009-04-19 21:32:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
class HotkeyWrapper : public QThread // Thread is actually only used on X11
|
2009-04-19 21:32:18 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
friend class QHotkeyApplication;
|
|
|
|
|
|
|
|
public:
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
DEF_EX( exInit, "Hotkey wrapper failed to init", std::exception )
|
|
|
|
|
2009-04-19 21:32:18 +00:00
|
|
|
HotkeyWrapper(QObject *parent);
|
|
|
|
virtual ~HotkeyWrapper();
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
/// The handle is passed back in hotkeyActivated() to inform which hotkey
|
|
|
|
/// was activated.
|
|
|
|
bool setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier,
|
|
|
|
int handle );
|
2009-04-19 21:32:18 +00:00
|
|
|
|
|
|
|
signals:
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
void hotkeyActivated( int );
|
2009-04-19 21:32:18 +00:00
|
|
|
|
|
|
|
protected slots:
|
2009-04-21 18:27:26 +00:00
|
|
|
|
2009-04-19 21:32:18 +00:00
|
|
|
void waitKey2();
|
|
|
|
|
2009-04-21 18:27:26 +00:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
bool checkState( quint32 vk, quint32 mod );
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2009-04-19 21:32:18 +00:00
|
|
|
void init();
|
|
|
|
quint32 nativeKey(int key);
|
|
|
|
|
|
|
|
QList<HotkeyStruct> hotkeys;
|
|
|
|
|
|
|
|
bool state2;
|
|
|
|
HotkeyStruct state2waiter;
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
virtual bool winEvent ( MSG * message, long * result );
|
|
|
|
HWND hwnd;
|
|
|
|
#else
|
2009-04-21 18:27:26 +00:00
|
|
|
|
|
|
|
static void recordEventCallback( XPointer, XRecordInterceptData * );
|
|
|
|
|
|
|
|
/// Called by recordEventCallback()
|
|
|
|
void handleRecordEvent( XRecordInterceptData * );
|
|
|
|
|
|
|
|
void run(); // QThread
|
|
|
|
|
|
|
|
// We do one-time init of those, translating keysyms to keycodes
|
|
|
|
KeyCode lShiftCode, rShiftCode, lCtrlCode, rCtrlCode, lAltCode, rAltCode;
|
|
|
|
|
|
|
|
quint32 currentModifiers;
|
|
|
|
|
|
|
|
Display * dataDisplay;
|
|
|
|
XRecordRange * recordRange;
|
|
|
|
XRecordContext recordContext;
|
|
|
|
XRecordClientSpec recordClientSpec;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
/// Emitted from the thread
|
|
|
|
void keyRecorded( quint32 vk, quint32 mod );
|
|
|
|
|
2009-04-19 21:32:18 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class QHotkeyApplication : public QApplication
|
|
|
|
{
|
|
|
|
friend class HotkeyWrapper;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QHotkeyApplication(int & argc, char ** argv);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void registerWrapper(HotkeyWrapper *wrapper);
|
|
|
|
void unregisterWrapper(HotkeyWrapper *wrapper);
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
virtual bool winEventFilter ( MSG * message, long * result );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QList<HotkeyWrapper*> hotkeyWrappers;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif // HOTKEYWRAPPER_H
|