summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/container.h2
-rw-r--r--include/layout.h3
-rw-r--r--sway/commands.c23
-rw-r--r--sway/layout.c44
4 files changed, 72 insertions, 0 deletions
diff --git a/include/container.h b/include/container.h
index fd621490..79e023fe 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
18enum swayc_layouts{ 19enum 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);
86swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); 87swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data);
87void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); 88void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
88 89
90
89// Mappings 91// Mappings
90void set_view_visibility(swayc_t *view, void *data); 92void set_view_visibility(swayc_t *view, void *data);
91void reset_gaps(swayc_t *view, void *data); 93void reset_gaps(swayc_t *view, void *data);
diff --git a/include/layout.h b/include/layout.h
index 75e72d2f..c1d7d8b4 100644
--- a/include/layout.h
+++ b/include/layout.h
@@ -17,6 +17,9 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child);
17swayc_t *replace_child(swayc_t *child, swayc_t *new_child); 17swayc_t *replace_child(swayc_t *child, swayc_t *new_child);
18swayc_t *remove_child(swayc_t *child); 18swayc_t *remove_child(swayc_t *child);
19 19
20void move_container(swayc_t* container,swayc_t* root,int direction);
21
22
20// Layout 23// Layout
21void arrange_windows(swayc_t *container, int width, int height); 24void arrange_windows(swayc_t *container, int width, int height);
22 25
diff --git a/sway/commands.c b/sway/commands.c
index 3ac7f4dd..e39b781a 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -341,6 +341,28 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char *
341 return true; 341 return true;
342} 342}
343 343
344static 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 {
361 return false;
362 }
363
364 return true;
365
344static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { 366static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
345 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { 367 if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
346 return false; 368 return false;
@@ -583,6 +605,7 @@ static struct cmd_handler handlers[] = {
583 { "kill", cmd_kill }, 605 { "kill", cmd_kill },
584 { "layout", cmd_layout }, 606 { "layout", cmd_layout },
585 { "log_colors", cmd_log_colors }, 607 { "log_colors", cmd_log_colors },
608 { "move",cmd_move},
586 { "reload", cmd_reload }, 609 { "reload", cmd_reload },
587 { "set", cmd_set }, 610 { "set", cmd_set },
588 { "split", cmd_split }, 611 { "split", cmd_split },
diff --git a/sway/layout.c b/sway/layout.c
index 8c011fdb..a48f15c4 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
111void move_container(swayc_t *container,swayc_t* root,int direction){
112 sway_log(L_DEBUG, "Moved window");
113 swayc_t *temp;
114 int i;
115 uint clength = root->children->length;
116 //Rearrange
117 for (i = 0; i < clength; ++i) {
118 swayc_t *child = root->children->items[i];
119 if(child->handle == container->handle){
120 if(clength == 1){
121 //Only one container, meh.
122 break;
123 }
124 //TODO: Implement horizontal movement.
125 //TODO: Implement move to a different workspace.
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
112void arrange_windows(swayc_t *container, int width, int height) { 156void arrange_windows(swayc_t *container, int width, int height) {
113 int i; 157 int i;