From d4e80cf301d77f69370cc81657c433990986cfa6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 16:56:05 +1000 Subject: Rename OP_MOVE to OP_MOVE_FLOATING In preparation for introducing OP_MOVE_TILING. --- sway/input/seat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sway/input/seat.c') diff --git a/sway/input/seat.c b/sway/input/seat.c index 5709a7f7..a908560a 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -963,13 +963,13 @@ void seat_begin_down(struct sway_seat *seat, struct sway_container *con, seat->op_moved = false; } -void seat_begin_move(struct sway_seat *seat, struct sway_container *con, - uint32_t button) { +void seat_begin_move_floating(struct sway_seat *seat, + struct sway_container *con, uint32_t button) { if (!seat->cursor) { wlr_log(WLR_DEBUG, "Ignoring move request due to no cursor device"); return; } - seat->operation = OP_MOVE; + seat->operation = OP_MOVE_FLOATING; seat->op_container = con; seat->op_button = button; cursor_set_image(seat->cursor, "grab", NULL); @@ -1017,7 +1017,7 @@ void seat_begin_resize_tiling(struct sway_seat *seat, void seat_end_mouse_operation(struct sway_seat *seat) { enum sway_seat_operation operation = seat->operation; - if (seat->operation == OP_MOVE) { + if (seat->operation == OP_MOVE_FLOATING) { // We "move" the container to its own location so it discovers its // output again. struct sway_container *con = seat->op_container; -- cgit v1.2.3 From 8bb40c24c7b045df0d43e9f22c096d1473f6f9f6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 21:34:21 +1000 Subject: Implement tiling drag Hold floating_modifier and drag a tiling view to a new location. --- sway/input/seat.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'sway/input/seat.c') diff --git a/sway/input/seat.c b/sway/input/seat.c index a908560a..86e5f809 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -975,6 +975,16 @@ void seat_begin_move_floating(struct sway_seat *seat, cursor_set_image(seat->cursor, "grab", NULL); } +void seat_begin_move_tiling(struct sway_seat *seat, + struct sway_container *con, uint32_t button) { + seat->operation = OP_MOVE_TILING; + seat->op_container = con; + seat->op_button = button; + seat->op_target_node = NULL; + seat->op_target_edge = 0; + cursor_set_image(seat->cursor, "grab", NULL); +} + void seat_begin_resize_floating(struct sway_seat *seat, struct sway_container *con, uint32_t button, enum wlr_edges edge) { if (!seat->cursor) { @@ -1015,6 +1025,68 @@ void seat_begin_resize_tiling(struct sway_seat *seat, seat->op_ref_height = con->height; } +static bool is_parallel(enum sway_container_layout layout, + enum wlr_edges edge) { + bool layout_is_horiz = layout == L_HORIZ || layout == L_TABBED; + bool edge_is_horiz = edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT; + return layout_is_horiz == edge_is_horiz; +} + +static void seat_end_move_tiling(struct sway_seat *seat) { + struct sway_container *con = seat->op_container; + struct sway_container *old_parent = con->parent; + struct sway_workspace *old_ws = con->workspace; + struct sway_node *target_node = seat->op_target_node; + struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ? + target_node->sway_workspace : target_node->sway_container->workspace; + enum wlr_edges edge = seat->op_target_edge; + int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT; + + container_detach(con); + if (old_parent) { + container_reap_empty(old_parent); + } + + // Moving container into empty workspace + if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) { + workspace_add_tiling(new_ws, con); + + // Moving container before/after another + } else if (target_node->type == N_CONTAINER) { + struct sway_container *target = target_node->sway_container; + enum sway_container_layout layout = container_parent_layout(target); + if (edge && !is_parallel(layout, edge)) { + enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || + edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; + container_split(target, new_layout); + } + container_add_sibling(target, con, after); + + // Target is a workspace which requires splitting + } else { + enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || + edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; + workspace_split(new_ws, new_layout); + workspace_insert_tiling(new_ws, con, after); + } + + // This is a bit dirty, but we'll set the dimensions to that of a sibling. + // I don't think there's any other way to make it consistent without + // changing how we auto-size containers. + list_t *siblings = container_get_siblings(con); + if (siblings->length > 1) { + int index = list_find(siblings, con); + struct sway_container *sibling = index == 0 ? siblings->items[1] : siblings->items[index - 1]; + con->width = sibling->width; + con->height = sibling->height; + } + + arrange_workspace(old_ws); + if (new_ws != old_ws) { + arrange_workspace(new_ws); + } +} + void seat_end_mouse_operation(struct sway_seat *seat) { enum sway_seat_operation operation = seat->operation; if (seat->operation == OP_MOVE_FLOATING) { @@ -1022,6 +1094,8 @@ void seat_end_mouse_operation(struct sway_seat *seat) { // output again. struct sway_container *con = seat->op_container; container_floating_move_to(con, con->x, con->y); + } else if (seat->operation == OP_MOVE_TILING && seat->op_target_node) { + seat_end_move_tiling(seat); } seat->operation = OP_NONE; seat->op_container = NULL; -- cgit v1.2.3 From 403905c11bf9996cf1937ec0067f33d013e78305 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 23:24:57 +1000 Subject: Fix line length --- sway/input/seat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sway/input/seat.c') diff --git a/sway/input/seat.c b/sway/input/seat.c index 86e5f809..231b545b 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1076,7 +1076,8 @@ static void seat_end_move_tiling(struct sway_seat *seat) { list_t *siblings = container_get_siblings(con); if (siblings->length > 1) { int index = list_find(siblings, con); - struct sway_container *sibling = index == 0 ? siblings->items[1] : siblings->items[index - 1]; + struct sway_container *sibling = index == 0 ? + siblings->items[1] : siblings->items[index - 1]; con->width = sibling->width; con->height = sibling->height; } -- cgit v1.2.3 From 679c7eb08c16daea8e3e1cff7bcf179e116d0e8e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 12 Sep 2018 08:46:46 +1000 Subject: Minor fixes to tiling drag implementation * Make container_add_sibling's `after` argument a boolean. * Use a constant for drop layout border * Make thickness an int * Add button state check * Move comments in seat_end_move_tiling --- sway/input/seat.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'sway/input/seat.c') diff --git a/sway/input/seat.c b/sway/input/seat.c index 231b545b..8704f90f 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1050,9 +1050,8 @@ static void seat_end_move_tiling(struct sway_seat *seat) { // Moving container into empty workspace if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) { workspace_add_tiling(new_ws, con); - - // Moving container before/after another } else if (target_node->type == N_CONTAINER) { + // Moving container before/after another struct sway_container *target = target_node->sway_container; enum sway_container_layout layout = container_parent_layout(target); if (edge && !is_parallel(layout, edge)) { @@ -1061,9 +1060,8 @@ static void seat_end_move_tiling(struct sway_seat *seat) { container_split(target, new_layout); } container_add_sibling(target, con, after); - - // Target is a workspace which requires splitting } else { + // Target is a workspace which requires splitting enum sway_container_layout new_layout = edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ; workspace_split(new_ws, new_layout); -- cgit v1.2.3