diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index acc027f3..72daf5ce 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -18,6 +18,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["togglesplit"] = toggleSplit; m_mDispatchers["splitratio"] = alterSplitRatio; m_mDispatchers["focusmonitor"] = focusMonitor; + m_mDispatchers["movecursortocorner"] = moveCursorToCorner; } void CKeybindManager::addKeybind(SKeybind kb) { @@ -556,3 +557,41 @@ void CKeybindManager::focusMonitor(std::string arg) { Debug::log(ERR, "Error in focusMonitor: no such monitor"); } } + +void CKeybindManager::moveCursorToCorner(std::string arg) { + if (!isNumber(arg)) { + Debug::log(ERR, "moveCursorToCorner, arg has to be a number."); + return; + } + + const auto CORNER = std::stoi(arg); + + if (CORNER < 0 || CORNER > 3) { + Debug::log(ERR, "moveCursorToCorner, corner not 0 - 3."); + return; + } + + const auto PWINDOW = g_pCompositor->m_pLastWindow; + + if (!g_pCompositor->windowValidMapped(PWINDOW)) + return; + + switch (CORNER) { + case 0: + // bottom left + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y + PWINDOW->m_vRealSize.vec().y); + break; + case 1: + // bottom right + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x + PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealPosition.vec().y + PWINDOW->m_vRealSize.vec().y); + break; + case 2: + // top right + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x + PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealPosition.vec().y); + break; + case 3: + // top left + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y); + break; + } +} \ No newline at end of file diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 014f2cdd..4317d7f6 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -46,6 +46,7 @@ private: static void alterSplitRatio(std::string); static void focusMonitor(std::string); static void toggleSplit(std::string); + static void moveCursorToCorner(std::string); }; inline std::unique_ptr g_pKeybindManager; \ No newline at end of file