diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 80 |
1 files changed, 41 insertions, 39 deletions
diff --git a/sway/commands.c b/sway/commands.c index 7e9169e8..51de7a50 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -40,37 +40,37 @@ enum expected_args { | |||
40 | 40 | ||
41 | static bool checkarg(int argc, char *name, enum expected_args type, int val) { | 41 | static bool checkarg(int argc, char *name, enum expected_args type, int val) { |
42 | switch (type) { | 42 | switch (type) { |
43 | case EXPECTED_MORE_THAN: | 43 | case EXPECTED_MORE_THAN: |
44 | if (argc > val) { | 44 | if (argc > val) { |
45 | return true; | 45 | return true; |
46 | } | 46 | } |
47 | sway_log(L_ERROR, "Invalid %s command." | 47 | sway_log(L_ERROR, "Invalid %s command." |
48 | "(expected more than %d argument%s, got %d", | 48 | "(expected more than %d argument%s, got %d", |
49 | name, val, (char*[2]){"s", ""}[argc==1], argc); | 49 | name, val, (char*[2]){"s", ""}[argc==1], argc); |
50 | break; | 50 | break; |
51 | case EXPECTED_AT_LEAST: | 51 | case EXPECTED_AT_LEAST: |
52 | if (argc >= val) { | 52 | if (argc >= val) { |
53 | return true; | 53 | return true; |
54 | } | 54 | } |
55 | sway_log(L_ERROR, "Invalid %s command." | 55 | sway_log(L_ERROR, "Invalid %s command." |
56 | "(expected at least %d argument%s, got %d", | 56 | "(expected at least %d argument%s, got %d", |
57 | name, val, (char*[2]){"s", ""}[argc==1], argc); | 57 | name, val, (char*[2]){"s", ""}[argc==1], argc); |
58 | break; | 58 | break; |
59 | case EXPECTED_LESS_THAN: | 59 | case EXPECTED_LESS_THAN: |
60 | if (argc < val) { | 60 | if (argc < val) { |
61 | return true; | 61 | return true; |
62 | }; | 62 | }; |
63 | sway_log(L_ERROR, "Invalid %s command." | 63 | sway_log(L_ERROR, "Invalid %s command." |
64 | "(expected less than %d argument%s, got %d", | 64 | "(expected less than %d argument%s, got %d", |
65 | name, val, (char*[2]){"s", ""}[argc==1], argc); | 65 | name, val, (char*[2]){"s", ""}[argc==1], argc); |
66 | break; | 66 | break; |
67 | case EXPECTED_EQUAL_TO: | 67 | case EXPECTED_EQUAL_TO: |
68 | if (argc == val) { | 68 | if (argc == val) { |
69 | return true; | 69 | return true; |
70 | }; | 70 | }; |
71 | sway_log(L_ERROR, "Invalid %s command." | 71 | sway_log(L_ERROR, "Invalid %s command." |
72 | "(expected %d arguments, got %d", name, val, argc); | 72 | "(expected %d arguments, got %d", name, val, argc); |
73 | break; | 73 | break; |
74 | } | 74 | } |
75 | return false; | 75 | return false; |
76 | } | 76 | } |
@@ -292,9 +292,11 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) { | |||
292 | return false; | 292 | return false; |
293 | } | 293 | } |
294 | swayc_t *parent = get_focused_container(&root_container); | 294 | swayc_t *parent = get_focused_container(&root_container); |
295 | |||
295 | while (parent->type == C_VIEW) { | 296 | while (parent->type == C_VIEW) { |
296 | parent = parent->parent; | 297 | parent = parent->parent; |
297 | } | 298 | } |
299 | |||
298 | if (strcasecmp(argv[0], "splith") == 0) { | 300 | if (strcasecmp(argv[0], "splith") == 0) { |
299 | parent->layout = L_HORIZ; | 301 | parent->layout = L_HORIZ; |
300 | } else if (strcasecmp(argv[0], "splitv") == 0) { | 302 | } else if (strcasecmp(argv[0], "splitv") == 0) { |
@@ -343,19 +345,17 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay | |||
343 | } | 345 | } |
344 | swayc_t *focused = get_focused_container(&root_container); | 346 | swayc_t *focused = get_focused_container(&root_container); |
345 | 347 | ||
346 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
347 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { | 348 | if (focused->type == C_WORKSPACE && focused->children->length <= 1) { |
349 | /* Case that focus is on an workspace with 0/1 children.change its layout */ | ||
348 | sway_log(L_DEBUG, "changing workspace layout"); | 350 | sway_log(L_DEBUG, "changing workspace layout"); |
349 | focused->layout = layout; | 351 | focused->layout = layout; |
350 | } | 352 | } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { |
351 | /* Case of no siblings. change parent layout */ | 353 | /* Case of no siblings. change parent layout */ |
352 | else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { | ||
353 | sway_log(L_DEBUG, "changing container layout"); | 354 | sway_log(L_DEBUG, "changing container layout"); |
354 | focused->parent->layout = layout; | 355 | focused->parent->layout = layout; |
355 | } | 356 | } else { |
356 | /* regular case where new split container is build around focused container | 357 | /* regular case where new split container is build around focused container |
357 | * or in case of workspace, container inherits its children */ | 358 | * or in case of workspace, container inherits its children */ |
358 | else { | ||
359 | sway_log(L_DEBUG, "Adding new container around current focused container"); | 359 | sway_log(L_DEBUG, "Adding new container around current focused container"); |
360 | swayc_t *parent = new_container(focused, layout); | 360 | swayc_t *parent = new_container(focused, layout); |
361 | set_focused_container(focused); | 361 | set_focused_container(focused); |
@@ -369,6 +369,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) { | |||
369 | if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) { | 369 | if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) { |
370 | return false; | 370 | return false; |
371 | } | 371 | } |
372 | |||
372 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { | 373 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { |
373 | _do_split(config, argc - 1, argv + 1, L_VERT); | 374 | _do_split(config, argc - 1, argv + 1, L_VERT); |
374 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { | 375 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { |
@@ -377,6 +378,7 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) { | |||
377 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); | 378 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); |
378 | return false; | 379 | return false; |
379 | } | 380 | } |
381 | |||
380 | return true; | 382 | return true; |
381 | } | 383 | } |
382 | 384 | ||