Skip to content

Commit

Permalink
Don't confine the CYCLE_DIR descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Apr 20, 2016
1 parent 1b62244 commit cd079d2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
24 changes: 16 additions & 8 deletions desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,34 @@ void activate_desktop(monitor_t *m, desktop_t *d)
put_status(SBSC_MASK_REPORT);
}

desktop_t *closest_desktop(monitor_t *m, desktop_t *d, cycle_dir_t dir, desktop_select_t sel)
bool find_closest_desktop(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, desktop_select_t sel)
{
monitor_t *m = ref->monitor;
desktop_t *d = ref->desktop;
desktop_t *f = (dir == CYCLE_PREV ? d->prev : d->next);

if (f == NULL) {
f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head);
#define HANDLE_BOUNDARIES(f) \
if (f == NULL) { \
m = (dir == CYCLE_PREV ? m->prev : m->next); \
if (m == NULL) { \
m = (dir == CYCLE_PREV ? mon_tail : mon_head); \
} \
f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); \
}
HANDLE_BOUNDARIES(f)

while (f != d) {
coordinates_t loc = {m, f, NULL};
if (desktop_matches(&loc, &loc, sel)) {
return f;
*dst = loc;
return true;
}
f = (dir == CYCLE_PREV ? f->prev : f->next);
if (f == NULL) {
f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head);
}
HANDLE_BOUNDARIES(f)
}
#undef HANDLE_BOUNDARIES

return NULL;
return false;
}

void change_layout(monitor_t *m, desktop_t *d, layout_t l)
Expand Down
2 changes: 1 addition & 1 deletion desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

void focus_desktop(monitor_t *m, desktop_t *d);
void activate_desktop(monitor_t *m, desktop_t *d);
desktop_t *closest_desktop(monitor_t *m, desktop_t *d, cycle_dir_t dir, desktop_select_t sel);
bool find_closest_desktop(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, desktop_select_t sel);
void change_layout(monitor_t *m, desktop_t *d, layout_t l);
bool transfer_desktop(monitor_t *ms, monitor_t *md, desktop_t *d);
desktop_t *make_desktop(const char *name, uint32_t id);
Expand Down
10 changes: 4 additions & 6 deletions query.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
if (parse_direction(desc, &dir)) {
dst->node = nearest_neighbor(ref->monitor, ref->desktop, ref->node, dir, sel);
} else if (parse_cycle_direction(desc, &cyc)) {
dst->node = closest_node(ref->monitor, ref->desktop, ref->node, cyc, sel);
find_closest_node(ref, dst, cyc, sel);
} else if (parse_history_direction(desc, &hdi)) {
history_find_node(hdi, ref, dst, sel);
} else if (streq("last", desc)) {
Expand Down Expand Up @@ -511,17 +511,15 @@ int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
uint16_t idx;
uint32_t id;
if (parse_cycle_direction(desc, &cyc)) {
dst->monitor = ref->monitor;
dst->desktop = closest_desktop(ref->monitor, ref->desktop, cyc, sel);
find_closest_desktop(ref, dst, cyc, sel);
} else if (parse_history_direction(desc, &hdi)) {
history_find_desktop(hdi, ref, dst, sel);
} else if (streq("last", desc)) {
history_find_desktop(HISTORY_OLDER, ref, dst, sel);
} else if (streq("focused", desc)) {
coordinates_t loc = {mon, mon->desk, NULL};
if (desktop_matches(&loc, ref, sel)) {
dst->monitor = mon;
dst->desktop = mon->desk;
*dst = loc;
}
} else if (colon != NULL) {
*colon = '\0';
Expand All @@ -530,7 +528,7 @@ int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
if (streq("focused", colon + 1)) {
coordinates_t loc = {dst->monitor, dst->monitor->desk, NULL};
if (desktop_matches(&loc, ref, sel)) {
dst->desktop = dst->monitor->desk;
*dst = loc;
}
} else if (parse_index(colon + 1, &idx)) {
free(desc_copy);
Expand Down
38 changes: 26 additions & 12 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,29 +1541,43 @@ bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desk
return true;
}

node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, node_select_t sel)
bool find_closest_node(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, node_select_t sel)
{
if (n == NULL) {
return NULL;
if (ref->node == NULL) {
return false;
}

monitor_t *m = ref->monitor;
desktop_t *d = ref->desktop;
node_t *n = ref->node;

node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
if (f == NULL) {
f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));

#define HANDLE_BOUNDARIES(f) \
while (f == NULL) { \
d = (dir == CYCLE_PREV ? d->prev : d->next); \
if (d == NULL) { \
m = (dir == CYCLE_PREV ? m->prev : m->next); \
if (m == NULL) { \
m = (dir == CYCLE_PREV ? mon_tail : mon_head); \
} \
d = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); \
} \
f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root)); \
}
HANDLE_BOUNDARIES(f);

coordinates_t ref = {m, d, n};
while (f != n) {
coordinates_t loc = {m, d, f};
if (f->client != NULL && !f->hidden && node_matches(&loc, &ref, sel)) {
return f;
if (f->client != NULL && !f->hidden && node_matches(&loc, ref, sel)) {
*dst = loc;
return true;
}
f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
if (f == NULL) {
f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
}
HANDLE_BOUNDARIES(f);
}
return NULL;
#undef HANDLE_EXTREMUM
return false;
}

void circulate_leaves(monitor_t *m, desktop_t *d, node_t *n, circulate_dir_t dir)
Expand Down
2 changes: 1 addition & 1 deletion tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void remove_node(monitor_t *m, desktop_t *d, node_t *n);
void destroy_tree(monitor_t *m, desktop_t *d, node_t *n);
bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2);
bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd);
node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, node_select_t sel);
bool find_closest_node(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, node_select_t sel);
void circulate_leaves(monitor_t *m, desktop_t *d, node_t *n, circulate_dir_t dir);
void set_vacant(monitor_t *m, desktop_t *d, node_t *n, bool value);
void set_vacant_local(monitor_t *m, desktop_t *d, node_t *n, bool value);
Expand Down

0 comments on commit cd079d2

Please sign in to comment.