From 84d6e640ff6e48c8161e1922349c7bce6b0b335f Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Tue, 21 Jun 2022 22:25:54 +0200 Subject: [PATCH] support all workspace types in workspace keyword --- src/config/ConfigManager.cpp | 4 ++-- src/config/ConfigManager.hpp | 2 +- src/events/Monitors.cpp | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d511c05a2..b76ab9659 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -495,11 +495,11 @@ void CConfigManager::handleWindowRule(const std::string& command, const std::str 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)); + const auto WORKSPACE = value.substr(value.find_first_of(',') + 1); for (auto& mr : m_dMonitorRules) { if (mr.name == DISPLAY) { - mr.defaultWorkspaceID = WORKSPACEID; + mr.defaultWorkspace = WORKSPACE; break; } } diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 866b8b8ed..0d4386c17 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -28,7 +28,7 @@ struct SMonitorRule { Vector2D offset = Vector2D(0,0); float scale = 1; float refreshRate = 60; - int defaultWorkspaceID = -1; + std::string defaultWorkspace = ""; bool disabled = false; wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; }; diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index 257565487..afbc0745a 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -114,7 +114,15 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { wlr_ext_workspace_group_handle_v1_output_enter(PNEWMONITOR->pWLRWorkspaceGroupHandle, PNEWMONITOR->output); // Workspace - const auto WORKSPACEID = monitorRule.defaultWorkspaceID == -1 ? g_pCompositor->m_lWorkspaces.size() + 1 /* Cuz workspaces doesnt have the new one yet and we start with 1 */ : monitorRule.defaultWorkspaceID; + std::string newDefaultWorkspaceName = ""; + auto WORKSPACEID = monitorRule.defaultWorkspace == "" ? g_pCompositor->m_lWorkspaces.size() + 1 : getWorkspaceIDFromString(monitorRule.defaultWorkspace, newDefaultWorkspaceName); + + if (WORKSPACEID == INT_MAX || WORKSPACEID == (long unsigned int)SPECIAL_WORKSPACE_ID) { + WORKSPACEID = g_pCompositor->m_lWorkspaces.size() + 1; + newDefaultWorkspaceName = std::to_string(WORKSPACEID); + + Debug::log(LOG, "Invalid workspace= directive name in monitor parsing, workspace name \"%s\" is invalid.", monitorRule.defaultWorkspace); + } auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID); @@ -127,14 +135,13 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PNEWMONITOR->ID); PNEWWORKSPACE->startAnim(true,true,true); } else { - g_pCompositor->m_lWorkspaces.emplace_back(newMonitor.ID); - PNEWWORKSPACE = &g_pCompositor->m_lWorkspaces.back(); + PNEWWORKSPACE = &g_pCompositor->m_lWorkspaces.emplace_back(newMonitor.ID); // We are required to set the name here immediately - wlr_ext_workspace_handle_v1_set_name(PNEWWORKSPACE->m_pWlrHandle, std::to_string(WORKSPACEID).c_str()); + wlr_ext_workspace_handle_v1_set_name(PNEWWORKSPACE->m_pWlrHandle, newDefaultWorkspaceName.c_str()); PNEWWORKSPACE->m_iID = WORKSPACEID; - PNEWWORKSPACE->m_szName = std::to_string(WORKSPACEID); + PNEWWORKSPACE->m_szName = newDefaultWorkspaceName; } PNEWMONITOR->activeWorkspace = PNEWWORKSPACE->m_iID;