From 3904351678f9e76ee67896e39641c82efbb9ed01 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 28 Jul 2022 12:00:10 +0200 Subject: [PATCH] Added layoutmsg and some master layout msgs --- src/layout/MasterLayout.cpp | 105 +++++++++++++++++++++++++++++++- src/managers/KeybindManager.cpp | 6 ++ src/managers/KeybindManager.hpp | 1 + 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index eb92458b..0599d573 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -406,7 +406,110 @@ void CHyprMasterLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) { } std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::string message) { - return ""; + auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { + g_pCompositor->focusWindow(PWINDOWTOCHANGETO); + Vector2D middle = PWINDOWTOCHANGETO->m_vRealPosition.goalv() + PWINDOWTOCHANGETO->m_vRealSize.goalv() / 2.f; + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); + }; + + if (message == "swapwithmaster") { + + const auto PWINDOW = header.pWindow; + + if (!isWindowTiled(PWINDOW)) + return 0; + + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + + if (!PMASTER || PMASTER->pWindow == PWINDOW) + return 0; + + switchWindows(PWINDOW, PMASTER->pWindow); + + switchToWindow(PWINDOW); + + return 0; + } else if (message == "cyclenext") { + const auto PWINDOW = header.pWindow; + + if (!isWindowTiled(PWINDOW)) + return 0; + + const auto PNODE = getNodeFromWindow(PWINDOW); + + if (PNODE->isMaster) { + // focus the first non master + for (auto n : m_lMasterNodesData) { + if (n.pWindow != PWINDOW && n.workspaceID == PWINDOW->m_iWorkspaceID) { + switchToWindow(n.pWindow); + break; + } + } + } else { + // focus next + bool reached = false; + bool found = false; + for (auto n : m_lMasterNodesData) { + if (n.pWindow == PWINDOW) { + reached = true; + continue; + } + + if (n.workspaceID == PWINDOW->m_iWorkspaceID && reached) { + switchToWindow(n.pWindow); + found = true; + break; + } + } + if (!found) { + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + + if (PMASTER) + switchToWindow(PMASTER->pWindow); + } + } + } else if (message == "cycleprev") { + const auto PWINDOW = header.pWindow; + + if (!isWindowTiled(PWINDOW)) + return 0; + + const auto PNODE = getNodeFromWindow(PWINDOW); + + if (PNODE->isMaster) { + // focus the first non master + for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) { + if (it->pWindow != PWINDOW && it->workspaceID == PWINDOW->m_iWorkspaceID) { + switchToWindow(it->pWindow); + break; + } + } + } else { + // focus next + bool reached = false; + bool found = false; + for (auto it = m_lMasterNodesData.rbegin(); it != m_lMasterNodesData.rend(); it++) { + if (it->pWindow == PWINDOW) { + reached = true; + continue; + } + + if (it->workspaceID == PWINDOW->m_iWorkspaceID && reached) { + switchToWindow(it->pWindow); + found = true; + break; + } + } + if (!found) { + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + + if (PMASTER) + switchToWindow(PMASTER->pWindow); + } + } + } + + return 0; } void CHyprMasterLayout::onEnable() { diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9910ed6c..15ff0533 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -34,6 +34,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["focuswindow"] = focusWindow; m_mDispatchers["submap"] = setSubmap; m_mDispatchers["pass"] = pass; + m_mDispatchers["layoutmsg"] = layoutmsg; m_tScrollTimer.reset(); } @@ -1303,4 +1304,9 @@ void CKeybindManager::pass(std::string regexp) { wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastCode - 8, WLR_BUTTON_RELEASED); wlr_seat_keyboard_notify_enter(g_pCompositor->m_sSeat.seat, PLASTSRF, KEYBOARD->keycodes, KEYBOARD->num_keycodes, &KEYBOARD->modifiers); +} + +void CKeybindManager::layoutmsg(std::string msg) { + SLayoutMessageHeader hd = {g_pCompositor->m_pLastWindow}; + g_pLayoutManager->getCurrentLayout()->layoutMessage(hd, msg); } \ No newline at end of file diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index bddbca6c..5ac98534 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -96,6 +96,7 @@ private: static void focusWindow(std::string); static void setSubmap(std::string); static void pass(std::string); + static void layoutmsg(std::string); friend class CCompositor; };