Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Introduce direction / orientation / position conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
orestisfl committed Oct 13, 2019
1 parent e5c430e commit 1e8e4d3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/data.h
Expand Up @@ -59,6 +59,8 @@ typedef enum { D_LEFT,
typedef enum { NO_ORIENTATION = 0,
HORIZ,
VERT } orientation_t;
typedef enum { BEFORE,
AFTER } position_t;
typedef enum { BS_NORMAL = 0,
BS_NONE = 1,
BS_PIXEL = 2 } border_style_t;
Expand Down
3 changes: 0 additions & 3 deletions include/move.h
Expand Up @@ -17,9 +17,6 @@
*/
void tree_move(Con *con, direction_t direction);

typedef enum { BEFORE,
AFTER } position_t;

/**
* This function detaches 'con' from its parent and inserts it either before or
* after 'target'.
Expand Down
12 changes: 12 additions & 0 deletions include/util.h
Expand Up @@ -181,3 +181,15 @@ ssize_t slurp(const char *path, char **buf);
*
*/
orientation_t orientation_from_direction(direction_t direction);

/**
* Convert a direction to its corresponding position.
*
*/
position_t position_from_direction(direction_t direction);

/**
* Convert orientation and position to the corresponding direction.
*
*/
direction_t direction_from_orientation_position(orientation_t orientation, position_t position);
20 changes: 20 additions & 0 deletions src/util.c
Expand Up @@ -518,3 +518,23 @@ ssize_t slurp(const char *path, char **buf) {
orientation_t orientation_from_direction(direction_t direction) {
return (direction == D_LEFT || direction == D_RIGHT) ? HORIZ : VERT;
}

/*
* Convert a direction to its corresponding position.
*
*/
position_t position_from_direction(direction_t direction) {
return (direction == D_LEFT || direction == D_UP) ? BEFORE : AFTER;
}

/*
* Convert orientation and position to the corresponding direction.
*
*/
direction_t direction_from_orientation_position(orientation_t orientation, position_t position) {
if (orientation == HORIZ) {
return position == BEFORE ? D_LEFT : D_RIGHT;
} else {
return position == BEFORE ? D_UP : D_DOWN;
}
}

0 comments on commit 1e8e4d3

Please sign in to comment.