Windows QPA: Move function to find screen by HWND to QWindowsScreenManager
Task-number: QTBUG-62971 Change-Id: Ida0a8e758723f0f617011a89dc89c266d2506aad Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>bb10
parent
aa4fef8812
commit
d03dba3f4a
|
|
@ -566,4 +566,19 @@ const QWindowsScreen *QWindowsScreenManager::screenAtDp(const QPoint &p) const
|
|||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
const QWindowsScreen *QWindowsScreenManager::screenForHwnd(HWND hwnd) const
|
||||
{
|
||||
HMONITOR hMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL);
|
||||
if (hMonitor == NULL)
|
||||
return nullptr;
|
||||
const auto it =
|
||||
std::find_if(m_screens.cbegin(), m_screens.cend(),
|
||||
[hMonitor](const QWindowsScreen *s)
|
||||
{
|
||||
return s->data().hMonitor == hMonitor
|
||||
&& (s->data().flags & QWindowsScreenData::VirtualDesktop) != 0;
|
||||
});
|
||||
return it != m_screens.cend() ? *it : nullptr;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ public:
|
|||
const WindowsScreenList &screens() const { return m_screens; }
|
||||
|
||||
const QWindowsScreen *screenAtDp(const QPoint &p) const;
|
||||
const QWindowsScreen *screenForHwnd(HWND hwnd) const;
|
||||
|
||||
private:
|
||||
void removeScreen(int index);
|
||||
|
|
|
|||
|
|
@ -1542,15 +1542,15 @@ void QWindowsWindow::handleGeometryChange()
|
|||
fireExpose(QRect(QPoint(0, 0), m_data.geometry.size()), true);
|
||||
}
|
||||
if (!parent() && previousGeometry.topLeft() != m_data.geometry.topLeft()) {
|
||||
HMONITOR hMonitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTONULL);
|
||||
QPlatformScreen *currentScreen = screen();
|
||||
const auto screens = QWindowsContext::instance()->screenManager().screens();
|
||||
auto newScreenIt = std::find_if(screens.begin(), screens.end(), [&](QWindowsScreen *s) {
|
||||
return s->data().hMonitor == hMonitor
|
||||
&& s->data().flags & QWindowsScreenData::VirtualDesktop;
|
||||
});
|
||||
if (newScreenIt != screens.end() && *newScreenIt != currentScreen)
|
||||
QWindowSystemInterface::handleWindowScreenChanged(window(), (*newScreenIt)->screen());
|
||||
const QWindowsScreen *newScreen =
|
||||
QWindowsContext::instance()->screenManager().screenForHwnd(m_data.hwnd);
|
||||
if (newScreen != nullptr && newScreen != currentScreen) {
|
||||
qCDebug(lcQpaWindows).noquote().nospace() << __FUNCTION__
|
||||
<< ' ' << window() << " \"" << currentScreen->name()
|
||||
<< "\"->\"" << newScreen->name() << '"';
|
||||
QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
|
||||
}
|
||||
}
|
||||
if (testFlag(SynchronousGeometryChangeEvent))
|
||||
QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
|
|
|
|||
Loading…
Reference in New Issue