summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowscontext.cpp
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-22 13:47:08 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 13:17:33 +0100
commit502d3d6744913899da87acfda5ebdab42c40329e (patch)
tree16658a328503bfd5a62b4fd5d69ffb66e9854b18 /src/plugins/platforms/windows/qwindowscontext.cpp
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowscontext.cpp71
1 files changed, 63 insertions, 8 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp
index 9757fa5f3f..88d3131de2 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)
@@ -546,15 +604,12 @@ QString QWindowsContext::registerWindowClass(QString cname,
// each one has to have window class names with a unique name
// The first instance gets the unmodified name; if the class
// has already been registered by another instance of Qt then
- // add a UUID.
- static int classExists = -1;
-
+ // add a UUID. The check needs to be performed for each name
+ // in case new message windows are added (QTBUG-81347).
const auto appInstance = static_cast<HINSTANCE>(GetModuleHandle(nullptr));
- if (classExists == -1) {
- WNDCLASS wcinfo;
- classExists = GetClassInfo(appInstance, reinterpret_cast<LPCWSTR>(cname.utf16()), &wcinfo);
- classExists = classExists && wcinfo.lpfnWndProc != proc;
- }
+ WNDCLASS wcinfo;
+ const bool classExists = GetClassInfo(appInstance, reinterpret_cast<LPCWSTR>(cname.utf16()), &wcinfo) == TRUE
+ && wcinfo.lpfnWndProc != proc;
if (classExists)
cname += QUuid::createUuid().toString();