aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-17 02:00:50 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-17 16:25:44 +0100
commit5f25541022fb19a170360536985a0b200a01277a (patch)
tree1ce6f24ccc65b0771c6e7b6b3309b32c6c109d46 /sway/tree/workspace.c
parentswaynag: remove double free of details button (diff)
downloadsway-5f25541022fb19a170360536985a0b200a01277a.tar.gz
sway-5f25541022fb19a170360536985a0b200a01277a.tar.zst
sway-5f25541022fb19a170360536985a0b200a01277a.zip
Allow output ids and wildcard for workspace output
This allows for output identifiers and to be used in the `workspace <workspace> output <outputs...>` command. Previously, only output names would be allowed. If an output identifier was given, it would never match an output. This also allows for the wildcard character (`*`) to be specified, which can be used to generate a list of workspace names that should be used when generating new workspaces
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index ed24b4fd..4f1c4a64 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -113,7 +113,10 @@ struct sway_workspace *workspace_create(struct sway_output *output,
113 113
114 // Add output priorities 114 // Add output priorities
115 for (int i = 0; i < wsc->outputs->length; ++i) { 115 for (int i = 0; i < wsc->outputs->length; ++i) {
116 list_add(ws->output_priority, strdup(wsc->outputs->items[i])); 116 char *name = wsc->outputs->items[i];
117 if (strcmp(name, "*") != 0) {
118 list_add(ws->output_priority, strdup(name));
119 }
117 } 120 }
118 } 121 }
119 } 122 }
@@ -183,6 +186,10 @@ static bool workspace_valid_on_output(const char *output_name,
183 struct workspace_config *wsc = workspace_find_config(ws_name); 186 struct workspace_config *wsc = workspace_find_config(ws_name);
184 char identifier[128]; 187 char identifier[128];
185 struct sway_output *output = output_by_name(output_name); 188 struct sway_output *output = output_by_name(output_name);
189 if (!output) {
190 output = output_by_identifier(output_name);
191 output_name = output->wlr_output->name;
192 }
186 output_get_identifier(identifier, sizeof(identifier), output); 193 output_get_identifier(identifier, sizeof(identifier), output);
187 194
188 if (!wsc) { 195 if (!wsc) {
@@ -190,7 +197,8 @@ static bool workspace_valid_on_output(const char *output_name,
190 } 197 }
191 198
192 for (int i = 0; i < wsc->outputs->length; i++) { 199 for (int i = 0; i < wsc->outputs->length; i++) {
193 if (strcmp(wsc->outputs->items[i], output_name) == 0 || 200 if (strcmp(wsc->outputs->items[i], "*") == 0 ||
201 strcmp(wsc->outputs->items[i], output_name) == 0 ||
194 strcmp(wsc->outputs->items[i], identifier) == 0) { 202 strcmp(wsc->outputs->items[i], identifier) == 0) {
195 return true; 203 return true;
196 } 204 }
@@ -286,6 +294,10 @@ char *workspace_next_name(const char *output_name) {
286 // assignments primarily, falling back to bindings and numbers. 294 // assignments primarily, falling back to bindings and numbers.
287 struct sway_mode *mode = config->current_mode; 295 struct sway_mode *mode = config->current_mode;
288 296
297 char identifier[128];
298 struct sway_output *output = output_by_name(output_name);
299 output_get_identifier(identifier, sizeof(identifier), output);
300
289 int order = INT_MAX; 301 int order = INT_MAX;
290 char *target = NULL; 302 char *target = NULL;
291 for (int i = 0; i < mode->keysym_bindings->length; ++i) { 303 for (int i = 0; i < mode->keysym_bindings->length; ++i) {
@@ -304,7 +316,9 @@ char *workspace_next_name(const char *output_name) {
304 } 316 }
305 bool found = false; 317 bool found = false;
306 for (int j = 0; j < wsc->outputs->length; ++j) { 318 for (int j = 0; j < wsc->outputs->length; ++j) {
307 if (strcmp(wsc->outputs->items[j], output_name) == 0) { 319 if (strcmp(wsc->outputs->items[j], "*") == 0 ||
320 strcmp(wsc->outputs->items[j], output_name) == 0 ||
321 strcmp(wsc->outputs->items[j], identifier) == 0) {
308 found = true; 322 found = true;
309 free(target); 323 free(target);
310 target = strdup(wsc->workspace); 324 target = strdup(wsc->workspace);
@@ -525,9 +539,15 @@ void workspace_output_add_priority(struct sway_workspace *workspace,
525 539
526struct sway_output *workspace_output_get_highest_available( 540struct sway_output *workspace_output_get_highest_available(
527 struct sway_workspace *ws, struct sway_output *exclude) { 541 struct sway_workspace *ws, struct sway_output *exclude) {
542 char exclude_id[128] = {'\0'};
543 if (exclude) {
544 output_get_identifier(exclude_id, sizeof(exclude_id), exclude);
545 }
546
528 for (int i = 0; i < ws->output_priority->length; i++) { 547 for (int i = 0; i < ws->output_priority->length; i++) {
529 char *name = ws->output_priority->items[i]; 548 char *name = ws->output_priority->items[i];
530 if (exclude && strcasecmp(name, exclude->wlr_output->name) == 0) { 549 if (exclude && (strcmp(name, exclude->wlr_output->name) == 0
550 || strcmp(name, exclude_id) == 0)) {
531 continue; 551 continue;
532 } 552 }
533 553
@@ -535,6 +555,11 @@ struct sway_output *workspace_output_get_highest_available(
535 if (output) { 555 if (output) {
536 return output; 556 return output;
537 } 557 }
558
559 output = output_by_identifier(name);
560 if (output) {
561 return output;
562 }
538 } 563 }
539 564
540 return NULL; 565 return NULL;