aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-08-14 09:07:59 -0400
committerLibravatar GitHub <noreply@github.com>2018-08-14 09:07:59 -0400
commitb4887ba154ab0d659c560a21194c8ca43b953632 (patch)
treed1d693231ab91f1ef2fe98a437cc260daf755142
parentMerge pull request #2454 from minus7/workspace-names (diff)
parentDon't commit multiple transactions at the same time (diff)
downloadsway-b4887ba154ab0d659c560a21194c8ca43b953632.tar.gz
sway-b4887ba154ab0d659c560a21194c8ca43b953632.tar.zst
sway-b4887ba154ab0d659c560a21194c8ca43b953632.zip
Merge pull request #2445 from RyanDwyer/resize-tiling-via-cursor
Implement resizing tiled containers via cursor
-rw-r--r--common/list.c9
-rw-r--r--include/list.h1
-rw-r--r--include/sway/commands.h7
-rw-r--r--include/sway/input/seat.h10
-rw-r--r--sway/commands/resize.c34
-rw-r--r--sway/desktop/transaction.c70
-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.c323
-rw-r--r--sway/input/seat.c38
11 files changed, 355 insertions, 145 deletions
diff --git a/common/list.c b/common/list.c
index 66d52f70..a3a22d8f 100644
--- a/common/list.c
+++ b/common/list.c
@@ -77,6 +77,15 @@ int list_seq_find(list_t *list, int compare(const void *item, const void *data),
77 return -1; 77 return -1;
78} 78}
79 79
80int list_find(list_t *list, void *item) {
81 for (int i = 0; i < list->length; i++) {
82 if (list->items[i] == item) {
83 return i;
84 }
85 }
86 return -1;
87}
88
80void list_swap(list_t *list, int src, int dest) { 89void list_swap(list_t *list, int src, int dest) {
81 void *tmp = list->items[src]; 90 void *tmp = list->items[src];
82 list->items[src] = list->items[dest]; 91 list->items[src] = list->items[dest];
diff --git a/include/list.h b/include/list.h
index 5a0d7d80..7c0e4bd2 100644
--- a/include/list.h
+++ b/include/list.h
@@ -20,6 +20,7 @@ void list_qsort(list_t *list, int compare(const void *left, const void *right));
20// Return index for first item in list that returns 0 for given compare 20// Return index for first item in list that returns 0 for given compare
21// function or -1 if none matches. 21// function or -1 if none matches.
22int list_seq_find(list_t *list, int compare(const void *item, const void *cmp_to), const void *cmp_to); 22int list_seq_find(list_t *list, int compare(const void *item, const void *cmp_to), const void *cmp_to);
23int list_find(list_t *list, void *item);
23// stable sort since qsort is not guaranteed to be stable 24// stable sort since qsort is not guaranteed to be stable
24void list_stable_sort(list_t *list, int compare(const void *a, const void *b)); 25void list_stable_sort(list_t *list, int compare(const void *a, const void *b));
25// swap two elements in a list 26// swap two elements in a list
diff --git a/include/sway/commands.h b/include/sway/commands.h
index f83907b2..545b21e6 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -1,6 +1,7 @@
1#ifndef _SWAY_COMMANDS_H 1#ifndef _SWAY_COMMANDS_H
2#define _SWAY_COMMANDS_H 2#define _SWAY_COMMANDS_H
3 3
4#include <wlr/util/edges.h>
4#include "config.h" 5#include "config.h"
5 6
6typedef struct cmd_results *sway_cmd(int argc, char **argv); 7typedef struct cmd_results *sway_cmd(int argc, char **argv);
@@ -84,6 +85,12 @@ char *cmd_results_to_json(struct cmd_results *results);
84struct cmd_results *add_color(const char *name, 85struct cmd_results *add_color(const char *name,
85 char *buffer, const char *color); 86 char *buffer, const char *color);
86 87
88/**
89 * TODO: Move this function and its dependent functions to container.c.
90 */
91void container_resize_tiled(struct sway_container *parent, enum wlr_edges edge,
92 int amount);
93
87sway_cmd cmd_assign; 94sway_cmd cmd_assign;
88sway_cmd cmd_bar; 95sway_cmd cmd_bar;
89sway_cmd cmd_bindcode; 96sway_cmd cmd_bindcode;
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h
index 92387601..eb4202f3 100644
--- a/include/sway/input/seat.h
+++ b/include/sway/input/seat.h
@@ -57,7 +57,8 @@ struct sway_seat {
57 enum { 57 enum {
58 OP_NONE, 58 OP_NONE,
59 OP_MOVE, 59 OP_MOVE,
60 OP_RESIZE, 60 OP_RESIZE_FLOATING,
61 OP_RESIZE_TILING,
61 } operation; 62 } operation;
62 63
63 struct sway_container *op_container; 64 struct sway_container *op_container;
@@ -159,8 +160,11 @@ void drag_icon_update_position(struct sway_drag_icon *icon);
159void seat_begin_move(struct sway_seat *seat, struct sway_container *con, 160void seat_begin_move(struct sway_seat *seat, struct sway_container *con,
160 uint32_t button); 161 uint32_t button);
161 162
162void seat_begin_resize(struct sway_seat *seat, struct sway_container *con, 163void seat_begin_resize_floating(struct sway_seat *seat,
163 uint32_t button, enum wlr_edges edge); 164 struct sway_container *con, uint32_t button, enum wlr_edges edge);
165
166void seat_begin_resize_tiling(struct sway_seat *seat,
167 struct sway_container *con, uint32_t button, enum wlr_edges edge);
164 168
165void seat_end_mouse_operation(struct sway_seat *seat); 169void seat_end_mouse_operation(struct sway_seat *seat);
166 170
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/transaction.c b/sway/desktop/transaction.c
index 4e6af86a..a449ffaa 100644
--- a/sway/desktop/transaction.c
+++ b/sway/desktop/transaction.c
@@ -33,6 +33,7 @@ struct sway_transaction {
33 list_t *instructions; // struct sway_transaction_instruction * 33 list_t *instructions; // struct sway_transaction_instruction *
34 size_t num_waiting; 34 size_t num_waiting;
35 size_t num_configures; 35 size_t num_configures;
36 uint32_t con_ids; // Bitwise XOR of view container IDs
36 struct timespec create_time; 37 struct timespec create_time;
37 struct timespec commit_time; 38 struct timespec commit_time;
38}; 39};
@@ -212,17 +213,43 @@ static void transaction_apply(struct sway_transaction *transaction) {
212 } 213 }
213} 214}
214 215
216static void transaction_commit(struct sway_transaction *transaction);
217
215static void transaction_progress_queue() { 218static void transaction_progress_queue() {
216 while (server.transactions->length) { 219 if (!server.transactions->length) {
217 struct sway_transaction *transaction = server.transactions->items[0]; 220 return;
218 if (transaction->num_waiting) { 221 }
219 return; 222 // There's only ever one committed transaction,
223 // and it's the first one in the queue.
224 struct sway_transaction *transaction = server.transactions->items[0];
225 if (transaction->num_waiting) {
226 return;
227 }
228 transaction_apply(transaction);
229 transaction_destroy(transaction);
230 list_del(server.transactions, 0);
231
232 if (!server.transactions->length) {
233 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
234 return;
235 }
236
237 // If there's a bunch of consecutive transactions which all apply to the
238 // same views, skip all except the last one.
239 while (server.transactions->length >= 2) {
240 struct sway_transaction *a = server.transactions->items[0];
241 struct sway_transaction *b = server.transactions->items[1];
242 if (a->con_ids == b->con_ids) {
243 list_del(server.transactions, 0);
244 transaction_destroy(a);
245 } else {
246 break;
220 } 247 }
221 transaction_apply(transaction);
222 transaction_destroy(transaction);
223 list_del(server.transactions, 0);
224 } 248 }
225 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1); 249
250 transaction = server.transactions->items[0];
251 transaction_commit(transaction);
252 transaction_progress_queue();
226} 253}
227 254
228static int handle_timeout(void *data) { 255static int handle_timeout(void *data) {
@@ -276,6 +303,7 @@ static void transaction_commit(struct sway_transaction *transaction) {
276 instruction->state.view_width, 303 instruction->state.view_width,
277 instruction->state.view_height); 304 instruction->state.view_height);
278 ++transaction->num_waiting; 305 ++transaction->num_waiting;
306 transaction->con_ids ^= con->id;
279 307
280 // From here on we are rendering a saved buffer of the view, which 308 // From here on we are rendering a saved buffer of the view, which
281 // means we can send a frame done event to make the client redraw it 309 // means we can send a frame done event to make the client redraw it
@@ -293,17 +321,6 @@ static void transaction_commit(struct sway_transaction *transaction) {
293 if (server.debug_txn_timings) { 321 if (server.debug_txn_timings) {
294 clock_gettime(CLOCK_MONOTONIC, &transaction->commit_time); 322 clock_gettime(CLOCK_MONOTONIC, &transaction->commit_time);
295 } 323 }
296 if (server.transactions->length || transaction->num_waiting) {
297 list_add(server.transactions, transaction);
298 } else {
299 // There are no other transactions in progress, and this one has nothing
300 // to wait for, so we can skip the queue.
301 wlr_log(WLR_DEBUG, "Transaction %p has nothing to wait for", transaction);
302 transaction_apply(transaction);
303 transaction_destroy(transaction);
304 idle_inhibit_v1_check_active(server.idle_inhibit_manager_v1);
305 return;
306 }
307 324
308 if (transaction->num_waiting) { 325 if (transaction->num_waiting) {
309 // Set up a timer which the views must respond within 326 // Set up a timer which the views must respond within
@@ -317,6 +334,9 @@ static void transaction_commit(struct sway_transaction *transaction) {
317 strerror(errno)); 334 strerror(errno));
318 handle_timeout(transaction); 335 handle_timeout(transaction);
319 } 336 }
337 } else {
338 wlr_log(WLR_DEBUG,
339 "Transaction %p has nothing to wait for", transaction);
320 } 340 }
321 341
322 // The debug tree shows the pending/live tree. Here is a good place to 342 // The debug tree shows the pending/live tree. Here is a good place to
@@ -403,5 +423,15 @@ void transaction_commit_dirty(void) {
403 container->dirty = false; 423 container->dirty = false;
404 } 424 }
405 server.dirty_containers->length = 0; 425 server.dirty_containers->length = 0;
406 transaction_commit(transaction); 426
427 list_add(server.transactions, transaction);
428
429 // There's only ever one committed transaction,
430 // and it's the first one in the queue.
431 if (server.transactions->length == 1) {
432 transaction_commit(transaction);
433 // Attempting to progress the queue here is useful
434 // if the transaction has nothing to wait for.
435 transaction_progress_queue();
436 }
407} 437}
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..3b70b471 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,7 +137,45 @@ static struct sway_container *container_at_coords(
136 return output->swayc; 137 return output->swayc;
137} 138}
138 139
139static enum wlr_edges find_resize_edge(struct sway_container *cont, 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
178static enum wlr_edges find_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) {
142 return WLR_EDGE_NONE; 181 return WLR_EDGE_NONE;
@@ -159,6 +198,20 @@ 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 return edge;
203}
204
205/**
206 * If the cursor is over a _resizable_ edge, return the edge.
207 * Edges that can't be resized are edges of the workspace.
208 */
209static enum wlr_edges find_resize_edge(struct sway_container *cont,
210 struct sway_cursor *cursor) {
211 enum wlr_edges edge = find_edge(cont, cursor);
212 if (edge && !container_is_floating(cont) && edge_is_external(cont, edge)) {
213 return WLR_EDGE_NONE;
214 }
162 return edge; 215 return edge;
163} 216}
164 217
@@ -209,7 +262,7 @@ static void calculate_floating_constraints(struct sway_container *con,
209 } 262 }
210} 263}
211 264
212static void handle_resize_motion(struct sway_seat *seat, 265static void handle_resize_floating_motion(struct sway_seat *seat,
213 struct sway_cursor *cursor) { 266 struct sway_cursor *cursor) {
214 struct sway_container *con = seat->op_container; 267 struct sway_container *con = seat->op_container;
215 enum wlr_edges edge = seat->op_resize_edge; 268 enum wlr_edges edge = seat->op_resize_edge;
@@ -301,6 +354,39 @@ static void handle_resize_motion(struct sway_seat *seat,
301 arrange_windows(con); 354 arrange_windows(con);
302} 355}
303 356
357static void handle_resize_tiling_motion(struct sway_seat *seat,
358 struct sway_cursor *cursor) {
359 int amount_x = 0;
360 int amount_y = 0;
361 int moved_x = cursor->cursor->x - seat->op_ref_lx;
362 int moved_y = cursor->cursor->y - seat->op_ref_ly;
363 enum wlr_edges edge_x = WLR_EDGE_NONE;
364 enum wlr_edges edge_y = WLR_EDGE_NONE;
365 struct sway_container *con = seat->op_container;
366
367 if (seat->op_resize_edge & WLR_EDGE_TOP) {
368 amount_y = (seat->op_ref_height - moved_y) - con->height;
369 edge_y = WLR_EDGE_TOP;
370 } else if (seat->op_resize_edge & WLR_EDGE_BOTTOM) {
371 amount_y = (seat->op_ref_height + moved_y) - con->height;
372 edge_y = WLR_EDGE_BOTTOM;
373 }
374 if (seat->op_resize_edge & WLR_EDGE_LEFT) {
375 amount_x = (seat->op_ref_width - moved_x) - con->width;
376 edge_x = WLR_EDGE_LEFT;
377 } else if (seat->op_resize_edge & WLR_EDGE_RIGHT) {
378 amount_x = (seat->op_ref_width + moved_x) - con->width;
379 edge_x = WLR_EDGE_RIGHT;
380 }
381
382 if (amount_x != 0) {
383 container_resize_tiled(seat->op_container, edge_x, amount_x);
384 }
385 if (amount_y != 0) {
386 container_resize_tiled(seat->op_container, edge_y, amount_y);
387 }
388}
389
304void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, 390void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
305 bool allow_refocusing) { 391 bool allow_refocusing) {
306 if (time_msec == 0) { 392 if (time_msec == 0) {
@@ -310,10 +396,18 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
310 struct sway_seat *seat = cursor->seat; 396 struct sway_seat *seat = cursor->seat;
311 397
312 if (seat->operation != OP_NONE) { 398 if (seat->operation != OP_NONE) {
313 if (seat->operation == OP_MOVE) { 399 switch (seat->operation) {
400 case OP_MOVE:
314 handle_move_motion(seat, cursor); 401 handle_move_motion(seat, cursor);
315 } else { 402 break;
316 handle_resize_motion(seat, cursor); 403 case OP_RESIZE_FLOATING:
404 handle_resize_floating_motion(seat, cursor);
405 break;
406 case OP_RESIZE_TILING:
407 handle_resize_tiling_motion(seat, cursor);
408 break;
409 case OP_NONE:
410 break;
317 } 411 }
318 cursor->previous.x = cursor->cursor->x; 412 cursor->previous.x = cursor->cursor->x;
319 cursor->previous.y = cursor->cursor->y; 413 cursor->previous.y = cursor->cursor->y;
@@ -375,12 +469,20 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec,
375 if (client != cursor->image_client) { 469 if (client != cursor->image_client) {
376 cursor_set_image(cursor, "left_ptr", client); 470 cursor_set_image(cursor, "left_ptr", client);
377 } 471 }
378 } else if (c && container_is_floating(c)) { 472 } else if (c) {
379 // Try a floating container's resize edge 473 // Try a container's resize edge
380 enum wlr_edges edge = find_resize_edge(c, cursor); 474 enum wlr_edges edge = find_resize_edge(c, cursor);
381 const char *image = edge == WLR_EDGE_NONE ? 475 if (edge == WLR_EDGE_NONE) {
382 "left_ptr" : wlr_xcursor_get_resize_name(edge); 476 cursor_set_image(cursor, "left_ptr", NULL);
383 cursor_set_image(cursor, image, NULL); 477 } else if (container_is_floating(c)) {
478 cursor_set_image(cursor, wlr_xcursor_get_resize_name(edge), NULL);
479 } else {
480 if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) {
481 cursor_set_image(cursor, "col-resize", NULL);
482 } else {
483 cursor_set_image(cursor, "row-resize", NULL);
484 }
485 }
384 } else { 486 } else {
385 cursor_set_image(cursor, "left_ptr", NULL); 487 cursor_set_image(cursor, "left_ptr", NULL);
386 } 488 }
@@ -423,57 +525,6 @@ static void handle_cursor_motion_absolute(
423 transaction_commit_dirty(); 525 transaction_commit_dirty();
424} 526}
425 527
426static void dispatch_cursor_button_floating(struct sway_cursor *cursor,
427 uint32_t time_msec, uint32_t button, enum wlr_button_state state,
428 struct wlr_surface *surface, double sx, double sy,
429 struct sway_container *cont) {
430 struct sway_seat *seat = cursor->seat;
431
432 seat_set_focus(seat, cont);
433
434 // Deny moving or resizing a fullscreen container
435 if (container_is_fullscreen_or_child(cont)) {
436 seat_pointer_notify_button(seat, time_msec, button, state);
437 return;
438 }
439 struct sway_container *floater = cont;
440 while (floater->parent->layout != L_FLOATING) {
441 floater = floater->parent;
442 }
443
444 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
445 bool mod_pressed = keyboard &&
446 (wlr_keyboard_get_modifiers(keyboard) & config->floating_mod);
447 enum wlr_edges edge = find_resize_edge(floater, cursor);
448 bool over_title = edge == WLR_EDGE_NONE && !surface;
449
450 // Check for beginning move
451 uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
452 if (button == btn_move && state == WLR_BUTTON_PRESSED &&
453 (mod_pressed || over_title)) {
454 seat_begin_move(seat, floater, button);
455 return;
456 }
457
458 // Check for beginning resize
459 bool resizing_via_border = button == BTN_LEFT && edge != WLR_EDGE_NONE;
460 uint32_t btn_resize = config->floating_mod_inverse ? BTN_LEFT : BTN_RIGHT;
461 bool resizing_via_mod = button == btn_resize && mod_pressed;
462 if ((resizing_via_border || resizing_via_mod) &&
463 state == WLR_BUTTON_PRESSED) {
464 if (edge == WLR_EDGE_NONE) {
465 edge |= cursor->cursor->x > floater->x + floater->width / 2 ?
466 WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
467 edge |= cursor->cursor->y > floater->y + floater->height / 2 ?
468 WLR_EDGE_BOTTOM : WLR_EDGE_TOP;
469 }
470 seat_begin_resize(seat, floater, button, edge);
471 return;
472 }
473
474 seat_pointer_notify_button(seat, time_msec, button, state);
475}
476
477/** 528/**
478 * Remove a button (and duplicates) to the sorted list of currently pressed buttons 529 * Remove a button (and duplicates) to the sorted list of currently pressed buttons
479 */ 530 */
@@ -553,26 +604,36 @@ static struct sway_binding* get_active_mouse_binding(const struct sway_cursor *c
553 604
554void dispatch_cursor_button(struct sway_cursor *cursor, 605void dispatch_cursor_button(struct sway_cursor *cursor,
555 uint32_t time_msec, uint32_t button, enum wlr_button_state state) { 606 uint32_t time_msec, uint32_t button, enum wlr_button_state state) {
607 if (time_msec == 0) {
608 time_msec = get_current_time_msec();
609 }
610 struct sway_seat *seat = cursor->seat;
611
612 // Handle ending seat operation
556 if (cursor->seat->operation != OP_NONE && 613 if (cursor->seat->operation != OP_NONE &&
557 button == cursor->seat->op_button && state == WLR_BUTTON_RELEASED) { 614 button == cursor->seat->op_button && state == WLR_BUTTON_RELEASED) {
558 seat_end_mouse_operation(cursor->seat); 615 seat_end_mouse_operation(seat);
559 seat_pointer_notify_button(cursor->seat, time_msec, button, state); 616 seat_pointer_notify_button(seat, time_msec, button, state);
560 return; 617 return;
561 } 618 }
562 if (time_msec == 0) {
563 time_msec = get_current_time_msec();
564 }
565 619
620 // Determine what's under the cursor
566 struct wlr_surface *surface = NULL; 621 struct wlr_surface *surface = NULL;
567 double sx, sy; 622 double sx, sy;
568 struct sway_container *cont = container_at_coords(cursor->seat, 623 struct sway_container *cont = container_at_coords(seat,
569 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); 624 cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
625 bool is_floating = cont && container_is_floating(cont);
626 bool is_floating_or_child = cont && container_is_floating_or_child(cont);
627 bool is_fullscreen_or_child = cont && container_is_fullscreen_or_child(cont);
628 enum wlr_edges edge = cont ? find_edge(cont, cursor) : WLR_EDGE_NONE;
629 enum wlr_edges resize_edge = edge ?
630 find_resize_edge(cont, cursor) : WLR_EDGE_NONE;
631 bool on_border = edge != WLR_EDGE_NONE;
632 bool on_contents = cont && !on_border && surface;
633 bool on_titlebar = cont && !on_border && !surface;
570 634
571 // Handle mouse bindings 635 // Handle mouse bindings
572 bool on_border = cont && (find_resize_edge(cont, cursor) != WLR_EDGE_NONE); 636 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
573 bool on_contents = !on_border && surface;
574 bool on_titlebar = !on_border && !surface;
575 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(cursor->seat->wlr_seat);
576 uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; 637 uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0;
577 638
578 struct sway_binding *binding = NULL; 639 struct sway_binding *binding = NULL;
@@ -588,45 +649,108 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
588 state_erase_button(cursor, button); 649 state_erase_button(cursor, button);
589 } 650 }
590 if (binding) { 651 if (binding) {
591 seat_execute_command(cursor->seat, binding); 652 seat_execute_command(seat, binding);
592 // TODO: do we want to pass on the event? 653 return;
593 } 654 }
594 655
656 // Handle clicking a layer surface
595 if (surface && wlr_surface_is_layer_surface(surface)) { 657 if (surface && wlr_surface_is_layer_surface(surface)) {
596 struct wlr_layer_surface *layer = 658 struct wlr_layer_surface *layer =
597 wlr_layer_surface_from_wlr_surface(surface); 659 wlr_layer_surface_from_wlr_surface(surface);
598 if (layer->current.keyboard_interactive) { 660 if (layer->current.keyboard_interactive) {
599 seat_set_focus_layer(cursor->seat, layer); 661 seat_set_focus_layer(seat, layer);
662 }
663 seat_pointer_notify_button(seat, time_msec, button, state);
664 return;
665 }
666
667 // Handle tiling resize via border
668 if (resize_edge && button == BTN_LEFT && state == WLR_BUTTON_PRESSED &&
669 !is_floating) {
670 seat_set_focus(seat, cont);
671 seat_begin_resize_tiling(seat, cont, button, edge);
672 return;
673 }
674
675 // Handle tiling resize via mod
676 bool mod_pressed = keyboard &&
677 (wlr_keyboard_get_modifiers(keyboard) & config->floating_mod);
678 if (!is_floating_or_child && mod_pressed && state == WLR_BUTTON_PRESSED) {
679 uint32_t btn_resize = config->floating_mod_inverse ?
680 BTN_LEFT : BTN_RIGHT;
681 if (button == btn_resize) {
682 edge = 0;
683 edge |= cursor->cursor->x > cont->x + cont->width / 2 ?
684 WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
685 edge |= cursor->cursor->y > cont->y + cont->height / 2 ?
686 WLR_EDGE_BOTTOM : WLR_EDGE_TOP;
687
688 const char *image = NULL;
689 if (edge == (WLR_EDGE_LEFT | WLR_EDGE_TOP)) {
690 image = "nw-resize";
691 } else if (edge == (WLR_EDGE_TOP | WLR_EDGE_RIGHT)) {
692 image = "ne-resize";
693 } else if (edge == (WLR_EDGE_RIGHT | WLR_EDGE_BOTTOM)) {
694 image = "se-resize";
695 } else if (edge == (WLR_EDGE_BOTTOM | WLR_EDGE_LEFT)) {
696 image = "sw-resize";
697 }
698 cursor_set_image(seat->cursor, image, NULL);
699 seat_set_focus(seat, cont);
700 seat_begin_resize_tiling(seat, cont, button, edge);
701 return;
600 } 702 }
601 seat_pointer_notify_button(cursor->seat, time_msec, button, state); 703 }
602 } else if (cont && container_is_floating_or_child(cont)) { 704
603 dispatch_cursor_button_floating(cursor, time_msec, button, state, 705 // Handle beginning floating move
604 surface, sx, sy, cont); 706 if (is_floating_or_child && !is_fullscreen_or_child &&
605 } else if (surface && cont && cont->type != C_VIEW) { 707 state == WLR_BUTTON_PRESSED) {
606 // Avoid moving keyboard focus from a surface that accepts it to one 708 uint32_t btn_move = config->floating_mod_inverse ? BTN_RIGHT : BTN_LEFT;
607 // that does not unless the change would move us to a new workspace. 709 if (button == btn_move && state == WLR_BUTTON_PRESSED &&
608 // 710 (mod_pressed || on_titlebar)) {
609 // This prevents, for example, losing focus when clicking on swaybar. 711 while (cont->parent->layout != L_FLOATING) {
610 struct sway_container *new_ws = cont; 712 cont = cont->parent;
611 if (new_ws && new_ws->type != C_WORKSPACE) { 713 }
612 new_ws = container_parent(new_ws, C_WORKSPACE); 714 seat_begin_move(seat, cont, button);
715 return;
613 } 716 }
614 struct sway_container *old_ws = seat_get_focus(cursor->seat); 717 }
615 if (old_ws && old_ws->type != C_WORKSPACE) { 718
616 old_ws = container_parent(old_ws, C_WORKSPACE); 719 // Handle beginning floating resize
720 if (is_floating_or_child && !is_fullscreen_or_child &&
721 state == WLR_BUTTON_PRESSED) {
722 // Via border
723 if (button == BTN_LEFT && resize_edge != WLR_EDGE_NONE) {
724 seat_begin_resize_floating(seat, cont, button, resize_edge);
725 return;
617 } 726 }
618 if (new_ws != old_ws) { 727
619 seat_set_focus(cursor->seat, cont); 728 // Via mod+click
729 struct sway_container *floater = cont;
730 while (floater->parent->layout != L_FLOATING) {
731 floater = floater->parent;
732 }
733 uint32_t btn_resize = config->floating_mod_inverse ?
734 BTN_LEFT : BTN_RIGHT;
735 if (button == btn_resize) {
736 edge = 0;
737 edge |= cursor->cursor->x > floater->x + floater->width / 2 ?
738 WLR_EDGE_RIGHT : WLR_EDGE_LEFT;
739 edge |= cursor->cursor->y > floater->y + floater->height / 2 ?
740 WLR_EDGE_BOTTOM : WLR_EDGE_TOP;
741 seat_begin_resize_floating(seat, floater, button, edge);
742 return;
620 } 743 }
621 seat_pointer_notify_button(cursor->seat, time_msec, button, state);
622 } else if (cont) {
623 seat_set_focus(cursor->seat, cont);
624 seat_pointer_notify_button(cursor->seat, time_msec, button, state);
625 } else {
626 seat_pointer_notify_button(cursor->seat, time_msec, button, state);
627 } 744 }
628 745
629 transaction_commit_dirty(); 746 // Handle clicking a container surface
747 if (cont) {
748 seat_set_focus(seat, cont);
749 seat_pointer_notify_button(seat, time_msec, button, state);
750 return;
751 }
752
753 seat_pointer_notify_button(seat, time_msec, button, state);
630} 754}
631 755
632static void handle_cursor_button(struct wl_listener *listener, void *data) { 756static void handle_cursor_button(struct wl_listener *listener, void *data) {
@@ -635,6 +759,7 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
635 struct wlr_event_pointer_button *event = data; 759 struct wlr_event_pointer_button *event = data;
636 dispatch_cursor_button(cursor, 760 dispatch_cursor_button(cursor,
637 event->time_msec, event->button, event->state); 761 event->time_msec, event->button, event->state);
762 transaction_commit_dirty();
638} 763}
639 764
640static void handle_cursor_axis(struct wl_listener *listener, void *data) { 765static void handle_cursor_axis(struct wl_listener *listener, void *data) {
@@ -782,6 +907,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) {
782 dispatch_cursor_button(cursor, event->time_msec, 907 dispatch_cursor_button(cursor, event->time_msec,
783 BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ? 908 BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ?
784 WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED); 909 WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED);
910 transaction_commit_dirty();
785} 911}
786 912
787static void handle_tool_button(struct wl_listener *listener, void *data) { 913static void handle_tool_button(struct wl_listener *listener, void *data) {
@@ -806,6 +932,7 @@ static void handle_tool_button(struct wl_listener *listener, void *data) {
806 cursor->tool_buttons--; 932 cursor->tool_buttons--;
807 break; 933 break;
808 } 934 }
935 transaction_commit_dirty();
809} 936}
810 937
811static void handle_request_set_cursor(struct wl_listener *listener, 938static void handle_request_set_cursor(struct wl_listener *listener,
diff --git a/sway/input/seat.c b/sway/input/seat.c
index eb6d2dac..57cc65f6 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,26 @@ 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
971void seat_end_mouse_operation(struct sway_seat *seat) { 985void seat_end_mouse_operation(struct sway_seat *seat) {
972 switch (seat->operation) { 986 if (seat->operation == OP_MOVE) {
973 case OP_MOVE: 987 // We "move" the container to its own location so it discovers its
974 { 988 // output again.
975 // We "move" the container to its own location so it discovers its 989 struct sway_container *con = seat->op_container;
976 // output again. 990 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 } 991 }
986 seat->operation = OP_NONE; 992 seat->operation = OP_NONE;
987 seat->op_container = NULL; 993 seat->op_container = NULL;