From 50370e4216110bed8068ce9b6c1095452cc8456f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 20 Mar 2022 15:55:47 +0100 Subject: added workspaces --- src/managers/KeybindManager.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/managers/KeybindManager.cpp') diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 35f2269d..68f6dbc4 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -43,6 +43,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t if (k.handler == "exec") { spawn(k.arg); } else if (k.handler == "killactive") { killActive(k.arg); } else if (k.handler == "togglefloating") { toggleActiveFloating(k.arg); } + else if (k.handler == "workspace") { changeworkspace(k.arg); } found = true; } @@ -84,4 +85,44 @@ void CKeybindManager::toggleActiveFloating(std::string args) { g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(ACTIVEWINDOW); } +} + +void CKeybindManager::changeworkspace(std::string args) { + int workspaceToChangeTo = 0; + try { + workspaceToChangeTo = stoi(args); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str()); + } + + // if it exists, we warp to it + if (g_pCompositor->getWorkspaceByID(workspaceToChangeTo)) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(g_pCompositor->getWorkspaceByID(workspaceToChangeTo)->monitorID); + + // if it's not visible, make it visible. + if (!g_pCompositor->isWorkspaceVisible(workspaceToChangeTo)) + PMONITOR->activeWorkspace = workspaceToChangeTo; + + // If the monitor is not the one our cursor's at, warp to it. + if (PMONITOR != g_pCompositor->getMonitorFromCursor()) { + Vector2D middle = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f; + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, middle.x, middle.y); + } + + // focus the first window + g_pCompositor->focusWindow(g_pCompositor->getFirstWindowOnWorkspace(workspaceToChangeTo)); + + return; + } + + // Workspace doesn't exist, create and switch + const auto PMONITOR = g_pCompositor->getMonitorFromCursor(); + + g_pCompositor->m_lWorkspaces.push_back(SWorkspace()); + const auto PWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); + + PWORKSPACE->ID = workspaceToChangeTo; + PWORKSPACE->monitorID = PMONITOR->ID; + + PMONITOR->activeWorkspace = workspaceToChangeTo; } \ No newline at end of file -- cgit v1.2.3