summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-09-11 19:19:17 -0400
committerLibravatar GitHub <noreply@github.com>2018-09-11 19:19:17 -0400
commit4fbec701fcf1505d1c13d7f5d8b55264b8f07e4e (patch)
tree82daa71d644f15c2e1e58ca9bdb2d4e1a75d3be9
parentMerge pull request #2617 from wmww/cursor-enter-on-focus-change (diff)
parentMinor fixes to tiling drag implementation (diff)
downloadsway-4fbec701fcf1505d1c13d7f5d8b55264b8f07e4e.tar.gz
sway-4fbec701fcf1505d1c13d7f5d8b55264b8f07e4e.tar.zst
sway-4fbec701fcf1505d1c13d7f5d8b55264b8f07e4e.zip
Merge pull request #2618 from RyanDwyer/tiling-drag
Implement tiling drag
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h1
-rw-r--r--include/sway/input/seat.h13
-rw-r--r--include/sway/tree/container.h5
-rw-r--r--include/sway/tree/workspace.h2
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/move.c2
-rw-r--r--sway/commands/tiling_drag.c13
-rw-r--r--sway/config.c1
-rw-r--r--sway/desktop/render.c20
-rw-r--r--sway/desktop/xdg_shell.c2
-rw-r--r--sway/desktop/xdg_shell_v6.c2
-rw-r--r--sway/desktop/xwayland.c2
-rw-r--r--sway/input/cursor.c160
-rw-r--r--sway/input/seat.c81
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/container.c15
-rw-r--r--sway/tree/view.c2
-rw-r--r--sway/tree/workspace.c15
19 files changed, 318 insertions, 21 deletions
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;
161sway_cmd cmd_swaybg_command; 161sway_cmd cmd_swaybg_command;
162sway_cmd cmd_swaynag_command; 162sway_cmd cmd_swaynag_command;
163sway_cmd cmd_swap; 163sway_cmd cmd_swap;
164sway_cmd cmd_tiling_drag;
164sway_cmd cmd_title_format; 165sway_cmd cmd_title_format;
165sway_cmd cmd_unmark; 166sway_cmd cmd_unmark;
166sway_cmd cmd_urgent; 167sway_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 {
365 bool validating; 365 bool validating;
366 bool auto_back_and_forth; 366 bool auto_back_and_forth;
367 bool show_marks; 367 bool show_marks;
368 bool tiling_drag;
368 369
369 bool edge_gaps; 370 bool edge_gaps;
370 bool smart_gaps; 371 bool smart_gaps;
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index b07d200d..e006faba 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -38,7 +38,8 @@ struct sway_drag_icon {
38enum sway_seat_operation { 38enum sway_seat_operation {
39 OP_NONE, 39 OP_NONE,
40 OP_DOWN, 40 OP_DOWN,
41 OP_MOVE, 41 OP_MOVE_FLOATING,
42 OP_MOVE_TILING,
42 OP_RESIZE_FLOATING, 43 OP_RESIZE_FLOATING,
43 OP_RESIZE_TILING, 44 OP_RESIZE_TILING,
44}; 45};
@@ -64,6 +65,9 @@ struct sway_seat {
64 // Operations (drag and resize) 65 // Operations (drag and resize)
65 enum sway_seat_operation operation; 66 enum sway_seat_operation operation;
66 struct sway_container *op_container; 67 struct sway_container *op_container;
68 struct sway_node *op_target_node; // target for tiling move
69 enum wlr_edges op_target_edge;
70 struct wlr_box op_drop_box;
67 enum wlr_edges op_resize_edge; 71 enum wlr_edges op_resize_edge;
68 uint32_t op_button; 72 uint32_t op_button;
69 bool op_resize_preserve_ratio; 73 bool op_resize_preserve_ratio;
@@ -172,8 +176,11 @@ void drag_icon_update_position(struct sway_drag_icon *icon);
172void seat_begin_down(struct sway_seat *seat, struct sway_container *con, 176void seat_begin_down(struct sway_seat *seat, struct sway_container *con,
173 uint32_t button, double sx, double sy); 177 uint32_t button, double sx, double sy);
174 178
175void seat_begin_move(struct sway_seat *seat, struct sway_container *con, 179void seat_begin_move_floating(struct sway_seat *seat,
176 uint32_t button); 180 struct sway_container *con, uint32_t button);
181
182void seat_begin_move_tiling(struct sway_seat *seat,
183 struct sway_container *con, uint32_t button);
177 184
178void seat_begin_resize_floating(struct sway_seat *seat, 185void seat_begin_resize_floating(struct sway_seat *seat,
179 struct sway_container *con, uint32_t button, enum wlr_edges edge); 186 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..5e281a2f 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,
279void container_insert_child(struct sway_container *parent, 279void container_insert_child(struct sway_container *parent,
280 struct sway_container *child, int i); 280 struct sway_container *child, int i);
281 281
282/**
283 * Side should be 0 to add before, or 1 to add after.
284 */
282void container_add_sibling(struct sway_container *parent, 285void container_add_sibling(struct sway_container *parent,
283 struct sway_container *child); 286 struct sway_container *child, bool after);
284 287
285void container_detach(struct sway_container *child); 288void container_detach(struct sway_container *child);
286 289
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);
126 126
127void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box); 127void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box);
128 128
129size_t workspace_num_tiling_views(struct sway_workspace *ws);
130
129#endif 131#endif
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[] = {
127 { "set", cmd_set }, 127 { "set", cmd_set },
128 { "show_marks", cmd_show_marks }, 128 { "show_marks", cmd_show_marks },
129 { "smart_gaps", cmd_smart_gaps }, 129 { "smart_gaps", cmd_smart_gaps },
130 { "tiling_drag", cmd_tiling_drag },
130 { "workspace", cmd_workspace }, 131 { "workspace", cmd_workspace },
131 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, 132 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
132}; 133};
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,
235 container->saved_width = container->saved_height = 0; 235 container->saved_width = container->saved_height = 0;
236 236
237 if (destination->view) { 237 if (destination->view) {
238 container_add_sibling(destination, container); 238 container_add_sibling(destination, container, 1);
239 } else { 239 } else {
240 container_add_child(destination, container); 240 container_add_child(destination, container);
241 } 241 }
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 @@
1#include "sway/commands.h"
2#include "util.h"
3
4struct cmd_results *cmd_tiling_drag(int argc, char **argv) {
5 struct cmd_results *error = NULL;
6 if ((error = checkarg(argc, "tiling_drag", EXPECTED_EQUAL_TO, 1))) {
7 return error;
8 }
9
10 config->tiling_drag = parse_boolean(argv[0], config->tiling_drag);
11
12 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
13}
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) {
225 config->auto_back_and_forth = false; 225 config->auto_back_and_forth = false;
226 config->reading = false; 226 config->reading = false;
227 config->show_marks = true; 227 config->show_marks = true;
228 config->tiling_drag = true;
228 229
229 config->edge_gaps = true; 230 config->edge_gaps = true;
230 config->smart_gaps = false; 231 config->smart_gaps = false;
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 8a6f63aa..1d2f445d 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -891,6 +891,24 @@ static void render_floating(struct sway_output *soutput,
891 } 891 }
892} 892}
893 893
894static void render_dropzones(struct sway_output *output,
895 pixman_region32_t *damage) {
896 struct sway_seat *seat;
897 wl_list_for_each(seat, &input_manager->seats, link) {
898 if (seat->operation == OP_MOVE_TILING && seat->op_target_node
899 && node_get_output(seat->op_target_node) == output) {
900 float color[4];
901 memcpy(&color, config->border_colors.focused.indicator,
902 sizeof(float) * 4);
903 premultiply_alpha(color, 0.5);
904 struct wlr_box box;
905 memcpy(&box, &seat->op_drop_box, sizeof(struct wlr_box));
906 scale_box(&box, output->wlr_output->scale);
907 render_rect(output->wlr_output, damage, &box, color);
908 }
909 }
910}
911
894void output_render(struct sway_output *output, struct timespec *when, 912void output_render(struct sway_output *output, struct timespec *when,
895 pixman_region32_t *damage) { 913 pixman_region32_t *damage) {
896 struct wlr_output *wlr_output = output->wlr_output; 914 struct wlr_output *wlr_output = output->wlr_output;
@@ -973,6 +991,8 @@ void output_render(struct sway_output *output, struct timespec *when,
973 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); 991 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
974 } 992 }
975 993
994 render_dropzones(output, damage);
995
976 struct sway_seat *seat = input_manager_current_seat(input_manager); 996 struct sway_seat *seat = input_manager_current_seat(input_manager);
977 struct sway_container *focus = seat_get_focused_container(seat); 997 struct sway_container *focus = seat_get_focused_container(seat);
978 if (focus && focus->view) { 998 if (focus && focus->view) {
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) {
333 struct wlr_xdg_toplevel_move_event *e = data; 333 struct wlr_xdg_toplevel_move_event *e = data;
334 struct sway_seat *seat = e->seat->seat->data; 334 struct sway_seat *seat = e->seat->seat->data;
335 if (e->serial == seat->last_button_serial) { 335 if (e->serial == seat->last_button_serial) {
336 seat_begin_move(seat, view->container, seat->last_button); 336 seat_begin_move_floating(seat, view->container, seat->last_button);
337 } 337 }
338} 338}
339 339
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) {
330 struct wlr_xdg_toplevel_v6_move_event *e = data; 330 struct wlr_xdg_toplevel_v6_move_event *e = data;
331 struct sway_seat *seat = e->seat->seat->data; 331 struct sway_seat *seat = e->seat->seat->data;
332 if (e->serial == seat->last_button_serial) { 332 if (e->serial == seat->last_button_serial) {
333 seat_begin_move(seat, view->container, seat->last_button); 333 seat_begin_move_floating(seat, view->container, seat->last_button);
334 } 334 }
335} 335}
336 336
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) {
449 return; 449 return;
450 } 450 }
451 struct sway_seat *seat = input_manager_current_seat(input_manager); 451 struct sway_seat *seat = input_manager_current_seat(input_manager);
452 seat_begin_move(seat, view->container, seat->last_button); 452 seat_begin_move_floating(seat, view->container, seat->last_button);
453} 453}
454 454
455static void handle_request_resize(struct wl_listener *listener, void *data) { 455static void handle_request_resize(struct wl_listener *listener, void *data) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 69a019bb..dc66d82d 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -26,6 +26,10 @@
26#include "sway/tree/workspace.h" 26#include "sway/tree/workspace.h"
27#include "wlr-layer-shell-unstable-v1-protocol.h" 27#include "wlr-layer-shell-unstable-v1-protocol.h"
28 28
29// When doing a tiling drag, this is the thickness of the dropzone
30// when dragging to the edge of a layout container.
31#define DROP_LAYOUT_BORDER 30
32
29static uint32_t get_current_time_msec() { 33static uint32_t get_current_time_msec() {
30 struct timespec now; 34 struct timespec now;
31 clock_gettime(CLOCK_MONOTONIC, &now); 35 clock_gettime(CLOCK_MONOTONIC, &now);
@@ -218,7 +222,7 @@ static void handle_down_motion(struct sway_seat *seat,
218 seat->op_moved = true; 222 seat->op_moved = true;
219} 223}
220 224
221static void handle_move_motion(struct sway_seat *seat, 225static void handle_move_floating_motion(struct sway_seat *seat,
222 struct sway_cursor *cursor) { 226 struct sway_cursor *cursor) {
223 struct sway_container *con = seat->op_container; 227 struct sway_container *con = seat->op_container;
224 desktop_damage_whole_container(con); 228 desktop_damage_whole_container(con);
@@ -228,6 +232,143 @@ static void handle_move_motion(struct sway_seat *seat,
228 desktop_damage_whole_container(con); 232 desktop_damage_whole_container(con);
229} 233}
230 234
235static void resize_box(struct wlr_box *box, enum wlr_edges edge,
236 int thickness) {
237 switch (edge) {
238 case WLR_EDGE_TOP:
239 box->height = thickness;
240 break;
241 case WLR_EDGE_LEFT:
242 box->width = thickness;
243 break;
244 case WLR_EDGE_RIGHT:
245 box->x = box->x + box->width - thickness;
246 box->width = thickness;
247 break;
248 case WLR_EDGE_BOTTOM:
249 box->y = box->y + box->height - thickness;
250 box->height = thickness;
251 break;
252 case WLR_EDGE_NONE:
253 box->x += thickness;
254 box->y += thickness;
255 box->width -= thickness * 2;
256 box->height -= thickness * 2;
257 break;
258 }
259}
260
261static void handle_move_tiling_motion(struct sway_seat *seat,
262 struct sway_cursor *cursor) {
263 struct wlr_surface *surface = NULL;
264 double sx, sy;
265 struct sway_node *node = node_at_coords(seat,
266 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
267 // Damage the old location
268 desktop_damage_box(&seat->op_drop_box);
269
270 if (!node) {
271 // Eg. hovered over a layer surface such as swaybar
272 seat->op_target_node = NULL;
273 seat->op_target_edge = WLR_EDGE_NONE;
274 return;
275 }
276
277 if (node->type == N_WORKSPACE) {
278 // Emtpy workspace
279 seat->op_target_node = node;
280 seat->op_target_edge = WLR_EDGE_NONE;
281 workspace_get_box(node->sway_workspace, &seat->op_drop_box);
282 desktop_damage_box(&seat->op_drop_box);
283 return;
284 }
285
286 // Deny moving within own workspace if this is the only child
287 struct sway_container *con = node->sway_container;
288 if (workspace_num_tiling_views(seat->op_container->workspace) == 1 &&
289 con->workspace == seat->op_container->workspace) {
290 seat->op_target_node = NULL;
291 seat->op_target_edge = WLR_EDGE_NONE;
292 return;
293 }
294
295 // Traverse the ancestors, trying to find a layout container perpendicular
296 // to the edge. Eg. close to the top or bottom of a horiz layout.
297 while (con) {
298 enum wlr_edges edge = WLR_EDGE_NONE;
299 enum sway_container_layout layout = container_parent_layout(con);
300 struct wlr_box parent;
301 con->parent ? container_get_box(con->parent, &parent) :
302 workspace_get_box(con->workspace, &parent);
303 if (layout == L_HORIZ || layout == L_TABBED) {
304 if (cursor->cursor->y < parent.y + DROP_LAYOUT_BORDER) {
305 edge = WLR_EDGE_TOP;
306 } else if (cursor->cursor->y > parent.y + parent.height
307 - DROP_LAYOUT_BORDER) {
308 edge = WLR_EDGE_BOTTOM;
309 }
310 } else if (layout == L_VERT || layout == L_STACKED) {
311 if (cursor->cursor->x < parent.x + DROP_LAYOUT_BORDER) {
312 edge = WLR_EDGE_LEFT;
313 } else if (cursor->cursor->x > parent.x + parent.width
314 - DROP_LAYOUT_BORDER) {
315 edge = WLR_EDGE_RIGHT;
316 }
317 }
318 if (edge) {
319 seat->op_target_node = node_get_parent(&con->node);
320 seat->op_target_edge = edge;
321 node_get_box(seat->op_target_node, &seat->op_drop_box);
322 resize_box(&seat->op_drop_box, edge, DROP_LAYOUT_BORDER);
323 desktop_damage_box(&seat->op_drop_box);
324 return;
325 }
326 con = con->parent;
327 }
328
329 // Use the hovered view - but we must be over the actual surface
330 con = node->sway_container;
331 if (!con->view->surface || node == &seat->op_container->node) {
332 seat->op_target_node = NULL;
333 seat->op_target_edge = WLR_EDGE_NONE;
334 return;
335 }
336
337 // Find the closest edge
338 size_t thickness = fmin(con->view->width, con->view->height) * 0.3;
339 size_t closest_dist = INT_MAX;
340 size_t dist;
341 seat->op_target_edge = WLR_EDGE_NONE;
342 if ((dist = cursor->cursor->y - con->y) < closest_dist) {
343 closest_dist = dist;
344 seat->op_target_edge = WLR_EDGE_TOP;
345 }
346 if ((dist = cursor->cursor->x - con->x) < closest_dist) {
347 closest_dist = dist;
348 seat->op_target_edge = WLR_EDGE_LEFT;
349 }
350 if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) {
351 closest_dist = dist;
352 seat->op_target_edge = WLR_EDGE_RIGHT;
353 }
354 if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) {
355 closest_dist = dist;
356 seat->op_target_edge = WLR_EDGE_BOTTOM;
357 }
358
359 if (closest_dist > thickness) {
360 seat->op_target_edge = WLR_EDGE_NONE;
361 }
362
363 seat->op_target_node = node;
364 seat->op_drop_box.x = con->view->x;
365 seat->op_drop_box.y = con->view->y;
366 seat->op_drop_box.width = con->view->width;
367 seat->op_drop_box.height = con->view->height;
368 resize_box(&seat->op_drop_box, seat->op_target_edge, thickness);
369 desktop_damage_box(&seat->op_drop_box);
370}
371
231static void calculate_floating_constraints(struct sway_container *con, 372static void calculate_floating_constraints(struct sway_container *con,
232 int *min_width, int *max_width, int *min_height, int *max_height) { 373 int *min_width, int *max_width, int *min_height, int *max_height) {
233 if (config->floating_minimum_width == -1) { // no minimum 374 if (config->floating_minimum_width == -1) { // no minimum
@@ -402,8 +543,11 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
402 case OP_DOWN: 543 case OP_DOWN:
403 handle_down_motion(seat, cursor, time_msec); 544 handle_down_motion(seat, cursor, time_msec);
404 break; 545 break;
405 case OP_MOVE: 546 case OP_MOVE_FLOATING:
406 handle_move_motion(seat, cursor); 547 handle_move_floating_motion(seat, cursor);
548 break;
549 case OP_MOVE_TILING:
550 handle_move_tiling_motion(seat, cursor);
407 break; 551 break;
408 case OP_RESIZE_FLOATING: 552 case OP_RESIZE_FLOATING:
409 handle_resize_floating_motion(seat, cursor); 553 handle_resize_floating_motion(seat, cursor);
@@ -719,7 +863,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
719 while (cont->parent) { 863 while (cont->parent) {
720 cont = cont->parent; 864 cont = cont->parent;
721 } 865 }
722 seat_begin_move(seat, cont, button); 866 seat_begin_move_floating(seat, cont, button);
723 return; 867 return;
724 } 868 }
725 } 869 }
@@ -751,6 +895,14 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
751 } 895 }
752 } 896 }
753 897
898 // Handle moving a tiling container
899 if (config->tiling_drag && mod_pressed && state == WLR_BUTTON_PRESSED &&
900 !is_floating_or_child && !cont->is_fullscreen) {
901 seat_pointer_notify_button(seat, time_msec, button, state);
902 seat_begin_move_tiling(seat, cont, button);
903 return;
904 }
905
754 // Handle mousedown on a container surface 906 // Handle mousedown on a container surface
755 if (surface && cont && state == WLR_BUTTON_PRESSED) { 907 if (surface && cont && state == WLR_BUTTON_PRESSED) {
756 seat_set_focus_container(seat, cont); 908 seat_set_focus_container(seat, cont);
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 5709a7f7..8704f90f 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -963,18 +963,28 @@ void seat_begin_down(struct sway_seat *seat, struct sway_container *con,
963 seat->op_moved = false; 963 seat->op_moved = false;
964} 964}
965 965
966void seat_begin_move(struct sway_seat *seat, struct sway_container *con, 966void seat_begin_move_floating(struct sway_seat *seat,
967 uint32_t button) { 967 struct sway_container *con, uint32_t button) {
968 if (!seat->cursor) { 968 if (!seat->cursor) {
969 wlr_log(WLR_DEBUG, "Ignoring move request due to no cursor device"); 969 wlr_log(WLR_DEBUG, "Ignoring move request due to no cursor device");
970 return; 970 return;
971 } 971 }
972 seat->operation = OP_MOVE; 972 seat->operation = OP_MOVE_FLOATING;
973 seat->op_container = con; 973 seat->op_container = con;
974 seat->op_button = button; 974 seat->op_button = button;
975 cursor_set_image(seat->cursor, "grab", NULL); 975 cursor_set_image(seat->cursor, "grab", NULL);
976} 976}
977 977
978void seat_begin_move_tiling(struct sway_seat *seat,
979 struct sway_container *con, uint32_t button) {
980 seat->operation = OP_MOVE_TILING;
981 seat->op_container = con;
982 seat->op_button = button;
983 seat->op_target_node = NULL;
984 seat->op_target_edge = 0;
985 cursor_set_image(seat->cursor, "grab", NULL);
986}
987
978void seat_begin_resize_floating(struct sway_seat *seat, 988void seat_begin_resize_floating(struct sway_seat *seat,
979 struct sway_container *con, uint32_t button, enum wlr_edges edge) { 989 struct sway_container *con, uint32_t button, enum wlr_edges edge) {
980 if (!seat->cursor) { 990 if (!seat->cursor) {
@@ -1015,13 +1025,76 @@ void seat_begin_resize_tiling(struct sway_seat *seat,
1015 seat->op_ref_height = con->height; 1025 seat->op_ref_height = con->height;
1016} 1026}
1017 1027
1028static bool is_parallel(enum sway_container_layout layout,
1029 enum wlr_edges edge) {
1030 bool layout_is_horiz = layout == L_HORIZ || layout == L_TABBED;
1031 bool edge_is_horiz = edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT;
1032 return layout_is_horiz == edge_is_horiz;
1033}
1034
1035static void seat_end_move_tiling(struct sway_seat *seat) {
1036 struct sway_container *con = seat->op_container;
1037 struct sway_container *old_parent = con->parent;
1038 struct sway_workspace *old_ws = con->workspace;
1039 struct sway_node *target_node = seat->op_target_node;
1040 struct sway_workspace *new_ws = target_node->type == N_WORKSPACE ?
1041 target_node->sway_workspace : target_node->sway_container->workspace;
1042 enum wlr_edges edge = seat->op_target_edge;
1043 int after = edge != WLR_EDGE_TOP && edge != WLR_EDGE_LEFT;
1044
1045 container_detach(con);
1046 if (old_parent) {
1047 container_reap_empty(old_parent);
1048 }
1049
1050 // Moving container into empty workspace
1051 if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) {
1052 workspace_add_tiling(new_ws, con);
1053 } else if (target_node->type == N_CONTAINER) {
1054 // Moving container before/after another
1055 struct sway_container *target = target_node->sway_container;
1056 enum sway_container_layout layout = container_parent_layout(target);
1057 if (edge && !is_parallel(layout, edge)) {
1058 enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
1059 edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
1060 container_split(target, new_layout);
1061 }
1062 container_add_sibling(target, con, after);
1063 } else {
1064 // Target is a workspace which requires splitting
1065 enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
1066 edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
1067 workspace_split(new_ws, new_layout);
1068 workspace_insert_tiling(new_ws, con, after);
1069 }
1070
1071 // This is a bit dirty, but we'll set the dimensions to that of a sibling.
1072 // I don't think there's any other way to make it consistent without
1073 // changing how we auto-size containers.
1074 list_t *siblings = container_get_siblings(con);
1075 if (siblings->length > 1) {
1076 int index = list_find(siblings, con);
1077 struct sway_container *sibling = index == 0 ?
1078 siblings->items[1] : siblings->items[index - 1];
1079 con->width = sibling->width;
1080 con->height = sibling->height;
1081 }
1082
1083 arrange_workspace(old_ws);
1084 if (new_ws != old_ws) {
1085 arrange_workspace(new_ws);
1086 }
1087}
1088
1018void seat_end_mouse_operation(struct sway_seat *seat) { 1089void seat_end_mouse_operation(struct sway_seat *seat) {
1019 enum sway_seat_operation operation = seat->operation; 1090 enum sway_seat_operation operation = seat->operation;
1020 if (seat->operation == OP_MOVE) { 1091 if (seat->operation == OP_MOVE_FLOATING) {
1021 // We "move" the container to its own location so it discovers its 1092 // We "move" the container to its own location so it discovers its
1022 // output again. 1093 // output again.
1023 struct sway_container *con = seat->op_container; 1094 struct sway_container *con = seat->op_container;
1024 container_floating_move_to(con, con->x, con->y); 1095 container_floating_move_to(con, con->x, con->y);
1096 } else if (seat->operation == OP_MOVE_TILING && seat->op_target_node) {
1097 seat_end_move_tiling(seat);
1025 } 1098 }
1026 seat->operation = OP_NONE; 1099 seat->operation = OP_NONE;
1027 seat->op_container = NULL; 1100 seat->op_container = NULL;
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(
83 'commands/swaybg_command.c', 83 'commands/swaybg_command.c',
84 'commands/swaynag_command.c', 84 'commands/swaynag_command.c',
85 'commands/swap.c', 85 'commands/swap.c',
86 'commands/tiling_drag.c',
86 'commands/title_format.c', 87 'commands/title_format.c',
87 'commands/unmark.c', 88 'commands/unmark.c',
88 'commands/urgent.c', 89 'commands/urgent.c',
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 0a69f8d5..df064573 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -835,8 +835,14 @@ void container_end_mouse_operation(struct sway_container *container) {
835 struct sway_seat *seat; 835 struct sway_seat *seat;
836 wl_list_for_each(seat, &input_manager->seats, link) { 836 wl_list_for_each(seat, &input_manager->seats, link) {
837 if (seat->op_container == container) { 837 if (seat->op_container == container) {
838 seat->op_target_node = NULL; // ensure tiling move doesn't apply
838 seat_end_mouse_operation(seat); 839 seat_end_mouse_operation(seat);
839 } 840 }
841 // If the user is doing a tiling drag over this container,
842 // keep the operation active but unset the target container.
843 if (seat->op_target_node == &container->node) {
844 seat->op_target_node = NULL;
845 }
840 } 846 }
841} 847}
842 848
@@ -1057,7 +1063,8 @@ list_t *container_get_current_siblings(struct sway_container *container) {
1057} 1063}
1058 1064
1059void container_handle_fullscreen_reparent(struct sway_container *con) { 1065void container_handle_fullscreen_reparent(struct sway_container *con) {
1060 if (!con->is_fullscreen || con->workspace->fullscreen == con) { 1066 if (!con->is_fullscreen || !con->workspace ||
1067 con->workspace->fullscreen == con) {
1061 return; 1068 return;
1062 } 1069 }
1063 if (con->workspace->fullscreen) { 1070 if (con->workspace->fullscreen) {
@@ -1086,13 +1093,13 @@ void container_insert_child(struct sway_container *parent,
1086} 1093}
1087 1094
1088void container_add_sibling(struct sway_container *fixed, 1095void container_add_sibling(struct sway_container *fixed,
1089 struct sway_container *active) { 1096 struct sway_container *active, bool after) {
1090 if (active->workspace) { 1097 if (active->workspace) {
1091 container_detach(active); 1098 container_detach(active);
1092 } 1099 }
1093 list_t *siblings = container_get_siblings(fixed); 1100 list_t *siblings = container_get_siblings(fixed);
1094 int index = list_find(siblings, fixed); 1101 int index = list_find(siblings, fixed);
1095 list_insert(siblings, index + 1, active); 1102 list_insert(siblings, index + after, active);
1096 active->parent = fixed->parent; 1103 active->parent = fixed->parent;
1097 active->workspace = fixed->workspace; 1104 active->workspace = fixed->workspace;
1098 container_for_each_child(active, set_workspace, NULL); 1105 container_for_each_child(active, set_workspace, NULL);
@@ -1145,7 +1152,7 @@ void container_detach(struct sway_container *child) {
1145 1152
1146void container_replace(struct sway_container *container, 1153void container_replace(struct sway_container *container,
1147 struct sway_container *replacement) { 1154 struct sway_container *replacement) {
1148 container_add_sibling(container, replacement); 1155 container_add_sibling(container, replacement, 1);
1149 container_detach(container); 1156 container_detach(container);
1150} 1157}
1151 1158
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) {
529 529
530 view->container = container_create(view); 530 view->container = container_create(view);
531 if (target_sibling) { 531 if (target_sibling) {
532 container_add_sibling(target_sibling, view->container); 532 container_add_sibling(target_sibling, view->container, 1);
533 } else { 533 } else {
534 workspace_add_tiling(ws, view->container); 534 workspace_add_tiling(ws, view->container);
535 } 535 }
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index b8e90892..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,
557} 557}
558 558
559struct sway_container *workspace_wrap_children(struct sway_workspace *ws) { 559struct sway_container *workspace_wrap_children(struct sway_workspace *ws) {
560 struct sway_container *fs = ws->fullscreen;
560 struct sway_container *middle = container_create(NULL); 561 struct sway_container *middle = container_create(NULL);
561 middle->layout = ws->layout; 562 middle->layout = ws->layout;
562 while (ws->tiling->length) { 563 while (ws->tiling->length) {
@@ -565,6 +566,7 @@ struct sway_container *workspace_wrap_children(struct sway_workspace *ws) {
565 container_add_child(middle, child); 566 container_add_child(middle, child);
566 } 567 }
567 workspace_add_tiling(ws, middle); 568 workspace_add_tiling(ws, middle);
569 ws->fullscreen = fs;
568 return middle; 570 return middle;
569} 571}
570 572
@@ -694,3 +696,16 @@ void workspace_get_box(struct sway_workspace *workspace, struct wlr_box *box) {
694 box->width = workspace->width; 696 box->width = workspace->width;
695 box->height = workspace->height; 697 box->height = workspace->height;
696} 698}
699
700static void count_tiling_views(struct sway_container *con, void *data) {
701 if (con->view && !container_is_floating_or_child(con)) {
702 size_t *count = data;
703 *count += 1;
704 }
705}
706
707size_t workspace_num_tiling_views(struct sway_workspace *ws) {
708 size_t count = 0;
709 workspace_for_each_container(ws, count_tiling_views, &count);
710 return count;
711}