aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-11 21:34:21 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-11 21:34:21 +1000
commit8bb40c24c7b045df0d43e9f22c096d1473f6f9f6 (patch)
tree0c4dbac1173f92337e2cff63d45c7d8fe7a3557f /sway
parentIntroduce tiling_drag directive (diff)
downloadsway-8bb40c24c7b045df0d43e9f22c096d1473f6f9f6.tar.gz
sway-8bb40c24c7b045df0d43e9f22c096d1473f6f9f6.tar.zst
sway-8bb40c24c7b045df0d43e9f22c096d1473f6f9f6.zip
Implement tiling drag
Hold floating_modifier and drag a tiling view to a new location.
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/move.c2
-rw-r--r--sway/desktop/render.c17
-rw-r--r--sway/input/cursor.c146
-rw-r--r--sway/input/seat.c74
-rw-r--r--sway/tree/container.c12
-rw-r--r--sway/tree/view.c2
-rw-r--r--sway/tree/workspace.c13
7 files changed, 261 insertions, 5 deletions
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/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,
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 render_rect(output->wlr_output, damage, &seat->op_drop_box, color);
905 }
906 }
907}
908
894void output_render(struct sway_output *output, struct timespec *when, 909void output_render(struct sway_output *output, struct timespec *when,
895 pixman_region32_t *damage) { 910 pixman_region32_t *damage) {
896 struct wlr_output *wlr_output = output->wlr_output; 911 struct wlr_output *wlr_output = output->wlr_output;
@@ -973,6 +988,8 @@ void output_render(struct sway_output *output, struct timespec *when,
973 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); 988 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]);
974 } 989 }
975 990
991 render_dropzones(output, damage);
992
976 struct sway_seat *seat = input_manager_current_seat(input_manager); 993 struct sway_seat *seat = input_manager_current_seat(input_manager);
977 struct sway_container *focus = seat_get_focused_container(seat); 994 struct sway_container *focus = seat_get_focused_container(seat);
978 if (focus && focus->view) { 995 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,
228 desktop_damage_whole_container(con); 228 desktop_damage_whole_container(con);
229} 229}
230 230
231static void resize_box(struct wlr_box *box, enum wlr_edges edge,
232 size_t thickness) {
233 switch (edge) {
234 case WLR_EDGE_TOP:
235 box->height = thickness;
236 break;
237 case WLR_EDGE_LEFT:
238 box->width = thickness;
239 break;
240 case WLR_EDGE_RIGHT:
241 box->x = box->x + box->width - thickness;
242 box->width = thickness;
243 break;
244 case WLR_EDGE_BOTTOM:
245 box->y = box->y + box->height - thickness;
246 box->height = thickness;
247 break;
248 case WLR_EDGE_NONE:
249 box->x += thickness;
250 box->y += thickness;
251 box->width -= thickness * 2;
252 box->height -= thickness * 2;
253 break;
254 }
255}
256
257static void handle_move_tiling_motion(struct sway_seat *seat,
258 struct sway_cursor *cursor) {
259 struct wlr_surface *surface = NULL;
260 double sx, sy;
261 struct sway_node *node = node_at_coords(seat,
262 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
263 // Damage the old location
264 desktop_damage_box(&seat->op_drop_box);
265
266 if (!node) {
267 // Eg. hovered over a layer surface such as swaybar
268 seat->op_target_node = NULL;
269 seat->op_target_edge = WLR_EDGE_NONE;
270 return;
271 }
272
273 if (node->type == N_WORKSPACE) {
274 // Emtpy workspace
275 seat->op_target_node = node;
276 seat->op_target_edge = WLR_EDGE_NONE;
277 workspace_get_box(node->sway_workspace, &seat->op_drop_box);
278 desktop_damage_box(&seat->op_drop_box);
279 return;
280 }
281
282 // Deny moving within own workspace if this is the only child
283 struct sway_container *con = node->sway_container;
284 if (workspace_num_tiling_views(seat->op_container->workspace) == 1 &&
285 con->workspace == seat->op_container->workspace) {
286 seat->op_target_node = NULL;
287 seat->op_target_edge = WLR_EDGE_NONE;
288 return;
289 }
290
291 // Traverse the ancestors, trying to find a layout container perpendicular
292 // to the edge. Eg. close to the top or bottom of a horiz layout.
293 while (con) {
294 enum wlr_edges edge = WLR_EDGE_NONE;
295 enum sway_container_layout layout = container_parent_layout(con);
296 struct wlr_box parent;
297 con->parent ? container_get_box(con->parent, &parent) :
298 workspace_get_box(con->workspace, &parent);
299 if (layout == L_HORIZ || layout == L_TABBED) {
300 if (cursor->cursor->y < parent.y + 30) {
301 edge = WLR_EDGE_TOP;
302 } else if (cursor->cursor->y > parent.y + parent.height - 30) {
303 edge = WLR_EDGE_BOTTOM;
304 }
305 } else if (layout == L_VERT || layout == L_STACKED) {
306 if (cursor->cursor->x < parent.x + 30) {
307 edge = WLR_EDGE_LEFT;
308 } else if (cursor->cursor->x > parent.x + parent.width - 30) {
309 edge = WLR_EDGE_RIGHT;
310 }
311 }
312 if (edge) {
313 seat->op_target_node = node_get_parent(&con->node);
314 seat->op_target_edge = edge;
315 node_get_box(seat->op_target_node, &seat->op_drop_box);
316 resize_box(&seat->op_drop_box, edge, 30);
317 desktop_damage_box(&seat->op_drop_box);
318 return;
319 }
320 con = con->parent;
321 }
322
323 // Use the hovered view - but we must be over the actual surface
324 con = node->sway_container;
325 if (!con->view->surface || node == &seat->op_container->node) {
326 seat->op_target_node = NULL;
327 seat->op_target_edge = WLR_EDGE_NONE;
328 return;
329 }
330
331 // Find the closest edge
332 size_t thickness = fmin(con->view->width, con->view->height) * 0.3;
333 size_t closest_dist = INT_MAX;
334 size_t dist;
335 seat->op_target_edge = WLR_EDGE_NONE;
336 if ((dist = cursor->cursor->y - con->y) < closest_dist) {
337 closest_dist = dist;
338 seat->op_target_edge = WLR_EDGE_TOP;
339 }
340 if ((dist = cursor->cursor->x - con->x) < closest_dist) {
341 closest_dist = dist;
342 seat->op_target_edge = WLR_EDGE_LEFT;
343 }
344 if ((dist = con->x + con->width - cursor->cursor->x) < closest_dist) {
345 closest_dist = dist;
346 seat->op_target_edge = WLR_EDGE_RIGHT;
347 }
348 if ((dist = con->y + con->height - cursor->cursor->y) < closest_dist) {
349 closest_dist = dist;
350 seat->op_target_edge = WLR_EDGE_BOTTOM;
351 }
352
353 if (closest_dist > thickness) {
354 seat->op_target_edge = WLR_EDGE_NONE;
355 }
356
357 seat->op_target_node = node;
358 seat->op_drop_box.x = con->view->x;
359 seat->op_drop_box.y = con->view->y;
360 seat->op_drop_box.width = con->view->width;
361 seat->op_drop_box.height = con->view->height;
362 resize_box(&seat->op_drop_box, seat->op_target_edge, thickness);
363 desktop_damage_box(&seat->op_drop_box);
364}
365
231static void calculate_floating_constraints(struct sway_container *con, 366static void calculate_floating_constraints(struct sway_container *con,
232 int *min_width, int *max_width, int *min_height, int *max_height) { 367 int *min_width, int *max_width, int *min_height, int *max_height) {
233 if (config->floating_minimum_width == -1) { // no minimum 368 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,
405 case OP_MOVE_FLOATING: 540 case OP_MOVE_FLOATING:
406 handle_move_floating_motion(seat, cursor); 541 handle_move_floating_motion(seat, cursor);
407 break; 542 break;
543 case OP_MOVE_TILING:
544 handle_move_tiling_motion(seat, cursor);
545 break;
408 case OP_RESIZE_FLOATING: 546 case OP_RESIZE_FLOATING:
409 handle_resize_floating_motion(seat, cursor); 547 handle_resize_floating_motion(seat, cursor);
410 break; 548 break;
@@ -751,6 +889,14 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
751 } 889 }
752 } 890 }
753 891
892 // Handle moving a tiling container
893 if (config->tiling_drag && mod_pressed && !is_floating_or_child &&
894 !cont->is_fullscreen) {
895 seat_pointer_notify_button(seat, time_msec, button, state);
896 seat_begin_move_tiling(seat, cont, button);
897 return;
898 }
899
754 // Handle mousedown on a container surface 900 // Handle mousedown on a container surface
755 if (surface && cont && state == WLR_BUTTON_PRESSED) { 901 if (surface && cont && state == WLR_BUTTON_PRESSED) {
756 seat_set_focus_container(seat, cont); 902 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,
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,6 +1025,68 @@ 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
1054 // Moving container before/after another
1055 } else if (target_node->type == N_CONTAINER) {
1056 struct sway_container *target = target_node->sway_container;
1057 enum sway_container_layout layout = container_parent_layout(target);
1058 if (edge && !is_parallel(layout, edge)) {
1059 enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
1060 edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
1061 container_split(target, new_layout);
1062 }
1063 container_add_sibling(target, con, after);
1064
1065 // Target is a workspace which requires splitting
1066 } else {
1067 enum sway_container_layout new_layout = edge == WLR_EDGE_TOP ||
1068 edge == WLR_EDGE_BOTTOM ? L_VERT : L_HORIZ;
1069 workspace_split(new_ws, new_layout);
1070 workspace_insert_tiling(new_ws, con, after);
1071 }
1072
1073 // This is a bit dirty, but we'll set the dimensions to that of a sibling.
1074 // I don't think there's any other way to make it consistent without
1075 // changing how we auto-size containers.
1076 list_t *siblings = container_get_siblings(con);
1077 if (siblings->length > 1) {
1078 int index = list_find(siblings, con);
1079 struct sway_container *sibling = index == 0 ? siblings->items[1] : siblings->items[index - 1];
1080 con->width = sibling->width;
1081 con->height = sibling->height;
1082 }
1083
1084 arrange_workspace(old_ws);
1085 if (new_ws != old_ws) {
1086 arrange_workspace(new_ws);
1087 }
1088}
1089
1018void seat_end_mouse_operation(struct sway_seat *seat) { 1090void seat_end_mouse_operation(struct sway_seat *seat) {
1019 enum sway_seat_operation operation = seat->operation; 1091 enum sway_seat_operation operation = seat->operation;
1020 if (seat->operation == OP_MOVE_FLOATING) { 1092 if (seat->operation == OP_MOVE_FLOATING) {
@@ -1022,6 +1094,8 @@ void seat_end_mouse_operation(struct sway_seat *seat) {
1022 // output again. 1094 // output again.
1023 struct sway_container *con = seat->op_container; 1095 struct sway_container *con = seat->op_container;
1024 container_floating_move_to(con, con->x, con->y); 1096 container_floating_move_to(con, con->x, con->y);
1097 } else if (seat->operation == OP_MOVE_TILING && seat->op_target_node) {
1098 seat_end_move_tiling(seat);
1025 } 1099 }
1026 seat->operation = OP_NONE; 1100 seat->operation = OP_NONE;
1027 seat->op_container = NULL; 1101 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) {
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
@@ -1086,13 +1092,13 @@ void container_insert_child(struct sway_container *parent,
1086} 1092}
1087 1093
1088void container_add_sibling(struct sway_container *fixed, 1094void container_add_sibling(struct sway_container *fixed,
1089 struct sway_container *active) { 1095 struct sway_container *active, int side) {
1090 if (active->workspace) { 1096 if (active->workspace) {
1091 container_detach(active); 1097 container_detach(active);
1092 } 1098 }
1093 list_t *siblings = container_get_siblings(fixed); 1099 list_t *siblings = container_get_siblings(fixed);
1094 int index = list_find(siblings, fixed); 1100 int index = list_find(siblings, fixed);
1095 list_insert(siblings, index + 1, active); 1101 list_insert(siblings, index + side, active);
1096 active->parent = fixed->parent; 1102 active->parent = fixed->parent;
1097 active->workspace = fixed->workspace; 1103 active->workspace = fixed->workspace;
1098 container_for_each_child(active, set_workspace, NULL); 1104 container_for_each_child(active, set_workspace, NULL);
@@ -1145,7 +1151,7 @@ void container_detach(struct sway_container *child) {
1145 1151
1146void container_replace(struct sway_container *container, 1152void container_replace(struct sway_container *container,
1147 struct sway_container *replacement) { 1153 struct sway_container *replacement) {
1148 container_add_sibling(container, replacement); 1154 container_add_sibling(container, replacement, 1);
1149 container_detach(container); 1155 container_detach(container);
1150} 1156}
1151 1157
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..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) {
694 box->width = workspace->width; 694 box->width = workspace->width;
695 box->height = workspace->height; 695 box->height = workspace->height;
696} 696}
697
698static void count_tiling_views(struct sway_container *con, void *data) {
699 if (con->view && !container_is_floating_or_child(con)) {
700 size_t *count = data;
701 *count += 1;
702 }
703}
704
705size_t workspace_num_tiling_views(struct sway_workspace *ws) {
706 size_t count = 0;
707 workspace_for_each_container(ws, count_tiling_views, &count);
708 return count;
709}