From b43161fd45c794448d17e705413949dbb62727db Mon Sep 17 00:00:00 2001 From: Taiyu Date: Mon, 10 Aug 2015 00:05:44 -0700 Subject: [PATCH 1/2] fixed focus_parent, moved into move_focus() function --- sway/commands.c | 7 +------ sway/movement.c | 14 ++++++++++++++ sway/movement.h | 11 ++++++----- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 40d9d353c..64130fdcb 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -112,12 +112,7 @@ int cmd_focus(struct sway_config *config, int argc, char **argv) { } else if (strcasecmp(argv[0], "down") == 0) { return move_focus(MOVE_DOWN); } else if (strcasecmp(argv[0], "parent") == 0) { - swayc_t *current = get_focused_container(&root_container); - if (current && current->parent) { - current->parent->focused = NULL; - unfocus_all(current->parent); - focus_view(current->parent); - } + return move_focus(MOVE_PARENT); } return 0; } diff --git a/sway/movement.c b/sway/movement.c index 108e25880..4503a7165 100644 --- a/sway/movement.c +++ b/sway/movement.c @@ -9,6 +9,20 @@ int move_focus(enum movement_direction direction) { swayc_t *current = get_focused_container(&root_container); swayc_t *parent = current->parent; + if(direction == MOVE_PARENT) { + current = parent; + parent = parent->parent; + if(parent->type == C_ROOT) { + sway_log(L_DEBUG, "Focus cannot move to parent"); + return 1; + } else { + sway_log(L_DEBUG, "Moving focus away from %p", current); + unfocus_all(parent); + focus_view (parent); + return 0; + } + } + while (true) { sway_log(L_DEBUG, "Moving focus away from %p", current); diff --git a/sway/movement.h b/sway/movement.h index 44e630ffe..a527674cb 100644 --- a/sway/movement.h +++ b/sway/movement.h @@ -4,11 +4,12 @@ #include #include "list.h" -enum movement_direction{ - MOVE_LEFT, - MOVE_RIGHT, - MOVE_UP, - MOVE_DOWN +enum movement_direction { + MOVE_LEFT, + MOVE_RIGHT, + MOVE_UP, + MOVE_DOWN, + MOVE_PARENT }; int move_focus(enum movement_direction direction); From f923c4e6b93a5361c1737b239dbacef6e7219b04 Mon Sep 17 00:00:00 2001 From: Taiyu Date: Mon, 10 Aug 2015 07:06:54 -0700 Subject: [PATCH 2/2] fixed style --- sway/movement.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sway/movement.c b/sway/movement.c index 4503a7165..a55d0350d 100644 --- a/sway/movement.c +++ b/sway/movement.c @@ -9,16 +9,16 @@ int move_focus(enum movement_direction direction) { swayc_t *current = get_focused_container(&root_container); swayc_t *parent = current->parent; - if(direction == MOVE_PARENT) { + if (direction == MOVE_PARENT) { current = parent; parent = parent->parent; - if(parent->type == C_ROOT) { + if (parent->type == C_ROOT) { sway_log(L_DEBUG, "Focus cannot move to parent"); return 1; } else { sway_log(L_DEBUG, "Moving focus away from %p", current); unfocus_all(parent); - focus_view (parent); + focus_view(parent); return 0; } }