From 2024f1da72d5144a30864d815608e2e856639bf6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 14 Jan 2019 21:22:53 +1000 Subject: Resize only current and immediate siblings rather than all siblings For example, create layout V[view view view] and resize the leftmost view using mod+rightclick. Previously, the edge between view 2 and 3 would be adjusted as well. Now this edge will remain constant, which matches the behaviour of i3. To do this operation correctly, the resize tiling seatop now keeps track of two containers, as the container that resizes horizontally will be a different container to the one which resizes vertically (one will be an ancestor). The tiling resize seatop now figures out these containers during the start of the operation and keeps references to them in the event. A new function container_find_resize_parent has been introduced to do this. This function is also used by the resize command. During cursor motion, the seatop logic is similar to before, but now has to choose the correct container to resize. In resize.c, container_resize_tiled and resize_tiled have been merged into one. One of them originally did nothing except pass the values through to the other. container_resize_tiled now takes a simplified approach where it just finds the immediate siblings on either side and resizes them without worrying about the others. The parellel_coord and parallel_size functions are no longer needed and have been removed. --- sway/input/seatop_resize_tiling.c | 67 ++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'sway/input') diff --git a/sway/input/seatop_resize_tiling.c b/sway/input/seatop_resize_tiling.c index 30431f04..cb0f723d 100644 --- a/sway/input/seatop_resize_tiling.c +++ b/sway/input/seatop_resize_tiling.c @@ -1,15 +1,22 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include "sway/commands.h" #include "sway/input/cursor.h" #include "sway/input/seat.h" struct seatop_resize_tiling_event { - struct sway_container *con; + struct sway_container *con; // leaf container + + // con, or ancestor of con which will be resized horizontally/vertically + struct sway_container *h_con; + struct sway_container *v_con; + enum wlr_edges edge; + enum wlr_edges edge_x, edge_y; double ref_lx, ref_ly; // cursor's x/y at start of op - double ref_width, ref_height; // container's size at start of op - double ref_con_lx, ref_con_ly; // container's x/y at start of op + double h_con_orig_width; // width of the horizontal ancestor at start + double v_con_orig_height; // height of the vertical ancestor at start }; static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { @@ -18,30 +25,27 @@ static void handle_motion(struct sway_seat *seat, uint32_t time_msec) { int amount_y = 0; int moved_x = seat->cursor->cursor->x - e->ref_lx; int moved_y = seat->cursor->cursor->y - e->ref_ly; - enum wlr_edges edge_x = WLR_EDGE_NONE; - enum wlr_edges edge_y = WLR_EDGE_NONE; - struct sway_container *con = e->con; - - if (e->edge & WLR_EDGE_TOP) { - amount_y = (e->ref_height - moved_y) - con->height; - edge_y = WLR_EDGE_TOP; - } else if (e->edge & WLR_EDGE_BOTTOM) { - amount_y = (e->ref_height + moved_y) - con->height; - edge_y = WLR_EDGE_BOTTOM; + + if (e->h_con) { + if (e->edge & WLR_EDGE_LEFT) { + amount_x = (e->h_con_orig_width - moved_x) - e->h_con->width; + } else if (e->edge & WLR_EDGE_RIGHT) { + amount_x = (e->h_con_orig_width + moved_x) - e->h_con->width; + } } - if (e->edge & WLR_EDGE_LEFT) { - amount_x = (e->ref_width - moved_x) - con->width; - edge_x = WLR_EDGE_LEFT; - } else if (e->edge & WLR_EDGE_RIGHT) { - amount_x = (e->ref_width + moved_x) - con->width; - edge_x = WLR_EDGE_RIGHT; + if (e->v_con) { + if (e->edge & WLR_EDGE_TOP) { + amount_y = (e->v_con_orig_height - moved_y) - e->v_con->height; + } else if (e->edge & WLR_EDGE_BOTTOM) { + amount_y = (e->v_con_orig_height + moved_y) - e->v_con->height; + } } if (amount_x != 0) { - container_resize_tiled(e->con, edge_x, amount_x); + container_resize_tiled(e->h_con, e->edge_x, amount_x); } if (amount_y != 0) { - container_resize_tiled(e->con, edge_y, amount_y); + container_resize_tiled(e->v_con, e->edge_y, amount_y); } } @@ -81,10 +85,23 @@ void seatop_begin_resize_tiling(struct sway_seat *seat, e->ref_lx = seat->cursor->cursor->x; e->ref_ly = seat->cursor->cursor->y; - e->ref_con_lx = con->x; - e->ref_con_ly = con->y; - e->ref_width = con->width; - e->ref_height = con->height; + + if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) { + e->edge_x = edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT); + e->h_con = container_find_resize_parent(e->con, e->edge_x); + + if (e->h_con) { + e->h_con_orig_width = e->h_con->width; + } + } + if (edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)) { + e->edge_y = edge & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM); + e->v_con = container_find_resize_parent(e->con, e->edge_y); + + if (e->v_con) { + e->v_con_orig_height = e->v_con->height; + } + } seat->seatop_impl = &seatop_impl; seat->seatop_data = e; -- cgit v1.2.3-54-g00ecf