summaryrefslogtreecommitdiffstats
path: root/sway/commands/split.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/split.c')
-rw-r--r--sway/commands/split.c103
1 files changed, 41 insertions, 62 deletions
diff --git a/sway/commands/split.c b/sway/commands/split.c
index e3045a4f..130ed31f 100644
--- a/sway/commands/split.c
+++ b/sway/commands/split.c
@@ -1,76 +1,41 @@
1#include <string.h> 1#include <string.h>
2#include <strings.h> 2#include <strings.h>
3#include <wlc/wlc-render.h>
4#include "sway/border.h"
5#include "sway/commands.h" 3#include "sway/commands.h"
6#include "sway/container.h" 4#include "sway/tree/container.h"
7#include "sway/focus.h" 5#include "sway/tree/layout.h"
8#include "sway/layout.h" 6#include "sway/tree/view.h"
7#include "sway/input/input-manager.h"
8#include "sway/input/seat.h"
9#include "log.h" 9#include "log.h"
10 10
11static struct cmd_results *_do_split(int argc, char **argv, int layout) { 11static struct cmd_results *do_split(int layout) {
12 char *name = layout == L_VERT ? "splitv" : 12 struct sway_container *con = config->handler_context.current_container;
13 layout == L_HORIZ ? "splith" : "split"; 13 struct sway_container *parent = container_split(con, layout);
14 struct cmd_results *error = NULL; 14 container_create_notify(parent);
15 if (config->reading) return cmd_results_new(CMD_FAILURE, name, "Can't be used in config file."); 15 arrange_windows(parent, -1, -1);
16 if (!config->active) return cmd_results_new(CMD_FAILURE, name, "Can only be used when sway is running.");
17 if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) {
18 return error;
19 }
20 swayc_t *focused = current_container;
21
22 // Case of floating window, don't split
23 if (focused->is_floating) {
24 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
25 }
26 /* Case that focus is on an workspace with 0/1 children.change its layout */
27 if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
28 sway_log(L_DEBUG, "changing workspace layout");
29 swayc_change_layout(focused, layout);
30 } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) {
31 /* Case of no siblings. change parent layout */
32 sway_log(L_DEBUG, "changing container layout");
33 swayc_change_layout(focused->parent, layout);
34 } else {
35 /* regular case where new split container is build around focused container
36 * or in case of workspace, container inherits its children */
37 sway_log(L_DEBUG, "Adding new container around current focused container");
38 sway_log(L_INFO, "FOCUSED SIZE: %.f %.f", focused->width, focused->height);
39 swayc_t *parent = new_container(focused, layout);
40 set_focused_container(focused);
41 arrange_windows(parent, -1, -1);
42 }
43
44 // update container every time
45 // if it is tabbed/stacked then the title must change
46 // if the indicator color is different then the border must change
47 update_container_border(focused);
48 swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
49 // schedule render to make changes take effect right away,
50 // otherwise we would have to wait for the view to render,
51 // which is unpredictable.
52 wlc_output_schedule_render(output->handle);
53 16
54 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 17 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
55} 18}
56 19
57struct cmd_results *cmd_split(int argc, char **argv) { 20struct cmd_results *cmd_split(int argc, char **argv) {
58 struct cmd_results *error = NULL; 21 struct cmd_results *error = NULL;
59 if (config->reading) return cmd_results_new(CMD_FAILURE, "split", "Can't be used in config file.");
60 if (!config->active) return cmd_results_new(CMD_FAILURE, "split", "Can only be used when sway is running.");
61 if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) { 22 if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
62 return error; 23 return error;
63 } 24 }
64 if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { 25 if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
65 _do_split(argc - 1, argv + 1, L_VERT); 26 do_split(L_VERT);
66 } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { 27 } else if (strcasecmp(argv[0], "h") == 0 ||
67 _do_split(argc - 1, argv + 1, L_HORIZ); 28 strcasecmp(argv[0], "horizontal") == 0) {
68 } else if (strcasecmp(argv[0], "t") == 0 || strcasecmp(argv[0], "toggle") == 0) { 29 do_split(L_HORIZ);
69 swayc_t *focused = current_container; 30 } else if (strcasecmp(argv[0], "t") == 0 ||
31 strcasecmp(argv[0], "toggle") == 0) {
32 struct sway_container *focused =
33 config->handler_context.current_container;
34
70 if (focused->parent->layout == L_VERT) { 35 if (focused->parent->layout == L_VERT) {
71 _do_split(argc - 1, argv + 1, L_HORIZ); 36 do_split(L_HORIZ);
72 } else { 37 } else {
73 _do_split(argc - 1, argv + 1, L_VERT); 38 do_split(L_VERT);
74 } 39 }
75 } else { 40 } else {
76 error = cmd_results_new(CMD_FAILURE, "split", 41 error = cmd_results_new(CMD_FAILURE, "split",
@@ -81,18 +46,32 @@ struct cmd_results *cmd_split(int argc, char **argv) {
81} 46}
82 47
83struct cmd_results *cmd_splitv(int argc, char **argv) { 48struct cmd_results *cmd_splitv(int argc, char **argv) {
84 return _do_split(argc, argv, L_VERT); 49 struct cmd_results *error = NULL;
50 if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
51 return error;
52 }
53 return do_split(L_VERT);
85} 54}
86 55
87struct cmd_results *cmd_splith(int argc, char **argv) { 56struct cmd_results *cmd_splith(int argc, char **argv) {
88 return _do_split(argc, argv, L_HORIZ); 57 struct cmd_results *error = NULL;
58 if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
59 return error;
60 }
61 return do_split(L_HORIZ);
89} 62}
90 63
91struct cmd_results *cmd_splitt(int argc, char **argv) { 64struct cmd_results *cmd_splitt(int argc, char **argv) {
92 swayc_t *focused = current_container; 65 struct cmd_results *error = NULL;
93 if (focused->parent->layout == L_VERT) { 66 if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
94 return _do_split(argc, argv, L_HORIZ); 67 return error;
68 }
69
70 struct sway_container *con = config->handler_context.current_container;
71
72 if (con->parent->layout == L_VERT) {
73 return do_split(L_HORIZ);
95 } else { 74 } else {
96 return _do_split(argc, argv, L_VERT); 75 return do_split(L_VERT);
97 } 76 }
98} 77}