Skip to content

Commit 8eb614f

Browse files
authored
Merge pull request Alexays#2438 from khaneliman/hyprland-workspace-array
hyprland persistent workspace support new config declaration
2 parents 347dd1c + 5230961 commit 8eb614f

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

man/waybar-hyprland-workspaces.5.scd

+19
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ Additional to workspace name matching, the following *format-icons* can be set.
7070
}
7171
```
7272

73+
```
74+
"hyprland/workspaces": {
75+
"format": "{name}: {icon}",
76+
"format-icons": {
77+
"1": "",
78+
"2": "",
79+
"3": "",
80+
"4": "",
81+
"5": "",
82+
"active": "",
83+
"default": ""
84+
},
85+
"persistent_workspaces": {
86+
"*": [ 2,3,4,5 ], // 2-5 on every monitor
87+
"HDMI-A-1": [ 1 ] // but only workspace 1 on HDMI-A-1
88+
}
89+
}
90+
```
91+
7392
# Style
7493

7594
- *#workspaces*

src/modules/hyprland/workspaces.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,17 @@ void Workspaces::fill_persistent_workspaces() {
201201
const std::vector<std::string> keys = persistent_workspaces.getMemberNames();
202202

203203
for (const std::string &key : keys) {
204+
// only add if either:
205+
// 1. key is "*" and this monitor is not already defined in the config
206+
// 2. key is the current monitor name
207+
bool can_create =
208+
(key == "*" && std::find(keys.begin(), keys.end(), bar_.output->name) == keys.end()) ||
209+
key == bar_.output->name;
204210
const Json::Value &value = persistent_workspaces[key];
211+
205212
if (value.isInt()) {
206213
// value is a number => create that many workspaces for this monitor
207-
// only add if either:
208-
// 1. key is "*" and this monitor is not already defined in the config
209-
// 2. key is the current monitor name
210-
if ((key == "*" && std::find(keys.begin(), keys.end(), bar_.output->name) == keys.end()) ||
211-
key == bar_.output->name) {
214+
if (can_create) {
212215
int amount = value.asInt();
213216
spdlog::debug("Creating {} persistent workspaces for monitor {}", amount,
214217
bar_.output->name);
@@ -217,14 +220,22 @@ void Workspaces::fill_persistent_workspaces() {
217220
std::to_string(monitor_id_ * amount + i + 1));
218221
}
219222
}
220-
221223
} else if (value.isArray() && !value.empty()) {
222-
// value is an array => key is a workspace name
223-
// values are monitor names this workspace should be shown on
224-
for (const Json::Value &monitor : value) {
225-
if (monitor.isString() && monitor.asString() == bar_.output->name) {
226-
persistent_workspaces_to_create_.emplace_back(key);
227-
break;
224+
// value is an array => create defined workspaces for this monitor
225+
if (can_create) {
226+
for (const Json::Value &workspace : value) {
227+
if (workspace.isInt()) {
228+
spdlog::debug("Creating workspace {} on monitor {}", workspace, bar_.output->name);
229+
persistent_workspaces_to_create_.emplace_back(std::to_string(workspace.asInt()));
230+
}
231+
}
232+
} else {
233+
// key is the workspace and value is array of monitors to create on
234+
for (const Json::Value &monitor : value) {
235+
if (monitor.isString() && monitor.asString() == bar_.output->name) {
236+
persistent_workspaces_to_create_.emplace_back(key);
237+
break;
238+
}
228239
}
229240
}
230241
} else {

0 commit comments

Comments
 (0)