Honor history_aware_focus for shift

This commit is contained in:
Bastien Dejean 2013-06-25 12:41:59 +02:00
parent 6059838a96
commit d2b3ebc459
3 changed files with 29 additions and 16 deletions

View file

@ -115,13 +115,18 @@ void process_message(char *msg, char *rsp)
else
change_layout(mon, mon->desk, LAYOUT_MONOCLE);
} else if (strcmp(cmd, "shift") == 0) {
node_t *f = mon->desk->focus;
if (f == NULL)
return;
char *dir = strtok(NULL, TOK_SEP);
if (dir != NULL) {
direction_t d;
if (parse_direction(dir, &d))
swap_nodes(mon->desk->focus, focus_by_distance ? nearest_neighbor(mon->desk, mon->desk->focus, d) : find_neighbor(mon->desk->focus, d));
if (parse_direction(dir, &d)) {
node_t *n = nearest_neighbor(mon->desk, f, d);
swap_nodes(f, n);
arrange(mon, mon->desk);
}
}
arrange(mon, mon->desk);
} else if (strcmp(cmd, "toggle_fullscreen") == 0) {
toggle_fullscreen(mon->desk, mon->desk->focus);
arrange(mon, mon->desk);
@ -452,16 +457,7 @@ void process_message(char *msg, char *rsp)
if (dir != NULL) {
direction_t d;
if (parse_direction(dir, &d)) {
node_t *n = NULL;
if (history_aware_focus)
n = nearest_from_history(mon->desk->history, f, d);
if (n == NULL) {
if (focus_by_distance) {
n = nearest_neighbor(mon->desk, f, d);
} else {
n = find_neighbor(f, d);
}
}
node_t *n = nearest_neighbor(mon->desk, f, d);
focus_node(mon, mon->desk, n);
}
}

20
tree.c
View file

@ -135,7 +135,23 @@ node_t *find_fence(node_t *n, direction_t dir)
return NULL;
}
node_t *find_neighbor(node_t *n, direction_t dir)
node_t *nearest_neighbor(desktop_t *d, node_t *n, direction_t dir)
{
node_t *nearest = NULL;
if (history_aware_focus)
nearest = nearest_from_history(d->history, n, dir);
if (nearest == NULL) {
if (focus_by_distance) {
nearest = nearest_from_distance(d, n, dir);
} else {
nearest = nearest_from_tree(n, dir);
}
}
return nearest;
}
node_t *nearest_from_tree(node_t *n, direction_t dir)
{
if (n == NULL)
return NULL;
@ -184,7 +200,7 @@ node_t *nearest_from_history(focus_history_t *f, node_t *n, direction_t dir)
return nearest;
}
node_t *nearest_neighbor(desktop_t *d, node_t *n, direction_t dir)
node_t *nearest_from_distance(desktop_t *d, node_t *n, direction_t dir)
{
if (n == NULL)
return NULL;

3
tree.h
View file

@ -17,8 +17,9 @@ node_t *next_leaf(node_t *, node_t *);
node_t *prev_leaf(node_t *, node_t *);
bool is_adjacent(node_t *, node_t *);
node_t *find_fence(node_t *, direction_t);
node_t *find_neighbor(node_t *, direction_t);
node_t *nearest_neighbor(desktop_t *, node_t *, direction_t);
node_t *nearest_from_tree(node_t *, direction_t);
node_t *nearest_from_distance(desktop_t *, node_t *, direction_t);
node_t *nearest_from_history(focus_history_t *, node_t *, direction_t);
void get_opposite(direction_t, direction_t *);
int tiled_area(node_t *);