diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 93 |
1 files changed, 30 insertions, 63 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index c9d7c7ac..03a32835 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -13,16 +13,10 @@ | |||
13 | #include "workspace.h" | 13 | #include "workspace.h" |
14 | #include "container.h" | 14 | #include "container.h" |
15 | #include "focus.h" | 15 | #include "focus.h" |
16 | #include "key_state.h" | 16 | #include "input_state.h" |
17 | 17 | ||
18 | static struct wlc_origin mouse_origin; | 18 | static struct wlc_origin mouse_origin; |
19 | 19 | ||
20 | static bool m1_held = false; | ||
21 | static bool dragging = false; | ||
22 | static bool m2_held = false; | ||
23 | static bool resizing = false; | ||
24 | static bool lock_left, lock_right, lock_top, lock_bottom = false; | ||
25 | |||
26 | static bool pointer_test(swayc_t *view, void *_origin) { | 20 | static bool pointer_test(swayc_t *view, void *_origin) { |
27 | const struct wlc_origin *origin = _origin; | 21 | const struct wlc_origin *origin = _origin; |
28 | // Determine the output that the view is under | 22 | // Determine the output that the view is under |
@@ -88,29 +82,6 @@ swayc_t *container_under_pointer(void) { | |||
88 | return lookup; | 82 | return lookup; |
89 | } | 83 | } |
90 | 84 | ||
91 | static struct wlc_geometry saved_floating; | ||
92 | |||
93 | static void start_floating(swayc_t *view) { | ||
94 | if (view->is_floating) { | ||
95 | saved_floating.origin.x = view->x; | ||
96 | saved_floating.origin.y = view->y; | ||
97 | saved_floating.size.w = view->width; | ||
98 | saved_floating.size.h = view->height; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | static void reset_floating(swayc_t *view) { | ||
103 | if (view->is_floating) { | ||
104 | view->x = saved_floating.origin.x; | ||
105 | view->y = saved_floating.origin.y; | ||
106 | view->width = saved_floating.size.w; | ||
107 | view->height = saved_floating.size.h; | ||
108 | arrange_windows(view->parent, -1, -1); | ||
109 | } | ||
110 | dragging = resizing = false; | ||
111 | lock_left = lock_right = lock_top = lock_bottom = false; | ||
112 | } | ||
113 | |||
114 | /* Handles */ | 85 | /* Handles */ |
115 | 86 | ||
116 | static bool handle_output_created(wlc_handle output) { | 87 | static bool handle_output_created(wlc_handle output) { |
@@ -327,7 +298,8 @@ static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifier | |||
327 | } | 298 | } |
328 | 299 | ||
329 | // Revert floating container back to original position on keypress | 300 | // Revert floating container back to original position on keypress |
330 | if (state == WLC_KEY_STATE_PRESSED && (dragging || resizing)) { | 301 | if (state == WLC_KEY_STATE_PRESSED && |
302 | (pointer_state.floating.drag || pointer_state.floating.resize)) { | ||
331 | reset_floating(get_focused_view(&root_container)); | 303 | reset_floating(get_focused_view(&root_container)); |
332 | } | 304 | } |
333 | 305 | ||
@@ -396,7 +368,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
396 | // Do checks to determine if proper keys are being held | 368 | // Do checks to determine if proper keys are being held |
397 | swayc_t *view = get_focused_view(active_workspace); | 369 | swayc_t *view = get_focused_view(active_workspace); |
398 | uint32_t edge = 0; | 370 | uint32_t edge = 0; |
399 | if (dragging && view) { | 371 | if (pointer_state.floating.drag && view) { |
400 | if (view->is_floating) { | 372 | if (view->is_floating) { |
401 | int dx = mouse_origin.x - prev_pos.x; | 373 | int dx = mouse_origin.x - prev_pos.x; |
402 | int dy = mouse_origin.y - prev_pos.y; | 374 | int dy = mouse_origin.y - prev_pos.y; |
@@ -404,7 +376,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
404 | view->y += dy; | 376 | view->y += dy; |
405 | changed_floating = true; | 377 | changed_floating = true; |
406 | } | 378 | } |
407 | } else if (resizing && view) { | 379 | } else if (pointer_state.floating.resize && view) { |
408 | if (view->is_floating) { | 380 | if (view->is_floating) { |
409 | int dx = mouse_origin.x - prev_pos.x; | 381 | int dx = mouse_origin.x - prev_pos.x; |
410 | int dy = mouse_origin.y - prev_pos.y; | 382 | int dy = mouse_origin.y - prev_pos.y; |
@@ -415,24 +387,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
415 | int midway_x = view->x + view->width/2; | 387 | int midway_x = view->x + view->width/2; |
416 | int midway_y = view->y + view->height/2; | 388 | int midway_y = view->y + view->height/2; |
417 | if (dx < 0) { | 389 | if (dx < 0) { |
418 | if (!lock_right) { | 390 | if (!pointer_state.lock.right) { |
419 | if (view->width > min_sane_w) { | 391 | if (view->width > min_sane_w) { |
420 | changed_floating = true; | 392 | changed_floating = true; |
421 | view->width += dx; | 393 | view->width += dx; |
422 | edge += WLC_RESIZE_EDGE_RIGHT; | 394 | edge += WLC_RESIZE_EDGE_RIGHT; |
423 | } | 395 | } |
424 | } else if (mouse_origin.x < midway_x && !lock_left) { | 396 | } else if (mouse_origin.x < midway_x && !pointer_state.lock.left) { |
425 | changed_floating = true; | 397 | changed_floating = true; |
426 | view->x += dx; | 398 | view->x += dx; |
427 | view->width -= dx; | 399 | view->width -= dx; |
428 | edge += WLC_RESIZE_EDGE_LEFT; | 400 | edge += WLC_RESIZE_EDGE_LEFT; |
429 | } | 401 | } |
430 | } else if (dx > 0) { | 402 | } else if (dx > 0) { |
431 | if (mouse_origin.x > midway_x && !lock_right) { | 403 | if (mouse_origin.x > midway_x && !pointer_state.lock.right) { |
432 | changed_floating = true; | 404 | changed_floating = true; |
433 | view->width += dx; | 405 | view->width += dx; |
434 | edge += WLC_RESIZE_EDGE_RIGHT; | 406 | edge += WLC_RESIZE_EDGE_RIGHT; |
435 | } else if (!lock_left) { | 407 | } else if (!pointer_state.lock.left) { |
436 | if (view->width > min_sane_w) { | 408 | if (view->width > min_sane_w) { |
437 | changed_floating = true; | 409 | changed_floating = true; |
438 | view->x += dx; | 410 | view->x += dx; |
@@ -443,24 +415,24 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
443 | } | 415 | } |
444 | 416 | ||
445 | if (dy < 0) { | 417 | if (dy < 0) { |
446 | if (!lock_bottom) { | 418 | if (!pointer_state.lock.bottom) { |
447 | if (view->height > min_sane_h) { | 419 | if (view->height > min_sane_h) { |
448 | changed_floating = true; | 420 | changed_floating = true; |
449 | view->height += dy; | 421 | view->height += dy; |
450 | edge += WLC_RESIZE_EDGE_BOTTOM; | 422 | edge += WLC_RESIZE_EDGE_BOTTOM; |
451 | } | 423 | } |
452 | } else if (mouse_origin.y < midway_y && !lock_top) { | 424 | } else if (mouse_origin.y < midway_y && !pointer_state.lock.top) { |
453 | changed_floating = true; | 425 | changed_floating = true; |
454 | view->y += dy; | 426 | view->y += dy; |
455 | view->height -= dy; | 427 | view->height -= dy; |
456 | edge += WLC_RESIZE_EDGE_TOP; | 428 | edge += WLC_RESIZE_EDGE_TOP; |
457 | } | 429 | } |
458 | } else if (dy > 0) { | 430 | } else if (dy > 0) { |
459 | if (mouse_origin.y > midway_y && !lock_bottom) { | 431 | if (mouse_origin.y > midway_y && !pointer_state.lock.bottom) { |
460 | changed_floating = true; | 432 | changed_floating = true; |
461 | view->height += dy; | 433 | view->height += dy; |
462 | edge += WLC_RESIZE_EDGE_BOTTOM; | 434 | edge += WLC_RESIZE_EDGE_BOTTOM; |
463 | } else if (!lock_top) { | 435 | } else if (!pointer_state.lock.top) { |
464 | if (view->height > min_sane_h) { | 436 | if (view->height > min_sane_h) { |
465 | changed_floating = true; | 437 | changed_floating = true; |
466 | view->y += dy; | 438 | view->y += dy; |
@@ -474,7 +446,8 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
474 | if (config->focus_follows_mouse && prev_handle != handle) { | 446 | if (config->focus_follows_mouse && prev_handle != handle) { |
475 | //Dont change focus if fullscreen | 447 | //Dont change focus if fullscreen |
476 | swayc_t *focused = get_focused_view(view); | 448 | swayc_t *focused = get_focused_view(view); |
477 | if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) && !(m1_held || m2_held)) { | 449 | if (!(focused->type == C_VIEW && wlc_view_get_state(focused->handle) & WLC_BIT_FULLSCREEN) |
450 | && !(pointer_state.l_held || pointer_state.r_held)) { | ||
478 | set_focused_container(container_under_pointer()); | 451 | set_focused_container(container_under_pointer()); |
479 | } | 452 | } |
480 | } | 453 | } |
@@ -497,13 +470,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
497 | return false; | 470 | return false; |
498 | } | 471 | } |
499 | 472 | ||
500 | enum pointer_values { | ||
501 | M_LEFT_CLICK = 272, | ||
502 | M_RIGHT_CLICK = 273, | ||
503 | M_SCROLL_CLICK = 274, | ||
504 | M_SCROLL_UP = 275, | ||
505 | M_SCROLL_DOWN = 276, | ||
506 | }; | ||
507 | 473 | ||
508 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 474 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
509 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { | 475 | uint32_t button, enum wlc_button_state state, const struct wlc_origin *origin) { |
@@ -515,10 +481,10 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
515 | if (state == WLC_BUTTON_STATE_PRESSED) { | 481 | if (state == WLC_BUTTON_STATE_PRESSED) { |
516 | sway_log(L_DEBUG, "Mouse button %u pressed", button); | 482 | sway_log(L_DEBUG, "Mouse button %u pressed", button); |
517 | if (button == M_LEFT_CLICK) { | 483 | if (button == M_LEFT_CLICK) { |
518 | m1_held = true; | 484 | pointer_state.l_held = true; |
519 | } | 485 | } |
520 | if (button == M_RIGHT_CLICK) { | 486 | if (button == M_RIGHT_CLICK) { |
521 | m2_held = true; | 487 | pointer_state.r_held = true; |
522 | } | 488 | } |
523 | swayc_t *pointer = container_under_pointer(); | 489 | swayc_t *pointer = container_under_pointer(); |
524 | set_focused_container(pointer); | 490 | set_focused_container(pointer); |
@@ -533,30 +499,31 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
533 | } | 499 | } |
534 | arrange_windows(pointer->parent, -1, -1); | 500 | arrange_windows(pointer->parent, -1, -1); |
535 | if (modifiers->mods & config->floating_mod) { | 501 | if (modifiers->mods & config->floating_mod) { |
536 | dragging = m1_held; | ||
537 | resizing = m2_held; | ||
538 | int midway_x = pointer->x + pointer->width/2; | 502 | int midway_x = pointer->x + pointer->width/2; |
539 | int midway_y = pointer->y + pointer->height/2; | 503 | int midway_y = pointer->y + pointer->height/2; |
540 | lock_bottom = origin->y < midway_y; | 504 | |
541 | lock_top = !lock_bottom; | 505 | pointer_state.floating.drag = pointer_state.l_held; |
542 | lock_right = origin->x < midway_x; | 506 | pointer_state.floating.resize = pointer_state.r_held; |
543 | lock_left = !lock_right; | 507 | pointer_state.lock.bottom = origin->y < midway_y; |
508 | pointer_state.lock.top = !pointer_state.lock.bottom; | ||
509 | pointer_state.lock.right = origin->x < midway_x; | ||
510 | pointer_state.lock.left = !pointer_state.lock.right; | ||
544 | start_floating(pointer); | 511 | start_floating(pointer); |
545 | } | 512 | } |
546 | //Dont want pointer sent to window while dragging or resizing | 513 | //Dont want pointer sent to window while dragging or resizing |
547 | return (dragging || resizing); | 514 | return (pointer_state.floating.drag || pointer_state.floating.resize); |
548 | } | 515 | } |
549 | return (pointer && pointer != focused); | 516 | return (pointer && pointer != focused); |
550 | } else { | 517 | } else { |
551 | sway_log(L_DEBUG, "Mouse button %u released", button); | 518 | sway_log(L_DEBUG, "Mouse button %u released", button); |
552 | if (button == M_LEFT_CLICK) { | 519 | if (button == M_LEFT_CLICK) { |
553 | m1_held = false; | 520 | pointer_state.l_held = false; |
554 | dragging = false; | 521 | pointer_state.floating.drag = false; |
555 | } | 522 | } |
556 | if (button == M_RIGHT_CLICK) { | 523 | if (button == M_RIGHT_CLICK) { |
557 | m2_held = false; | 524 | pointer_state.r_held = false; |
558 | resizing = false; | 525 | pointer_state.floating.resize = false; |
559 | lock_top = lock_bottom = lock_left = lock_right = false; | 526 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; |
560 | } | 527 | } |
561 | } | 528 | } |
562 | return false; | 529 | return false; |