16 #ifndef hifi_ApplicationEventHandler_h
17 #define hifi_ApplicationEventHandler_h
19 #include <QtCore/QAbstractNativeEventFilter>
20 #include <qsystemdetection.h>
22 #include <MainWindow.h>
24 #include "Application.h"
27 static const UINT UWM_IDENTIFY_INSTANCES =
28 RegisterWindowMessage(
"UWM_IDENTIFY_INSTANCES_{8AB82783-B74A-4258-955B-8188C22AA0D6}_" + qgetenv(
"USERNAME"));
29 static const UINT UWM_SHOW_APPLICATION =
30 RegisterWindowMessage(
"UWM_SHOW_APPLICATION_{71123FD6-3DA8-4DC1-9C27-8A12A6250CBA}_" + qgetenv(
"USERNAME"));
32 class MyNativeEventFilter :
public QAbstractNativeEventFilter {
34 static MyNativeEventFilter& getInstance() {
35 static MyNativeEventFilter staticInstance;
36 return staticInstance;
39 bool nativeEventFilter(
const QByteArray &eventType,
void* msg,
long* result) Q_DECL_OVERRIDE {
40 if (eventType ==
"windows_generic_MSG") {
41 MSG* message = (MSG*)msg;
43 if (message->message == UWM_IDENTIFY_INSTANCES) {
44 *result = UWM_IDENTIFY_INSTANCES;
48 if (message->message == UWM_SHOW_APPLICATION) {
49 MainWindow* applicationWindow = qApp->getWindow();
50 if (applicationWindow->isMinimized()) {
51 applicationWindow->showNormal();
53 qApp->setActiveWindow(applicationWindow);
61 if (message->message == WM_DEVICECHANGE) {
62 const float MIN_DELTA_SECONDS = 2.0f;
63 static float lastTriggerTime = 0.0f;
64 const float deltaSeconds = secTimestampNow() - lastTriggerTime;
65 lastTriggerTime = secTimestampNow();
66 if (deltaSeconds > MIN_DELTA_SECONDS) {