aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-21 07:24:17 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-21 07:24:17 -0400
commita436fc17ffe3b8c7a98e8b0f4ae7ec765635d4aa (patch)
tree100d217f50e6116fbc7823fcb474b1060fde06e6
parentFix compiler warnings (which were really errors) (diff)
parentFixed style errors (diff)
downloadsway-a436fc17ffe3b8c7a98e8b0f4ae7ec765635d4aa.tar.gz
sway-a436fc17ffe3b8c7a98e8b0f4ae7ec765635d4aa.tar.zst
sway-a436fc17ffe3b8c7a98e8b0f4ae7ec765635d4aa.zip
Merge pull request #105 from Half-Shot/master
Basic 'move' functionality.
-rw-r--r--include/container.h2
-rw-r--r--include/layout.h3
-rw-r--r--sway/commands.c24
-rw-r--r--sway/layout.c44
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
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 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);
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,enum movement_direction direction);
21
22
20// Layout 23// Layout
21void arrange_windows(swayc_t *container, double width, double height); 24void 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
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 return false;
361 }
362 return true;
363}
364
344static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { 365static 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.
113void 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
112void arrange_windows(swayc_t *container, double width, double height) { 156void arrange_windows(swayc_t *container, double width, double height) {
113 int i; 157 int i;