1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-18 16:32:33 +02:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Elias Steurer 2023-07-13 14:20:38 +02:00
commit daaeeff824
2 changed files with 47 additions and 30 deletions

View File

@ -5,7 +5,9 @@
#include <QtQml> #include <QtQml>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <shellscalingapi.h>
#include <vector> #include <vector>
#include <windows.h>
/*! /*!
\class WinWindow \class WinWindow
@ -148,7 +150,7 @@ ScreenPlay::WallpaperExitCode WinWindow::start()
configureWindowGeometry(); configureWindowGeometry();
// We do not support autopause for multi monitor wallpaper and // We do not support autopause for multi monitor wallpaper and
// wallpaper than contain audio, see BaseWindow::setup(). // wallpaper than contain audio, see BaseWindow::setup().
if (activeScreensList().length() == 1) { if (activeScreensList().length() == 1) {
if (checkWallpaperVisible()) { if (checkWallpaperVisible()) {
@ -217,8 +219,9 @@ void WinWindow::setupWallpaperForOneScreen(int activeScreen)
const int borderOffset = -1; const int borderOffset = -1;
ScreenPlayUtil::WinMonitorStats monitors; ScreenPlayUtil::WinMonitorStats monitors;
const int width = std::abs(monitors.rcMonitors[activeScreen].right - monitors.rcMonitors[activeScreen].left) + boderWidth; const int width = (std::abs(monitors.rcMonitors[activeScreen].right - monitors.rcMonitors[activeScreen].left) / scaling) + boderWidth;
const int height = std::abs(monitors.rcMonitors[activeScreen].top - monitors.rcMonitors[activeScreen].bottom) + boderWidth; const int height = (std::abs(monitors.rcMonitors[activeScreen].top - monitors.rcMonitors[activeScreen].bottom) / scaling) + boderWidth;
const int x = monitors.rcMonitors[activeScreen].left + m_zeroPoint.x() + borderOffset; const int x = monitors.rcMonitors[activeScreen].left + m_zeroPoint.x() + borderOffset;
const int y = monitors.rcMonitors[activeScreen].top + m_zeroPoint.y() + borderOffset; const int y = monitors.rcMonitors[activeScreen].top + m_zeroPoint.y() + borderOffset;
qInfo() << QString("Setup window activeScreen: %1 scaling: %2 x: %3 y: %4 width: %5 height: %6").arg(activeScreen).arg(scaling).arg(x).arg(y).arg(width).arg(height); qInfo() << QString("Setup window activeScreen: %1 scaling: %2 x: %3 y: %4 width: %5 height: %6").arg(activeScreen).arg(scaling).arg(x).arg(y).arg(width).arg(height);
@ -328,38 +331,52 @@ bool WinWindow::searchWorkerWindowToParentTo()
} }
/*! /*!
\brief Reads the physicalDotsPerInch and mapps them to scaling factors. \brief Returns scaling factor as reported by Windows.
This is needed to detect if the user has different monitors with
different scaling factors.
screen->physicalDotsPerInch()
100% -> 109 -> 1
125% -> 120 -> 1.25
150% -> 161 -> 1.5
...
*/ */
float WinWindow::getScaling(const int monitorIndex) float WinWindow::getScaling(const int monitorIndex) const
{ {
QScreen* screen = QGuiApplication::screens().at(monitorIndex); // Get all monitors
const int factor = screen->physicalDotsPerInch(); int monitorCount = GetSystemMetrics(SM_CMONITORS);
switch (factor) {
case 72: if (monitorIndex < 0 || monitorIndex >= monitorCount) {
return 1; // Invalid monitor index
case 107: return 1.0f;
return 1.5;
case 109:
return 1;
case 161:
return 1;
default:
qWarning() << "Monitor with factor: " << factor << " detected! This is not supported!";
return 1;
} }
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. \brief Returns true of at least one monitor has active scaling enabled.
*/ */
bool WinWindow::hasWindowScaling() bool WinWindow::hasWindowScaling() const
{ {
const auto screens = QGuiApplication::screens(); const auto screens = QGuiApplication::screens();
for (int i = 0; i < screens.count(); i++) { for (int i = 0; i < screens.count(); i++) {

View File

@ -55,8 +55,8 @@ private:
void setupWindowMouseHook(); void setupWindowMouseHook();
bool searchWorkerWindowToParentTo(); bool searchWorkerWindowToParentTo();
void configureWindowGeometry(); void configureWindowGeometry();
float getScaling(const int monitorIndex); bool hasWindowScaling() const;
bool hasWindowScaling(); float getScaling(const int monitorIndex) const;
private slots: private slots:
void checkForFullScreenWindow(); void checkForFullScreenWindow();