@@ -201,14 +201,17 @@ void Workspaces::fill_persistent_workspaces() {
201
201
const std::vector<std::string> keys = persistent_workspaces.getMemberNames ();
202
202
203
203
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 ;
204
210
const Json::Value &value = persistent_workspaces[key];
211
+
205
212
if (value.isInt ()) {
206
213
// 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) {
212
215
int amount = value.asInt ();
213
216
spdlog::debug (" Creating {} persistent workspaces for monitor {}" , amount,
214
217
bar_.output ->name );
@@ -217,14 +220,22 @@ void Workspaces::fill_persistent_workspaces() {
217
220
std::to_string (monitor_id_ * amount + i + 1 ));
218
221
}
219
222
}
220
-
221
223
} 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
+ }
228
239
}
229
240
}
230
241
} else {
0 commit comments