From f2e634c603a202eabb536e1dfb988569741b50c5 Mon Sep 17 00:00:00 2001 From: maybetaken <296496296@qq.com> Date: Thu, 25 Jan 2024 10:39:53 +0800 Subject: [PATCH 1/2] Use windows style screen names This patch wants to modify screen names like windows displays settings do. If someone has two identical screens, the name of the two screens are identical this makes it not 'friendly' though there is a suffix index included. Signed-off-by: maybetaken <296496296@qq.com> --- src/plugins/platforms/windows/qwindowsscreen.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index a50f9fd4b05..a2166c68d37 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -277,7 +277,9 @@ static bool monitorData(HMONITOR hMonitor, QWindowsScreenData *data) setMonitorDataFromSetupApi(*data, pathGroup); } if (data->name.isEmpty()) - data->name = data->deviceName; + data->name.append(u"Internal Display"); + data->name.prepend(u": "); + data->name.prepend(data->deviceName); if (data->deviceName == u"WinDisc") { data->flags |= QWindowsScreenData::LockScreen; } else { From e566c178fe879ad25692797e6d3b7ec255127f35 Mon Sep 17 00:00:00 2001 From: maybetaken <296496296@qq.com> Date: Fri, 26 Jan 2024 08:47:48 +0800 Subject: [PATCH 2/2] Remove unused deviceIndex Screen name won't be indentical after szDevice name prepend, so remove unused deviceIndex. Signed-off-by: maybetaken <296496296@qq.com> --- src/plugins/platforms/windows/qwindowsscreen.cpp | 15 ++------------- src/plugins/platforms/windows/qwindowsscreen.h | 1 - 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp index a2166c68d37..1d0e2089877 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.cpp +++ b/src/plugins/platforms/windows/qwindowsscreen.cpp @@ -344,16 +344,7 @@ BOOL QT_WIN_CALLBACK monitorEnumCallback(HMONITOR hMonitor, HDC, LPRECT, LPARAM QWindowsScreenData data; if (monitorData(hMonitor, &data)) { auto *result = reinterpret_cast(p); - auto it = std::find_if(result->rbegin(), result->rend(), - [&data](QWindowsScreenData i){ return i.name == data.name; }); - if (it != result->rend()) { - int previousIndex = 1; - if (it->deviceIndex.has_value()) - previousIndex = it->deviceIndex.value(); - else - (*it).deviceIndex = 1; - data.deviceIndex = previousIndex + 1; - } + // QWindowSystemInterface::handleScreenAdded() documentation specifies that first // added screen will be the primary screen, so order accordingly. // Note that the side effect of this policy is that there is no way to change primary @@ -415,9 +406,7 @@ QWindowsScreen::QWindowsScreen(const QWindowsScreenData &data) : QString QWindowsScreen::name() const { - return m_data.deviceIndex.has_value() - ? (u"%1 (%2)"_s).arg(m_data.name, QString::number(m_data.deviceIndex.value())) - : m_data.name; + return m_data.name; } QPixmap QWindowsScreen::grabWindow(WId window, int xIn, int yIn, int width, int height) const diff --git a/src/plugins/platforms/windows/qwindowsscreen.h b/src/plugins/platforms/windows/qwindowsscreen.h index 0467ab2a0c6..4e20c87705d 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.h +++ b/src/plugins/platforms/windows/qwindowsscreen.h @@ -38,7 +38,6 @@ struct QWindowsScreenData HMONITOR hMonitor = nullptr; QString deviceName; QString devicePath; - std::optional deviceIndex = std::nullopt; }; class QWindowsScreen : public QPlatformScreen, public QNativeInterface::QWindowsScreen