aboutsummaryrefslogtreecommitdiff
path: root/sway/movement.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2015-08-09 20:10:26 -0400
committerDrew DeVault <sir@cmpwn.com>2015-08-09 20:10:26 -0400
commit9f091c7f82a73144b4eb4ca4f5f800c811fbab46 (patch)
tree76726b112e18cc537e080568c7e5df30520a3ed9 /sway/movement.c
parent1669da719c96e80cc5c462bbd648b17c7cd25a82 (diff)
Add movement support
Diffstat (limited to 'sway/movement.c')
-rw-r--r--sway/movement.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/sway/movement.c b/sway/movement.c
new file mode 100644
index 00000000..197df7b2
--- /dev/null
+++ b/sway/movement.c
@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <stdbool.h>
+#include "list.h"
+#include "log.h"
+#include "layout.h"
+#include "movement.h"
+
+void move_focus(enum movement_direction direction) {
+ swayc_t *current = get_focused_container(&root_container);
+ swayc_t *parent = current->parent;
+
+ while (true) {
+ sway_log(L_DEBUG, "Moving focus away from %p", current);
+
+ // Test if we can even make a difference here
+ bool can_move = false;
+ int diff = 0;
+ if (direction == MOVE_LEFT || direction == MOVE_RIGHT) {
+ if (parent->layout == L_HORIZ) {
+ can_move = true;
+ diff = direction == MOVE_LEFT ? -1 : 1;
+ }
+ } else {
+ if (parent->layout == L_VERT) {
+ can_move = true;
+ diff = direction == MOVE_UP ? -1 : 1;
+ }
+ }
+ sway_log(L_DEBUG, "Can move? %s", can_move ? "yes" : "no");
+ if (can_move) {
+ int i;
+ for (i = 0; i < parent->children->length; ++i) {
+ swayc_t *child = parent->children->items[i];
+ if (child == current) {
+ break;
+ }
+ }
+ int desired = i + diff;
+ sway_log(L_DEBUG, "Moving from %d to %d", i, desired);
+ if (desired < 0 || desired >= parent->children->length) {
+ can_move = false;
+ } else {
+ unfocus_all(&root_container);
+ focus_view(parent->children->items[desired]);
+ return;
+ }
+ }
+ if (!can_move) {
+ sway_log(L_DEBUG, "Can't move at current level, moving up tree");
+ current = parent;
+ parent = parent->parent;
+ if (parent->type == C_ROOT) {
+ // Nothing we can do
+ return;
+ }
+ }
+ }
+}