hyprland new persistent_workspace configuration style

This commit is contained in:
Austin Horstman 2023-08-28 23:34:28 -05:00
parent b665843085
commit 52309615c1
No known key found for this signature in database
2 changed files with 42 additions and 12 deletions

View File

@ -69,6 +69,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) {
const Json::Value &value = persistent_workspaces[key];
if (value.isInt()) {
// value is a number => create that many workspaces for this monitor
// only add if either: // only add if either:
// 1. key is "*" and this monitor is not already defined in the config // 1. key is "*" and this monitor is not already defined in the config
// 2. key is the current monitor name // 2. key is the current monitor name
if ((key == "*" && std::find(keys.begin(), keys.end(), bar_.output->name) == keys.end()) || bool can_create =
key == bar_.output->name) { (key == "*" && std::find(keys.begin(), keys.end(), bar_.output->name) == keys.end()) ||
key == bar_.output->name;
const Json::Value &value = persistent_workspaces[key];
if (value.isInt()) {
// value is a number => create that many workspaces for this monitor
if (can_create) {
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,10 +220,17 @@ 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 &workspace : value) {
if (workspace.isInt()) {
spdlog::debug("Creating workspace {} on monitor {}", workspace, bar_.output->name);
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) { for (const Json::Value &monitor : value) {
if (monitor.isString() && monitor.asString() == bar_.output->name) { if (monitor.isString() && monitor.asString() == bar_.output->name) {
persistent_workspaces_to_create_.emplace_back(key); persistent_workspaces_to_create_.emplace_back(key);
@ -231,6 +241,7 @@ void Workspaces::fill_persistent_workspaces() {
} }
} }
} }
}
void Workspaces::create_persistent_workspaces() { void Workspaces::create_persistent_workspaces() {
for (const std::string &workspace_name : persistent_workspaces_to_create_) { for (const std::string &workspace_name : persistent_workspaces_to_create_) {