diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-08-12 00:38:19 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-08-18 17:25:06 +0100 |
commit | 23601a8771f6e98e04bb4bfb9dd75ed399a20717 (patch) | |
tree | af7f151dfb62412efef27f91c5776ec78602a0b5 | |
parent | commands: saner workspace number handling (diff) | |
download | sway-23601a8771f6e98e04bb4bfb9dd75ed399a20717.tar.gz sway-23601a8771f6e98e04bb4bfb9dd75ed399a20717.tar.zst sway-23601a8771f6e98e04bb4bfb9dd75ed399a20717.zip |
commands: complete assign command
-rw-r--r-- | include/sway/criteria.h | 9 | ||||
-rw-r--r-- | sway/commands/assign.c | 27 | ||||
-rw-r--r-- | sway/sway.5.scd | 9 | ||||
-rw-r--r-- | sway/tree/view.c | 23 |
4 files changed, 45 insertions, 23 deletions
diff --git a/include/sway/criteria.h b/include/sway/criteria.h index b4ff7d49..7a1e547b 100644 --- a/include/sway/criteria.h +++ b/include/sway/criteria.h | |||
@@ -7,10 +7,11 @@ | |||
7 | #include "tree/view.h" | 7 | #include "tree/view.h" |
8 | 8 | ||
9 | enum criteria_type { | 9 | enum criteria_type { |
10 | CT_COMMAND = 1 << 0, | 10 | CT_COMMAND = 1 << 0, |
11 | CT_ASSIGN_OUTPUT = 1 << 1, | 11 | CT_ASSIGN_OUTPUT = 1 << 1, |
12 | CT_ASSIGN_WORKSPACE = 1 << 2, | 12 | CT_ASSIGN_WORKSPACE = 1 << 2, |
13 | CT_NO_FOCUS = 1 << 3, | 13 | CT_ASSIGN_WORKSPACE_NUMBER = 1 << 3, |
14 | CT_NO_FOCUS = 1 << 4, | ||
14 | }; | 15 | }; |
15 | 16 | ||
16 | struct criteria { | 17 | struct criteria { |
diff --git a/sway/commands/assign.c b/sway/commands/assign.c index 0bc0929a..04582e88 100644 --- a/sway/commands/assign.c +++ b/sway/commands/assign.c | |||
@@ -22,27 +22,38 @@ struct cmd_results *cmd_assign(int argc, char **argv) { | |||
22 | return error; | 22 | return error; |
23 | } | 23 | } |
24 | 24 | ||
25 | ++argv; | 25 | --argc; ++argv; |
26 | int target_len = argc - 1; | ||
27 | 26 | ||
28 | if (strncmp(*argv, "→", strlen("→")) == 0) { | 27 | if (strncmp(*argv, "→", strlen("→")) == 0) { |
29 | if (argc < 3) { | 28 | if (argc < 2) { |
30 | free(criteria); | 29 | free(criteria); |
31 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); | 30 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); |
32 | } | 31 | } |
32 | --argc; | ||
33 | ++argv; | 33 | ++argv; |
34 | --target_len; | ||
35 | } | 34 | } |
36 | 35 | ||
37 | if (strcmp(*argv, "output") == 0) { | 36 | if (strcmp(*argv, "output") == 0) { |
38 | criteria->type = CT_ASSIGN_OUTPUT; | 37 | criteria->type = CT_ASSIGN_OUTPUT; |
39 | ++argv; | 38 | --argc; ++argv; |
40 | --target_len; | ||
41 | } else { | 39 | } else { |
42 | criteria->type = CT_ASSIGN_WORKSPACE; | 40 | if (strcmp(*argv, "workspace") == 0) { |
41 | --argc; ++argv; | ||
42 | } | ||
43 | if (strcmp(*argv, "number") == 0) { | ||
44 | --argc; ++argv; | ||
45 | if (argv[0][0] < '0' || argv[0][0] > '9') { | ||
46 | free(criteria); | ||
47 | return cmd_results_new(CMD_INVALID, "assign", | ||
48 | "Invalid workspace number '%s'", argv[0]); | ||
49 | } | ||
50 | criteria->type = CT_ASSIGN_WORKSPACE_NUMBER; | ||
51 | } else { | ||
52 | criteria->type = CT_ASSIGN_WORKSPACE; | ||
53 | } | ||
43 | } | 54 | } |
44 | 55 | ||
45 | criteria->target = join_args(argv, target_len); | 56 | criteria->target = join_args(argv, argc); |
46 | 57 | ||
47 | list_add(config->criteria, criteria); | 58 | list_add(config->criteria, criteria); |
48 | wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, | 59 | wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 8e56d5bb..83188067 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -219,13 +219,20 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). | |||
219 | The following commands may be used either in the configuration file or at | 219 | The following commands may be used either in the configuration file or at |
220 | runtime. | 220 | runtime. |
221 | 221 | ||
222 | *assign* <criteria> [→] <workspace> | 222 | *assign* <criteria> [→] [workspace] [number] <workspace> |
223 | Assigns views matching _criteria_ (see *CRITERIA* for details) to | 223 | Assigns views matching _criteria_ (see *CRITERIA* for details) to |
224 | _workspace_. The → (U+2192) is optional and cosmetic. This command is | 224 | _workspace_. The → (U+2192) is optional and cosmetic. This command is |
225 | equivalent to: | 225 | equivalent to: |
226 | 226 | ||
227 | for\_window <criteria> move container to workspace <workspace> | 227 | for\_window <criteria> move container to workspace <workspace> |
228 | 228 | ||
229 | *assign* <criteria> [→] output left|right|up|down|<name> | ||
230 | Assigns views matching _criteria_ (see *CRITERIA* for details) to the | ||
231 | specified output. The → (U+2192) is optional and cosmetic. This command is | ||
232 | equivalent to: | ||
233 | |||
234 | for\_window <criteria> move container to output <output> | ||
235 | |||
229 | *bindsym* [--release|--locked] <key combo> <command> | 236 | *bindsym* [--release|--locked] <key combo> <command> |
230 | Binds _key combo_ to execute the sway command _command_ when pressed. You | 237 | Binds _key combo_ to execute the sway command _command_ when pressed. You |
231 | may use XKB key names here (*xev*(1) is a good tool for discovering these). | 238 | may use XKB key names here (*xev*(1) is a good tool for discovering these). |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 4495c150..4c8e1774 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -450,12 +450,22 @@ static struct sway_container *select_workspace(struct sway_view *view) { | |||
450 | 450 | ||
451 | // Check if there's any `assign` criteria for the view | 451 | // Check if there's any `assign` criteria for the view |
452 | list_t *criterias = criteria_for_view(view, | 452 | list_t *criterias = criteria_for_view(view, |
453 | CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT); | 453 | CT_ASSIGN_WORKSPACE | CT_ASSIGN_WORKSPACE_NUMBER | CT_ASSIGN_OUTPUT); |
454 | struct sway_container *ws = NULL; | 454 | struct sway_container *ws = NULL; |
455 | for (int i = 0; i < criterias->length; ++i) { | 455 | for (int i = 0; i < criterias->length; ++i) { |
456 | struct criteria *criteria = criterias->items[i]; | 456 | struct criteria *criteria = criterias->items[i]; |
457 | if (criteria->type == CT_ASSIGN_WORKSPACE) { | 457 | if (criteria->type == CT_ASSIGN_OUTPUT) { |
458 | ws = workspace_by_name(criteria->target); | 458 | struct sway_container *output = output_by_name(criteria->target); |
459 | if (output) { | ||
460 | ws = seat_get_active_child(seat, output); | ||
461 | break; | ||
462 | } | ||
463 | } else { | ||
464 | // CT_ASSIGN_WORKSPACE(_NUMBER) | ||
465 | ws = criteria->type == CT_ASSIGN_WORKSPACE_NUMBER ? | ||
466 | workspace_by_number(criteria->target) : | ||
467 | workspace_by_name(criteria->target); | ||
468 | |||
459 | if (!ws) { | 469 | if (!ws) { |
460 | if (strcasecmp(criteria->target, "back_and_forth") == 0) { | 470 | if (strcasecmp(criteria->target, "back_and_forth") == 0) { |
461 | if (prev_workspace_name) { | 471 | if (prev_workspace_name) { |
@@ -466,13 +476,6 @@ static struct sway_container *select_workspace(struct sway_view *view) { | |||
466 | } | 476 | } |
467 | } | 477 | } |
468 | break; | 478 | break; |
469 | } else { | ||
470 | // CT_ASSIGN_OUTPUT | ||
471 | struct sway_container *output = output_by_name(criteria->target); | ||
472 | if (output) { | ||
473 | ws = seat_get_active_child(seat, output); | ||
474 | break; | ||
475 | } | ||
476 | } | 479 | } |
477 | } | 480 | } |
478 | list_free(criterias); | 481 | list_free(criterias); |