Merge pull request #2438 from khaneliman/hyprland-workspace-array

hyprland persistent workspace support new config declaration
This commit is contained in:
Alexis Rouillard 2023-09-01 09:10:23 +02:00 committed by GitHub
commit 8eb614f69e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 12 deletions

View File

@ -70,6 +70,25 @@ Additional to workspace name matching, the following *format-icons* can be set.
} }
``` ```
```
"hyprland/workspaces": {
"format": "{name}: {icon}",
"format-icons": {
"1": "",
"2": "",
"3": "",
"4": "",
"5": "",
"active": "",
"default": ""
},
"persistent_workspaces": {
"*": [ 2,3,4,5 ], // 2-5 on every monitor
"HDMI-A-1": [ 1 ] // but only workspace 1 on HDMI-A-1
}
}
```
# Style # Style
- *#workspaces* - *#workspaces*

View File

@ -201,14 +201,17 @@ void Workspaces::fill_persistent_workspaces() {
const std::vector<std::string> keys = persistent_workspaces.getMemberNames(); const std::vector<std::string> keys = persistent_workspaces.getMemberNames();
for (const std::string &key : keys) { for (const std::string &key : keys) {
// only add if either:
// 1. key is "*" and this monitor is not already defined in the config
// 2. key is the current monitor name
bool can_create =
(key == "*" && std::find(keys.begin(), keys.end(), bar_.output->name) == keys.end()) ||
key == bar_.output->name;
const Json::Value &value = persistent_workspaces[key]; const Json::Value &value = persistent_workspaces[key];
if (value.isInt()) { if (value.isInt()) {
// value is a number => create that many workspaces for this monitor // value is a number => create that many workspaces for this monitor
// only add if either: if (can_create) {
// 1. key is "*" and this monitor is not already defined in the config
// 2. key is the current monitor name
if ((key == "*" && std::find(keys.begin(), keys.end(), bar_.output->name) == keys.end()) ||
key == bar_.output->name) {
int amount = value.asInt(); int amount = value.asInt();
spdlog::debug("Creating {} persistent workspaces for monitor {}", amount, spdlog::debug("Creating {} persistent workspaces for monitor {}", amount,
bar_.output->name); bar_.output->name);
@ -217,14 +220,22 @@ void Workspaces::fill_persistent_workspaces() {
std::to_string(monitor_id_ * amount + i + 1)); std::to_string(monitor_id_ * amount + i + 1));
} }
} }
} else if (value.isArray() && !value.empty()) { } else if (value.isArray() && !value.empty()) {
// value is an array => key is a workspace name // value is an array => create defined workspaces for this monitor
// values are monitor names this workspace should be shown on if (can_create) {
for (const Json::Value &monitor : value) { for (const Json::Value &workspace : value) {
if (monitor.isString() && monitor.asString() == bar_.output->name) { if (workspace.isInt()) {
persistent_workspaces_to_create_.emplace_back(key); spdlog::debug("Creating workspace {} on monitor {}", workspace, bar_.output->name);
break; persistent_workspaces_to_create_.emplace_back(std::to_string(workspace.asInt()));
}
}
} else {
// key is the workspace and value is array of monitors to create on
for (const Json::Value &monitor : value) {
if (monitor.isString() && monitor.asString() == bar_.output->name) {
persistent_workspaces_to_create_.emplace_back(key);
break;
}
} }
} }
} else { } else {