From 83c44dc39f2ac0324107bfde328d7032e65343cc Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Mon, 2 Jul 2018 20:28:24 +0000 Subject: hotkey: fixed windows support git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8096 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/General.pro | 6 +++--- src/plugins/General/hotkey/hotkeymanager.h | 7 +++++-- src/plugins/General/hotkey/hotkeymanager_win.cpp | 25 ++++++++++++++---------- 3 files changed, 23 insertions(+), 15 deletions(-) (limited to 'src') 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 #include #include +#ifdef Q_OS_WIN +#include +#endif #include class QEvent; @@ -99,7 +102,7 @@ private: #endif #ifdef Q_OS_WIN - QList m_filters; + QList 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 #include #include +#include #include #include #include @@ -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(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; } } -- cgit v1.2.3-13-gbd6f