aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/split.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-31 00:44:17 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-03-31 15:37:16 -0400
commit7706d83160267be61accb1b6f7bdc2f43299cae7 (patch)
tree64b9751ee7edf613c9e3a06d1f5446501f4ddbaf /sway/commands/split.c
parentMerge pull request #1684 from swaywm/follow-warp (diff)
downloadsway-7706d83160267be61accb1b6f7bdc2f43299cae7.tar.gz
sway-7706d83160267be61accb1b6f7bdc2f43299cae7.tar.zst
sway-7706d83160267be61accb1b6f7bdc2f43299cae7.zip
basic split containers
Diffstat (limited to 'sway/commands/split.c')
-rw-r--r--sway/commands/split.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/sway/commands/split.c b/sway/commands/split.c
new file mode 100644
index 00000000..6df20e88
--- /dev/null
+++ b/sway/commands/split.c
@@ -0,0 +1,107 @@
1#include <string.h>
2#include <strings.h>
3#include "sway/commands.h"
4#include "sway/tree/container.h"
5#include "sway/tree/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"
10
11static struct cmd_results *_do_split(int argc, char **argv, int layout) {
12 char *name = layout == L_VERT ? "splitv" :
13 layout == L_HORIZ ? "splith" : "split";
14 struct cmd_results *error = NULL;
15 if (config->reading) {
16 return cmd_results_new(CMD_FAILURE, name,
17 "Can't be used in config file.");
18 }
19 if (!config->active) {
20 return cmd_results_new(CMD_FAILURE, name,
21 "Can only be used when sway is running.");
22 }
23 if ((error = checkarg(argc, name, EXPECTED_EQUAL_TO, 0))) {
24 return error;
25 }
26
27 struct sway_container *focused = config->handler_context.current_container;
28
29 // TODO floating: dont split
30
31 /* Case that focus is on an workspace with 0/1 children.change its layout */
32 if (focused->type == C_WORKSPACE && focused->children->length <= 1) {
33 wlr_log(L_DEBUG, "changing workspace layout");
34 container_set_layout(focused, layout);
35 } else if (focused->type != C_WORKSPACE &&
36 focused->parent->children->length == 1) {
37 /* Case of no siblings. change parent layout */
38 wlr_log(L_DEBUG, "changing container layout");
39 container_set_layout(focused->parent, layout);
40 } else {
41 // regular case where new split container is build around focused
42 // container or in case of workspace, container inherits its children
43 wlr_log(L_DEBUG,
44 "Adding new container around current focused container");
45 wlr_log(L_INFO, "FOCUSED SIZE: %.f %.f",
46 focused->width, focused->height);
47
48 struct sway_container *parent = container_split(focused, layout);
49 arrange_windows(parent, -1, -1);
50 }
51
52 // TODO borders: update borders
53
54 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
55}
56
57struct cmd_results *cmd_split(int argc, char **argv) {
58 struct cmd_results *error = NULL;
59 if (config->reading) {
60 return cmd_results_new(CMD_FAILURE, "split",
61 "Can't be used in config file.");
62 }
63 if (!config->active) {
64 return cmd_results_new(CMD_FAILURE, "split",
65 "Can only be used when sway is running.");
66 }
67 if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
68 return error;
69 }
70 if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
71 _do_split(argc - 1, argv + 1, L_VERT);
72 } else if (strcasecmp(argv[0], "h") == 0 ||
73 strcasecmp(argv[0], "horizontal") == 0) {
74 _do_split(argc - 1, argv + 1, L_HORIZ);
75 } else if (strcasecmp(argv[0], "t") == 0 ||
76 strcasecmp(argv[0], "toggle") == 0) {
77 struct sway_container *focused =
78 config->handler_context.current_container;
79 if (focused->parent->layout == L_VERT) {
80 _do_split(argc - 1, argv + 1, L_HORIZ);
81 } else {
82 _do_split(argc - 1, argv + 1, L_VERT);
83 }
84 } else {
85 error = cmd_results_new(CMD_FAILURE, "split",
86 "Invalid split command (expected either horizontal or vertical).");
87 return error;
88 }
89 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
90}
91
92struct cmd_results *cmd_splitv(int argc, char **argv) {
93 return _do_split(argc, argv, L_VERT);
94}
95
96struct cmd_results *cmd_splith(int argc, char **argv) {
97 return _do_split(argc, argv, L_HORIZ);
98}
99
100struct cmd_results *cmd_splitt(int argc, char **argv) {
101 struct sway_container *focused = config->handler_context.current_container;
102 if (focused->parent->layout == L_VERT) {
103 return _do_split(argc, argv, L_HORIZ);
104 } else {
105 return _do_split(argc, argv, L_VERT);
106 }
107}