source: smplayer/trunk/src/myapplication.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

File size: 7.7 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "myapplication.h"
20
21#ifdef SINGLE_INSTANCE
22MyApplication::MyApplication ( const QString & appId, int & argc, char ** argv )
23 : QtSingleApplication(appId, argc, argv)
24{
25#if defined(USE_WINEVENTFILTER) && QT_VERSION >= 0x050000
26 installNativeEventFilter(this);
27#endif
28};
29
30#else
31
32MyApplication::MyApplication ( const QString & appId, int & argc, char ** argv )
33 : QApplication(argc, argv)
34{
35#if defined(USE_WINEVENTFILTER) && QT_VERSION >= 0x050000
36 installNativeEventFilter(this);
37#endif
38};
39
40#endif
41
42#if defined(USE_WINEVENTFILTER) && QT_VERSION >= 0x050000
43bool MyApplication::nativeEventFilter(const QByteArray &eventType, void *message, long *result) {
44 //qDebug() << "MyApplication::nativeEventFilter:" <<eventType;
45
46 if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") {
47 MSG * m = static_cast<MSG *>(message);
48 return winEventFilter(m, result);
49 }
50
51 return false;
52}
53#endif
54
55#ifdef USE_WINEVENTFILTER
56#include <QKeyEvent>
57#include <QEvent>
58#include <QWidget>
59#include <windows.h>
60#include <QDebug>
61
62#ifndef WM_APPCOMMAND
63#define WM_APPCOMMAND 0x0319
64#endif
65
66#ifndef FAPPCOMMAND_MOUSE
67#define FAPPCOMMAND_MOUSE 0x8000
68#define FAPPCOMMAND_KEY 0
69#define FAPPCOMMAND_OEM 0x1000
70#define FAPPCOMMAND_MASK 0xF000
71#define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
72#define GET_DEVICE_LPARAM(lParam) ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
73#define GET_MOUSEORKEY_LPARAM GET_DEVICE_LPARAM
74#define GET_FLAGS_LPARAM(lParam) (LOWORD(lParam))
75#define GET_KEYSTATE_LPARAM(lParam) GET_FLAGS_LPARAM(lParam)
76
77#define APPCOMMAND_BROWSER_BACKWARD 1
78#define APPCOMMAND_BROWSER_FORWARD 2
79#define APPCOMMAND_BROWSER_REFRESH 3
80#define APPCOMMAND_BROWSER_STOP 4
81#define APPCOMMAND_BROWSER_SEARCH 5
82#define APPCOMMAND_BROWSER_FAVORITES 6
83#define APPCOMMAND_BROWSER_HOME 7
84#define APPCOMMAND_VOLUME_MUTE 8
85#define APPCOMMAND_VOLUME_DOWN 9
86#define APPCOMMAND_VOLUME_UP 10
87#define APPCOMMAND_MEDIA_NEXTTRACK 11
88#define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
89#define APPCOMMAND_MEDIA_STOP 13
90#define APPCOMMAND_MEDIA_PLAY_PAUSE 14
91#define APPCOMMAND_LAUNCH_MAIL 15
92#define APPCOMMAND_LAUNCH_MEDIA_SELECT 16
93#define APPCOMMAND_LAUNCH_APP1 17
94#define APPCOMMAND_LAUNCH_APP2 18
95#define APPCOMMAND_BASS_DOWN 19
96#define APPCOMMAND_BASS_BOOST 20
97#define APPCOMMAND_BASS_UP 21
98#define APPCOMMAND_TREBLE_DOWN 22
99#define APPCOMMAND_TREBLE_UP 23
100#endif // FAPPCOMMAND_MOUSE
101
102// New commands from Windows XP (some even Sp1)
103#ifndef APPCOMMAND_MICROPHONE_VOLUME_MUTE
104#define APPCOMMAND_MICROPHONE_VOLUME_MUTE 24
105#define APPCOMMAND_MICROPHONE_VOLUME_DOWN 25
106#define APPCOMMAND_MICROPHONE_VOLUME_UP 26
107#define APPCOMMAND_HELP 27
108#define APPCOMMAND_FIND 28
109#define APPCOMMAND_NEW 29
110#define APPCOMMAND_OPEN 30
111#define APPCOMMAND_CLOSE 31
112#define APPCOMMAND_SAVE 32
113#define APPCOMMAND_PRINT 33
114#define APPCOMMAND_UNDO 34
115#define APPCOMMAND_REDO 35
116#define APPCOMMAND_COPY 36
117#define APPCOMMAND_CUT 37
118#define APPCOMMAND_PASTE 38
119#define APPCOMMAND_REPLY_TO_MAIL 39
120#define APPCOMMAND_FORWARD_MAIL 40
121#define APPCOMMAND_SEND_MAIL 41
122#define APPCOMMAND_SPELL_CHECK 42
123#define APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE 43
124#define APPCOMMAND_MIC_ON_OFF_TOGGLE 44
125#define APPCOMMAND_CORRECTION_LIST 45
126#define APPCOMMAND_MEDIA_PLAY 46
127#define APPCOMMAND_MEDIA_PAUSE 47
128#define APPCOMMAND_MEDIA_RECORD 48
129#define APPCOMMAND_MEDIA_FAST_FORWARD 49
130#define APPCOMMAND_MEDIA_REWIND 50
131#define APPCOMMAND_MEDIA_CHANNEL_UP 51
132#define APPCOMMAND_MEDIA_CHANNEL_DOWN 52
133#endif // APPCOMMAND_MICROPHONE_VOLUME_MUTE
134
135#define VK_MEDIA_NEXT_TRACK 0xB0
136#define VK_MEDIA_PREV_TRACK 0xB1
137#define VK_MEDIA_PLAY_PAUSE 0xB3
138#define VK_MEDIA_STOP 0xB2
139
140
141bool MyApplication::winEventFilter(MSG * msg, long * result) {
142 //qDebug() << "MyApplication::winEventFilter" << msg->message << "lParam:" << msg->lParam;
143
144 static uint last_appcommand = 0;
145
146 if (msg->message == WM_KEYDOWN) {
147 //qDebug("MyApplication::winEventFilter: WM_KEYDOWN: %X", msg->wParam);
148 bool eat_key = false;
149 if ((last_appcommand == APPCOMMAND_MEDIA_NEXTTRACK) && (msg->wParam == VK_MEDIA_NEXT_TRACK)) eat_key = true;
150 else
151 if ((last_appcommand == APPCOMMAND_MEDIA_PREVIOUSTRACK) && (msg->wParam == VK_MEDIA_PREV_TRACK)) eat_key = true;
152 else
153 if ((last_appcommand == APPCOMMAND_MEDIA_PLAY_PAUSE) && (msg->wParam == VK_MEDIA_PLAY_PAUSE)) eat_key = true;
154 else
155 if ((last_appcommand == APPCOMMAND_MEDIA_STOP) && (msg->wParam == VK_MEDIA_STOP)) eat_key = true;
156
157 if (eat_key) {
158 qDebug() << "MyApplication::winEventFilter: ignoring key" << msg->wParam;
159 last_appcommand = 0;
160 //*result = true;
161 return true;
162 }
163 }
164 else
165 if (msg->message == WM_APPCOMMAND) {
166 /*
167 QKeySequence k(Qt::Key_MediaTogglePlayPause);
168 qDebug() << "MyApplication::winEventFilter" << k.toString();
169 */
170
171 //qDebug() << "MyApplication::winEventFilter" << msg->message << "lParam:" << msg->lParam;
172 uint cmd = GET_APPCOMMAND_LPARAM(msg->lParam);
173 uint uDevice = GET_DEVICE_LPARAM(msg->lParam);
174 uint dwKeys = GET_KEYSTATE_LPARAM(msg->lParam);
175 qDebug() << "MyApplication::winEventFilter: cmd:" << cmd <<"uDevice:" << uDevice << "dwKeys:" << dwKeys;
176
177 //if (uDevice == FAPPCOMMAND_KEY) {
178 int key = 0;
179 Qt::KeyboardModifiers modifier = Qt::NoModifier;
180 QString name;
181
182 switch (cmd) {
183 case APPCOMMAND_MEDIA_PAUSE: key = Qt::Key_MediaPause; name = "Media Pause"; break;
184 case APPCOMMAND_MEDIA_PLAY: key = Qt::Key_MediaPlay; name = "Media Play"; break;
185 case APPCOMMAND_MEDIA_STOP: key = Qt::Key_MediaStop; name = "Media Stop"; break;
186 case APPCOMMAND_MEDIA_PLAY_PAUSE: key = Qt::Key_MediaTogglePlayPause; name = "Toggle Media Play/Pause"; break;
187
188 case APPCOMMAND_MEDIA_NEXTTRACK: key = Qt::Key_MediaNext; name = "Media Next"; break;
189 case APPCOMMAND_MEDIA_PREVIOUSTRACK: key = Qt::Key_MediaPrevious; name = "Media Previous"; break;
190
191 case APPCOMMAND_MEDIA_FAST_FORWARD: key = Qt::Key_F; modifier = Qt::ShiftModifier | Qt::ControlModifier; break;
192 case APPCOMMAND_MEDIA_REWIND: key = Qt::Key_B; modifier = Qt::ShiftModifier | Qt::ControlModifier; break;
193 }
194
195 if (key != 0) {
196 last_appcommand = cmd;
197
198 QKeyEvent event(QEvent::KeyPress, key, modifier, name);
199 QWidget * w = QApplication::focusWidget();
200 if (w) QCoreApplication::sendEvent(w, &event);
201 //*result = true;
202 return true;
203 }
204 //}
205 }
206
207 return false;
208}
209#endif // USE_WINEVENTFILTER
210
211#include "moc_myapplication.cpp"
212
Note: See TracBrowser for help on using the repository browser.