aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-09 19:27:25 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-09 19:27:25 -0400
commit22315865696264aeef296364c7fc420b972a10fb (patch)
tree97c2650060252b5966f9f6ec68b51e84e84e40be /sway/commands.c
parentMerge pull request #3 from jdiez17/log_colors_option (diff)
downloadsway-22315865696264aeef296364c7fc420b972a10fb.tar.gz
sway-22315865696264aeef296364c7fc420b972a10fb.tar.zst
sway-22315865696264aeef296364c7fc420b972a10fb.zip
Implement splith/splitv
Ref #2
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/sway/commands.c b/sway/commands.c
index efa72f19..322c9519 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -146,21 +146,38 @@ int cmd_set(struct sway_config *config, int argc, char **argv) {
146 return 0; 146 return 0;
147} 147}
148 148
149int cmd_log_colors(struct sway_config *config, int argc, char **argv) { 149int _do_split(struct sway_config *config, int argc, char **argv, int layout) {
150 if (argc != 1) { 150 if (argc != 0) {
151 sway_log(L_ERROR, "Invalid log_colors command (expected 1 argument, got %d)", argc); 151 sway_log(L_ERROR, "Invalid splitv command (expected 0 arguments, got %d)", argc);
152 return 1;
153 }
154
155 if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) {
156 sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]);
157 return 1; 152 return 1;
158 } 153 }
159 154 swayc_t *focused = get_focused_container(&root_container);
160 sway_log_colors(!strcasecmp(argv[0], "yes")); 155 swayc_t *parent = focused->parent;
156 sway_log(L_DEBUG, "Splitting %p vertically with %p", parent, focused);
157 int index = remove_container_from_parent(parent, focused);
158 swayc_t *new_container = create_container(parent, -1);
159 new_container->layout = layout;
160 new_container->weight = focused->weight;
161 new_container->width = focused->width;
162 new_container->height = focused->height;
163 new_container->x = focused->x;
164 new_container->y = focused->y;
165 focused->weight = 1;
166 focused->parent = new_container;
167 list_insert(parent->children, index, new_container);
168 list_add(new_container->children, focused);
169 focus_view(focused);
170 arrange_windows(parent, -1, -1);
161 return 0; 171 return 0;
162} 172}
163 173
174int cmd_splitv(struct sway_config *config, int argc, char **argv) {
175 return _do_split(config, argc, argv, L_VERT);
176}
177
178int cmd_splith(struct sway_config *config, int argc, char **argv) {
179 return _do_split(config, argc, argv, L_HORIZ);
180}
164 181
165/* Keep alphabetized */ 182/* Keep alphabetized */
166struct cmd_handler handlers[] = { 183struct cmd_handler handlers[] = {
@@ -169,8 +186,9 @@ struct cmd_handler handlers[] = {
169 { "exit", cmd_exit }, 186 { "exit", cmd_exit },
170 { "focus_follows_mouse", cmd_focus_follows_mouse }, 187 { "focus_follows_mouse", cmd_focus_follows_mouse },
171 { "layout", cmd_layout }, 188 { "layout", cmd_layout },
172 { "log_colors", cmd_log_colors },
173 { "set", cmd_set }, 189 { "set", cmd_set },
190 { "splith", cmd_splith },
191 { "splitv", cmd_splitv }
174}; 192};
175 193
176char **split_directive(char *line, int *argc) { 194char **split_directive(char *line, int *argc) {