diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-10 14:10:09 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-08-12 10:45:54 +1000 |
commit | b4a0363d1721b2ad2d5afb65764ecb575bd55fa4 (patch) | |
tree | f6ec316550cd113040e82a7f0cee0429fff349e5 /sway/input/cursor.c | |
parent | Merge pull request #2452 from janza/position-command-fix-args (diff) | |
download | sway-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/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 97 |
1 files changed, 90 insertions, 7 deletions
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 | */ | ||
144 | static 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 | |||
139 | static enum wlr_edges find_resize_edge(struct sway_container *cont, | 178 | static 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 | ||
212 | static void handle_resize_motion(struct sway_seat *seat, | 256 | static 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 | ||
348 | static 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 | |||
304 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | 373 | void 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); |