diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-07-02 20:28:24 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2018-07-02 20:28:24 +0000 |
| commit | 83c44dc39f2ac0324107bfde328d7032e65343cc (patch) | |
| tree | a30efc76f1f3c131da90e3c8d0bf95ce3b41e4bc /src/plugins/General | |
| parent | 5d07e21aa082e936e0d2e74ae931c772fe325568 (diff) | |
| download | qmmp-83c44dc39f2ac0324107bfde328d7032e65343cc.tar.gz qmmp-83c44dc39f2ac0324107bfde328d7032e65343cc.tar.bz2 qmmp-83c44dc39f2ac0324107bfde328d7032e65343cc.zip | |
hotkey: fixed windows support
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8096 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General')
| -rw-r--r-- | src/plugins/General/General.pro | 6 | ||||
| -rw-r--r-- | src/plugins/General/hotkey/hotkeymanager.h | 7 | ||||
| -rw-r--r-- | src/plugins/General/hotkey/hotkeymanager_win.cpp | 25 |
3 files changed, 23 insertions, 15 deletions
diff --git a/src/plugins/General/General.pro b/src/plugins/General/General.pro index 022054166..a1f11294a 100644 --- a/src/plugins/General/General.pro +++ b/src/plugins/General/General.pro @@ -9,12 +9,12 @@ SUBDIRS += statusicon \ streambrowser \ trackchange \ copypaste \ - rgscan + rgscan \ + hotkey unix:SUBDIRS += mpris \ kdenotify \ converter \ - gnomehotkey \ - hotkey + gnomehotkey contains(CONFIG, UDISKS2_PLUGIN){ unix:SUBDIRS += udisks2 diff --git a/src/plugins/General/hotkey/hotkeymanager.h b/src/plugins/General/hotkey/hotkeymanager.h index 200aa68f4..b7674f78d 100644 --- a/src/plugins/General/hotkey/hotkeymanager.h +++ b/src/plugins/General/hotkey/hotkeymanager.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2009-2013 by Ilya Kotov * + * Copyright (C) 2009-2018 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,9 @@ #include <QString> #include <QTableWidgetItem> #include <QList> +#ifdef Q_OS_WIN +#include <QAbstractNativeEventFilter> +#endif #include <qmmpui/general.h> class QEvent; @@ -99,7 +102,7 @@ private: #endif #ifdef Q_OS_WIN - QList<QWidget *> m_filters; + QList<QAbstractNativeEventFilter *> m_filters; #endif }; diff --git a/src/plugins/General/hotkey/hotkeymanager_win.cpp b/src/plugins/General/hotkey/hotkeymanager_win.cpp index 3edc818be..3992c14b9 100644 --- a/src/plugins/General/hotkey/hotkeymanager_win.cpp +++ b/src/plugins/General/hotkey/hotkeymanager_win.cpp @@ -24,6 +24,7 @@ #include <QEvent>
#include <QKeyEvent>
#include <QCoreApplication>
+#include <QAbstractNativeEventFilter>
#include <QApplication>
#include <windows.h>
#include <winuser.h>
@@ -96,10 +97,10 @@ quint32 Hotkey::defaultKey(int act) return keyMap[act];
}
-class KeyFilterWidget : public QWidget
+class KeyFilter : public QAbstractNativeEventFilter
{
public:
- KeyFilterWidget(const Hotkey &hotkey)
+ KeyFilter(const Hotkey &hotkey) : QAbstractNativeEventFilter()
{
m_hotkey = hotkey;
m_mods = 0;
@@ -115,23 +116,29 @@ public: m_mods |= MOD_WIN;
- if(RegisterHotKey(winId(), m_mods^m_hotkey.key, m_mods, m_hotkey.key))
+ if(RegisterHotKey(NULL, m_mods^m_hotkey.key, m_mods, m_hotkey.key))
{
m_id = m_mods^m_hotkey.key;
qDebug("KeyFilterWidget: registered key=0x%x, mod=0x%x", hotkey.key, m_mods);
}
else
qWarning("KeyFilterWidget: unable to register key=0x%x, mod=0x%x", hotkey.key, m_mods);
+
+ qApp->installNativeEventFilter(this);
}
- ~KeyFilterWidget()
+ virtual ~KeyFilter()
{
+ qApp->removeNativeEventFilter(this);
if(m_id)
- UnregisterHotKey(winId(), m_id);
+ UnregisterHotKey(NULL, m_id);
}
- bool winEvent(MSG* m, long* result)
+ bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
+ Q_UNUSED(eventType);
+ Q_UNUSED(result);
+ MSG* m = static_cast<MSG*>(message);
if (m->message == WM_HOTKEY && m->wParam == m_id)
{
SoundCore *core = SoundCore::instance();
@@ -187,15 +194,13 @@ public: qApp->processEvents();
return true;
}
- return QWidget::winEvent(m, result);
+ return false;
}
private:
Hotkey m_hotkey;
UINT m_mods;
WPARAM m_id;
-
-
};
HotkeyManager::HotkeyManager(QObject *parent) : QObject(parent)
@@ -218,7 +223,7 @@ HotkeyManager::HotkeyManager(QObject *parent) : QObject(parent) hotkey.code = MapVirtualKey(key, 0);
hotkey.mod = mod;
- KeyFilterWidget *filerWidget = new KeyFilterWidget(hotkey);
+ KeyFilter *filerWidget = new KeyFilter(hotkey);
m_filters << filerWidget;
}
}
|
