diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-17 20:34:53 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-17 20:34:53 -0400 |
commit | 780893a9338fe948cbb12c3b0ce3942ec8001ccf (patch) | |
tree | 67355e90ac69bc773427be3d5c3275980e8754c5 | |
parent | Rearrange main.c some more (diff) | |
download | sway-780893a9338fe948cbb12c3b0ce3942ec8001ccf.tar.gz sway-780893a9338fe948cbb12c3b0ce3942ec8001ccf.tar.zst sway-780893a9338fe948cbb12c3b0ce3942ec8001ccf.zip |
Add support for workspace [name] output [name]
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | sway/commands.c | 60 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/container.c | 19 |
4 files changed, 61 insertions, 25 deletions
diff --git a/include/config.h b/include/config.h index c9fd374c..38e93eb8 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -21,10 +21,16 @@ struct sway_mode { | |||
21 | list_t *bindings; | 21 | list_t *bindings; |
22 | }; | 22 | }; |
23 | 23 | ||
24 | struct workspace_output { | ||
25 | char *output; | ||
26 | char *workspace; | ||
27 | }; | ||
28 | |||
24 | struct sway_config { | 29 | struct sway_config { |
25 | list_t *symbols; | 30 | list_t *symbols; |
26 | list_t *modes; | 31 | list_t *modes; |
27 | list_t *cmd_queue; | 32 | list_t *cmd_queue; |
33 | list_t *workspace_outputs; | ||
28 | struct sway_mode *current_mode; | 34 | struct sway_mode *current_mode; |
29 | 35 | ||
30 | // Flags | 36 | // Flags |
diff --git a/sway/commands.c b/sway/commands.c index 5035316e..444e6159 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -410,37 +410,51 @@ static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
410 | } | 410 | } |
411 | 411 | ||
412 | static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | 412 | static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { |
413 | if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { | 413 | if (!checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1)) { |
414 | return false; | 414 | return false; |
415 | } | 415 | } |
416 | 416 | ||
417 | // Handle workspace next/prev | 417 | if (argc == 1) { |
418 | if (strcmp(argv[0], "next") == 0) { | 418 | // Handle workspace next/prev |
419 | workspace_next(); | 419 | if (strcmp(argv[0], "next") == 0) { |
420 | return true; | 420 | workspace_next(); |
421 | } | 421 | return true; |
422 | } | ||
422 | 423 | ||
423 | if (strcmp(argv[0], "prev") == 0) { | 424 | if (strcmp(argv[0], "prev") == 0) { |
424 | workspace_next(); | 425 | workspace_next(); |
425 | return true; | 426 | return true; |
426 | } | 427 | } |
427 | 428 | ||
428 | // Handle workspace output_next/prev | 429 | // Handle workspace output_next/prev |
429 | if (strcmp(argv[0], "next_on_output") == 0) { | 430 | if (strcmp(argv[0], "next_on_output") == 0) { |
430 | workspace_output_next(); | 431 | workspace_output_next(); |
431 | return true; | 432 | return true; |
432 | } | 433 | } |
433 | 434 | ||
434 | if (strcmp(argv[0], "prev_on_output") == 0) { | 435 | if (strcmp(argv[0], "prev_on_output") == 0) { |
435 | workspace_output_prev(); | 436 | workspace_output_prev(); |
436 | return true; | 437 | return true; |
437 | } | 438 | } |
438 | 439 | ||
439 | swayc_t *workspace = workspace_find_by_name(argv[0]); | 440 | swayc_t *workspace = workspace_find_by_name(argv[0]); |
440 | if (!workspace) { | 441 | if (!workspace) { |
441 | workspace = workspace_create(argv[0]); | 442 | workspace = workspace_create(argv[0]); |
443 | } | ||
444 | workspace_switch(workspace); | ||
445 | } else { | ||
446 | if (strcasecmp(argv[1], "output") == 0) { | ||
447 | if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3)) { | ||
448 | return false; | ||
449 | } | ||
450 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | ||
451 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", argv[0], argv[2]); | ||
452 | wso->workspace = strdup(argv[0]); | ||
453 | wso->output = strdup(argv[2]); | ||
454 | list_add(config->workspace_outputs, wso); | ||
455 | // TODO: Consider moving any existing workspace to that output? This might be executed sometime after config load | ||
456 | } | ||
442 | } | 457 | } |
443 | workspace_switch(workspace); | ||
444 | return true; | 458 | return true; |
445 | } | 459 | } |
446 | 460 | ||
diff --git a/sway/config.c b/sway/config.c index dabbf8e5..f06d55f8 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -159,6 +159,7 @@ void config_defaults(struct sway_config *config) { | |||
159 | config->symbols = create_list(); | 159 | config->symbols = create_list(); |
160 | config->modes = create_list(); | 160 | config->modes = create_list(); |
161 | config->cmd_queue = create_list(); | 161 | config->cmd_queue = create_list(); |
162 | config->workspace_outputs = create_list(); | ||
162 | config->current_mode = malloc(sizeof(struct sway_mode)); | 163 | config->current_mode = malloc(sizeof(struct sway_mode)); |
163 | config->current_mode->name = NULL; | 164 | config->current_mode->name = NULL; |
164 | config->current_mode->bindings = create_list(); | 165 | config->current_mode->bindings = create_list(); |
diff --git a/sway/container.c b/sway/container.c index f10fbecf..3534721d 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <strings.h> | 3 | #include <strings.h> |
4 | #include "config.h" | ||
4 | #include "container.h" | 5 | #include "container.h" |
5 | #include "workspace.h" | 6 | #include "workspace.h" |
6 | #include "layout.h" | 7 | #include "layout.h" |
@@ -63,14 +64,28 @@ swayc_t *new_output(wlc_handle handle) { | |||
63 | container_map(&root_container, add_output_widths, &total_width); | 64 | container_map(&root_container, add_output_widths, &total_width); |
64 | 65 | ||
65 | //Create workspace | 66 | //Create workspace |
66 | char *ws_name = workspace_next_name(); | 67 | char *ws_name = NULL; |
68 | if (name) { | ||
69 | int i; | ||
70 | for (i = 0; i < config->workspace_outputs->length; ++i) { | ||
71 | struct workspace_output *wso = config->workspace_outputs->items[i]; | ||
72 | if (strcasecmp(wso->output, name) == 0) { | ||
73 | sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); | ||
74 | ws_name = strdup(wso->workspace); | ||
75 | break; | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | if (!ws_name) { | ||
80 | ws_name = workspace_next_name(); | ||
81 | } | ||
67 | new_workspace(output, ws_name); | 82 | new_workspace(output, ws_name); |
68 | free(ws_name); | 83 | free(ws_name); |
69 | 84 | ||
70 | return output; | 85 | return output; |
71 | } | 86 | } |
72 | 87 | ||
73 | swayc_t *new_workspace(swayc_t * output, const char *name) { | 88 | swayc_t *new_workspace(swayc_t *output, const char *name) { |
74 | sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); | 89 | sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); |
75 | swayc_t *workspace = new_swayc(C_WORKSPACE); | 90 | swayc_t *workspace = new_swayc(C_WORKSPACE); |
76 | 91 | ||