mirror of
https://github.com/NickHu/sway
synced 2024-12-27 21:58:11 +01:00
commands: complete assign command
This commit is contained in:
parent
e81cc8a575
commit
23601a8771
4 changed files with 45 additions and 23 deletions
|
@ -10,7 +10,8 @@ enum criteria_type {
|
||||||
CT_COMMAND = 1 << 0,
|
CT_COMMAND = 1 << 0,
|
||||||
CT_ASSIGN_OUTPUT = 1 << 1,
|
CT_ASSIGN_OUTPUT = 1 << 1,
|
||||||
CT_ASSIGN_WORKSPACE = 1 << 2,
|
CT_ASSIGN_WORKSPACE = 1 << 2,
|
||||||
CT_NO_FOCUS = 1 << 3,
|
CT_ASSIGN_WORKSPACE_NUMBER = 1 << 3,
|
||||||
|
CT_NO_FOCUS = 1 << 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct criteria {
|
struct criteria {
|
||||||
|
|
|
@ -22,27 +22,38 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
++argv;
|
--argc; ++argv;
|
||||||
int target_len = argc - 1;
|
|
||||||
|
|
||||||
if (strncmp(*argv, "→", strlen("→")) == 0) {
|
if (strncmp(*argv, "→", strlen("→")) == 0) {
|
||||||
if (argc < 3) {
|
if (argc < 2) {
|
||||||
free(criteria);
|
free(criteria);
|
||||||
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
|
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
|
||||||
}
|
}
|
||||||
|
--argc;
|
||||||
++argv;
|
++argv;
|
||||||
--target_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(*argv, "output") == 0) {
|
if (strcmp(*argv, "output") == 0) {
|
||||||
criteria->type = CT_ASSIGN_OUTPUT;
|
criteria->type = CT_ASSIGN_OUTPUT;
|
||||||
++argv;
|
--argc; ++argv;
|
||||||
--target_len;
|
} else {
|
||||||
|
if (strcmp(*argv, "workspace") == 0) {
|
||||||
|
--argc; ++argv;
|
||||||
|
}
|
||||||
|
if (strcmp(*argv, "number") == 0) {
|
||||||
|
--argc; ++argv;
|
||||||
|
if (argv[0][0] < '0' || argv[0][0] > '9') {
|
||||||
|
free(criteria);
|
||||||
|
return cmd_results_new(CMD_INVALID, "assign",
|
||||||
|
"Invalid workspace number '%s'", argv[0]);
|
||||||
|
}
|
||||||
|
criteria->type = CT_ASSIGN_WORKSPACE_NUMBER;
|
||||||
} else {
|
} else {
|
||||||
criteria->type = CT_ASSIGN_WORKSPACE;
|
criteria->type = CT_ASSIGN_WORKSPACE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
criteria->target = join_args(argv, target_len);
|
criteria->target = join_args(argv, argc);
|
||||||
|
|
||||||
list_add(config->criteria, criteria);
|
list_add(config->criteria, criteria);
|
||||||
wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
|
wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
|
||||||
|
|
|
@ -219,13 +219,20 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1).
|
||||||
The following commands may be used either in the configuration file or at
|
The following commands may be used either in the configuration file or at
|
||||||
runtime.
|
runtime.
|
||||||
|
|
||||||
*assign* <criteria> [→] <workspace>
|
*assign* <criteria> [→] [workspace] [number] <workspace>
|
||||||
Assigns views matching _criteria_ (see *CRITERIA* for details) to
|
Assigns views matching _criteria_ (see *CRITERIA* for details) to
|
||||||
_workspace_. The → (U+2192) is optional and cosmetic. This command is
|
_workspace_. The → (U+2192) is optional and cosmetic. This command is
|
||||||
equivalent to:
|
equivalent to:
|
||||||
|
|
||||||
for\_window <criteria> move container to workspace <workspace>
|
for\_window <criteria> move container to workspace <workspace>
|
||||||
|
|
||||||
|
*assign* <criteria> [→] output left|right|up|down|<name>
|
||||||
|
Assigns views matching _criteria_ (see *CRITERIA* for details) to the
|
||||||
|
specified output. The → (U+2192) is optional and cosmetic. This command is
|
||||||
|
equivalent to:
|
||||||
|
|
||||||
|
for\_window <criteria> move container to output <output>
|
||||||
|
|
||||||
*bindsym* [--release|--locked] <key combo> <command>
|
*bindsym* [--release|--locked] <key combo> <command>
|
||||||
Binds _key combo_ to execute the sway command _command_ when pressed. You
|
Binds _key combo_ to execute the sway command _command_ when pressed. You
|
||||||
may use XKB key names here (*xev*(1) is a good tool for discovering these).
|
may use XKB key names here (*xev*(1) is a good tool for discovering these).
|
||||||
|
|
|
@ -450,12 +450,22 @@ static struct sway_container *select_workspace(struct sway_view *view) {
|
||||||
|
|
||||||
// Check if there's any `assign` criteria for the view
|
// Check if there's any `assign` criteria for the view
|
||||||
list_t *criterias = criteria_for_view(view,
|
list_t *criterias = criteria_for_view(view,
|
||||||
CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT);
|
CT_ASSIGN_WORKSPACE | CT_ASSIGN_WORKSPACE_NUMBER | CT_ASSIGN_OUTPUT);
|
||||||
struct sway_container *ws = NULL;
|
struct sway_container *ws = NULL;
|
||||||
for (int i = 0; i < criterias->length; ++i) {
|
for (int i = 0; i < criterias->length; ++i) {
|
||||||
struct criteria *criteria = criterias->items[i];
|
struct criteria *criteria = criterias->items[i];
|
||||||
if (criteria->type == CT_ASSIGN_WORKSPACE) {
|
if (criteria->type == CT_ASSIGN_OUTPUT) {
|
||||||
ws = workspace_by_name(criteria->target);
|
struct sway_container *output = output_by_name(criteria->target);
|
||||||
|
if (output) {
|
||||||
|
ws = seat_get_active_child(seat, output);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// CT_ASSIGN_WORKSPACE(_NUMBER)
|
||||||
|
ws = criteria->type == CT_ASSIGN_WORKSPACE_NUMBER ?
|
||||||
|
workspace_by_number(criteria->target) :
|
||||||
|
workspace_by_name(criteria->target);
|
||||||
|
|
||||||
if (!ws) {
|
if (!ws) {
|
||||||
if (strcasecmp(criteria->target, "back_and_forth") == 0) {
|
if (strcasecmp(criteria->target, "back_and_forth") == 0) {
|
||||||
if (prev_workspace_name) {
|
if (prev_workspace_name) {
|
||||||
|
@ -466,13 +476,6 @@ static struct sway_container *select_workspace(struct sway_view *view) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
// CT_ASSIGN_OUTPUT
|
|
||||||
struct sway_container *output = output_by_name(criteria->target);
|
|
||||||
if (output) {
|
|
||||||
ws = seat_get_active_child(seat, output);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list_free(criterias);
|
list_free(criterias);
|
||||||
|
|
Loading…
Reference in a new issue