diff options
Diffstat (limited to 'src/managers')
-rw-r--r-- | src/managers/XWaylandManager.cpp | 30 | ||||
-rw-r--r-- | src/managers/XWaylandManager.hpp | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 832173eb..5e5c6262 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -213,6 +213,36 @@ void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscree pWindow->m_pXDGSurface->toplevel->setFullscreen(fullscreen); } +Vector2D CHyprXWaylandManager::waylandToXWaylandCoords(const Vector2D& coord) { + static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling"); + + PHLMONITOR pMonitor = nullptr; + double bestDistance = __FLT_MAX__; + for (const auto& m : g_pCompositor->m_vMonitors) { + const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize; + + double distance = vecToRectDistanceSquared(coord, {m->vecPosition.x, m->vecPosition.y}, {m->vecPosition.x + SIZ.x - 1, m->vecPosition.y + SIZ.y - 1}); + + if (distance < bestDistance) { + bestDistance = distance; + pMonitor = m; + } + } + + if (!pMonitor) + return Vector2D{}; + + // get local coords + Vector2D result = coord - pMonitor->vecPosition; + // if scaled, scale + if (*PXWLFORCESCALEZERO) + result *= pMonitor->scale; + // add pos + result += pMonitor->vecXWaylandPosition; + + return result; +} + Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { static auto PXWLFORCESCALEZERO = CConfigValue<Hyprlang::INT>("xwayland:force_zero_scaling"); diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index 508a20d6..18627a78 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -22,6 +22,7 @@ class CHyprXWaylandManager { bool shouldBeFloated(PHLWINDOW, bool pending = false); void checkBorders(PHLWINDOW); Vector2D xwaylandToWaylandCoords(const Vector2D&); + Vector2D waylandToXWaylandCoords(const Vector2D&); }; inline std::unique_ptr<CHyprXWaylandManager> g_pXWaylandManager;
\ No newline at end of file |