Introduce direction / orientation / position conversion functions
This commit is contained in:
parent
e5c430e419
commit
1e8e4d3e7f
|
@ -59,6 +59,8 @@ typedef enum { D_LEFT,
|
||||||
typedef enum { NO_ORIENTATION = 0,
|
typedef enum { NO_ORIENTATION = 0,
|
||||||
HORIZ,
|
HORIZ,
|
||||||
VERT } orientation_t;
|
VERT } orientation_t;
|
||||||
|
typedef enum { BEFORE,
|
||||||
|
AFTER } position_t;
|
||||||
typedef enum { BS_NORMAL = 0,
|
typedef enum { BS_NORMAL = 0,
|
||||||
BS_NONE = 1,
|
BS_NONE = 1,
|
||||||
BS_PIXEL = 2 } border_style_t;
|
BS_PIXEL = 2 } border_style_t;
|
||||||
|
|
|
@ -17,9 +17,6 @@
|
||||||
*/
|
*/
|
||||||
void tree_move(Con *con, direction_t direction);
|
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
|
* This function detaches 'con' from its parent and inserts it either before or
|
||||||
* after 'target'.
|
* after 'target'.
|
||||||
|
|
|
@ -181,3 +181,15 @@ ssize_t slurp(const char *path, char **buf);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
orientation_t orientation_from_direction(direction_t direction);
|
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
src/util.c
20
src/util.c
|
@ -518,3 +518,23 @@ ssize_t slurp(const char *path, char **buf) {
|
||||||
orientation_t orientation_from_direction(direction_t direction) {
|
orientation_t orientation_from_direction(direction_t direction) {
|
||||||
return (direction == D_LEFT || direction == D_RIGHT) ? HORIZ : VERT;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue