summaryrefslogtreecommitdiff
path: root/src/managers/KeybindManager.cpp
diff options
context:
space:
mode:
authorvaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-20 15:55:47 +0100
committervaxerski <43317083+vaxerski@users.noreply.github.com>2022-03-20 15:55:47 +0100
commit50370e4216110bed8068ce9b6c1095452cc8456f (patch)
treeb5e76f1d32756aa5327d29e213abba2bd027992a /src/managers/KeybindManager.cpp
parent45addfb31d02dac2ac7651410178e7a0cfde00f4 (diff)
added workspaces
Diffstat (limited to 'src/managers/KeybindManager.cpp')
-rw-r--r--src/managers/KeybindManager.cpp41
1 files changed, 41 insertions, 0 deletions
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