mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-07 03:22:33 +01:00
Fix Qt6 scaling changes on Windows
This commit is contained in:
parent
fc4fb2ccdd
commit
e6d817d1e0
@ -107,8 +107,8 @@ LRESULT __stdcall MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam)
|
|||||||
if (type == QMouseEvent::Type::MouseButtonPress) {
|
if (type == QMouseEvent::Type::MouseButtonPress) {
|
||||||
}
|
}
|
||||||
QTimer::singleShot(100, [&]() {
|
QTimer::singleShot(100, [&]() {
|
||||||
//auto eventPress = QMouseEvent(QMouseEvent::Type::MouseButtonPress, g_LastMousePosition, mouseButton, mouseButtons, {});
|
// auto eventPress = QMouseEvent(QMouseEvent::Type::MouseButtonPress, g_LastMousePosition, mouseButton, mouseButtons, {});
|
||||||
//qInfo() << mouseButton << QApplication::sendEvent(g_winGlobalHook, &eventPress) << g_globalOffset.x() << g_globalOffset.y();
|
// qInfo() << mouseButton << QApplication::sendEvent(g_winGlobalHook, &eventPress) << g_globalOffset.x() << g_globalOffset.y();
|
||||||
auto eventRelease = QMouseEvent(QMouseEvent::Type::MouseButtonRelease, g_LastMousePosition, mouseButton, mouseButtons, {});
|
auto eventRelease = QMouseEvent(QMouseEvent::Type::MouseButtonRelease, g_LastMousePosition, mouseButton, mouseButtons, {});
|
||||||
QApplication::sendEvent(g_winGlobalHook, &eventRelease);
|
QApplication::sendEvent(g_winGlobalHook, &eventRelease);
|
||||||
});
|
});
|
||||||
@ -224,14 +224,8 @@ WinWindow::WinWindow(
|
|||||||
qmlRegisterSingletonInstance<WinWindow>("ScreenPlayWallpaper", 1, 0, "Wallpaper", this);
|
qmlRegisterSingletonInstance<WinWindow>("ScreenPlayWallpaper", 1, 0, "Wallpaper", this);
|
||||||
|
|
||||||
configureWindowGeometry();
|
configureWindowGeometry();
|
||||||
bool hasWindowScaling = false;
|
|
||||||
for (int i = 0; i < screens.count(); i++) {
|
if (hasWindowScaling()) {
|
||||||
if (getScaling(i) != 1) {
|
|
||||||
hasWindowScaling = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasWindowScaling) {
|
|
||||||
qInfo() << "Monitor with scaling detected!";
|
qInfo() << "Monitor with scaling detected!";
|
||||||
configureWindowGeometry();
|
configureWindowGeometry();
|
||||||
}
|
}
|
||||||
@ -296,45 +290,27 @@ BOOL CALLBACK GetMonitorByIndex(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMo
|
|||||||
*/
|
*/
|
||||||
void WinWindow::setupWallpaperForOneScreen(int activeScreen)
|
void WinWindow::setupWallpaperForOneScreen(int activeScreen)
|
||||||
{
|
{
|
||||||
|
|
||||||
const QRect screenRect = QApplication::screens().at(activeScreen)->geometry();
|
const QRect screenRect = QApplication::screens().at(activeScreen)->geometry();
|
||||||
|
|
||||||
const float scaling = 1; //getScaling(activeScreen);
|
|
||||||
for (int i = 0; i < QApplication::screens().count(); i++) {
|
|
||||||
// qInfo() << i << "scaling " << getScaling(i) << QApplication::screens().at(i)->geometry();
|
|
||||||
}
|
|
||||||
|
|
||||||
// qInfo() << activeScreen << "Monitor 0" << getScaling(0) << QApplication::screens().at(0)->geometry();
|
|
||||||
// qInfo() << activeScreen << "Monitor 1" << getScaling(1) << QApplication::screens().at(1)->geometry();
|
|
||||||
|
|
||||||
WinMonitorStats Monitors;
|
|
||||||
int width = std::abs(Monitors.rcMonitors[activeScreen].right - Monitors.rcMonitors[activeScreen].left);
|
|
||||||
int height = std::abs(Monitors.rcMonitors[activeScreen].top - Monitors.rcMonitors[activeScreen].bottom);
|
|
||||||
//qInfo() << "scaling " << scaling << width << height << " activeScreen " << activeScreen;
|
|
||||||
//qInfo() << "scaling " << scaling << screenRect.width() << screenRect.height() << " activeScreen " << activeScreen;
|
|
||||||
|
|
||||||
const int boderWidth = 2;
|
const int boderWidth = 2;
|
||||||
const int borderOffset = -1;
|
const float scaling = getScaling(activeScreen);
|
||||||
// Needs to be set like to this work. I do not know why...
|
const auto width = screenRect.width() * scaling + boderWidth;
|
||||||
if (!SetWindowPos(
|
const auto height = screenRect.height() * scaling + boderWidth;
|
||||||
m_windowHandle,
|
|
||||||
nullptr,
|
|
||||||
Monitors.rcMonitors[activeScreen].left + borderOffset,
|
|
||||||
Monitors.rcMonitors[activeScreen].top + borderOffset,
|
|
||||||
width + boderWidth,
|
|
||||||
height + boderWidth,
|
|
||||||
SWP_HIDEWINDOW)) {
|
|
||||||
qFatal("Could not set window pos");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetWindowPos(
|
const int borderOffset = -1;
|
||||||
m_windowHandle,
|
const int x = screenRect.x() + m_zeroPoint.x() + borderOffset;
|
||||||
nullptr,
|
const int y = screenRect.y() + m_zeroPoint.y() + borderOffset;
|
||||||
screenRect.x() + m_zeroPoint.x() + borderOffset,
|
|
||||||
screenRect.y() + 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);
|
||||||
screenRect.width() * scaling + boderWidth,
|
|
||||||
screenRect.height() * scaling + boderWidth,
|
{
|
||||||
SWP_HIDEWINDOW)) {
|
// Must be called twice for some reason when window has scaling...
|
||||||
qFatal("Could not set window pos");
|
if (!SetWindowPos(m_windowHandle, nullptr, x, y, width, height, SWP_HIDEWINDOW)) {
|
||||||
|
qFatal("Could not set window pos");
|
||||||
|
}
|
||||||
|
if (!SetWindowPos(m_windowHandle, nullptr, x, y, width, height, SWP_HIDEWINDOW)) {
|
||||||
|
qFatal("Could not set window pos");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SetParent(m_windowHandle, m_windowHandleWorker) == nullptr) {
|
if (SetParent(m_windowHandle, m_windowHandleWorker) == nullptr) {
|
||||||
@ -407,44 +383,48 @@ bool WinWindow::searchWorkerWindowToParentTo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Reads the logicalDotsPerInch and mapps them to scaling factors.
|
\brief Reads the physicalDotsPerInch and mapps them to scaling factors.
|
||||||
This is needed to detect if the user has different monitors with
|
This is needed to detect if the user has different monitors with
|
||||||
different scaling factors.
|
different scaling factors.
|
||||||
|
|
||||||
screen->logicalDotsPerInch()
|
screen->physicalDotsPerInch()
|
||||||
100% -> 96 -> 1
|
100% -> 109 -> 1
|
||||||
125% -> 120 -> 1.25
|
125% -> 120 -> 1.25
|
||||||
150% -> 144 -> 1.5
|
150% -> 161 -> 1.5
|
||||||
...
|
...
|
||||||
*/
|
*/
|
||||||
float WinWindow::getScaling(const int monitorIndex)
|
float WinWindow::getScaling(const int monitorIndex)
|
||||||
{
|
{
|
||||||
QScreen* screen = QApplication::screens().at(monitorIndex);
|
QScreen* screen = QApplication::screens().at(monitorIndex);
|
||||||
const int factor = screen->logicalDotsPerInch();
|
const int factor = screen->physicalDotsPerInch();
|
||||||
switch (factor) {
|
switch (factor) {
|
||||||
case 96:
|
case 72:
|
||||||
return 1;
|
return 1;
|
||||||
case 120:
|
case 107:
|
||||||
return 1.25;
|
|
||||||
case 144:
|
|
||||||
return 1.5;
|
return 1.5;
|
||||||
case 168:
|
|
||||||
return 1.75;
|
case 109:
|
||||||
case 192:
|
return 1;
|
||||||
return 2;
|
case 161:
|
||||||
case 216:
|
return 1;
|
||||||
return 2.25;
|
|
||||||
case 240:
|
|
||||||
return 2.5;
|
|
||||||
case 288:
|
|
||||||
return 3;
|
|
||||||
case 336:
|
|
||||||
return 3.5;
|
|
||||||
default:
|
default:
|
||||||
qWarning() << "Monitor with factor: " << factor << " detected! This is not supported!";
|
qWarning() << "Monitor with factor: " << factor << " detected! This is not supported!";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*!
|
||||||
|
\brief Returns true of at least one monitor has active scaling enabled.
|
||||||
|
*/
|
||||||
|
bool WinWindow::hasWindowScaling()
|
||||||
|
{
|
||||||
|
const auto screens = QApplication::screens();
|
||||||
|
for (int i = 0; i < screens.count(); i++) {
|
||||||
|
if (getScaling(i) != 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Sets the size and the parent to the worker handle to be displayed behind the
|
\brief Sets the size and the parent to the worker handle to be displayed behind the
|
||||||
@ -452,7 +432,7 @@ float WinWindow::getScaling(const int monitorIndex)
|
|||||||
*/
|
*/
|
||||||
void WinWindow::configureWindowGeometry()
|
void WinWindow::configureWindowGeometry()
|
||||||
{
|
{
|
||||||
ShowWindow(m_windowHandle, SW_HIDE);
|
setVisible(false);
|
||||||
|
|
||||||
if (!searchWorkerWindowToParentTo()) {
|
if (!searchWorkerWindowToParentTo()) {
|
||||||
qFatal("No worker window found");
|
qFatal("No worker window found");
|
||||||
|
@ -96,6 +96,7 @@ private:
|
|||||||
bool searchWorkerWindowToParentTo();
|
bool searchWorkerWindowToParentTo();
|
||||||
void configureWindowGeometry();
|
void configureWindowGeometry();
|
||||||
float getScaling(const int monitorIndex);
|
float getScaling(const int monitorIndex);
|
||||||
|
bool hasWindowScaling();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void checkForFullScreenWindow();
|
void checkForFullScreenWindow();
|
||||||
|
Loading…
Reference in New Issue
Block a user