diff options
-rw-r--r-- | include/container.h | 2 | ||||
-rw-r--r-- | include/layout.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 24 | ||||
-rw-r--r-- | sway/layout.c | 44 |
4 files changed, 72 insertions, 1 deletions
diff --git a/include/container.h b/include/container.h index 3598067c..4e21461c 100644 --- a/include/container.h +++ b/include/container.h | |||
@@ -15,6 +15,7 @@ enum swayc_types{ | |||
15 | C_TYPES, | 15 | C_TYPES, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | |||
18 | enum swayc_layouts{ | 19 | enum swayc_layouts{ |
19 | L_NONE, | 20 | L_NONE, |
20 | L_HORIZ, | 21 | L_HORIZ, |
@@ -86,6 +87,7 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); | |||
86 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | 87 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); |
87 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | 88 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); |
88 | 89 | ||
90 | |||
89 | // Mappings | 91 | // Mappings |
90 | void set_view_visibility(swayc_t *view, void *data); | 92 | void set_view_visibility(swayc_t *view, void *data); |
91 | void reset_gaps(swayc_t *view, void *data); | 93 | void reset_gaps(swayc_t *view, void *data); |
diff --git a/include/layout.h b/include/layout.h index 20044b95..55bb6709 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -17,6 +17,9 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); | |||
17 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); | 17 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); |
18 | swayc_t *remove_child(swayc_t *child); | 18 | swayc_t *remove_child(swayc_t *child); |
19 | 19 | ||
20 | void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); | ||
21 | |||
22 | |||
20 | // Layout | 23 | // Layout |
21 | void arrange_windows(swayc_t *container, double width, double height); | 24 | void arrange_windows(swayc_t *container, double width, double height); |
22 | 25 | ||
diff --git a/sway/commands.c b/sway/commands.c index d1bbdc89..cb96703e 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -206,7 +206,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
206 | if (!view->is_floating) { | 206 | if (!view->is_floating) { |
207 | // Remove view from its current location | 207 | // Remove view from its current location |
208 | destroy_container(remove_child(view)); | 208 | destroy_container(remove_child(view)); |
209 | 209 | ||
210 | // and move it into workspace floating | 210 | // and move it into workspace floating |
211 | add_floating(active_workspace,view); | 211 | add_floating(active_workspace,view); |
212 | view->x = (active_workspace->width - view->width)/2; | 212 | view->x = (active_workspace->width - view->width)/2; |
@@ -341,6 +341,27 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * | |||
341 | return true; | 341 | return true; |
342 | } | 342 | } |
343 | 343 | ||
344 | static bool cmd_move(struct sway_config *config, int argc, char **argv) { | ||
345 | if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { | ||
346 | return false; | ||
347 | } | ||
348 | |||
349 | swayc_t *view = get_focused_container(&root_container); | ||
350 | |||
351 | if (strcasecmp(argv[0], "left") == 0) { | ||
352 | move_container(view,&root_container,MOVE_LEFT); | ||
353 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
354 | move_container(view,&root_container,MOVE_RIGHT); | ||
355 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
356 | move_container(view,&root_container,MOVE_UP); | ||
357 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
358 | move_container(view,&root_container,MOVE_DOWN); | ||
359 | } else { | ||
360 | return false; | ||
361 | } | ||
362 | return true; | ||
363 | } | ||
364 | |||
344 | static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | 365 | static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { |
345 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { | 366 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { |
346 | return false; | 367 | return false; |
@@ -736,6 +757,7 @@ static struct cmd_handler handlers[] = { | |||
736 | { "kill", cmd_kill }, | 757 | { "kill", cmd_kill }, |
737 | { "layout", cmd_layout }, | 758 | { "layout", cmd_layout }, |
738 | { "log_colors", cmd_log_colors }, | 759 | { "log_colors", cmd_log_colors }, |
760 | { "move", cmd_move}, | ||
739 | { "reload", cmd_reload }, | 761 | { "reload", cmd_reload }, |
740 | { "resize", cmd_resize }, | 762 | { "resize", cmd_resize }, |
741 | { "set", cmd_set }, | 763 | { "set", cmd_set }, |
diff --git a/sway/layout.c b/sway/layout.c index 35aa4942..7eaa9ea4 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -108,6 +108,50 @@ swayc_t *remove_child(swayc_t *child) { | |||
108 | return parent; | 108 | return parent; |
109 | } | 109 | } |
110 | 110 | ||
111 | //TODO: Implement horizontal movement. | ||
112 | //TODO: Implement move to a different workspace. | ||
113 | void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){ | ||
114 | sway_log(L_DEBUG, "Moved window"); | ||
115 | swayc_t *temp; | ||
116 | int i; | ||
117 | uint clength = root->children->length; | ||
118 | //Rearrange | ||
119 | for (i = 0; i < clength; ++i) { | ||
120 | swayc_t *child = root->children->items[i]; | ||
121 | if (child->handle == container->handle){ | ||
122 | if (clength == 1){ | ||
123 | //Only one container, meh. | ||
124 | break; | ||
125 | } | ||
126 | if (direction == MOVE_LEFT && i > 0){ | ||
127 | temp = root->children->items[i-1]; | ||
128 | root->children->items[i] = temp; | ||
129 | root->children->items[i-1] = container; | ||
130 | arrange_windows(&root_container,-1,-1); | ||
131 | } | ||
132 | else if (direction == MOVE_RIGHT && i < clength-1){ | ||
133 | temp = root->children->items[i+1]; | ||
134 | root->children->items[i] = temp; | ||
135 | root->children->items[i+1] = container; | ||
136 | arrange_windows(&root_container,-1,-1); | ||
137 | |||
138 | } | ||
139 | else if (direction == MOVE_UP){ | ||
140 | sway_log(L_INFO, "Moving up not implemented"); | ||
141 | } | ||
142 | else if (direction == MOVE_DOWN){ | ||
143 | sway_log(L_INFO, "Moving down not implemented"); | ||
144 | } | ||
145 | |||
146 | break; | ||
147 | } | ||
148 | else if (child->children != NULL){ | ||
149 | move_container(container,child,direction); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | } | ||
154 | |||
111 | 155 | ||
112 | void arrange_windows(swayc_t *container, double width, double height) { | 156 | void arrange_windows(swayc_t *container, double width, double height) { |
113 | int i; | 157 | int i; |