aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/General/hotkey/hotkeymanager.h11
-rw-r--r--src/plugins/General/hotkey/hotkeymanager_win.cpp233
-rw-r--r--src/plugins/General/hotkey/hotkeymanager_x11.cpp2
3 files changed, 111 insertions, 135 deletions
diff --git a/src/plugins/General/hotkey/hotkeymanager.h b/src/plugins/General/hotkey/hotkeymanager.h
index 753b24393..f892d0969 100644
--- a/src/plugins/General/hotkey/hotkeymanager.h
+++ b/src/plugins/General/hotkey/hotkeymanager.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2009-2012 by Ilya Kotov *
+ * Copyright (C) 2009-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -26,6 +26,7 @@
#include <qmmpui/general.h>
class QEvent;
+class QWidget;
/**
@author Ilya Kotov <forkotov02@hotmail.ru>
@@ -78,10 +79,13 @@ public:
static QList<long> ignModifiersList();
static quint32 keycodeToKeysym(quint32 keycode);
+#ifdef Q_WS_X11
protected:
virtual bool eventFilter(QObject* o, QEvent* e);
+#endif
private:
+#ifdef Q_WS_X11
static void ensureModifiers();
QList <Hotkey *> m_grabbedKeys;
static long m_alt_mask;
@@ -90,6 +94,11 @@ private:
static long m_hyper_mask;
static long m_numlock_mask;
static bool m_haveMods;
+#endif
+
+#ifdef Q_OS_WIN
+ QList<QWidget *> m_filters;
+#endif
};
#endif
diff --git a/src/plugins/General/hotkey/hotkeymanager_win.cpp b/src/plugins/General/hotkey/hotkeymanager_win.cpp
index cb9c5b3f0..12463bfa2 100644
--- a/src/plugins/General/hotkey/hotkeymanager_win.cpp
+++ b/src/plugins/General/hotkey/hotkeymanager_win.cpp
@@ -61,141 +61,50 @@ quint32 Hotkey::defaultKey(int act)
return keyMap[act];
}
-WPARAM nextId132 = 1;
-
-
class KeyFilterWidget : public QWidget
{
public:
- KeyFilterWidget()
- {}
-
- ~KeyFilterWidget()
- {
-
- }
-
-bool winEvent(MSG* m, long* result)
-{
- if (m->message == WM_HOTKEY)
+ KeyFilterWidget(const Hotkey &hotkey)
{
- qDebug("HOT KEY PRESSED!!!");
- return true;
- }
- return QWidget::winEvent(m, result);
-}
-};
+ m_hotkey = hotkey;
+ m_mods = 0;
+ m_id = 0;
+ if(m_hotkey.mod & HOTKEYF_CONTROL)
+ m_mods |= MOD_CONTROL;
+ if(m_hotkey.mod & HOTKEYF_SHIFT)
+ m_mods |= MOD_SHIFT;
+ if(m_hotkey.mod & HOTKEYF_ALT)
+ m_mods |= MOD_ALT;
+ if(m_hotkey.mod & HOTKEYF_EXT)
+ m_mods |= MOD_WIN;
-HotkeyManager::HotkeyManager(QObject *parent) : QObject(parent)
-{
- QCoreApplication::instance()->installEventFilter(this);
- KeyFilterWidget *w = new KeyFilterWidget;
- //qDebug("+++%d++++", int(WId));
- QSettings settings(Qmmp::configFile(), QSettings::IniFormat); //load settings
- settings.beginGroup("Hotkey");
- for (int i = Hotkey::PLAY; i <= Hotkey::JUMP_TO_TRACK; ++i)
- {
- qDebug("----");
- quint32 key = settings.value(QString("key_%1").arg(i), Hotkey::defaultKey(i)).toUInt();
- quint32 mod = settings.value(QString("modifiers_%1").arg(i), 0).toUInt();
-
- if (key)
+ if(RegisterHotKey(winId(), m_mods^m_hotkey.key, m_mods, m_hotkey.key))
{
-
- Hotkey *hotkey = new Hotkey;
- hotkey->action = i;
- hotkey->key = key;
- //hotkey->code = keycodeToKeysym(hotkey->key);
- /*if(!hotkey->code)
- continue;*/
-
- qDebug("1");
- if(RegisterHotKey(w->winId(), MOD_CONTROL^hotkey->key, MOD_CONTROL, hotkey->key))
- {
- qDebug("registered");
- nextId132++;
- }
- else
- {
- qDebug("failed");
- }
- qDebug("2");
-
- //hotkey->mod = mod | mask_mod;
- m_grabbedKeys << hotkey;
+ 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);
}
- settings.endGroup();
-}
-
-HotkeyManager::~HotkeyManager()
-{
- /*foreach(Hotkey *key, m_grabbedKeys)
- {
- if(key->code)
- XUngrabKey(QX11Info::display(), key->code, key->mod, QX11Info::appRootWindow());
- }
- while (!m_grabbedKeys.isEmpty())
- delete m_grabbedKeys.takeFirst ();*/
-}
-
-const QString HotkeyManager::getKeyString(quint32 key, quint32 modifiers)
-{
- qDebug("%ux++%ux", key, modifiers);
- QString strModList[] = { "Control", "Shift", "Alt"};
- quint32 modList[] = { HOTKEYF_CONTROL, HOTKEYF_SHIFT, HOTKEYF_ALT};
-
- MOD_CONTROL, MOD_ALT, HOTKEYF_EXT;
-
- QString keyStr;
- for (int j = 0; j < 3; j++)
- {
- if (modifiers & modList[j])
- keyStr.append(strModList[j] + "+");
- }
-
- LONG lScan = MapVirtualKey(key, 0) << 16;
-
- int nBufferLen = 64;
- std::wstring str;
- int nLen;
- do
- {
- nBufferLen *= 2;
- str.resize(nBufferLen);
- nLen = ::GetKeyNameTextW(lScan, &str[0], nBufferLen);
- }
- while (nLen == nBufferLen);
-
- keyStr += QString::fromWCharArray(str.c_str());
-
- return keyStr;
-}
-bool HotkeyManager::eventFilter(QObject* o, QEvent* e)
-{
- if (e->type() == QEvent::KeyPress)
+ ~KeyFilterWidget()
{
- qDebug("KEY EVENT!!");
+ if(m_id)
+ UnregisterHotKey(winId(), m_id);
}
- //receive events from active and root windows only
- /*if (e->type() == QEvent::KeyPress && (o == qApp->desktop () || o == qApp->activeWindow ()))
+ bool winEvent(MSG* m, long* result)
{
- QKeyEvent* k = static_cast<QKeyEvent*>(e);
- quint32 key = keycodeToKeysym(k->nativeScanCode());
- quint32 mod = k->nativeModifiers ();
- SoundCore *core = SoundCore::instance();
- MediaPlayer *player = MediaPlayer::instance();
- foreach(Hotkey *hotkey, m_grabbedKeys)
+ if (m->message == WM_HOTKEY && m->wParam == m_id)
{
- if (hotkey->key != key || hotkey->mod != mod)
- continue;
- qDebug("HotkeyManager: [%s] pressed", qPrintable(getKeyString(key, mod)));
+ SoundCore *core = SoundCore::instance();
+ MediaPlayer *player = MediaPlayer::instance();
+ qDebug("KeyFilterWidget: [%s] pressed",
+ qPrintable(HotkeyManager::getKeyString(m_hotkey.key, m_hotkey.mod)));
- switch (hotkey->action)
+ switch (m_hotkey.action)
{
case Hotkey::PLAY:
player->play();
@@ -208,7 +117,7 @@ bool HotkeyManager::eventFilter(QObject* o, QEvent* e)
break;
case Hotkey::PLAY_PAUSE:
if (core->state() == Qmmp::Stopped)
- MediaPlayer::instance()->play();
+ player->play();
else if (core->state() != Qmmp::FatalError)
core->pause();
break;
@@ -230,7 +139,7 @@ bool HotkeyManager::eventFilter(QObject* o, QEvent* e)
int right = core->rightVolume();
if (left || right)
balance = (right - left)*100/volume;
- if(hotkey->action == Hotkey::VOLUME_UP)
+ if(m_hotkey.action == Hotkey::VOLUME_UP)
volume = qMin (100, volume + 5);
else
volume = qMax (0, volume - 5);
@@ -250,26 +159,84 @@ bool HotkeyManager::eventFilter(QObject* o, QEvent* e)
}
qApp->processEvents();
+ return true;
}
- }*/
- return QObject::eventFilter(o, e);
+ return QWidget::winEvent(m, result);
+ }
+
+private:
+ Hotkey m_hotkey;
+ UINT m_mods;
+ WPARAM m_id;
+
+
+};
+
+HotkeyManager::HotkeyManager(QObject *parent) : QObject(parent)
+{
+ QCoreApplication::instance()->installEventFilter(this);
+
+
+ QSettings settings(Qmmp::configFile(), QSettings::IniFormat); //load settings
+ settings.beginGroup("Hotkey");
+ for (int i = Hotkey::PLAY; i <= Hotkey::JUMP_TO_TRACK; ++i)
+ {
+ quint32 key = settings.value(QString("key_%1").arg(i), Hotkey::defaultKey(i)).toUInt();
+ quint32 mod = settings.value(QString("modifiers_%1").arg(i), 0).toUInt();
+
+ if (key)
+ {
+ Hotkey hotkey;
+ hotkey.action = i;
+ hotkey.key = key;
+ hotkey.code = MapVirtualKey(key, 0);
+ hotkey.mod = mod;
+
+ KeyFilterWidget *filerWidget = new KeyFilterWidget(hotkey);
+ m_filters << filerWidget;
+ }
+ }
+ settings.endGroup();
}
-long HotkeyManager::m_alt_mask = 0;
-long HotkeyManager::m_meta_mask = 0;
-long HotkeyManager::m_super_mask = 0;
-long HotkeyManager::m_hyper_mask = 0;
-long HotkeyManager::m_numlock_mask = 0;
-bool HotkeyManager::m_haveMods = false;
+HotkeyManager::~HotkeyManager()
+{
+ qDeleteAll(m_filters);
+}
+
+const QString HotkeyManager::getKeyString(quint32 key, quint32 modifiers)
+{
+ QString strModList[] = { "Ctrl", "Shift", "Alt", "Win"};
+ quint32 modList[] = { HOTKEYF_CONTROL, HOTKEYF_SHIFT, HOTKEYF_ALT, HOTKEYF_EXT};
+
+ QString keyStr;
+ for (int j = 0; j < 3; j++)
+ {
+ if (modifiers & modList[j])
+ keyStr.append(strModList[j] + "+");
+ }
+
+ LONG lScan = MapVirtualKey(key, 0) << 16;
-void HotkeyManager::ensureModifiers(){}
+ int nBufferLen = 64;
+ std::wstring str;
+ int nLen;
+ do
+ {
+ nBufferLen *= 2;
+ str.resize(nBufferLen);
+ nLen = ::GetKeyNameTextW(lScan, &str[0], nBufferLen);
+ }
+ while (nLen == nBufferLen);
+
+ keyStr += QString::fromWCharArray(str.c_str());
+
+ return keyStr;
+}
QList<long> HotkeyManager::ignModifiersList()
{
- ensureModifiers();
- QList<long> ret;
- ret << 0;
- return ret;
+ return QList<long>();
}
quint32 HotkeyManager::keycodeToKeysym(quint32 keycode)
diff --git a/src/plugins/General/hotkey/hotkeymanager_x11.cpp b/src/plugins/General/hotkey/hotkeymanager_x11.cpp
index c5bf0e7ca..241b2ea64 100644
--- a/src/plugins/General/hotkey/hotkeymanager_x11.cpp
+++ b/src/plugins/General/hotkey/hotkeymanager_x11.cpp
@@ -164,7 +164,7 @@ bool HotkeyManager::eventFilter(QObject* o, QEvent* e)
break;
case Hotkey::PLAY_PAUSE:
if (core->state() == Qmmp::Stopped)
- MediaPlayer::instance()->play();
+ player->play();
else if (core->state() != Qmmp::FatalError)
core->pause();
break;