From 5b866b643be559c41662f5e67ee4fecbbcc1f2f8 Mon Sep 17 00:00:00 2001 From: nothingTVatYT Date: Sun, 8 Oct 2023 22:05:53 +0200 Subject: [PATCH] fix GetDesktopSize for Linux --- .../Engine/Platform/Linux/LinuxPlatform.cpp | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index af2c02ca6..4787b4549 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -2700,6 +2700,8 @@ Float2 LinuxPlatform::GetDesktopSize() if (screenIdx >= count) return Float2::Zero; + // this function is used as a fallback to place a window at the center of + // a screen so we report only one screen instead of the real desktop Float2 size((float)xsi[screenIdx].width, (float)xsi[screenIdx].height); X11::XFree(xsi); return size; @@ -2739,8 +2741,40 @@ Rectangle LinuxPlatform::GetMonitorBounds(const Float2& screenPos) Rectangle LinuxPlatform::GetVirtualDesktopBounds() { - // TODO: do it in a proper way - return Rectangle(Float2::Zero, GetDesktopSize()); + if (!xDisplay) + return Rectangle::Empty; + + int event, err; + const bool ok = X11::XineramaQueryExtension(xDisplay, &event, &err); + if (!ok) + return Rectangle::Empty; + + int count; + X11::XineramaScreenInfo* xsi = X11::XineramaQueryScreens(xDisplay, &count); + if (count <= 0) + return Rectangle::Empty; + // get all screen dimensions and assume the monitors form a rectangle + // as you can arrange monitors to your liking this is not necessarily the case + int minX = INT32_MAX, minY = INT32_MAX; + int maxX = 0, maxY = 0; + for (int i = 0; i < count; i++) + { + int maxScreenX = xsi[i].x_org + xsi[i].width; + int maxScreenY = xsi[i].y_org + xsi[i].height; + if (maxScreenX > maxX) + maxX = maxScreenX; + if (maxScreenY > maxY) + maxY = maxScreenY; + if (minX > xsi[i].x_org) + minX = xsi[i].x_org; + if (minY > xsi[i].y_org) + minY = xsi[i].y_org; + } + + Float2 org(static_cast(minX), static_cast(minY)); + Float2 size(static_cast(maxX - minX), static_cast(maxY - minY)); + X11::XFree(xsi); + return Rectangle(org, size); } String LinuxPlatform::GetMainDirectory()