mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 07:56:31 +01:00
Add split [h|v|horizontal|vertical] command
This commit is contained in:
parent
749238b130
commit
360b3d67b0
1 changed files with 28 additions and 3 deletions
|
@ -31,6 +31,7 @@ static struct modifier_key modifiers[] = {
|
||||||
|
|
||||||
enum expected_args {
|
enum expected_args {
|
||||||
EXPECTED_MORE_THAN,
|
EXPECTED_MORE_THAN,
|
||||||
|
EXPECTED_AT_LEAST,
|
||||||
EXPECTED_LESS_THAN,
|
EXPECTED_LESS_THAN,
|
||||||
EXPECTED_EQUAL_TO
|
EXPECTED_EQUAL_TO
|
||||||
};
|
};
|
||||||
|
@ -42,7 +43,15 @@ static bool checkarg(int argc, char *name, enum expected_args type, int val) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
sway_log(L_ERROR, "Invalid %s command."
|
sway_log(L_ERROR, "Invalid %s command."
|
||||||
"(expected more then %d argument%s, got %d",
|
"(expected more than %d argument%s, got %d",
|
||||||
|
name, val, (char*[2]){"s", ""}[argc==1], argc);
|
||||||
|
break;
|
||||||
|
case EXPECTED_AT_LEAST:
|
||||||
|
if (argc >= val) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
sway_log(L_ERROR, "Invalid %s command."
|
||||||
|
"(expected at least %d argument%s, got %d",
|
||||||
name, val, (char*[2]){"s", ""}[argc==1], argc);
|
name, val, (char*[2]){"s", ""}[argc==1], argc);
|
||||||
break;
|
break;
|
||||||
case EXPECTED_LESS_THAN:
|
case EXPECTED_LESS_THAN:
|
||||||
|
@ -50,7 +59,7 @@ static bool checkarg(int argc, char *name, enum expected_args type, int val) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
sway_log(L_ERROR, "Invalid %s command."
|
sway_log(L_ERROR, "Invalid %s command."
|
||||||
"(expected less then %d argument%s, got %d",
|
"(expected less than %d argument%s, got %d",
|
||||||
name, val, (char*[2]){"s", ""}[argc==1], argc);
|
name, val, (char*[2]){"s", ""}[argc==1], argc);
|
||||||
break;
|
break;
|
||||||
case EXPECTED_EQUAL_TO:
|
case EXPECTED_EQUAL_TO:
|
||||||
|
@ -257,6 +266,21 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool cmd_split(struct sway_config *config, int argc, char **argv) {
|
||||||
|
if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
|
||||||
|
_do_split(config, argc, argv, L_VERT);
|
||||||
|
} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) {
|
||||||
|
_do_split(config, argc, argv, L_HORIZ);
|
||||||
|
} else {
|
||||||
|
sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical).");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool cmd_splitv(struct sway_config *config, int argc, char **argv) {
|
static bool cmd_splitv(struct sway_config *config, int argc, char **argv) {
|
||||||
return _do_split(config, argc, argv, L_VERT);
|
return _do_split(config, argc, argv, L_VERT);
|
||||||
}
|
}
|
||||||
|
@ -279,7 +303,7 @@ static bool cmd_log_colors(struct sway_config *config, int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) {
|
static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) {
|
||||||
if (!checkarg(argc, "fullscreen", EXPECTED_EQUAL_TO, 0)) {
|
if (!checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,6 +349,7 @@ static struct cmd_handler handlers[] = {
|
||||||
{ "log_colors", cmd_log_colors },
|
{ "log_colors", cmd_log_colors },
|
||||||
{ "reload", cmd_reload },
|
{ "reload", cmd_reload },
|
||||||
{ "set", cmd_set },
|
{ "set", cmd_set },
|
||||||
|
{ "split", cmd_split },
|
||||||
{ "splith", cmd_splith },
|
{ "splith", cmd_splith },
|
||||||
{ "splitv", cmd_splitv },
|
{ "splitv", cmd_splitv },
|
||||||
{ "workspace", cmd_workspace }
|
{ "workspace", cmd_workspace }
|
||||||
|
|
Loading…
Reference in a new issue