Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string, ActiveMethod> m_activeMap = {
{"ID", ActiveMethod::ID}, {"NAME", ActiveMethod::NAME}, {"DEFAULT", ActiveMethod::DEFAULT}};

std::string m_formatBefore;
std::string m_formatAfter;

Expand Down
7 changes: 7 additions & 0 deletions man/waybar-hyprland-workspaces.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++
Expand Down
22 changes: 20 additions & 2 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<ActiveMethod>(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()) {
Expand Down Expand Up @@ -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);
Expand Down
Loading