aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-10 14:10:09 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-12 10:45:54 +1000
commitb4a0363d1721b2ad2d5afb65764ecb575bd55fa4 (patch)
treef6ec316550cd113040e82a7f0cee0429fff349e5 /sway
parentMerge pull request #2452 from janza/position-command-fix-args (diff)
downloadsway-b4a0363d1721b2ad2d5afb65764ecb575bd55fa4.tar.gz
sway-b4a0363d1721b2ad2d5afb65764ecb575bd55fa4.tar.zst
sway-b4a0363d1721b2ad2d5afb65764ecb575bd55fa4.zip
Implement resizing tiled containers via cursor
* The OP_RESIZE seat operation has been renamed to OP_RESIZE_FLOATING, and OP_RESIZE_TILING has been introduced. * Similar to the above, seat_begin_resize and handle_resize_motion have been renamed and tiling variants introduced. * resize.c's resize_tiled has to be used, so container_resize_tiled has been introduced in resize.c to allow external code to call it.
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/resize.c34
-rw-r--r--sway/desktop/xdg_shell.c3
-rw-r--r--sway/desktop/xdg_shell_v6.c3
-rw-r--r--sway/desktop/xwayland.c2
-rw-r--r--sway/input/cursor.c97
-rw-r--r--sway/input/seat.c41
6 files changed, 149 insertions, 31 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index c3560985..0f3005f4 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -158,8 +158,8 @@ static int parallel_size(struct sway_container *c, enum resize_axis a) {
158 return normalize_axis(a) == RESIZE_AXIS_HORIZONTAL ? c->width : c->height; 158 return normalize_axis(a) == RESIZE_AXIS_HORIZONTAL ? c->width : c->height;
159} 159}
160 160
161static void resize_tiled(int amount, enum resize_axis axis) { 161static void resize_tiled(struct sway_container *parent, int amount,
162 struct sway_container *parent = config->handler_context.current_container; 162 enum resize_axis axis) {
163 struct sway_container *focused = parent; 163 struct sway_container *focused = parent;
164 if (!parent) { 164 if (!parent) {
165 return; 165 return;
@@ -297,6 +297,28 @@ static void resize_tiled(int amount, enum resize_axis axis) {
297 arrange_windows(parent->parent); 297 arrange_windows(parent->parent);
298} 298}
299 299
300void container_resize_tiled(struct sway_container *parent,
301 enum wlr_edges edge, int amount) {
302 enum resize_axis axis = RESIZE_AXIS_INVALID;
303 switch (edge) {
304 case WLR_EDGE_TOP:
305 axis = RESIZE_AXIS_UP;
306 break;
307 case WLR_EDGE_RIGHT:
308 axis = RESIZE_AXIS_RIGHT;
309 break;
310 case WLR_EDGE_BOTTOM:
311 axis = RESIZE_AXIS_DOWN;
312 break;
313 case WLR_EDGE_LEFT:
314 axis = RESIZE_AXIS_LEFT;
315 break;
316 case WLR_EDGE_NONE:
317 break;
318 }
319 resize_tiled(parent, amount, axis);
320}
321
300/** 322/**
301 * Implement `resize <grow|shrink>` for a floating container. 323 * Implement `resize <grow|shrink>` for a floating container.
302 */ 324 */
@@ -398,7 +420,7 @@ static struct cmd_results *resize_adjust_tiled(enum resize_axis axis,
398 } 420 }
399 } 421 }
400 422
401 resize_tiled(amount->amount, axis); 423 resize_tiled(current, amount->amount, axis);
402 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 424 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
403} 425}
404 426
@@ -421,7 +443,8 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con,
421 } 443 }
422 } 444 }
423 if (width->unit == RESIZE_UNIT_PX) { 445 if (width->unit == RESIZE_UNIT_PX) {
424 resize_tiled(width->amount - con->width, RESIZE_AXIS_HORIZONTAL); 446 resize_tiled(con, width->amount - con->width,
447 RESIZE_AXIS_HORIZONTAL);
425 } 448 }
426 } 449 }
427 450
@@ -439,7 +462,8 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con,
439 } 462 }
440 } 463 }
441 if (height->unit == RESIZE_UNIT_PX) { 464 if (height->unit == RESIZE_UNIT_PX) {
442 resize_tiled(height->amount - con->height, RESIZE_AXIS_VERTICAL); 465 resize_tiled(con, height->amount - con->height,
466 RESIZE_AXIS_HORIZONTAL);
443 } 467 }
444 } 468 }
445 469
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 3b73f99c..af9d49b8 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -331,7 +331,8 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
331 struct wlr_xdg_toplevel_resize_event *e = data; 331 struct wlr_xdg_toplevel_resize_event *e = data;
332 struct sway_seat *seat = e->seat->seat->data; 332 struct sway_seat *seat = e->seat->seat->data;
333 if (e->serial == seat->last_button_serial) { 333 if (e->serial == seat->last_button_serial) {
334 seat_begin_resize(seat, view->swayc, seat->last_button, e->edges); 334 seat_begin_resize_floating(seat, view->swayc,
335 seat->last_button, e->edges);
335 } 336 }
336} 337}
337 338
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index a947fb35..c6ac0f4e 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -327,7 +327,8 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
327 struct wlr_xdg_toplevel_v6_resize_event *e = data; 327 struct wlr_xdg_toplevel_v6_resize_event *e = data;
328 struct sway_seat *seat = e->seat->seat->data; 328 struct sway_seat *seat = e->seat->seat->data;
329 if (e->serial == seat->last_button_serial) { 329 if (e->serial == seat->last_button_serial) {
330 seat_begin_resize(seat, view->swayc, seat->last_button, e->edges); 330 seat_begin_resize_floating(seat, view->swayc,
331 seat->last_button, e->edges);
331 } 332 }
332} 333}
333 334
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 393185bd..5e8afa65 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -432,7 +432,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
432 } 432 }
433 struct wlr_xwayland_resize_event *e = data; 433 struct wlr_xwayland_resize_event *e = data;
434 struct sway_seat *seat = input_manager_current_seat(input_manager); 434 struct sway_seat *seat = input_manager_current_seat(input_manager);
435 seat_begin_resize(seat, view->swayc, seat->last_button, e->edges); 435 seat_begin_resize_floating(seat, view->swayc, seat->last_button, e->edges);
436} 436}
437 437
438static void handle_set_title(struct wl_listener *listener, void *data) { 438static void handle_set_title(struct wl_listener *listener, void *data) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 3f417e96..4b689535 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -12,6 +12,7 @@
12#include "list.h" 12#include "list.h"
13#include "log.h" 13#include "log.h"
14#include "config.h" 14#include "config.h"
15#include "sway/commands.h"
15#include "sway/desktop.h" 16#include "sway/desktop.h"
16#include "sway/desktop/transaction.h" 17#include "sway/desktop/transaction.h"
17#include "sway/input/cursor.h" 18#include "sway/input/cursor.h"
@@ -136,6 +137,44 @@ static struct sway_container *container_at_coords(
136 return output->swayc; 137 return output->swayc;
137} 138}
138 139
140/**
141 * Determine if the edge of the given container is on the edge of the
142 * workspace/output.
143 */
144static bool edge_is_external(struct sway_container *cont, enum wlr_edges edge) {
145 enum sway_container_layout layout = L_NONE;
146 switch (edge) {
147 case WLR_EDGE_TOP:
148 case WLR_EDGE_BOTTOM:
149 layout = L_VERT;
150 break;
151 case WLR_EDGE_LEFT:
152 case WLR_EDGE_RIGHT:
153 layout = L_HORIZ;
154 break;
155 case WLR_EDGE_NONE:
156 sway_assert(false, "Never reached");
157 return false;
158 }
159
160 // Iterate the parents until we find one with the layout we want,
161 // then check if the child has siblings between it and the edge.
162 while (cont->type != C_OUTPUT) {
163 if (cont->parent->layout == layout) {
164 int index = list_find(cont->parent->children, cont);
165 if (index > 0 && (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_TOP)) {
166 return false;
167 }
168 if (index < cont->parent->children->length - 1 &&
169 (edge == WLR_EDGE_RIGHT || edge == WLR_EDGE_BOTTOM)) {
170 return false;
171 }
172 }
173 cont = cont->parent;
174 }
175 return true;
176}
177
139static enum wlr_edges find_resize_edge(struct sway_container *cont, 178static enum wlr_edges find_resize_edge(struct sway_container *cont,
140 struct sway_cursor *cursor) { 179 struct sway_cursor *cursor) {
141 if (cont->type != C_VIEW) { 180 if (cont->type != C_VIEW) {
@@ -159,6 +198,11 @@ static enum wlr_edges find_resize_edge(struct sway_container *cont,
159 if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) { 198 if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) {
160 edge |= WLR_EDGE_BOTTOM; 199 edge |= WLR_EDGE_BOTTOM;
161 } 200 }
201
202 if (edge && !container_is_floating(cont) && edge_is_external(cont, edge)) {
203 return WLR_EDGE_NONE;
204 }
205
162 return edge; 206 return edge;
163} 207}
164 208
@@ -209,7 +253,7 @@ static void calculate_floating_constraints(struct sway_container *con,
209 } 253 }
210} 254}
211 255
212static void handle_resize_motion(struct sway_seat *seat, 256static void handle_resize_floating_motion(struct sway_seat *seat,
213 struct sway_cursor *cursor) { 257 struct sway_cursor *cursor) {
214 struct sway_container *con = seat->op_container; 258 struct sway_container *con = seat->op_container;
215 enum wlr_edges edge = seat->op_resize_edge; 259 enum wlr_edges edge = seat->op_resize_edge;
@@ -301,6 +345,31 @@ static void handle_resize_motion(struct sway_seat *seat,
301 arrange_windows(con); 345 arrange_windows(con);
302} 346}
303 347
348static void handle_resize_tiling_motion(struct sway_seat *seat,
349 struct sway_cursor *cursor) {
350 int amount = 0;
351 int moved_x = cursor->cursor->x - seat->op_ref_lx;
352 int moved_y = cursor->cursor->y - seat->op_ref_ly;
353 struct sway_container *con = seat->op_container;
354 switch (seat->op_resize_edge) {
355 case WLR_EDGE_TOP:
356 amount = (seat->op_ref_height - moved_y) - con->height;
357 break;
358 case WLR_EDGE_BOTTOM:
359 amount = (seat->op_ref_height + moved_y) - con->height;
360 break;
361 case WLR_EDGE_LEFT:
362 amount = (seat->op_ref_width - moved_x) - con->width;
363 break;
364 case WLR_EDGE_RIGHT:
365 amount = (seat->op_ref_width + moved_x) - con->width;
366 break;
367 case WLR_EDGE_NONE:
368 break;
369 }
370 container_resize_tiled(seat->op_container, seat->op_resize_edge, amount);
371}
372
304void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, 373void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
305 bool allow_refocusing) { 374 bool allow_refocusing) {
306 if (time_msec == 0) { 375 if (time_msec == 0) {
@@ -310,10 +379,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
310 struct sway_seat *seat = cursor->seat; 379 struct sway_seat *seat = cursor->seat;
311 380
312 if (seat->operation != OP_NONE) { 381 if (seat->operation != OP_NONE) {
313 if (seat->operation == OP_MOVE) { 382 switch (seat->operation) {
383 case OP_MOVE:
314 handle_move_motion(seat, cursor); 384 handle_move_motion(seat, cursor);
315 } else { 385 break;
316 handle_resize_motion(seat, cursor); 386 case OP_RESIZE_FLOATING:
387 handle_resize_floating_motion(seat, cursor);
388 break;
389 case OP_RESIZE_TILING:
390 handle_resize_tiling_motion(seat, cursor);
391 break;
392 case OP_NONE:
393 break;
317 } 394 }
318 cursor->previous.x = cursor->cursor->x; 395 cursor->previous.x = cursor->cursor->x;
319 cursor->previous.y = cursor->cursor->y; 396 cursor->previous.y = cursor->cursor->y;
@@ -375,8 +452,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
375 if (client != cursor->image_client) { 452 if (client != cursor->image_client) {
376 cursor_set_image(cursor, "left_ptr", client); 453 cursor_set_image(cursor, "left_ptr", client);
377 } 454 }
378 } else if (c && container_is_floating(c)) { 455 } else if (c) {
379 // Try a floating container's resize edge 456 // Try a container's resize edge
380 enum wlr_edges edge = find_resize_edge(c, cursor); 457 enum wlr_edges edge = find_resize_edge(c, cursor);
381 const char *image = edge == WLR_EDGE_NONE ? 458 const char *image = edge == WLR_EDGE_NONE ?
382 "left_ptr" : wlr_xcursor_get_resize_name(edge); 459 "left_ptr" : wlr_xcursor_get_resize_name(edge);
@@ -467,7 +544,7 @@ static void dispatch_cursor_button_floating(struct sway_cursor *cursor,
467 edge |= cursor->cursor->y > floater->y + floater->height / 2 ? 544 edge |= cursor->cursor->y > floater->y + floater->height / 2 ?
468 WLR_EDGE_BOTTOM : WLR_EDGE_TOP; 545 WLR_EDGE_BOTTOM : WLR_EDGE_TOP;
469 } 546 }
470 seat_begin_resize(seat, floater, button, edge); 547 seat_begin_resize_floating(seat, floater, button, edge);
471 return; 548 return;
472 } 549 }
473 550
@@ -592,6 +669,8 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
592 // TODO: do we want to pass on the event? 669 // TODO: do we want to pass on the event?
593 } 670 }
594 671
672 enum wlr_edges edge = cont ? find_resize_edge(cont, cursor) : WLR_EDGE_NONE;
673
595 if (surface && wlr_surface_is_layer_surface(surface)) { 674 if (surface && wlr_surface_is_layer_surface(surface)) {
596 struct wlr_layer_surface *layer = 675 struct wlr_layer_surface *layer =
597 wlr_layer_surface_from_wlr_surface(surface); 676 wlr_layer_surface_from_wlr_surface(surface);
@@ -599,6 +678,10 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
599 seat_set_focus_layer(cursor->seat, layer); 678 seat_set_focus_layer(cursor->seat, layer);
600 } 679 }
601 seat_pointer_notify_button(cursor->seat, time_msec, button, state); 680 seat_pointer_notify_button(cursor->seat, time_msec, button, state);
681 } else if (edge && button == BTN_LEFT &&
682 !container_is_floating(cont)) {
683 seat_set_focus(cursor->seat, cont);
684 seat_begin_resize_tiling(cursor->seat, cont, BTN_LEFT, edge);
602 } else if (cont && container_is_floating_or_child(cont)) { 685 } else if (cont && container_is_floating_or_child(cont)) {
603 dispatch_cursor_button_floating(cursor, time_msec, button, state, 686 dispatch_cursor_button_floating(cursor, time_msec, button, state,
604 surface, sx, sy, cont); 687 surface, sx, sy, cont);
diff --git a/sway/input/seat.c b/sway/input/seat.c
index eb6d2dac..6d9e85dc 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -942,14 +942,14 @@ void seat_begin_move(struct sway_seat *seat, struct sway_container *con,
942 cursor_set_image(seat->cursor, "grab", NULL); 942 cursor_set_image(seat->cursor, "grab", NULL);
943} 943}
944 944
945void seat_begin_resize(struct sway_seat *seat, struct sway_container *con, 945void seat_begin_resize_floating(struct sway_seat *seat,
946 uint32_t button, enum wlr_edges edge) { 946 struct sway_container *con, uint32_t button, enum wlr_edges edge) {
947 if (!seat->cursor) { 947 if (!seat->cursor) {
948 wlr_log(WLR_DEBUG, "Ignoring resize request due to no cursor device"); 948 wlr_log(WLR_DEBUG, "Ignoring resize request due to no cursor device");
949 return; 949 return;
950 } 950 }
951 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); 951 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
952 seat->operation = OP_RESIZE; 952 seat->operation = OP_RESIZE_FLOATING;
953 seat->op_container = con; 953 seat->op_container = con;
954 seat->op_resize_preserve_ratio = keyboard && 954 seat->op_resize_preserve_ratio = keyboard &&
955 (wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT); 955 (wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT);
@@ -968,20 +968,29 @@ void seat_begin_resize(struct sway_seat *seat, struct sway_container *con,
968 cursor_set_image(seat->cursor, image, NULL); 968 cursor_set_image(seat->cursor, image, NULL);
969} 969}
970 970
971void seat_begin_resize_tiling(struct sway_seat *seat,
972 struct sway_container *con, uint32_t button, enum wlr_edges edge) {
973 seat->operation = OP_RESIZE_TILING;
974 seat->op_container = con;
975 seat->op_resize_edge = edge;
976 seat->op_button = button;
977 seat->op_ref_lx = seat->cursor->cursor->x;
978 seat->op_ref_ly = seat->cursor->cursor->y;
979 seat->op_ref_con_lx = con->x;
980 seat->op_ref_con_ly = con->y;
981 seat->op_ref_width = con->width;
982 seat->op_ref_height = con->height;
983
984 const char *image = wlr_xcursor_get_resize_name(edge);
985 cursor_set_image(seat->cursor, image, NULL);
986}
987
971void seat_end_mouse_operation(struct sway_seat *seat) { 988void seat_end_mouse_operation(struct sway_seat *seat) {
972 switch (seat->operation) { 989 if (seat->operation == OP_MOVE) {
973 case OP_MOVE: 990 // We "move" the container to its own location so it discovers its
974 { 991 // output again.
975 // We "move" the container to its own location so it discovers its 992 struct sway_container *con = seat->op_container;
976 // output again. 993 container_floating_move_to(con, con->x, con->y);
977 struct sway_container *con = seat->op_container;
978 container_floating_move_to(con, con->x, con->y);
979 }
980 case OP_RESIZE:
981 // Don't need to do anything here.
982 break;
983 case OP_NONE:
984 break;
985 } 994 }
986 seat->operation = OP_NONE; 995 seat->operation = OP_NONE;
987 seat->op_container = NULL; 996 seat->op_container = NULL;