From f108ec78e261940d271e18caa509dbb93de90165 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 23 Mar 2022 16:51:48 +0100 Subject: [PATCH] Added movetoworkspace --- example/hyprland.conf | 13 ++++++++- src/layout/DwindleLayout.cpp | 11 +++++++- src/managers/KeybindManager.cpp | 50 +++++++++++++++++++++++++++++++-- src/managers/KeybindManager.hpp | 1 + 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index 24793ea3..f2479eb8 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -34,4 +34,15 @@ bind=SUPER,6,workspace,6 bind=SUPER,7,workspace,7 bind=SUPER,8,workspace,8 bind=SUPER,9,workspace,9 -bind=SUPER,0,workspace,10 \ No newline at end of file +bind=SUPER,0,workspace,10 + +bind=ALT,1,movetoworkspace,1 +bind=ALT,2,movetoworkspace,2 +bind=ALT,3,movetoworkspace,3 +bind=ALT,4,movetoworkspace,4 +bind=ALT,5,movetoworkspace,5 +bind=ALT,6,movetoworkspace,6 +bind=ALT,7,movetoworkspace,7 +bind=ALT,8,movetoworkspace,8 +bind=ALT,9,movetoworkspace,9 +bind=ALT,0,movetoworkspace,10 \ No newline at end of file diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index b03f0ffd..3c1ee742 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -116,6 +116,9 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode) { } void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) { + if (pWindow->m_bIsFloating) + return; + m_lDwindleNodesData.push_back(SDwindleNodeData()); const auto PNODE = &m_lDwindleNodesData.back(); @@ -127,7 +130,13 @@ void CHyprDwindleLayout::onWindowCreated(CWindow* pWindow) { PNODE->isNode = false; PNODE->layout = this; - SDwindleNodeData* OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal())); + SDwindleNodeData* OPENINGON; + const auto MONFROMCURSOR = g_pCompositor->getMonitorFromCursor(); + + if (PMONITOR == MONFROMCURSOR) + OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal())); + else + OPENINGON = getFirstNodeOnWorkspace(MONFROMCURSOR->activeWorkspace); // if it's the first, it's easy. Make it fullscreen. if (!OPENINGON) { diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 49afd31d..29273f14 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -35,10 +35,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t // oMg such performance hit!!11! // this little maneouver is gonna cost us 4µs const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); - // TODO: fix this with shift, shift makes all the keys uppercase - // if (shift) KBKEY -= someindex + const auto KBKEYUPPER = xkb_keysym_to_upper(KBKEY); - if (key != KBKEY) + if (key != KBKEY && key != KBKEYUPPER) continue; // yes. @@ -47,6 +46,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t else if (k.handler == "togglefloating") { toggleActiveFloating(k.arg); } else if (k.handler == "workspace") { changeworkspace(k.arg); } else if (k.handler == "fullscreen") { fullscreenActive(k.arg); } + else if (k.handler == "movetoworkspace") { moveActiveToWorkspace(k.arg); } found = true; } @@ -155,4 +155,48 @@ void CKeybindManager::fullscreenActive(std::string args) { return; g_pLayoutManager->getCurrentLayout()->fullscreenRequestForWindow(PWINDOW); +} + +void CKeybindManager::moveActiveToWorkspace(std::string args) { + const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); + + if (!g_pCompositor->windowValidMapped(PWINDOW)) + return; + + int workspaceID; + try { + workspaceID = stoi(args); + } catch( ... ) { + Debug::log(ERR, "Invalid movetoworkspace: %s", args.c_str()); + return; + } + + g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); + + const auto OLDWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + + // hack + g_pKeybindManager->changeworkspace(std::to_string(workspaceID)); + + const auto NEWWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceID); + + OLDWORKSPACE->hasFullscreenWindow = false; + + PWINDOW->m_iWorkspaceID = workspaceID; + PWINDOW->m_iMonitorID = NEWWORKSPACE->monitorID; + PWINDOW->m_bIsFullscreen = false; + + if (NEWWORKSPACE->hasFullscreenWindow) { + g_pCompositor->getFullscreenWindowOnWorkspace(workspaceID)->m_bIsFullscreen = false; + NEWWORKSPACE->hasFullscreenWindow = false; + } + + // Hack: So that the layout doesnt find our window at the cursor + PWINDOW->m_vPosition = Vector2D(-42069, -42069); + g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); + + if (PWINDOW->m_bIsFloating) { + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->monitorID)->vecPosition; + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(NEWWORKSPACE->monitorID)->vecPosition; + } } \ No newline at end of file diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 817b34fb..ae19d589 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -28,6 +28,7 @@ private: void toggleActiveFloating(std::string); void changeworkspace(std::string); void fullscreenActive(std::string); + void moveActiveToWorkspace(std::string); }; inline std::unique_ptr g_pKeybindManager; \ No newline at end of file