From 82fd62aa20c1eb16802ad4f4f5a7b55901e494d3 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Wed, 27 Mar 2024 18:43:27 +0100 Subject: [PATCH] Respect monitor scale --- src/Wayland.cpp | 9 +++++++-- src/Wayland.h | 1 + src/Window.cpp | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Wayland.cpp b/src/Wayland.cpp index e007b07..dcb66ae 100644 --- a/src/Wayland.cpp +++ b/src/Wayland.cpp @@ -188,7 +188,12 @@ namespace Wayland it->second.height = height; } static void OnOutputDone(void*, wl_output* output) {} - static void OnOutputScale(void*, wl_output*, int32_t) {} + static void OnOutputScale(void*, wl_output* output, int32_t scale) + { + auto it = monitors.find(output); + ASSERT(it != monitors.end(), "Error: OnOutputScale called on unknown monitor"); + it->second.scale = scale; + } static void OnOutputName(void*, wl_output* output, const char* name) { auto it = monitors.find(output); @@ -206,7 +211,7 @@ namespace Wayland if (strcmp(interface, "wl_output") == 0) { wl_output* output = (wl_output*)wl_registry_bind(registry, name, &wl_output_interface, 4); - Monitor mon = Monitor{"", name, 0, 0, nullptr, (uint32_t)monitors.size()}; + Monitor mon = Monitor{"", name, 0, 0, 0, nullptr, (uint32_t)monitors.size()}; monitors.emplace(output, mon); LOG("Wayland: Register at ID " << mon.ID); diff --git a/src/Wayland.h b/src/Wayland.h index 70b6864..7a594b8 100644 --- a/src/Wayland.h +++ b/src/Wayland.h @@ -12,6 +12,7 @@ namespace Wayland uint32_t wlName; int32_t width; int32_t height; + int32_t scale; // TODO: Handle fractional scaling zext_workspace_group_handle_v1* workspaceGroup; // The Gdk monitor index. This is only a hacky approximation, since there is no way to get the wl_output from a GdkMonitor uint32_t ID; diff --git a/src/Window.cpp b/src/Window.cpp index 052cfc1..50120be 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -246,7 +246,7 @@ int Window::GetWidth() const const Wayland::Monitor* mon = Wayland::FindMonitorByName(m_MonitorName); ASSERT(mon, "Window: Couldn't find monitor"); - return mon->width; + return mon->width / mon->scale; } int Window::GetHeight() const @@ -257,7 +257,7 @@ int Window::GetHeight() const const Wayland::Monitor* mon = Wayland::FindMonitorByName(m_MonitorName); ASSERT(mon, "Window: Couldn't find monitor"); - return mon->width; + return mon->height / mon->scale; } void Window::MonitorAdded(GdkDisplay*, GdkMonitor*)