diff options
author | Ikalco <[email protected]> | 2024-09-14 17:37:18 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-09-14 23:37:18 +0100 |
commit | e74efd87e5aa38f9cf84cb3848ee1ab26e5e4bcb (patch) | |
tree | 3bcccd577801e01e385410de74be40341a832e2e /src/Compositor.cpp | |
parent | 4dbdb556fe441506ec5cf129c65b14e514dbcc5a (diff) | |
download | Hyprland-e74efd87e5aa38f9cf84cb3848ee1ab26e5e4bcb.tar.gz Hyprland-e74efd87e5aa38f9cf84cb3848ee1ab26e5e4bcb.zip |
internal: fix initial cursor warping (#7793)
Diffstat (limited to 'src/Compositor.cpp')
-rw-r--r-- | src/Compositor.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index da659654..8e1b11b0 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2943,6 +2943,38 @@ PHLWINDOW CCompositor::windowForCPointer(CWindow* pWindow) { return {}; } +static void checkDefaultCursorWarp(SP<CMonitor> monitor) { + static auto PCURSORMONITOR = CConfigValue<std::string>("cursor:default_monitor"); + static bool cursorDefaultDone = false; + static bool firstLaunch = true; + + const auto POS = monitor->middle(); + + // by default, cursor should be set to first monitor detected + // this is needed as a default if the monitor given in config above doesn't exist + if (firstLaunch) { + firstLaunch = false; + g_pCompositor->warpCursorTo(POS, true); + g_pInputManager->refocus(); + return; + } + + if (!cursorDefaultDone && *PCURSORMONITOR != STRVAL_EMPTY) { + if (*PCURSORMONITOR == monitor->szName) { + cursorDefaultDone = true; + g_pCompositor->warpCursorTo(POS, true); + g_pInputManager->refocus(); + return; + } + } + + // modechange happend check if cursor is on that monitor and warp it to middle to not place it out of bounds if resolution changed. + if (g_pCompositor->getMonitorFromCursor() == monitor.get()) { + g_pCompositor->warpCursorTo(POS, true); + g_pInputManager->refocus(); + } +} + void CCompositor::onNewMonitor(SP<Aquamarine::IOutput> output) { // add it to real auto PNEWMONITOR = g_pCompositor->m_vRealMonitors.emplace_back(makeShared<CMonitor>(output)); @@ -2977,6 +3009,8 @@ void CCompositor::onNewMonitor(SP<Aquamarine::IOutput> output) { g_pConfigManager->m_bWantsMonitorReload = true; g_pCompositor->scheduleFrameForMonitor(PNEWMONITOR.get(), IOutput::AQ_SCHEDULE_NEW_MONITOR); + checkDefaultCursorWarp(PNEWMONITOR); + for (auto const& w : g_pCompositor->m_vWindows) { if (w->m_iMonitorID == PNEWMONITOR->ID) { w->m_iLastSurfaceMonitorID = MONITOR_INVALID; |