diff options
author | vaxerski <[email protected]> | 2022-04-21 16:38:48 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2022-04-21 16:38:48 +0200 |
commit | b618fc1caa4063bbed8373935db7e00b2f0cc9fe (patch) | |
tree | 3080cea972386b28dc7d624c1a7c600f6e8124a4 | |
parent | c02afa0c2725b353c56706fa0186143f661cc283 (diff) | |
download | Hyprland-b618fc1caa4063bbed8373935db7e00b2f0cc9fe.tar.gz Hyprland-b618fc1caa4063bbed8373935db7e00b2f0cc9fe.zip |
Added named workspaces
-rw-r--r-- | src/Compositor.cpp | 34 | ||||
-rw-r--r-- | src/Compositor.hpp | 3 | ||||
-rw-r--r-- | src/helpers/Workspace.hpp | 3 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 49 |
4 files changed, 71 insertions, 18 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 2ed12112..0a0a55e4 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -708,4 +708,38 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow) { } return nullptr; +} + +int CCompositor::getNextAvailableNamedWorkspace() { + int highest = -1337 - 1; + for (auto& w : m_lWorkspaces) { + if (w.m_iID < 0 && w.m_iID > highest) + highest = w.m_iID; + } + + return highest + 1; +} + +CWorkspace* CCompositor::getWorkspaceByName(const std::string& name) { + for (auto& w : m_lWorkspaces) { + if (w.m_szName == name) + return &w; + } + + return nullptr; +} + +CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) { + if (str.find("name:") == 0) { + return getWorkspaceByName(str.substr(str.find_first_of(':') + 1)); + } + + try { + int id = std::stoi(str); + return getWorkspaceByID(id); + } catch (std::exception& e) { + Debug::log(ERR, "Error in getWorkspaceByString, invalid id"); + } + + return nullptr; }
\ No newline at end of file diff --git a/src/Compositor.hpp b/src/Compositor.hpp index ebc2abe3..2fff5078 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -96,6 +96,8 @@ public: CWindow* getWindowFromSurface(wlr_surface*); bool isWorkspaceVisible(const int&); CWorkspace* getWorkspaceByID(const int&); + CWorkspace* getWorkspaceByName(const std::string&); + CWorkspace* getWorkspaceByString(const std::string&); void sanityCheckWorkspaces(); int getWindowsOnWorkspace(const int&); CWindow* getFirstWindowOnWorkspace(const int&); @@ -108,6 +110,7 @@ public: CWindow* getWindowInDirection(CWindow*, char); void deactivateAllWLRWorkspaces(); CWindow* getNextWindowOnWorkspace(CWindow*); + int getNextAvailableNamedWorkspace(); private: void initAllSignals(); diff --git a/src/helpers/Workspace.hpp b/src/helpers/Workspace.hpp index 465c385b..7988faf2 100644 --- a/src/helpers/Workspace.hpp +++ b/src/helpers/Workspace.hpp @@ -7,7 +7,10 @@ public: CWorkspace(int monitorID); ~CWorkspace(); + // Workspaces ID-based have IDs > 0 + // and workspaces name-based have IDs starting with -1337 int m_iID = -1; + std::string m_szName = ""; uint64_t m_iMonitorID = -1; bool m_bHasFullscreenWindow = false; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 3f91e7f2..6d3417fc 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -154,7 +154,22 @@ void CKeybindManager::toggleActivePseudo(std::string args) { } void CKeybindManager::changeworkspace(std::string args) { - int workspaceToChangeTo = std::clamp((int)getPlusMinusKeywordResult(args, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); + int workspaceToChangeTo = 0; + std::string workspaceName = ""; + + if (args.find("name:") == 0) { + const auto WORKSPACENAME = args.substr(args.find_first_of(':') + 1); + const auto WORKSPACE = g_pCompositor->getWorkspaceByName(WORKSPACENAME); + if (!WORKSPACE) { + workspaceToChangeTo = g_pCompositor->getNextAvailableNamedWorkspace(); + } else { + workspaceToChangeTo = WORKSPACE->m_iID; + } + workspaceName = WORKSPACENAME; + } else { + workspaceToChangeTo = std::clamp((int)getPlusMinusKeywordResult(args, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); + workspaceName = std::to_string(workspaceToChangeTo); + } if (workspaceToChangeTo == INT_MAX) { Debug::log(ERR, "Error in changeworkspace, invalid value"); @@ -211,10 +226,11 @@ void CKeybindManager::changeworkspace(std::string args) { const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); // We are required to set the name here immediately - wlr_ext_workspace_handle_v1_set_name(PWORKSPACE->m_pWlrHandle, std::to_string(workspaceToChangeTo).c_str()); + wlr_ext_workspace_handle_v1_set_name(PWORKSPACE->m_pWlrHandle, workspaceName.c_str()); PWORKSPACE->m_iID = workspaceToChangeTo; PWORKSPACE->m_iMonitorID = PMONITOR->ID; + PWORKSPACE->m_szName = workspaceName; PMONITOR->activeWorkspace = workspaceToChangeTo; @@ -258,32 +274,29 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { 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)); + g_pKeybindManager->changeworkspace(args); + + const auto PWORKSPACE = g_pCompositor->getWorkspaceByString(args); - const auto NEWWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceID); + if (PWORKSPACE == OLDWORKSPACE) { + Debug::log(LOG, "Not moving to workspace because it didn't change."); + return; + } OLDWORKSPACE->m_bHasFullscreenWindow = false; - PWINDOW->m_iWorkspaceID = workspaceID; - PWINDOW->m_iMonitorID = NEWWORKSPACE->m_iMonitorID; + PWINDOW->m_iWorkspaceID = PWORKSPACE->m_iID; + PWINDOW->m_iMonitorID = PWORKSPACE->m_iMonitorID; PWINDOW->m_bIsFullscreen = false; - if (NEWWORKSPACE->m_bHasFullscreenWindow) { - g_pCompositor->getFullscreenWindowOnWorkspace(workspaceID)->m_bIsFullscreen = false; - NEWWORKSPACE->m_bHasFullscreenWindow = false; + if (PWORKSPACE->m_bHasFullscreenWindow) { + g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID)->m_bIsFullscreen = false; + PWORKSPACE->m_bHasFullscreenWindow = false; } // Hack: So that the layout doesnt find our window at the cursor @@ -299,7 +312,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { if (PWINDOW->m_bIsFloating) { PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition - g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID)->vecPosition; - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(NEWWORKSPACE->m_iMonitorID)->vecPosition; + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition + g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID)->vecPosition; PWINDOW->m_vEffectivePosition = PWINDOW->m_vRealPosition; PWINDOW->m_vPosition = PWINDOW->m_vRealPosition; } |