diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index f71a6e4231..888741efd0 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -92,6 +92,7 @@ class Workspaces : public AModule, public EventHandler { static auto populateBoolConfig(const Json::Value& config, const std::string& key, bool& member) -> void; auto populateSortByConfig(const Json::Value& config) -> void; + auto populateActiveByConfig(const Json::Value& config) -> void; auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void; auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void; auto populateWindowRewriteConfig(const Json::Value& config) -> void; @@ -176,6 +177,11 @@ class Workspaces : public AModule, public EventHandler { {"SPECIAL-CENTERED", SortMethod::SPECIAL_CENTERED}, {"DEFAULT", SortMethod::DEFAULT}}; + enum class ActiveMethod { ID, NAME, DEFAULT }; + ActiveMethod m_activeBy = ActiveMethod::DEFAULT; + static inline const std::map m_activeMap = { + {"ID", ActiveMethod::ID}, {"NAME", ActiveMethod::NAME}, {"DEFAULT", ActiveMethod::DEFAULT}}; + std::string m_formatBefore; std::string m_formatAfter; diff --git a/man/waybar-hyprland-workspaces.5.scd b/man/waybar-hyprland-workspaces.5.scd index 3010fb4558..1a9b0ef06d 100644 --- a/man/waybar-hyprland-workspaces.5.scd +++ b/man/waybar-hyprland-workspaces.5.scd @@ -147,6 +147,13 @@ This setting is ignored if *workspace-taskbar.enable* is set to true. default: false ++ If set to false workspaces group will be shown only in assigned output. Otherwise, all workspace groups are shown. +*active-by*: ++ + typeof: string ++ + default: "default" ++ + If set to id, workspaces will be set as active by id. + If set to name, workspaces will set as active by name. + If none of those, workspaces will set as active by default behavior. + *active-only*: ++ typeof: bool ++ default: false ++ diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 6f43f208b5..27670647a8 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -668,6 +668,7 @@ auto Workspaces::parseConfig(const Json::Value& config) -> void { m_persistentWorkspaceConfig = config.get("persistent-workspaces", Json::Value()); populateSortByConfig(config); + populateActiveByConfig(config); populateIgnoreWorkspacesConfig(config); populateFormatWindowSeparatorConfig(config); @@ -722,6 +723,20 @@ auto Workspaces::populateSortByConfig(const Json::Value& config) -> void { } } +auto Workspaces::populateActiveByConfig(const Json::Value& config) -> void { + const auto& configActiveBy = config["active-by"]; + if (configActiveBy.isString()) { + auto activeByStr = configActiveBy.asString(); + try { + m_activeBy = waybar::util::parseStringToEnum(activeByStr, m_activeMap); + } catch (const std::invalid_argument& e) { + m_activeBy = ActiveMethod::DEFAULT; + spdlog::warn( + "Invalid string representation for active-by. Falling back to default active method."); + } + } +} + auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value& config) -> void { auto ignoreWorkspaces = config["ignore-workspaces"]; if (ignoreWorkspaces.isArray()) { @@ -1135,10 +1150,13 @@ void Workspaces::updateWorkspaceStates() { for (auto& workspace : m_workspaces) { bool isActiveByName = - !currentWorkspaceName.empty() && workspace->name() == currentWorkspaceName; + !currentWorkspaceName.empty() && + workspace->name() == currentWorkspaceName; workspace->setActive( - workspace->id() == m_activeWorkspaceId || isActiveByName || + ((m_activeBy == ActiveMethod::ID || m_activeBy == ActiveMethod::DEFAULT) && + workspace->id() == m_activeWorkspaceId ) || + (m_activeBy == ActiveMethod::NAME && isActiveByName) || (workspace->isSpecial() && workspace->name() == m_activeSpecialWorkspaceName)); if (workspace->isActive() && workspace->isUrgent()) { workspace->setUrgent(false);