diff options
author | Half-Shot <half-shot@molrams.com> | 2015-08-20 21:27:38 +0100 |
---|---|---|
committer | Half-Shot <half-shot@molrams.com> | 2015-08-20 21:29:40 +0100 |
commit | 2a62c5c7fb71fc815663281793ba6a89d2b246ed (patch) | |
tree | 88928911011bf8c1726198a7cbed8e21bb140253 | |
parent | Merge branch 'master' of https://github.com/SirCmpwn/sway (diff) | |
download | sway-2a62c5c7fb71fc815663281793ba6a89d2b246ed.tar.gz sway-2a62c5c7fb71fc815663281793ba6a89d2b246ed.tar.zst sway-2a62c5c7fb71fc815663281793ba6a89d2b246ed.zip |
Basic left right move command implemented.
-rw-r--r-- | include/container.h | 2 | ||||
-rw-r--r-- | include/layout.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 25 | ||||
-rw-r--r-- | sway/layout.c | 45 |
4 files changed, 71 insertions, 4 deletions
diff --git a/include/container.h b/include/container.h index 186ee8b6..63529e44 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, |
@@ -75,6 +76,7 @@ swayc_t *destroy_view(swayc_t *view); | |||
75 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); | 76 | swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); |
76 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); | 77 | void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); |
77 | 78 | ||
79 | |||
78 | // Mappings | 80 | // Mappings |
79 | void set_view_visibility(swayc_t *view, void *data); | 81 | void set_view_visibility(swayc_t *view, void *data); |
80 | 82 | ||
diff --git a/include/layout.h b/include/layout.h index 282f92ee..79241698 100644 --- a/include/layout.h +++ b/include/layout.h | |||
@@ -15,6 +15,9 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); | |||
15 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); | 15 | swayc_t *replace_child(swayc_t *child, swayc_t *new_child); |
16 | swayc_t *remove_child(swayc_t *child); | 16 | swayc_t *remove_child(swayc_t *child); |
17 | 17 | ||
18 | void move_container(swayc_t* container,swayc_t* root,int direction); | ||
19 | |||
20 | |||
18 | // Layout | 21 | // Layout |
19 | void arrange_windows(swayc_t *container, int width, int height); | 22 | void arrange_windows(swayc_t *container, int width, int height); |
20 | 23 | ||
diff --git a/sway/commands.c b/sway/commands.c index 9a3ea5d6..1ca5c17f 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -282,8 +282,27 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * | |||
282 | } | 282 | } |
283 | 283 | ||
284 | static bool cmd_move(struct sway_config *config, int argc, char **argv) { | 284 | static bool cmd_move(struct sway_config *config, int argc, char **argv) { |
285 | sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. | 285 | if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { |
286 | return false; | ||
287 | } | ||
288 | |||
289 | swayc_t *view = get_focused_container(&root_container); | ||
290 | |||
291 | if (strcasecmp(argv[0], "left") == 0) { | ||
292 | move_container(view,&root_container,MOVE_LEFT); | ||
293 | } else if (strcasecmp(argv[0], "right") == 0) { | ||
294 | move_container(view,&root_container,MOVE_RIGHT); | ||
295 | } else if (strcasecmp(argv[0], "up") == 0) { | ||
296 | move_container(view,&root_container,MOVE_UP); | ||
297 | } else if (strcasecmp(argv[0], "down") == 0) { | ||
298 | move_container(view,&root_container,MOVE_DOWN); | ||
299 | } else | ||
300 | { | ||
301 | return false; | ||
302 | } | ||
303 | |||
286 | return true; | 304 | return true; |
305 | |||
287 | } | 306 | } |
288 | 307 | ||
289 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { | 308 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { |
@@ -492,13 +511,13 @@ static struct cmd_handler handlers[] = { | |||
492 | { "kill", cmd_kill }, | 511 | { "kill", cmd_kill }, |
493 | { "layout", cmd_layout }, | 512 | { "layout", cmd_layout }, |
494 | { "log_colors", cmd_log_colors }, | 513 | { "log_colors", cmd_log_colors }, |
514 | { "move",cmd_move}, | ||
495 | { "reload", cmd_reload }, | 515 | { "reload", cmd_reload }, |
496 | { "set", cmd_set }, | 516 | { "set", cmd_set }, |
497 | { "split", cmd_split }, | 517 | { "split", cmd_split }, |
498 | { "splith", cmd_splith }, | 518 | { "splith", cmd_splith }, |
499 | { "splitv", cmd_splitv }, | 519 | { "splitv", cmd_splitv }, |
500 | { "workspace", cmd_workspace }, | 520 | { "workspace", cmd_workspace } |
501 | { "cmd_move",cmd_move} | ||
502 | }; | 521 | }; |
503 | 522 | ||
504 | static char **split_directive(char *line, int *argc) { | 523 | static char **split_directive(char *line, int *argc) { |
diff --git a/sway/layout.c b/sway/layout.c index 105359d2..9fdfd62a 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -91,6 +91,50 @@ swayc_t *remove_child(swayc_t *child) { | |||
91 | return parent; | 91 | return parent; |
92 | } | 92 | } |
93 | 93 | ||
94 | void move_container(swayc_t *container,swayc_t* root,int direction){ | ||
95 | sway_log(L_DEBUG, "Moved window"); | ||
96 | swayc_t *temp; | ||
97 | int i; | ||
98 | uint clength = root->children->length; | ||
99 | //Rearrange | ||
100 | for (i = 0; i < clength; ++i) { | ||
101 | swayc_t *child = root->children->items[i]; | ||
102 | if(child->handle == container->handle){ | ||
103 | if(clength == 1){ | ||
104 | //Only one container, meh. | ||
105 | break; | ||
106 | } | ||
107 | |||
108 | //TODO: Implement move to a different workspace. | ||
109 | if(direction == MOVE_LEFT && i > 0){ | ||
110 | temp = root->children->items[i-1]; | ||
111 | root->children->items[i] = temp; | ||
112 | root->children->items[i-1] = container; | ||
113 | arrange_windows(&root_container,-1,-1); | ||
114 | } | ||
115 | else if(direction == MOVE_RIGHT && i < clength-1){ | ||
116 | temp = root->children->items[i+1]; | ||
117 | root->children->items[i] = temp; | ||
118 | root->children->items[i+1] = container; | ||
119 | arrange_windows(&root_container,-1,-1); | ||
120 | |||
121 | } | ||
122 | else if(direction == MOVE_UP){ | ||
123 | sway_log(L_INFO, "Moving up not implemented"); | ||
124 | } | ||
125 | else if(direction == MOVE_DOWN){ | ||
126 | sway_log(L_INFO, "Moving down not implemented"); | ||
127 | } | ||
128 | |||
129 | break; | ||
130 | } | ||
131 | else if(child->children != NULL){ | ||
132 | move_container(container,child,direction); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | } | ||
137 | |||
94 | 138 | ||
95 | void arrange_windows(swayc_t *container, int width, int height) { | 139 | void arrange_windows(swayc_t *container, int width, int height) { |
96 | int i; | 140 | int i; |
@@ -282,4 +326,3 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { | |||
282 | } | 326 | } |
283 | return NULL; | 327 | return NULL; |
284 | } | 328 | } |
285 | |||