summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowscontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 38b9823d6b..5c1b00a1c9 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -273,6 +273,8 @@ struct QWindowsContextPrivate {
const HRESULT m_oleInitializeResult;
QWindow *m_lastActiveWindow = nullptr;
bool m_asyncExpose = false;
+ HPOWERNOTIFY m_powerNotification = nullptr;
+ HWND m_powerDummyWindow = nullptr;
};
QWindowsContextPrivate::QWindowsContextPrivate()
@@ -313,6 +315,13 @@ QWindowsContext::~QWindowsContext()
#if QT_CONFIG(tabletevent)
d->m_tabletSupport.reset(); // Destroy internal window before unregistering classes.
#endif
+
+ if (d->m_powerNotification)
+ UnregisterPowerSettingNotification(d->m_powerNotification);
+
+ if (d->m_powerDummyWindow)
+ DestroyWindow(d->m_powerDummyWindow);
+
unregisterWindowClasses();
if (d->m_oleInitializeResult == S_OK || d->m_oleInitializeResult == S_FALSE)
OleUninitialize();
@@ -380,6 +389,55 @@ bool QWindowsContext::initPointer(unsigned integrationOptions)
return true;
}
+extern "C" LRESULT QT_WIN_CALLBACK qWindowsPowerWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ if (message != WM_POWERBROADCAST || wParam != PBT_POWERSETTINGCHANGE)
+ return DefWindowProc(hwnd, message, wParam, lParam);
+
+ static bool initialized = false; // ignore the initial change
+ if (!initialized) {
+ initialized = true;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+
+ auto setting = reinterpret_cast<const POWERBROADCAST_SETTING *>(lParam);
+ if (setting) {
+ auto data = reinterpret_cast<const DWORD *>(&setting->Data);
+ if (*data == 1) {
+ // Repaint the windows when returning from sleeping display mode.
+ const auto tlw = QGuiApplication::topLevelWindows();
+ for (auto w : tlw) {
+ if (w->isVisible() && w->windowState() != Qt::WindowMinimized) {
+ if (auto tw = QWindowsWindow::windowsWindowOf(w)) {
+ if (HWND hwnd = tw->handle()) {
+ InvalidateRect(hwnd, nullptr, false);
+ }
+ }
+ }
+ }
+ }
+ }
+ return DefWindowProc(hwnd, message, wParam, lParam);
+}
+
+bool QWindowsContext::initPowerNotificationHandler()
+{
+ if (d->m_powerNotification)
+ return false;
+
+ d->m_powerDummyWindow = createDummyWindow(QStringLiteral("QtPowerDummyWindow"), L"QtPowerDummyWindow", qWindowsPowerWindowProc);
+ if (!d->m_powerDummyWindow)
+ return false;
+
+ d->m_powerNotification = RegisterPowerSettingNotification(d->m_powerDummyWindow, &GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
+ if (!d->m_powerNotification) {
+ DestroyWindow(d->m_powerDummyWindow);
+ d->m_powerDummyWindow = nullptr;
+ return false;
+ }
+ return true;
+}
+
void QWindowsContext::setTabletAbsoluteRange(int a)
{
#if QT_CONFIG(tabletevent)