aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/General')
-rw-r--r--src/plugins/General/General.pro6
-rw-r--r--src/plugins/General/hotkey/hotkeymanager.h7
-rw-r--r--src/plugins/General/hotkey/hotkeymanager_win.cpp25
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;
}
}