diff options
author | taiyu <taiyu.len@gmail.com> | 2015-08-24 01:11:21 -0700 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-08-24 01:11:21 -0700 |
commit | dbad30a409b83d2e327e5eb2a53b46f12e462258 (patch) | |
tree | beedc915a86c4a1109fd0cf4de7961642ccd8354 /sway | |
parent | b054ac9d4973c8803ff8981eb1f1a754434efe4d (diff) |
add limit to swayc_in_direction
Diffstat (limited to 'sway')
-rw-r--r-- | sway/container.c | 26 | ||||
-rw-r--r-- | sway/input_state.c | 13 | ||||
-rw-r--r-- | sway/layout.c | 9 |
3 files changed, 41 insertions, 7 deletions
diff --git a/sway/container.c b/sway/container.c index d4f7c693..d23cef8f 100644 --- a/sway/container.c +++ b/sway/container.c @@ -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; diff --git a/sway/input_state.c b/sway/input_state.c index e911d9cf..10425c57 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -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; } diff --git a/sway/layout.c b/sway/layout.c index bc12b9b1..a37e137c 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -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; |