diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-20 09:28:22 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-22 23:10:19 +1000 |
commit | ff445cc85597ee6bfae01f03d3c246e2326f3981 (patch) | |
tree | 53c720bc54733d1660bffddf87291c887667d093 /sway/input/cursor.c | |
parent | Use wlr_keyboard_get_modifiers (diff) | |
download | sway-ff445cc85597ee6bfae01f03d3c246e2326f3981.tar.gz sway-ff445cc85597ee6bfae01f03d3c246e2326f3981.tar.zst sway-ff445cc85597ee6bfae01f03d3c246e2326f3981.zip |
Implement xdg shell request_move and request_resize events
Also does a few other related things:
* Now uses enum wlr_edges instead of our own enum resize_edge
* Now uses wlr_xcursor_get_resize_name and removes our own
find_resize_edge_name
* Renames drag to move for consistency
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r-- | sway/input/cursor.c | 100 |
1 files changed, 31 insertions, 69 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 8723e2b4..8b9208c6 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -143,33 +143,33 @@ static struct sway_container *container_at_coords( | |||
143 | return output->swayc; | 143 | return output->swayc; |
144 | } | 144 | } |
145 | 145 | ||
146 | static enum resize_edge find_resize_edge(struct sway_container *cont, | 146 | static enum wlr_edges find_resize_edge(struct sway_container *cont, |
147 | struct sway_cursor *cursor) { | 147 | struct sway_cursor *cursor) { |
148 | if (cont->type != C_VIEW) { | 148 | if (cont->type != C_VIEW) { |
149 | return RESIZE_EDGE_NONE; | 149 | return WLR_EDGE_NONE; |
150 | } | 150 | } |
151 | struct sway_view *view = cont->sway_view; | 151 | struct sway_view *view = cont->sway_view; |
152 | if (view->border == B_NONE || !view->border_thickness || view->using_csd) { | 152 | if (view->border == B_NONE || !view->border_thickness || view->using_csd) { |
153 | return RESIZE_EDGE_NONE; | 153 | return WLR_EDGE_NONE; |
154 | } | 154 | } |
155 | 155 | ||
156 | enum resize_edge edge = 0; | 156 | enum wlr_edges edge = 0; |
157 | if (cursor->cursor->x < cont->x + view->border_thickness) { | 157 | if (cursor->cursor->x < cont->x + view->border_thickness) { |
158 | edge |= RESIZE_EDGE_LEFT; | 158 | edge |= WLR_EDGE_LEFT; |
159 | } | 159 | } |
160 | if (cursor->cursor->y < cont->y + view->border_thickness) { | 160 | if (cursor->cursor->y < cont->y + view->border_thickness) { |
161 | edge |= RESIZE_EDGE_TOP; | 161 | edge |= WLR_EDGE_TOP; |
162 | } | 162 | } |
163 | if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) { | 163 | if (cursor->cursor->x >= cont->x + cont->width - view->border_thickness) { |
164 | edge |= RESIZE_EDGE_RIGHT; | 164 | edge |= WLR_EDGE_RIGHT; |
165 | } | 165 | } |
166 | if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) { | 166 | if (cursor->cursor->y >= cont->y + cont->height - view->border_thickness) { |
167 | edge |= RESIZE_EDGE_BOTTOM; | 167 | edge |= WLR_EDGE_BOTTOM; |
168 | } | 168 | } |
169 | return edge; | 169 | return edge; |
170 | } | 170 | } |
171 | 171 | ||
172 | static void handle_drag_motion(struct sway_seat *seat, | 172 | static void handle_move_motion(struct sway_seat *seat, |
173 | struct sway_cursor *cursor) { | 173 | struct sway_cursor *cursor) { |
174 | struct sway_container *con = seat->op_container; | 174 | struct sway_container *con = seat->op_container; |
175 | desktop_damage_whole_container(con); | 175 | desktop_damage_whole_container(con); |
@@ -218,22 +218,22 @@ static void calculate_floating_constraints(struct sway_container *con, | |||
218 | static void handle_resize_motion(struct sway_seat *seat, | 218 | static void handle_resize_motion(struct sway_seat *seat, |
219 | struct sway_cursor *cursor) { | 219 | struct sway_cursor *cursor) { |
220 | struct sway_container *con = seat->op_container; | 220 | struct sway_container *con = seat->op_container; |
221 | enum resize_edge edge = seat->op_resize_edge; | 221 | enum wlr_edges edge = seat->op_resize_edge; |
222 | 222 | ||
223 | // The amount the mouse has moved since the start of the resize operation | 223 | // The amount the mouse has moved since the start of the resize operation |
224 | // Positive is down/right | 224 | // Positive is down/right |
225 | double mouse_move_x = cursor->cursor->x - seat->op_ref_lx; | 225 | double mouse_move_x = cursor->cursor->x - seat->op_ref_lx; |
226 | double mouse_move_y = cursor->cursor->y - seat->op_ref_ly; | 226 | double mouse_move_y = cursor->cursor->y - seat->op_ref_ly; |
227 | 227 | ||
228 | if (edge == RESIZE_EDGE_TOP || edge == RESIZE_EDGE_BOTTOM) { | 228 | if (edge == WLR_EDGE_TOP || edge == WLR_EDGE_BOTTOM) { |
229 | mouse_move_x = 0; | 229 | mouse_move_x = 0; |
230 | } | 230 | } |
231 | if (edge == RESIZE_EDGE_LEFT || edge == RESIZE_EDGE_RIGHT) { | 231 | if (edge == WLR_EDGE_LEFT || edge == WLR_EDGE_RIGHT) { |
232 | mouse_move_y = 0; | 232 | mouse_move_y = 0; |
233 | } | 233 | } |
234 | 234 | ||
235 | double grow_width = edge & RESIZE_EDGE_LEFT ? -mouse_move_x : mouse_move_x; | 235 | double grow_width = edge & WLR_EDGE_LEFT ? -mouse_move_x : mouse_move_x; |
236 | double grow_height = edge & RESIZE_EDGE_TOP ? -mouse_move_y : mouse_move_y; | 236 | double grow_height = edge & WLR_EDGE_TOP ? -mouse_move_y : mouse_move_y; |
237 | 237 | ||
238 | if (seat->op_resize_preserve_ratio) { | 238 | if (seat->op_resize_preserve_ratio) { |
239 | double x_multiplier = grow_width / seat->op_ref_width; | 239 | double x_multiplier = grow_width / seat->op_ref_width; |
@@ -259,16 +259,16 @@ static void handle_resize_motion(struct sway_seat *seat, | |||
259 | // Determine grow x/y values - these are relative to the container's x/y at | 259 | // Determine grow x/y values - these are relative to the container's x/y at |
260 | // the start of the resize operation. | 260 | // the start of the resize operation. |
261 | double grow_x = 0, grow_y = 0; | 261 | double grow_x = 0, grow_y = 0; |
262 | if (edge & RESIZE_EDGE_LEFT) { | 262 | if (edge & WLR_EDGE_LEFT) { |
263 | grow_x = -grow_width; | 263 | grow_x = -grow_width; |
264 | } else if (edge & RESIZE_EDGE_RIGHT) { | 264 | } else if (edge & WLR_EDGE_RIGHT) { |
265 | grow_x = 0; | 265 | grow_x = 0; |
266 | } else { | 266 | } else { |
267 | grow_x = -grow_width / 2; | 267 | grow_x = -grow_width / 2; |
268 | } | 268 | } |
269 | if (edge & RESIZE_EDGE_TOP) { | 269 | if (edge & WLR_EDGE_TOP) { |
270 | grow_y = -grow_height; | 270 | grow_y = -grow_height; |
271 | } else if (edge & RESIZE_EDGE_BOTTOM) { | 271 | } else if (edge & WLR_EDGE_BOTTOM) { |
272 | grow_y = 0; | 272 | grow_y = 0; |
273 | } else { | 273 | } else { |
274 | grow_y = -grow_height / 2; | 274 | grow_y = -grow_height / 2; |
@@ -299,31 +299,6 @@ static void handle_resize_motion(struct sway_seat *seat, | |||
299 | transaction_commit_dirty(); | 299 | transaction_commit_dirty(); |
300 | } | 300 | } |
301 | 301 | ||
302 | static const char *edge_to_image_name(enum resize_edge edge) { | ||
303 | switch (edge) { | ||
304 | case RESIZE_EDGE_NONE: | ||
305 | return "left_ptr"; | ||
306 | case RESIZE_EDGE_TOP: | ||
307 | return "top_side"; | ||
308 | case RESIZE_EDGE_RIGHT: | ||
309 | return "right_side"; | ||
310 | case RESIZE_EDGE_BOTTOM: | ||
311 | return "bottom_side"; | ||
312 | case RESIZE_EDGE_LEFT: | ||
313 | return "left_side"; | ||
314 | } | ||
315 | if (edge == (RESIZE_EDGE_TOP | RESIZE_EDGE_LEFT)) { | ||
316 | return "top_left_corner"; | ||
317 | } else if (edge == (RESIZE_EDGE_TOP | RESIZE_EDGE_RIGHT)) { | ||
318 | return "top_right_corner"; | ||
319 | } else if (edge == (RESIZE_EDGE_BOTTOM | RESIZE_EDGE_LEFT)) { | ||
320 | return "bottom_left_corner"; | ||
321 | } else if (edge == (RESIZE_EDGE_BOTTOM | RESIZE_EDGE_RIGHT)) { | ||
322 | return "bottom_right_corner"; | ||
323 | } | ||
324 | return "left_ptr"; | ||
325 | } | ||
326 | |||
327 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | 302 | void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, |
328 | bool allow_refocusing) { | 303 | bool allow_refocusing) { |
329 | if (time_msec == 0) { | 304 | if (time_msec == 0) { |
@@ -333,8 +308,8 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
333 | struct sway_seat *seat = cursor->seat; | 308 | struct sway_seat *seat = cursor->seat; |
334 | 309 | ||
335 | if (seat->operation != OP_NONE) { | 310 | if (seat->operation != OP_NONE) { |
336 | if (seat->operation == OP_DRAG) { | 311 | if (seat->operation == OP_MOVE) { |
337 | handle_drag_motion(seat, cursor); | 312 | handle_move_motion(seat, cursor); |
338 | } else { | 313 | } else { |
339 | handle_resize_motion(seat, cursor); | 314 | handle_resize_motion(seat, cursor); |
340 | } | 315 | } |
@@ -402,8 +377,9 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
402 | } | 377 | } |
403 | } else if (c && container_is_floating(c)) { | 378 | } else if (c && container_is_floating(c)) { |
404 | // Try a floating container's resize edge | 379 | // Try a floating container's resize edge |
405 | enum resize_edge edge = find_resize_edge(c, cursor); | 380 | enum wlr_edges edge = find_resize_edge(c, cursor); |
406 | const char *image = edge_to_image_name(edge); | 381 | const char *image = edge == WLR_EDGE_NONE ? |
382 | "left_ptr" : wlr_xcursor_get_resize_name(edge); | ||
407 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image, | 383 | wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, image, |
408 | cursor->cursor); | 384 | cursor->cursor); |
409 | cursor->image_client = NULL; | 385 | cursor->image_client = NULL; |
@@ -452,7 +428,7 @@ static void handle_cursor_motion_absolute( | |||
452 | } | 428 | } |
453 | 429 | ||
454 | static void handle_end_operation(struct sway_seat *seat) { | 430 | static void handle_end_operation(struct sway_seat *seat) { |
455 | if (seat->operation == OP_DRAG) { | 431 | if (seat->operation == OP_MOVE) { |
456 | // We "move" the container to its own location so it discovers its | 432 | // We "move" the container to its own location so it discovers its |
457 | // output again. | 433 | // output again. |
458 | struct sway_container *con = seat->op_container; | 434 | struct sway_container *con = seat->op_container; |
@@ -472,7 +448,7 @@ static void dispatch_cursor_button_floating(struct sway_cursor *cursor, | |||
472 | struct sway_container *cont) { | 448 | struct sway_container *cont) { |
473 | struct sway_seat *seat = cursor->seat; | 449 | struct sway_seat *seat = cursor->seat; |
474 | 450 | ||
475 | // Deny dragging or resizing a fullscreen view | 451 | // Deny moving or resizing a fullscreen view |
476 | if (cont->type == C_VIEW && cont->sway_view->is_fullscreen) { | 452 | if (cont->type == C_VIEW && cont->sway_view->is_fullscreen) { |
477 | wlr_seat_pointer_notify_button(seat->wlr_seat, time_msec, button, state); | 453 | wlr_seat_pointer_notify_button(seat->wlr_seat, time_msec, button, state); |
478 | return; | 454 | return; |
@@ -481,36 +457,22 @@ static void dispatch_cursor_button_floating(struct sway_cursor *cursor, | |||
481 | struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); | 457 | struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); |
482 | bool mod_pressed = keyboard && | 458 | bool mod_pressed = keyboard && |
483 | (wlr_keyboard_get_modifiers(keyboard) & config->floating_mod); | 459 | (wlr_keyboard_get_modifiers(keyboard) & config->floating_mod); |
484 | enum resize_edge edge = find_resize_edge(cont, cursor); | 460 | enum wlr_edges edge = find_resize_edge(cont, cursor); |
485 | bool over_title = edge == RESIZE_EDGE_NONE && !surface; | 461 | bool over_title = edge == WLR_EDGE_NONE && !surface; |
486 | 462 | ||
487 | // Check for beginning drag | 463 | // Check for beginning move |
488 | if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED && | 464 | if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED && |
489 | (mod_pressed || over_title)) { | 465 | (mod_pressed || over_title)) { |
490 | seat->operation = OP_DRAG; | 466 | seat_begin_move(seat, cont); |
491 | seat->op_container = cont; | ||
492 | seat->op_button = button; | ||
493 | return; | 467 | return; |
494 | } | 468 | } |
495 | 469 | ||
496 | // Check for beginning resize | 470 | // Check for beginning resize |
497 | bool resizing_via_border = button == BTN_LEFT && edge != RESIZE_EDGE_NONE; | 471 | bool resizing_via_border = button == BTN_LEFT && edge != WLR_EDGE_NONE; |
498 | bool resizing_via_mod = button == BTN_RIGHT && mod_pressed; | 472 | bool resizing_via_mod = button == BTN_RIGHT && mod_pressed; |
499 | if ((resizing_via_border || resizing_via_mod) && | 473 | if ((resizing_via_border || resizing_via_mod) && |
500 | state == WLR_BUTTON_PRESSED) { | 474 | state == WLR_BUTTON_PRESSED) { |
501 | seat->operation = OP_RESIZE; | 475 | seat_begin_resize(seat, cont, button, edge); |
502 | seat->op_container = cont; | ||
503 | seat->op_resize_preserve_ratio = keyboard && | ||
504 | (wlr_keyboard_get_modifiers(keyboard) & WLR_MODIFIER_SHIFT); | ||
505 | seat->op_resize_edge = resizing_via_mod ? | ||
506 | RESIZE_EDGE_BOTTOM | RESIZE_EDGE_RIGHT : edge; | ||
507 | seat->op_button = button; | ||
508 | seat->op_ref_lx = cursor->cursor->x; | ||
509 | seat->op_ref_ly = cursor->cursor->y; | ||
510 | seat->op_ref_con_lx = cont->x; | ||
511 | seat->op_ref_con_ly = cont->y; | ||
512 | seat->op_ref_width = cont->width; | ||
513 | seat->op_ref_height = cont->height; | ||
514 | return; | 476 | return; |
515 | } | 477 | } |
516 | 478 | ||