From c24b45671abe1f768e9b5e0a35930ad76e2d8bcc Mon Sep 17 00:00:00 2001 From: vaxerski Date: Mon, 19 Sep 2022 19:04:48 +0100 Subject: mouse binds overhaul --- src/managers/KeybindManager.cpp | 43 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9b4827c9..47f42e2b 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -43,6 +43,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["swapnext"] = swapnext; m_mDispatchers["swapactiveworkspaces"] = swapActiveWorkspaces; m_mDispatchers["pin"] = pinActive; + m_mDispatchers["mouse"] = mouse; m_tScrollTimer.reset(); } @@ -278,7 +279,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& } for (auto& k : m_lKeybinds) { - if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release && k.handler != "pass") || k.shadowed) + if (modmask != k.modmask || (g_pCompositor->m_sSeat.exclusiveClient && !k.locked) || k.submap != m_szCurrentSelectedSubmap || (!pressed && !k.release && k.handler != "pass" && k.handler != "mouse") || k.shadowed) continue; if (!key.empty()) { @@ -307,7 +308,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& return true; } - const auto DISPATCHER = m_mDispatchers.find(k.handler); + const auto DISPATCHER = m_mDispatchers.find(k.mouse ? "mouse" : k.handler); // Should never happen, as we check in the ConfigManager, but oh well if (DISPATCHER == m_mDispatchers.end()) { @@ -318,7 +319,10 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const std::string& m_iPassPressed = (int)pressed; - DISPATCHER->second(k.arg); + if (k.handler == "mouse") + DISPATCHER->second((pressed ? "1" : "0") + k.arg); + else + DISPATCHER->second(k.arg); m_iPassPressed = -1; @@ -1576,3 +1580,36 @@ void CKeybindManager::pinActive(std::string args) { PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal()); } + +void CKeybindManager::mouse(std::string args) { + const auto TRUEARG = args.substr(1); + const auto PRESSED = args[0] == '1'; + + if (TRUEARG == "movewindow") { + if (PRESSED) { + g_pInputManager->currentlyDraggedWindow = g_pCompositor->windowFromCursor(); + g_pInputManager->dragMode = MBIND_MOVE; + + g_pLayoutManager->getCurrentLayout()->onBeginDragWindow(); + } else { + if (g_pInputManager->currentlyDraggedWindow) { + g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); + g_pInputManager->currentlyDraggedWindow = nullptr; + g_pInputManager->dragMode = MBIND_INVALID; + } + } + } else if (TRUEARG == "resizewindow") { + if (PRESSED) { + g_pInputManager->currentlyDraggedWindow = g_pCompositor->windowFromCursor(); + g_pInputManager->dragMode = MBIND_RESIZE; + + g_pLayoutManager->getCurrentLayout()->onBeginDragWindow(); + } else { + if (g_pInputManager->currentlyDraggedWindow) { + g_pLayoutManager->getCurrentLayout()->onEndDragWindow(); + g_pInputManager->currentlyDraggedWindow = nullptr; + g_pInputManager->dragMode = MBIND_INVALID; + } + } + } +} -- cgit v1.2.3