From d4e80cf301d77f69370cc81657c433990986cfa6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 16:56:05 +1000 Subject: [PATCH 1/7] Rename OP_MOVE to OP_MOVE_FLOATING In preparation for introducing OP_MOVE_TILING. --- include/sway/input/seat.h | 6 +++--- sway/desktop/xdg_shell.c | 2 +- sway/desktop/xdg_shell_v6.c | 2 +- sway/desktop/xwayland.c | 2 +- sway/input/cursor.c | 8 ++++---- sway/input/seat.c | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index b07d200d..1ae34be5 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -38,7 +38,7 @@ struct sway_drag_icon { enum sway_seat_operation { OP_NONE, OP_DOWN, - OP_MOVE, + OP_MOVE_FLOATING, OP_RESIZE_FLOATING, OP_RESIZE_TILING, }; @@ -172,8 +172,8 @@ void drag_icon_update_position(struct sway_drag_icon *icon); void seat_begin_down(struct sway_seat *seat, struct sway_container *con, uint32_t button, double sx, double sy); -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); void seat_begin_resize_floating(struct sway_seat *seat, struct sway_container *con, uint32_t button, enum wlr_edges edge); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index b9ca396a..00448be7 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -333,7 +333,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_move_event *e = data; struct sway_seat *seat = e->seat->seat->data; if (e->serial == seat->last_button_serial) { - seat_begin_move(seat, view->container, seat->last_button); + seat_begin_move_floating(seat, view->container, seat->last_button); } } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 0c121adc..d2c9a68b 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -330,7 +330,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel_v6_move_event *e = data; struct sway_seat *seat = e->seat->seat->data; if (e->serial == seat->last_button_serial) { - seat_begin_move(seat, view->container, seat->last_button); + seat_begin_move_floating(seat, view->container, seat->last_button); } } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 6761b6bc..3619f202 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -449,7 +449,7 @@ static void handle_request_move(struct wl_listener *listener, void *data) { return; } struct sway_seat *seat = input_manager_current_seat(input_manager); - seat_begin_move(seat, view->container, seat->last_button); + seat_begin_move_floating(seat, view->container, seat->last_button); } static void handle_request_resize(struct wl_listener *listener, void *data) { diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 69a019bb..cd87e976 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -218,7 +218,7 @@ static void handle_down_motion(struct sway_seat *seat, seat->op_moved = true; } -static void handle_move_motion(struct sway_seat *seat, +static void handle_move_floating_motion(struct sway_seat *seat, struct sway_cursor *cursor) { struct sway_container *con = seat->op_container; desktop_damage_whole_container(con); @@ -402,8 +402,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, case OP_DOWN: handle_down_motion(seat, cursor, time_msec); break; - case OP_MOVE: - handle_move_motion(seat, cursor); + case OP_MOVE_FLOATING: + handle_move_floating_motion(seat, cursor); break; case OP_RESIZE_FLOATING: handle_resize_floating_motion(seat, cursor); @@ -719,7 +719,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor, while (cont->parent) { cont = cont->parent; } - seat_begin_move(seat, cont, button); + seat_begin_move_floating(seat, cont, button); return; } } 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; From ec9c4de564286d3795dd204e2c0a69b10f7572be Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 17:17:19 +1000 Subject: [PATCH 2/7] Introduce tiling_drag directive --- include/sway/commands.h | 1 + include/sway/config.h | 1 + sway/commands.c | 1 + sway/commands/tiling_drag.c | 13 +++++++++++++ sway/config.c | 1 + sway/meson.build | 1 + 6 files changed, 18 insertions(+) create mode 100644 sway/commands/tiling_drag.c diff --git a/include/sway/commands.h b/include/sway/commands.h index b0b5ed0f..e51b12fd 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -161,6 +161,7 @@ sway_cmd cmd_sticky; sway_cmd cmd_swaybg_command; sway_cmd cmd_swaynag_command; sway_cmd cmd_swap; +sway_cmd cmd_tiling_drag; sway_cmd cmd_title_format; sway_cmd cmd_unmark; sway_cmd cmd_urgent; diff --git a/include/sway/config.h b/include/sway/config.h index b52bb681..b53c1f1f 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -365,6 +365,7 @@ struct sway_config { bool validating; bool auto_back_and_forth; bool show_marks; + bool tiling_drag; bool edge_gaps; bool smart_gaps; diff --git a/sway/commands.c b/sway/commands.c index b32628cd..41e1c653 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -127,6 +127,7 @@ static struct cmd_handler handlers[] = { { "set", cmd_set }, { "show_marks", cmd_show_marks }, { "smart_gaps", cmd_smart_gaps }, + { "tiling_drag", cmd_tiling_drag }, { "workspace", cmd_workspace }, { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, }; diff --git a/sway/commands/tiling_drag.c b/sway/commands/tiling_drag.c new file mode 100644 index 00000000..92fbde7c --- /dev/null +++ b/sway/commands/tiling_drag.c @@ -0,0 +1,13 @@ +#include "sway/commands.h" +#include "util.h" + +struct cmd_results *cmd_tiling_drag(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "tiling_drag", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + config->tiling_drag = parse_boolean(argv[0], config->tiling_drag); + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config.c b/sway/config.c index 6ff4da03..830fb65f 100644 --- a/sway/config.c +++ b/sway/config.c @@ -225,6 +225,7 @@ static void config_defaults(struct sway_config *config) { config->auto_back_and_forth = false; config->reading = false; config->show_marks = true; + config->tiling_drag = true; config->edge_gaps = true; config->smart_gaps = false; diff --git a/sway/meson.build b/sway/meson.build index 8891ebc0..01c83a33 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -83,6 +83,7 @@ sway_sources = files( 'commands/swaybg_command.c', 'commands/swaynag_command.c', 'commands/swap.c', + 'commands/tiling_drag.c', 'commands/title_format.c', 'commands/unmark.c', 'commands/urgent.c', From 8bb40c24c7b045df0d43e9f22c096d1473f6f9f6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 21:34:21 +1000 Subject: [PATCH 3/7] Implement tiling drag Hold floating_modifier and drag a tiling view to a new location. --- include/sway/input/seat.h | 7 ++ include/sway/tree/container.h | 5 +- include/sway/tree/workspace.h | 2 + sway/commands/move.c | 2 +- sway/desktop/render.c | 17 ++++ sway/input/cursor.c | 146 ++++++++++++++++++++++++++++++++++ sway/input/seat.c | 74 +++++++++++++++++ sway/tree/container.c | 12 ++- sway/tree/view.c | 2 +- sway/tree/workspace.c | 13 +++ 10 files changed, 274 insertions(+), 6 deletions(-) diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 1ae34be5..e006faba 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h @@ -39,6 +39,7 @@ enum sway_seat_operation { OP_NONE, OP_DOWN, OP_MOVE_FLOATING, + OP_MOVE_TILING, OP_RESIZE_FLOATING, OP_RESIZE_TILING, }; @@ -64,6 +65,9 @@ struct sway_seat { // Operations (drag and resize) enum sway_seat_operation operation; struct sway_container *op_container; + struct sway_node *op_target_node; // target for tiling move + enum wlr_edges op_target_edge; + struct wlr_box op_drop_box; enum wlr_edges op_resize_edge; uint32_t op_button; bool op_resize_preserve_ratio; @@ -175,6 +179,9 @@ void seat_begin_down(struct sway_seat *seat, struct sway_container *con, void seat_begin_move_floating(struct sway_seat *seat, struct sway_container *con, uint32_t button); +void seat_begin_move_tiling(struct sway_seat *seat, + struct sway_container *con, uint32_t button); + void seat_begin_resize_floating(struct sway_seat *seat, struct sway_container *con, uint32_t button, enum wlr_edges edge); diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 2735daa3..94d30ced 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -279,8 +279,11 @@ void container_add_child(struct sway_container *parent, void container_insert_child(struct sway_container *parent, struct sway_container *child, int i); +/** + * Side should be 0 to add before, or 1 to add after. + */ void container_add_sibling(struct sway_container *parent, - struct sway_container *child); + struct sway_container *child, int side); void container_detach(struct sway_container *child); diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index af9a071a..e4b616d1 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -126,4 +126,6 @@ void workspace_update_representation(struct sway_workspace *ws); void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box); +size_t workspace_num_tiling_views(struct sway_workspace *ws); + #endif diff --git a/sway/commands/move.c b/sway/commands/move.c index 2e9c00f8..b2cca5be 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -235,7 +235,7 @@ static void container_move_to_container(struct sway_container *container, container->saved_width = container->saved_height = 0; if (destination->view) { - container_add_sibling(destination, container); + container_add_sibling(destination, container, 1); } else { container_add_child(destination, container); } diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 8a6f63aa..8b5b3e95 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -891,6 +891,21 @@ static void render_floating(struct sway_output *soutput, } } +static void render_dropzones(struct sway_output *output, + pixman_region32_t *damage) { + struct sway_seat *seat; + wl_list_for_each(seat, &input_manager->seats, link) { + if (seat->operation == OP_MOVE_TILING && seat->op_target_node + && node_get_output(seat->op_target_node) == output) { + float color[4]; + memcpy(&color, config->border_colors.focused.indicator, + sizeof(float) * 4); + premultiply_alpha(color, 0.5); + render_rect(output->wlr_output, damage, &seat->op_drop_box, color); + } + } +} + void output_render(struct sway_output *output, struct timespec *when, pixman_region32_t *damage) { struct wlr_output *wlr_output = output->wlr_output; @@ -973,6 +988,8 @@ void output_render(struct sway_output *output, struct timespec *when, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); } + render_dropzones(output, damage); + struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = seat_get_focused_container(seat); if (focus && focus->view) { diff --git a/sway/input/cursor.c b/sway/input/cursor.c index cd87e976..b0f8e531 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -228,6 +228,141 @@ static void handle_move_floating_motion(struct sway_seat *seat, desktop_damage_whole_container(con); } +static void resize_box(struct wlr_box *box, enum wlr_edges edge, + size_t thickness) { + switch (edge) { + case WLR_EDGE_TOP: + box->height = thickness; + break; + case WLR_EDGE_LEFT: + box->width = thickness; + break; + case WLR_EDGE_RIGHT: + box->x = box->x + box->width - thickness; + box->width = thickness; + break; + case WLR_EDGE_BOTTOM: + box->y = box->y + box->height - thickness; + box->height = thickness; + break; + case WLR_EDGE_NONE: + box->x += thickness; + box->y += thickness; + box->width -= thickness * 2; + box->height -= thickness * 2; + break; + } +} + +static void handle_move_tiling_motion(struct sway_seat *seat, + struct sway_cursor *cursor) { + struct wlr_surface *surface = NULL; + double sx, sy; + struct sway_node *node = node_at_coords(seat, + cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + // Damage the old location + desktop_damage_box(&seat->op_drop_box); + + if (!node) { + // Eg. hovered over a layer surface such as swaybar + seat->op_target_node = NULL; + seat->op_target_edge = WLR_EDGE_NONE; + return; + } + + if (node->type == N_WORKSPACE) { + // Emtpy workspace + seat->op_target_node = node; + seat->op_target_edge = WLR_EDGE_NONE; + workspace_get_box(node->sway_workspace, &seat->op_drop_box); + desktop_damage_box(&seat->op_drop_box); + return; + } + + // Deny moving within own workspace if this is the only child + struct sway_container *con = node->sway_container; + if (workspace_num_tiling_views(seat->op_container->workspace) == 1 && + con->workspace == seat->op_container->workspace) { + seat->op_target_node = NULL; + seat->op_target_edge = WLR_EDGE_NONE; + return; + } + + // Traverse the ancestors, trying to find a layout container perpendicular + // to the edge. Eg. close to the top or bottom of a horiz layout. + while (con) { + enum wlr_edges edge = WLR_EDGE_NONE; + enum sway_container_layout layout = container_parent_layout(con); + struct wlr_box parent; + con->parent ? container_get_box(con->parent, &parent) : + workspace_get_box(con->workspace, &parent); + if (layout == L_HORIZ || layout == L_TABBED) { + if (cursor->cursor->y < parent.y + 30) { + edge = WLR_EDGE_TOP; + } else if (cursor->cursor->y > parent.y + parent.height - 30) { + edge = WLR_EDGE_BOTTOM; + } + } else if (layout == L_VERT || layout == L_STACKED) { + if (cursor->cursor->x < parent.x + 30) { + edge = WLR_EDGE_LEFT; + } else if (cursor->cursor->x > parent.x + parent.width - 30) { + edge = WLR_EDGE_RIGHT; + } + } + if (edge) { + seat->op_target_node = node_get_parent(&con->node); + seat->op_target_edge = edge; + node_get_box(seat->op_target_node, &seat->op_drop_box); + resize_box(&seat->op_drop_box, edge, 30); + desktop_damage_box(&seat->op_drop_box); + return; + } + con = con->parent; + } + + // Use the hovered view - but we must be over the actual surface + con = node->sway_container; + if (!con->view->surface || node == &seat->op_container->node) { + seat->op_target_node = NULL; + seat->op_target_edge = WLR_EDGE_NONE; + return; + } + + // Find the closest edge + size_t thickness = fmin(con->view->width, con->view->height) * 0.3; + size_t closest_dist = INT_MAX; + size_t dist; + seat->op_target_edge = WLR_EDGE_NONE; + if ((dist = cursor->cursor->y - con->y) < closest_dist) { + closest_dist = dist; + seat->op_target_edge = WLR_EDGE_TOP; + } + if ((dist = cursor->cursor->x - con->x) < closest_dist) { + closest_dist = dist; + seat->op_target_edge = WLR_EDGE_LEFT; + } + if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) { + closest_dist = dist; + seat->op_target_edge = WLR_EDGE_RIGHT; + } + if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) { + closest_dist = dist; + seat->op_target_edge = WLR_EDGE_BOTTOM; + } + + if (closest_dist > thickness) { + seat->op_target_edge = WLR_EDGE_NONE; + } + + seat->op_target_node = node; + seat->op_drop_box.x = con->view->x; + seat->op_drop_box.y = con->view->y; + seat->op_drop_box.width = con->view->width; + seat->op_drop_box.height = con->view->height; + resize_box(&seat->op_drop_box, seat->op_target_edge, thickness); + desktop_damage_box(&seat->op_drop_box); +} + static void calculate_floating_constraints(struct sway_container *con, int *min_width, int *max_width, int *min_height, int *max_height) { if (config->floating_minimum_width == -1) { // no minimum @@ -405,6 +540,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, case OP_MOVE_FLOATING: handle_move_floating_motion(seat, cursor); break; + case OP_MOVE_TILING: + handle_move_tiling_motion(seat, cursor); + break; case OP_RESIZE_FLOATING: handle_resize_floating_motion(seat, cursor); break; @@ -751,6 +889,14 @@ void dispatch_cursor_button(struct sway_cursor *cursor, } } + // Handle moving a tiling container + if (config->tiling_drag && mod_pressed && !is_floating_or_child && + !cont->is_fullscreen) { + seat_pointer_notify_button(seat, time_msec, button, state); + seat_begin_move_tiling(seat, cont, button); + return; + } + // Handle mousedown on a container surface if (surface && cont && state == WLR_BUTTON_PRESSED) { seat_set_focus_container(seat, cont); 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; diff --git a/sway/tree/container.c b/sway/tree/container.c index 0a69f8d5..ff10c1ab 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -835,8 +835,14 @@ void container_end_mouse_operation(struct sway_container *container) { struct sway_seat *seat; wl_list_for_each(seat, &input_manager->seats, link) { if (seat->op_container == container) { + seat->op_target_node = NULL; // ensure tiling move doesn't apply seat_end_mouse_operation(seat); } + // If the user is doing a tiling drag over this container, + // keep the operation active but unset the target container. + if (seat->op_target_node == &container->node) { + seat->op_target_node = NULL; + } } } @@ -1086,13 +1092,13 @@ void container_insert_child(struct sway_container *parent, } void container_add_sibling(struct sway_container *fixed, - struct sway_container *active) { + struct sway_container *active, int side) { if (active->workspace) { container_detach(active); } list_t *siblings = container_get_siblings(fixed); int index = list_find(siblings, fixed); - list_insert(siblings, index + 1, active); + list_insert(siblings, index + side, active); active->parent = fixed->parent; active->workspace = fixed->workspace; container_for_each_child(active, set_workspace, NULL); @@ -1145,7 +1151,7 @@ void container_detach(struct sway_container *child) { void container_replace(struct sway_container *container, struct sway_container *replacement) { - container_add_sibling(container, replacement); + container_add_sibling(container, replacement, 1); container_detach(container); } diff --git a/sway/tree/view.c b/sway/tree/view.c index 65ac8b32..d4ffa06b 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -529,7 +529,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { view->container = container_create(view); if (target_sibling) { - container_add_sibling(target_sibling, view->container); + container_add_sibling(target_sibling, view->container, 1); } else { workspace_add_tiling(ws, view->container); } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index b8e90892..d4b57a0f 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -694,3 +694,16 @@ void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box) { box->width = workspace->width; box->height = workspace->height; } + +static void count_tiling_views(struct sway_container *con, void *data) { + if (con->view && !container_is_floating_or_child(con)) { + size_t *count = data; + *count += 1; + } +} + +size_t workspace_num_tiling_views(struct sway_workspace *ws) { + size_t count = 0; + workspace_for_each_container(ws, count_tiling_views, &count); + return count; +} From eb74317c2d8e2f58bde1f04bb900ed4948005752 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 22:26:39 +1000 Subject: [PATCH 4/7] Fix dropzone box on scaled outputs --- sway/desktop/render.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 8b5b3e95..1d2f445d 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -901,7 +901,10 @@ static void render_dropzones(struct sway_output *output, memcpy(&color, config->border_colors.focused.indicator, sizeof(float) * 4); premultiply_alpha(color, 0.5); - render_rect(output->wlr_output, damage, &seat->op_drop_box, color); + struct wlr_box box; + memcpy(&box, &seat->op_drop_box, sizeof(struct wlr_box)); + scale_box(&box, output->wlr_output->scale); + render_rect(output->wlr_output, damage, &box, color); } } } From 403905c11bf9996cf1937ec0067f33d013e78305 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 23:24:57 +1000 Subject: [PATCH 5/7] Fix line length --- sway/input/seat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } From df95c61044c37b511922db03eb5bd868b374e9d4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 11 Sep 2018 23:38:17 +1000 Subject: [PATCH 6/7] Fix crash in workspace_wrap_children When workspace_wrap_children is called on a workspace which has a fullscreen child and the fullscreen child is a direct child of the workspace, sway would crash. The workspace's fullscreen pointer is unset when the fullscreen container is detached and applied again when added to a parent, but in this case the parent hadn't yet been added to the workspace which meant con->workspace was NULL. The fix makes container_handle_fullscreen_reparent return if there's no workspace, and the fullscreen pointer is reapplied in workspace_wrap_children. --- sway/tree/container.c | 3 ++- sway/tree/workspace.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sway/tree/container.c b/sway/tree/container.c index ff10c1ab..21a0cd76 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1063,7 +1063,8 @@ list_t *container_get_current_siblings(struct sway_container *container) { } void container_handle_fullscreen_reparent(struct sway_container *con) { - if (!con->is_fullscreen || con->workspace->fullscreen == con) { + if (!con->is_fullscreen || !con->workspace || + con->workspace->fullscreen == con) { return; } if (con->workspace->fullscreen) { diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d4b57a0f..18746430 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -557,6 +557,7 @@ struct sway_container *workspace_find_container(struct sway_workspace *ws, } struct sway_container *workspace_wrap_children(struct sway_workspace *ws) { + struct sway_container *fs = ws->fullscreen; struct sway_container *middle = container_create(NULL); middle->layout = ws->layout; while (ws->tiling->length) { @@ -565,6 +566,7 @@ struct sway_container *workspace_wrap_children(struct sway_workspace *ws) { container_add_child(middle, child); } workspace_add_tiling(ws, middle); + ws->fullscreen = fs; return middle; } From 679c7eb08c16daea8e3e1cff7bcf179e116d0e8e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 12 Sep 2018 08:46:46 +1000 Subject: [PATCH 7/7] 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 --- include/sway/tree/container.h | 2 +- sway/input/cursor.c | 22 ++++++++++++++-------- sway/input/seat.c | 6 ++---- sway/tree/container.c | 4 ++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 94d30ced..5e281a2f 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -283,7 +283,7 @@ void container_insert_child(struct sway_container *parent, * Side should be 0 to add before, or 1 to add after. */ void container_add_sibling(struct sway_container *parent, - struct sway_container *child, int side); + struct sway_container *child, bool after); void container_detach(struct sway_container *child); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index b0f8e531..dc66d82d 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -26,6 +26,10 @@ #include "sway/tree/workspace.h" #include "wlr-layer-shell-unstable-v1-protocol.h" +// When doing a tiling drag, this is the thickness of the dropzone +// when dragging to the edge of a layout container. +#define DROP_LAYOUT_BORDER 30 + static uint32_t get_current_time_msec() { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); @@ -229,7 +233,7 @@ static void handle_move_floating_motion(struct sway_seat *seat, } static void resize_box(struct wlr_box *box, enum wlr_edges edge, - size_t thickness) { + int thickness) { switch (edge) { case WLR_EDGE_TOP: box->height = thickness; @@ -297,15 +301,17 @@ static void handle_move_tiling_motion(struct sway_seat *seat, con->parent ? container_get_box(con->parent, &parent) : workspace_get_box(con->workspace, &parent); if (layout == L_HORIZ || layout == L_TABBED) { - if (cursor->cursor->y < parent.y + 30) { + if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) { edge = WLR_EDGE_TOP; - } else if (cursor->cursor->y > parent.y + parent.height - 30) { + } else if (cursor->cursor->y > parent.y + parent.height + - DROP_LAYOUT_BORDER) { edge = WLR_EDGE_BOTTOM; } } else if (layout == L_VERT || layout == L_STACKED) { - if (cursor->cursor->x < parent.x + 30) { + if (cursor->cursor->x < parent.x + DROP_LAYOUT_BORDER) { edge = WLR_EDGE_LEFT; - } else if (cursor->cursor->x > parent.x + parent.width - 30) { + } else if (cursor->cursor->x > parent.x + parent.width + - DROP_LAYOUT_BORDER) { edge = WLR_EDGE_RIGHT; } } @@ -313,7 +319,7 @@ static void handle_move_tiling_motion(struct sway_seat *seat, seat->op_target_node = node_get_parent(&con->node); seat->op_target_edge = edge; node_get_box(seat->op_target_node, &seat->op_drop_box); - resize_box(&seat->op_drop_box, edge, 30); + resize_box(&seat->op_drop_box, edge, DROP_LAYOUT_BORDER); desktop_damage_box(&seat->op_drop_box); return; } @@ -890,8 +896,8 @@ void dispatch_cursor_button(struct sway_cursor *cursor, } // Handle moving a tiling container - if (config->tiling_drag && mod_pressed && !is_floating_or_child && - !cont->is_fullscreen) { + if (config->tiling_drag && mod_pressed && state == WLR_BUTTON_PRESSED && + !is_floating_or_child && !cont->is_fullscreen) { seat_pointer_notify_button(seat, time_msec, button, state); seat_begin_move_tiling(seat, cont, button); return; 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); diff --git a/sway/tree/container.c b/sway/tree/container.c index 21a0cd76..df064573 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1093,13 +1093,13 @@ void container_insert_child(struct sway_container *parent, } void container_add_sibling(struct sway_container *fixed, - struct sway_container *active, int side) { + struct sway_container *active, bool after) { if (active->workspace) { container_detach(active); } list_t *siblings = container_get_siblings(fixed); int index = list_find(siblings, fixed); - list_insert(siblings, index + side, active); + list_insert(siblings, index + after, active); active->parent = fixed->parent; active->workspace = fixed->workspace; container_for_each_child(active, set_workspace, NULL);