1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "log.h"
static struct cmd_results *do_split(int layout) {
struct sway_container *con = config->handler_context.container;
struct sway_workspace *ws = config->handler_context.workspace;
if (con) {
if (container_is_scratchpad_hidden_or_child(con) &&
con->pending.fullscreen_mode != FULLSCREEN_GLOBAL) {
return cmd_results_new(CMD_FAILURE,
"Cannot split a hidden scratchpad container");
}
container_split(con, layout);
} else {
workspace_split(ws, layout);
}
if (root->fullscreen_global) {
arrange_root();
} else {
arrange_workspace(ws);
}
return cmd_results_new(CMD_SUCCESS, NULL);
}
static struct cmd_results *do_unsplit() {
struct sway_container *con = config->handler_context.container;
struct sway_workspace *ws = config->handler_context.workspace;
if (con && con->pending.parent && con->pending.parent->pending.children->length == 1) {
container_flatten(con->pending.parent);
} else {
return cmd_results_new(CMD_FAILURE, "Can only flatten a child container with no siblings");
}
if (root->fullscreen_global) {
arrange_root();
} else {
arrange_workspace(ws);
}
return cmd_results_new(CMD_SUCCESS, NULL);
}
struct cmd_results *cmd_split(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) {
return error;
}
if (!root->outputs->length) {
return cmd_results_new(CMD_INVALID,
"Can't run this command while there's no outputs connected.");
}
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
return do_split(L_VERT);
} else if (strcasecmp(argv[0], "h") == 0 ||
strcasecmp(argv[0], "horizontal") == 0) {
return do_split(L_HORIZ);
} else if (strcasecmp(argv[0], "t") == 0 ||
strcasecmp(argv[0], "toggle") == 0) {
struct sway_container *focused = config->handler_context.container;
if (focused && container_parent_layout(focused) == L_VERT) {
return do_split(L_HORIZ);
} else {
return do_split(L_VERT);
}
} else if (strcasecmp(argv[0], "n") == 0 ||
strcasecmp(argv[0], "none") == 0) {
return do_unsplit();
} else {
return cmd_results_new(CMD_FAILURE,
"Invalid split command (expected either horizontal or vertical).");
}
return cmd_results_new(CMD_SUCCESS, NULL);
}
struct cmd_results *cmd_splitv(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "splitv", EXPECTED_EQUAL_TO, 0))) {
return error;
}
return do_split(L_VERT);
}
struct cmd_results *cmd_splith(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "splith", EXPECTED_EQUAL_TO, 0))) {
return error;
}
return do_split(L_HORIZ);
}
struct cmd_results *cmd_splitt(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "splitt", EXPECTED_EQUAL_TO, 0))) {
return error;
}
struct sway_container *con = config->handler_context.container;
if (con && container_parent_layout(con) == L_VERT) {
return do_split(L_HORIZ);
} else {
return do_split(L_VERT);
}
}
|