1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-03 00:59:47 +02:00

Remove old code

This commit is contained in:
Elias Steurer 2023-11-12 07:32:45 +01:00
parent 4849905a4a
commit c9498b366e
5 changed files with 11 additions and 194 deletions

View File

@ -114,16 +114,15 @@ void MonitorListModel::loadMonitors()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QModelIndex index; QModelIndex index;
WinMonitorStats monitors; auto monitors = WindowsIntegration().GetAllMonitors();
// This offset lets us center the monitor selection view in the center // This offset lets us center the monitor selection view in the center
int offsetX = 0; int offsetX = 0;
int offsetY = 0; int offsetY = 0;
const int moinitorCount = monitors.iMonitors.size();
for (int i = 0; i < moinitorCount; i++) { for (auto& monitor : monitors) {
const int x = monitors.rcMonitors[i].left; const int x = monitor.position.left;
const int y = monitors.rcMonitors[i].top; const int y = monitor.position.top;
if (x < 0) { if (x < 0) {
offsetX += (x * -1); offsetX += (x * -1);
} }
@ -132,11 +131,11 @@ void MonitorListModel::loadMonitors()
} }
} }
for (int i = 0; i < moinitorCount; i++) { for(int i = 0; auto& monitor : monitors) {
const int width = std::abs(monitors.rcMonitors[i].right - monitors.rcMonitors[i].left); const int width = std::abs(monitor.position.right - monitor.position.left);
const int height = std::abs(monitors.rcMonitors[i].top - monitors.rcMonitors[i].bottom); const int height = std::abs(monitor.position.top - monitor.position.bottom);
const int x = monitors.rcMonitors[i].left; const int x = monitor.position.left;
const int y = monitors.rcMonitors[i].top; const int y = monitor.position.top;
QRect geometry( QRect geometry(
x + offsetX, x + offsetX,
y + offsetY, y + offsetY,
@ -145,6 +144,7 @@ void MonitorListModel::loadMonitors()
beginInsertRows(index, m_monitorList.size(), m_monitorList.size()); beginInsertRows(index, m_monitorList.size(), m_monitorList.size());
m_monitorList.append(Monitor { i, geometry }); m_monitorList.append(Monitor { i, geometry });
endInsertRows(); endInsertRows();
i++;
} }
#else #else
QModelIndex index; QModelIndex index;

View File

@ -1,111 +0,0 @@
#include "windowshook.h"
BOOL CALLBACK WinMonitorStats::MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData)
{
WinMonitorStats* pThis = reinterpret_cast<WinMonitorStats*>(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<int>(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<HWND*>(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<LPARAM>(&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;
}

View File

@ -1,41 +0,0 @@
#pragma once
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#include <algorithm>
#include <iostream>
#include <shellscalingapi.h>
#include <vector>
struct WinMonitorStats {
WinMonitorStats()
{
EnumDisplayMonitors(NULL, NULL, MonitorEnum, (LPARAM)this);
}
static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData);
std::vector<int> iMonitors;
std::vector<HMONITOR> hMonitors;
std::vector<HDC> hdcMonitors;
std::vector<RECT> rcMonitors;
std::vector<DEVICE_SCALE_FACTOR> scaleFactor;
std::vector<std::pair<UINT, UINT>> 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;
};

View File

@ -41,38 +41,7 @@ BOOL CALLBACK GetMonitorByHandle(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcM
BOOL CALLBACK FindTheDesiredWnd(HWND hWnd, LPARAM lParam); BOOL CALLBACK FindTheDesiredWnd(HWND hWnd, LPARAM lParam);
BOOL WINAPI SearchForWorkerWindow(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<WinMonitorStats*>(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<size_t> iMonitors;
std::vector<HMONITOR> hMonitors;
std::vector<HDC> hdcMonitors;
std::vector<RECT> rcMonitors;
std::vector<DEVICE_SCALE_FACTOR> scaleFactor;
std::vector<std::pair<UINT, UINT>> sizes;
};
struct Point { struct Point {
int x = 0; int x = 0;

View File

@ -107,7 +107,7 @@ def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Build and Package ScreenPlay') description='Build and Package ScreenPlay')
parser.add_argument('--skip-aqt', action="store_true", dest="skip_aqt", 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", parser.add_argument('--setup-godot', action="store_true", dest="setup_godot",
help="Downloads Godot Editor.") help="Downloads Godot Editor.")
args = parser.parse_args() args = parser.parse_args()