From 2e18fa268a21727d6c9c302e557a5d0f81fad714 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 20 Mar 2022 16:01:47 +0100 Subject: [PATCH] default workspace option --- example/hyprland.conf | 7 ++++++- src/config/ConfigManager.cpp | 17 ++++++++++++++++- src/config/ConfigManager.hpp | 2 ++ src/events/Events.cpp | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/example/hyprland.conf b/example/hyprland.conf index 6c4a7b4a..c10abe72 100644 --- a/example/hyprland.conf +++ b/example/hyprland.conf @@ -4,6 +4,7 @@ # Refer to the wiki for more information. monitor=,1280x720@60,0x0,0.5,1 +workspace=DP-1,1 general { max_fps=240 @@ -15,4 +16,8 @@ general { border_size=1 col.active_border=0x66ee1111 col.inactive_border=0x66333333 -} \ No newline at end of file +} + +bind=SUPER,T,exec,xterm +bind=SUPER,Q,killactive, +bind=SUPERSHIFT,Q,exec,pkill Hyprland \ No newline at end of file diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index a0aa4cdf..17a3232a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -156,6 +156,19 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v g_pKeybindManager->addKeybind(SKeybind{KEY, MOD, HANDLER, COMMAND}); } +void CConfigManager::handleDefaultWorkspace(const std::string& command, const std::string& value) { + + const auto DISPLAY = value.substr(0, value.find_first_of(',')); + const auto WORKSPACEID = stoi(value.substr(value.find_first_of(',') + 1)); + + for (auto& mr : m_dMonitorRules) { + if (mr.name == DISPLAY) { + mr.defaultWorkspaceID = WORKSPACEID; + break; + } + } +} + void CConfigManager::parseLine(std::string& line) { // first check if its not a comment const auto COMMENTSTART = line.find_first_of('#'); @@ -207,9 +220,11 @@ void CConfigManager::parseLine(std::string& line) { } else if (COMMAND == "bind") { handleBind(COMMAND, VALUE); return; + } else if (COMMAND == "workspace") { + handleDefaultWorkspace(COMMAND, VALUE); + return; } - configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); } diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index c06c41f7..c34aadb1 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -20,6 +20,7 @@ struct SMonitorRule { float mfact = 0.5; float scale = 1; float refreshRate = 60; + int defaultWorkspaceID = -1; }; class CConfigManager { @@ -55,6 +56,7 @@ private: void handleRawExec(const std::string&, const std::string&); void handleMonitor(const std::string&, const std::string&); void handleBind(const std::string&, const std::string&); + void handleDefaultWorkspace(const std::string&, const std::string&); }; inline std::unique_ptr g_pConfigManager; \ No newline at end of file diff --git a/src/events/Events.cpp b/src/events/Events.cpp index db8318ba..621a6325 100644 --- a/src/events/Events.cpp +++ b/src/events/Events.cpp @@ -72,7 +72,7 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { g_pCompositor->m_lWorkspaces.push_back(SWorkspace()); const auto PNEWWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); - PNEWWORKSPACE->ID = g_pCompositor->m_lWorkspaces.size(); + PNEWWORKSPACE->ID = monitorRule.defaultWorkspaceID == -1 ? g_pCompositor->m_lWorkspaces.size() : monitorRule.defaultWorkspaceID; PNEWWORKSPACE->monitorID = newMonitor.ID; newMonitor.activeWorkspace = PNEWWORKSPACE->ID;