add limit to swayc_in_direction

This commit is contained in:
taiyu 2015-08-24 01:11:21 -07:00
parent b054ac9d49
commit dbad30a409
5 changed files with 47 additions and 7 deletions

View file

@ -84,6 +84,11 @@ swayc_t *destroy_view(swayc_t *view);
swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data);
swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types);
swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts);
// Follow focused until type/layout
swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types);
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts);
swayc_t *swayc_by_handle(wlc_handle handle);
swayc_t *swayc_active_output(void);
swayc_t *swayc_active_workspace(void);

View file

@ -29,6 +29,7 @@ void arrange_windows(swayc_t *container, double width, double height);
swayc_t *get_focused_container(swayc_t *parent);
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir);
swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_direction dir, swayc_t *limit);
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge);

View file

@ -398,6 +398,32 @@ swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) {
return container;
}
swayc_t *swayc_focus_by_type(swayc_t *container, enum swayc_types type) {
if (!ASSERT_NONNULL(container)) {
return NULL;
}
if (!sway_assert(type < C_TYPES && type >= C_ROOT, "%s: invalid type", __func__)) {
return NULL;
}
do {
container = container->focused;
} while (container && container->type != type);
return container;
}
swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts layout) {
if (!ASSERT_NONNULL(container)) {
return NULL;
}
if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "%s: invalid layout", __func__)) {
return NULL;
}
do {
container = container->focused;
} while (container && container->layout != layout);
return container;
}
static swayc_t *_swayc_by_handle_helper(wlc_handle handle, swayc_t *parent) {
if (!parent || !parent->children) {
return NULL;

View file

@ -119,15 +119,20 @@ static void set_initial_view(swayc_t *view) {
static void set_initial_sibling(void) {
bool reset = true;
if ((initial.horiz.ptr = get_swayc_in_direction(initial.ptr, lock.left ? MOVE_RIGHT: MOVE_LEFT))) {
swayc_t *ws = swayc_active_workspace_for(initial.ptr);
if ((initial.horiz.ptr = get_swayc_in_direction_under(initial.ptr,
lock.left ? MOVE_RIGHT: MOVE_LEFT, ws))) {
initial.horiz.w = initial.horiz.ptr->width;
initial.horiz.parent.ptr = get_swayc_in_direction(initial.horiz.ptr, lock.left ? MOVE_LEFT : MOVE_RIGHT);
initial.horiz.parent.ptr = get_swayc_in_direction_under(initial.horiz.ptr,
lock.left ? MOVE_LEFT : MOVE_RIGHT, ws);
initial.horiz.parent.w = initial.horiz.parent.ptr->width;
reset = false;
}
if ((initial.vert.ptr = get_swayc_in_direction(initial.ptr, lock.top ? MOVE_DOWN: MOVE_UP))) {
if ((initial.vert.ptr = get_swayc_in_direction_under(initial.ptr,
lock.top ? MOVE_DOWN: MOVE_UP, ws))) {
initial.vert.h = initial.vert.ptr->height;
initial.vert.parent.ptr = get_swayc_in_direction(initial.vert.ptr, lock.top ? MOVE_UP : MOVE_DOWN);
initial.vert.parent.ptr = get_swayc_in_direction_under(initial.vert.ptr,
lock.top ? MOVE_UP : MOVE_DOWN, ws);
initial.vert.parent.h = initial.vert.parent.ptr->height;
reset = false;
}

View file

@ -353,8 +353,7 @@ void arrange_windows(swayc_t *container, double width, double height) {
layout_log(&root_container, 0);
}
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) {
swayc_t *get_swayc_in_direction_under(swayc_t *container, enum movement_direction dir, swayc_t *limit) {
swayc_t *parent = container->parent;
if (dir == MOVE_PARENT) {
@ -453,7 +452,7 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir)
if (!can_move) {
container = parent;
parent = parent->parent;
if (!parent) {
if (!parent || container == limit) {
// Nothing we can do
return NULL;
}
@ -461,6 +460,10 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir)
}
}
swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) {
return get_swayc_in_direction_under(container, dir, NULL);
}
void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) {
int i;
bool layout_match = true;