summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowscontext.cpp
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-11-15 01:00:11 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2019-11-15 16:29:40 +0100
commitadc7bbe910a4b89a579ffa93da5a937cfc1379f4 (patch)
treee28a2fadc82652798302cc7f79a6f4310a2eb8d7 /src/plugins/platforms/windows/qwindowscontext.cpp
parent14bb413309092adc53e8451daff5690c4698c07d (diff)
parentc15a069830baf87f57c84e86326cf86ba9a39713 (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts: src/gui/rhi/qshader.cpp tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp Change-Id: I1c4ae718eb3592a0a0a90af9d11553f3ab68cad5
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 f7d04b667d..a2dd25f8cc 100644
--- a/src/plugins/platforms/windows/qwindowscontext.cpp
+++ b/src/plugins/platforms/windows/qwindowscontext.cpp
@@ -274,6 +274,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()
@@ -314,6 +316,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();
@@ -381,6 +390,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)