From c9498b366e808fd72cfe6f70c4259be3c6918acd Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Sun, 12 Nov 2023 07:32:45 +0100 Subject: [PATCH] Remove old code --- ScreenPlay/src/monitorlistmodel.cpp | 20 ++-- ScreenPlayWallpaper/src/windowshook.cpp | 111 ------------------- ScreenPlayWallpaper/src/windowshook.h | 41 ------- ScreenPlayWallpaper/src/windowsintegration.h | 31 ------ Tools/setup.py | 2 +- 5 files changed, 11 insertions(+), 194 deletions(-) delete mode 100644 ScreenPlayWallpaper/src/windowshook.cpp delete mode 100644 ScreenPlayWallpaper/src/windowshook.h diff --git a/ScreenPlay/src/monitorlistmodel.cpp b/ScreenPlay/src/monitorlistmodel.cpp index a5d2e954..4a3fdfd0 100644 --- a/ScreenPlay/src/monitorlistmodel.cpp +++ b/ScreenPlay/src/monitorlistmodel.cpp @@ -114,16 +114,15 @@ void MonitorListModel::loadMonitors() #ifdef Q_OS_WIN QModelIndex index; - WinMonitorStats monitors; + auto monitors = WindowsIntegration().GetAllMonitors(); // This offset lets us center the monitor selection view in the center int offsetX = 0; int offsetY = 0; - const int moinitorCount = monitors.iMonitors.size(); - for (int i = 0; i < moinitorCount; i++) { - const int x = monitors.rcMonitors[i].left; - const int y = monitors.rcMonitors[i].top; + for (auto& monitor : monitors) { + const int x = monitor.position.left; + const int y = monitor.position.top; if (x < 0) { offsetX += (x * -1); } @@ -132,11 +131,11 @@ void MonitorListModel::loadMonitors() } } - for (int i = 0; i < moinitorCount; i++) { - const int width = std::abs(monitors.rcMonitors[i].right - monitors.rcMonitors[i].left); - const int height = std::abs(monitors.rcMonitors[i].top - monitors.rcMonitors[i].bottom); - const int x = monitors.rcMonitors[i].left; - const int y = monitors.rcMonitors[i].top; + for(int i = 0; auto& monitor : monitors) { + const int width = std::abs(monitor.position.right - monitor.position.left); + const int height = std::abs(monitor.position.top - monitor.position.bottom); + const int x = monitor.position.left; + const int y = monitor.position.top; QRect geometry( x + offsetX, y + offsetY, @@ -145,6 +144,7 @@ void MonitorListModel::loadMonitors() beginInsertRows(index, m_monitorList.size(), m_monitorList.size()); m_monitorList.append(Monitor { i, geometry }); endInsertRows(); + i++; } #else QModelIndex index; diff --git a/ScreenPlayWallpaper/src/windowshook.cpp b/ScreenPlayWallpaper/src/windowshook.cpp deleted file mode 100644 index 032721f0..00000000 --- a/ScreenPlayWallpaper/src/windowshook.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "windowshook.h" - -BOOL CALLBACK WinMonitorStats::MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData) -{ - WinMonitorStats* pThis = reinterpret_cast(pData); - auto scaleFactor = DEVICE_SCALE_FACTOR::DEVICE_SCALE_FACTOR_INVALID; - GetScaleFactorForMonitor(hMon, &scaleFactor); - - UINT x = 0; - UINT y = 0; - GetDpiForMonitor(hMon, MONITOR_DPI_TYPE::MDT_RAW_DPI, &x, &y); - pThis->sizes.push_back({ x, y }); - pThis->scaleFactor.push_back(scaleFactor); - pThis->hMonitors.push_back(hMon); - pThis->hdcMonitors.push_back(hdc); - pThis->rcMonitors.push_back(*lprcMonitor); - pThis->iMonitors.push_back(static_cast(pThis->hdcMonitors.size())); - - // qInfo() << std::abs(lprcMonitor->right - lprcMonitor->left) << std::abs(lprcMonitor->top - lprcMonitor->bottom); - - return TRUE; -} -/*! - \brief Searches for the worker window for our window to parent to. -*/ -BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam) -{ - // 0xXXXXXXX "" WorkerW - // ... - // 0xXXXXXXX "" SHELLDLL_DefView - // 0xXXXXXXXX "FolderView" SysListView32 - // 0xXXXXXXXX "" WorkerW <---- We want this one - // 0xXXXXXXXX "Program Manager" Progman - if (FindWindowExW(hwnd, nullptr, L"SHELLDLL_DefView", nullptr)) - *reinterpret_cast(lparam) = FindWindowExW(nullptr, hwnd, L"WorkerW", nullptr); - return TRUE; -} - -bool WindowsHook::searchWorkerWindowToParentTo() -{ - - HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager"); - const DWORD WM_SPAWN_WORKER = 0x052C; - SendMessageTimeoutW(progman_hwnd, WM_SPAWN_WORKER, 0xD, 0x1, SMTO_NORMAL, - 10000, nullptr); - - return EnumWindows(SearchForWorkerWindow, reinterpret_cast(&windowHandleWorker)); -} - -/*! - \brief Returns scaling factor as reported by Windows. -*/ -float WindowsHook::getScaling(const int monitorIndex) const -{ - // Get all monitors - int monitorCount = GetSystemMetrics(SM_CMONITORS); - - if (monitorIndex < 0 || monitorIndex >= monitorCount) { - // Invalid monitor index - return 1.0f; - } - - DISPLAY_DEVICE displayDevice; - ZeroMemory(&displayDevice, sizeof(displayDevice)); - displayDevice.cb = sizeof(displayDevice); - - // Enumerate through monitors until we find the one we're looking for - for (int i = 0; EnumDisplayDevices(NULL, i, &displayDevice, 0); i++) { - if (i == monitorIndex) { - DEVMODE devMode; - ZeroMemory(&devMode, sizeof(devMode)); - devMode.dmSize = sizeof(devMode); - - // Get settings for selected monitor - if (!EnumDisplaySettings(displayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &devMode)) { - // Unable to get monitor settings - return 1.0f; - } - - // Get DPI for selected monitor - HMONITOR hMonitor = MonitorFromPoint({ devMode.dmPosition.x, devMode.dmPosition.y }, MONITOR_DEFAULTTONEAREST); - UINT dpiX = 0, dpiY = 0; - if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY))) { - return (float)dpiX / 96.0f; // Standard DPI is 96 - } - } - } - - // If we reach here, it means we couldn't find the monitor with the given index or couldn't get the DPI. - return 1.0f; -} - -/*! - \brief Returns true of at least one monitor has active scaling enabled. -*/ -bool WindowsHook::hasWindowScaling() const -{ - auto enumMonitorCallback = [](HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL { - int scaling = GetDeviceCaps(hdcMonitor, LOGPIXELSX) / 96; - if (scaling != 1) { - *(bool*)dwData = true; - return false; // Stop enumeration - } - return true; // Continue enumeration - }; - - bool hasScaling = false; - EnumDisplayMonitors(NULL, NULL, enumMonitorCallback, (LPARAM)&hasScaling); - - return hasScaling; -} \ No newline at end of file diff --git a/ScreenPlayWallpaper/src/windowshook.h b/ScreenPlayWallpaper/src/windowshook.h deleted file mode 100644 index d291b36e..00000000 --- a/ScreenPlayWallpaper/src/windowshook.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#include -#include -#include -#include - -struct WinMonitorStats { - - WinMonitorStats() - { - EnumDisplayMonitors(NULL, NULL, MonitorEnum, (LPARAM)this); - } - - static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData); - std::vector iMonitors; - std::vector hMonitors; - std::vector hdcMonitors; - std::vector rcMonitors; - std::vector scaleFactor; - std::vector> sizes; - int index = 0; -}; - -struct Point { - int x = 0; - int y = 0; -}; - -struct WindowsHook { - bool searchWorkerWindowToParentTo(); - float getScaling(const int monitorIndex) const; - bool hasWindowScaling() const; - HWND windowHandle {}; - HWND windowHandleWorker {}; - Point zeroPoint; -}; \ No newline at end of file diff --git a/ScreenPlayWallpaper/src/windowsintegration.h b/ScreenPlayWallpaper/src/windowsintegration.h index b455150e..14cf94a6 100644 --- a/ScreenPlayWallpaper/src/windowsintegration.h +++ b/ScreenPlayWallpaper/src/windowsintegration.h @@ -41,38 +41,7 @@ BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcM BOOL CALLBACK FindTheDesiredWnd(HWND hWnd, LPARAM lParam); BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam); -struct WinMonitorStats { - WinMonitorStats() - { - EnumDisplayMonitors(NULL, NULL, MonitorEnum, (LPARAM)this); - } - - static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData) - { - WinMonitorStats* pThis = reinterpret_cast(pData); - auto scaleFactor = DEVICE_SCALE_FACTOR::DEVICE_SCALE_FACTOR_INVALID; - GetScaleFactorForMonitor(hMon, &scaleFactor); - - UINT x = 0; - UINT y = 0; - GetDpiForMonitor(hMon, MONITOR_DPI_TYPE::MDT_RAW_DPI, &x, &y); - pThis->sizes.push_back({ x, y }); - pThis->scaleFactor.push_back(scaleFactor); - pThis->hMonitors.push_back(hMon); - pThis->hdcMonitors.push_back(hdc); - pThis->rcMonitors.push_back(*lprcMonitor); - pThis->iMonitors.push_back(pThis->hdcMonitors.size()); - - return TRUE; - } - std::vector iMonitors; - std::vector hMonitors; - std::vector hdcMonitors; - std::vector rcMonitors; - std::vector scaleFactor; - std::vector> sizes; -}; struct Point { int x = 0; diff --git a/Tools/setup.py b/Tools/setup.py index 89fdaa1d..53d8589d 100755 --- a/Tools/setup.py +++ b/Tools/setup.py @@ -107,7 +107,7 @@ def main(): parser = argparse.ArgumentParser( description='Build and Package ScreenPlay') parser.add_argument('--skip-aqt', action="store_true", dest="skip_aqt", - help="Downloads QtCreator and needed binaries \Windows: C:\aqt\nLinux & macOS:~/aqt/.") + help="Downloads QtCreator and needed binaries Windows: C:\\aqt\\nLinux & macOS:~/aqt/.") parser.add_argument('--setup-godot', action="store_true", dest="setup_godot", help="Downloads Godot Editor.") args = parser.parse_args()