From 9ef866bfea19dd0e52b7608a11c0e0d34df7f5e4 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 18 Aug 2015 12:50:15 +0100 Subject: [PATCH 1/5] Beguin work on the move command. Stubbed method. --- sway/commands.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index 51de7a50c..2ecfeb983 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -281,6 +281,11 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * return true; } +static bool cmd_move(struct sway_config *config, int argc, char **argv) { + sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. + return true; +} + static bool cmd_kill(struct sway_config *config, int argc, char **argv) { swayc_t *view = get_focused_container(&root_container); wlc_view_close(view->handle); From d6ab5e481be2faa0e911d0b3109ae01fe79eb25f Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 18 Aug 2015 12:50:15 +0100 Subject: [PATCH 2/5] Beguin work on the move command. Stubbed method. --- sway/commands.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/commands.c b/sway/commands.c index 51de7a50c..197040640 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -281,6 +281,11 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * return true; } +static bool cmd_move(struct sway_config *config, int argc, char **argv) { + sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. + return true; +} + static bool cmd_kill(struct sway_config *config, int argc, char **argv) { swayc_t *view = get_focused_container(&root_container); wlc_view_close(view->handle); @@ -492,7 +497,8 @@ static struct cmd_handler handlers[] = { { "split", cmd_split }, { "splith", cmd_splith }, { "splitv", cmd_splitv }, - { "workspace", cmd_workspace } + { "workspace", cmd_workspace }, + { "cmd_move",cmd_move} }; static char **split_directive(char *line, int *argc) { From 2a62c5c7fb71fc815663281793ba6a89d2b246ed Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 20 Aug 2015 21:27:38 +0100 Subject: [PATCH 3/5] Basic left right move command implemented. --- include/container.h | 2 ++ include/layout.h | 3 +++ sway/commands.c | 25 ++++++++++++++++++++++--- sway/layout.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/include/container.h b/include/container.h index 186ee8b6b..63529e441 100644 --- a/include/container.h +++ b/include/container.h @@ -15,6 +15,7 @@ enum swayc_types{ C_TYPES, }; + enum swayc_layouts{ L_NONE, L_HORIZ, @@ -75,6 +76,7 @@ swayc_t *destroy_view(swayc_t *view); swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); + // Mappings void set_view_visibility(swayc_t *view, void *data); diff --git a/include/layout.h b/include/layout.h index 282f92ee0..79241698a 100644 --- a/include/layout.h +++ b/include/layout.h @@ -15,6 +15,9 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); +void move_container(swayc_t* container,swayc_t* root,int direction); + + // Layout void arrange_windows(swayc_t *container, int width, int height); diff --git a/sway/commands.c b/sway/commands.c index 9a3ea5d66..1ca5c17ff 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 * } static bool cmd_move(struct sway_config *config, int argc, char **argv) { - sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. + if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { + return false; + } + + swayc_t *view = get_focused_container(&root_container); + + if (strcasecmp(argv[0], "left") == 0) { + move_container(view,&root_container,MOVE_LEFT); + } else if (strcasecmp(argv[0], "right") == 0) { + move_container(view,&root_container,MOVE_RIGHT); + } else if (strcasecmp(argv[0], "up") == 0) { + move_container(view,&root_container,MOVE_UP); + } else if (strcasecmp(argv[0], "down") == 0) { + move_container(view,&root_container,MOVE_DOWN); + } else + { + return false; + } + return true; + } static bool cmd_kill(struct sway_config *config, int argc, char **argv) { @@ -492,13 +511,13 @@ static struct cmd_handler handlers[] = { { "kill", cmd_kill }, { "layout", cmd_layout }, { "log_colors", cmd_log_colors }, + { "move",cmd_move}, { "reload", cmd_reload }, { "set", cmd_set }, { "split", cmd_split }, { "splith", cmd_splith }, { "splitv", cmd_splitv }, - { "workspace", cmd_workspace }, - { "cmd_move",cmd_move} + { "workspace", cmd_workspace } }; static char **split_directive(char *line, int *argc) { diff --git a/sway/layout.c b/sway/layout.c index 105359d26..9fdfd62a9 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -91,6 +91,50 @@ swayc_t *remove_child(swayc_t *child) { return parent; } +void move_container(swayc_t *container,swayc_t* root,int direction){ + sway_log(L_DEBUG, "Moved window"); + swayc_t *temp; + int i; + uint clength = root->children->length; + //Rearrange + for (i = 0; i < clength; ++i) { + swayc_t *child = root->children->items[i]; + if(child->handle == container->handle){ + if(clength == 1){ + //Only one container, meh. + break; + } + + //TODO: Implement move to a different workspace. + if(direction == MOVE_LEFT && i > 0){ + temp = root->children->items[i-1]; + root->children->items[i] = temp; + root->children->items[i-1] = container; + arrange_windows(&root_container,-1,-1); + } + else if(direction == MOVE_RIGHT && i < clength-1){ + temp = root->children->items[i+1]; + root->children->items[i] = temp; + root->children->items[i+1] = container; + arrange_windows(&root_container,-1,-1); + + } + else if(direction == MOVE_UP){ + sway_log(L_INFO, "Moving up not implemented"); + } + else if(direction == MOVE_DOWN){ + sway_log(L_INFO, "Moving down not implemented"); + } + + break; + } + else if(child->children != NULL){ + move_container(container,child,direction); + } + } + +} + void arrange_windows(swayc_t *container, int width, int height) { int i; @@ -282,4 +326,3 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { } return NULL; } - From 713bf29ec901b711d782e96721898c32fcd5d56e Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 20 Aug 2015 21:45:00 +0100 Subject: [PATCH 4/5] Few stray bits --- include/layout.h | 2 +- sway/commands.c | 1 + sway/layout.c | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/layout.h b/include/layout.h index c1d7d8b46..5c73af997 100644 --- a/include/layout.h +++ b/include/layout.h @@ -17,7 +17,7 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); -void move_container(swayc_t* container,swayc_t* root,int direction); +void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); // Layout diff --git a/sway/commands.c b/sway/commands.c index e39b781a2..5d79104f6 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -362,6 +362,7 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { } return true; +} static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { diff --git a/sway/layout.c b/sway/layout.c index a48f15c4f..0c1f736d9 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -108,7 +108,9 @@ swayc_t *remove_child(swayc_t *child) { return parent; } -void move_container(swayc_t *container,swayc_t* root,int direction){ +//TODO: Implement horizontal movement. +//TODO: Implement move to a different workspace. +void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){ sway_log(L_DEBUG, "Moved window"); swayc_t *temp; int i; @@ -121,8 +123,6 @@ void move_container(swayc_t *container,swayc_t* root,int direction){ //Only one container, meh. break; } - //TODO: Implement horizontal movement. - //TODO: Implement move to a different workspace. if(direction == MOVE_LEFT && i > 0){ temp = root->children->items[i-1]; root->children->items[i] = temp; From 68213d57c5c758d05582ef8a9f0db226ddbaefc7 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 20 Aug 2015 22:29:36 +0100 Subject: [PATCH 5/5] Fixed style errors --- sway/commands.c | 8 +++----- sway/layout.c | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 5d79104f6..af4cd56f1 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) { if (!view->is_floating) { // Remove view from its current location destroy_container(remove_child(view)); - + // and move it into workspace floating add_floating(active_workspace,view); view->x = (active_workspace->width - view->width)/2; @@ -356,11 +356,9 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { move_container(view,&root_container,MOVE_UP); } else if (strcasecmp(argv[0], "down") == 0) { move_container(view,&root_container,MOVE_DOWN); - } else - { + } else { return false; } - return true; } @@ -606,7 +604,7 @@ static struct cmd_handler handlers[] = { { "kill", cmd_kill }, { "layout", cmd_layout }, { "log_colors", cmd_log_colors }, - { "move",cmd_move}, + { "move", cmd_move}, { "reload", cmd_reload }, { "set", cmd_set }, { "split", cmd_split }, diff --git a/sway/layout.c b/sway/layout.c index 0c1f736d9..a75367275 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -118,34 +118,34 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir //Rearrange for (i = 0; i < clength; ++i) { swayc_t *child = root->children->items[i]; - if(child->handle == container->handle){ - if(clength == 1){ + if (child->handle == container->handle){ + if (clength == 1){ //Only one container, meh. break; } - if(direction == MOVE_LEFT && i > 0){ + if (direction == MOVE_LEFT && i > 0){ temp = root->children->items[i-1]; root->children->items[i] = temp; root->children->items[i-1] = container; arrange_windows(&root_container,-1,-1); } - else if(direction == MOVE_RIGHT && i < clength-1){ + else if (direction == MOVE_RIGHT && i < clength-1){ temp = root->children->items[i+1]; root->children->items[i] = temp; root->children->items[i+1] = container; arrange_windows(&root_container,-1,-1); } - else if(direction == MOVE_UP){ + else if (direction == MOVE_UP){ sway_log(L_INFO, "Moving up not implemented"); } - else if(direction == MOVE_DOWN){ + else if (direction == MOVE_DOWN){ sway_log(L_INFO, "Moving down not implemented"); } break; } - else if(child->children != NULL){ + else if (child->children != NULL){ move_container(container,child,direction); } }