From 6e1b79e0573bce6544d457a071eaf1adefa1d7ff Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Thu, 23 Aug 2018 15:36:23 +0300 Subject: [PATCH] Introduce orientation_from_direction --- include/util.h | 6 ++++++ src/move.c | 2 +- src/resize.c | 2 +- src/util.c | 8 ++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/util.h b/include/util.h index d58e21b7..90ddc4a4 100644 --- a/include/util.h +++ b/include/util.h @@ -174,3 +174,9 @@ bool parse_long(const char *str, long *out, int base); * */ ssize_t slurp(const char *path, char **buf); + +/** + * Convert a direction to its corresponding orientation. + * + */ +orientation_t orientation_from_direction(direction_t direction); diff --git a/src/move.c b/src/move.c index 5bff3dae..32178e6b 100644 --- a/src/move.c +++ b/src/move.c @@ -265,7 +265,7 @@ void tree_move(Con *con, int direction) { return; } - orientation_t o = (direction == D_LEFT || direction == D_RIGHT ? HORIZ : VERT); + orientation_t o = orientation_from_direction(direction); Con *same_orientation = con_parent_with_orientation(con, o); /* The do {} while is used to 'restart' at this point with a different diff --git a/src/resize.c b/src/resize.c index ee50bfbc..184dc7c5 100644 --- a/src/resize.c +++ b/src/resize.c @@ -57,7 +57,7 @@ bool resize_find_tiling_participants(Con **current, Con **other, direction_t dir } /* Go up in the tree and search for a container to resize */ - const orientation_t search_orientation = ((direction == D_LEFT || direction == D_RIGHT) ? HORIZ : VERT); + const orientation_t search_orientation = orientation_from_direction(direction); const bool dir_backwards = (direction == D_UP || direction == D_LEFT); while (first->type != CT_WORKSPACE && first->type != CT_FLOATING_CON && diff --git a/src/util.c b/src/util.c index dc3444f7..a59283a8 100644 --- a/src/util.c +++ b/src/util.c @@ -507,3 +507,11 @@ ssize_t slurp(const char *path, char **buf) { } return (ssize_t)n; } + +/* + * Convert a direction to its corresponding orientation. + * + */ +orientation_t orientation_from_direction(direction_t direction) { + return (direction == D_LEFT || direction == D_RIGHT) ? HORIZ : VERT; +} -- 2.39.5