bool ScreenLockListenerWin::nativeEventFilter(const QByteArray& eventType, void* message, long*) { if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG") { MSG* m = static_cast<MSG*>(message); if (m->message == WM_POWERBROADCAST) { if (m->wParam == PBT_POWERSETTINGCHANGE) { const POWERBROADCAST_SETTING* setting = reinterpret_cast<const POWERBROADCAST_SETTING*>(m->lParam); if (setting != nullptr && setting->PowerSetting == GUID_LIDSWITCH_STATE_CHANGE) { const DWORD* state = reinterpret_cast<const DWORD*>(&setting->Data); if (*state == 0) { emit screenLocked(); return true; } } } else if (m->wParam == PBT_APMSUSPEND) { emit screenLocked(); return true; } } if (m->message == WM_WTSSESSION_CHANGE) { if (m->wParam == WTS_CONSOLE_DISCONNECT) { emit screenLocked(); return true; } if (m->wParam == WTS_SESSION_LOCK) { emit screenLocked(); return true; } } } return false; }
void SystemMonitor::initialize() { d = new SystemMonitorPrivate(this); QAbstractEventDispatcher::instance()->installNativeEventFilter(d); connect(&d->network, SIGNAL(online()), this, SIGNAL(online())); connect(&d->network, SIGNAL(offline()), this, SIGNAL(offline())); connect(&d->screen, SIGNAL(screenLocked()), this, SIGNAL(screenLocked())); connect(&d->screen, SIGNAL(screenUnlocked()), this, SIGNAL(screenUnlocked())); connect(&d->screen, SIGNAL(screenSaverStarted()), this, SIGNAL(screenSaverStarted())); connect(&d->screen, SIGNAL(screenSaverStopped()), this, SIGNAL(screenSaverStopped())); }
void ApplicationEventHandler::removeObserver(IApplicationEventHandlerObserver* _observer) { QObject* observer = dynamic_cast<QObject*>(_observer); disconnect(this, SIGNAL(urlReceivedSignal(QUrl)), observer, SLOT(urlReceived(QUrl))); disconnect(this, SIGNAL(screenLockedSignal()), observer, SLOT(screenLocked())); disconnect(this, SIGNAL(screenUnlockedSignal()), observer, SLOT(screenUnlocked())); }