summaryrefslogtreecommitdiffstats
path: root/sway/movement.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/movement.c')
-rw-r--r--sway/movement.c70
1 files changed, 0 insertions, 70 deletions
diff --git a/sway/movement.c b/sway/movement.c
deleted file mode 100644
index 12726392..00000000
--- a/sway/movement.c
+++ /dev/null
@@ -1,70 +0,0 @@
1#include <stdlib.h>
2#include <stdbool.h>
3#include "list.h"
4#include "log.h"
5#include "layout.h"
6#include "movement.h"
7
8bool move_focus(enum movement_direction direction) {
9 swayc_t *current = get_focused_container(&root_container);
10 swayc_t *parent = current->parent;
11
12 if (direction == MOVE_PARENT) {
13 if (parent->type == C_OUTPUT) {
14 sway_log(L_DEBUG, "Focus cannot move to parent");
15 return false;
16 } else {
17 sway_log(L_DEBUG, "Moving focus away from %p to %p", current, parent);
18 unfocus_all(parent->parent);
19 focus_view(parent);
20 return true;
21 }
22 }
23
24 while (true) {
25 sway_log(L_DEBUG, "Moving focus away from %p", current);
26
27 // Test if we can even make a difference here
28 bool can_move = false;
29 int diff = 0;
30 if (direction == MOVE_LEFT || direction == MOVE_RIGHT) {
31 if (parent->layout == L_HORIZ || parent->type == C_ROOT) {
32 can_move = true;
33 diff = direction == MOVE_LEFT ? -1 : 1;
34 }
35 } else {
36 if (parent->layout == L_VERT) {
37 can_move = true;
38 diff = direction == MOVE_UP ? -1 : 1;
39 }
40 }
41 sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no");
42 if (can_move) {
43 int i;
44 for (i = 0; i < parent->children->length; ++i) {
45 swayc_t *child = parent->children->items[i];
46 if (child == current) {
47 break;
48 }
49 }
50 int desired = i + diff;
51 sway_log(L_DEBUG, "Moving from %d to %d", i, desired);
52 if (desired < 0 || desired >= parent->children->length) {
53 can_move = false;
54 } else {
55 unfocus_all(&root_container);
56 focus_view(parent->children->items[desired]);
57 return true;
58 }
59 }
60 if (!can_move) {
61 sway_log(L_DEBUG, "Can't move at current level, moving up tree");
62 current = parent;
63 parent = parent->parent;
64 if (!parent) {
65 // Nothing we can do
66 return false;
67 }
68 }
69 }
70}