summaryrefslogtreecommitdiffstats
path: root/sway/handlers.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/handlers.c')
-rw-r--r--sway/handlers.c109
1 files changed, 100 insertions, 9 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 5993223d..a71328e3 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -1,6 +1,7 @@
1#include <xkbcommon/xkbcommon.h> 1#include <xkbcommon/xkbcommon.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <stdbool.h> 3#include <stdbool.h>
4#include <math.h>
4#include <wlc/wlc.h> 5#include <wlc/wlc.h>
5#include <ctype.h> 6#include <ctype.h>
6 7
@@ -351,7 +352,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
351 return false; 352 return false;
352 } 353 }
353 // Do checks to determine if proper keys are being held 354 // Do checks to determine if proper keys are being held
354 swayc_t *view = get_focused_view(active_workspace); 355 swayc_t *view = container_under_pointer();
355 uint32_t edge = 0; 356 uint32_t edge = 0;
356 if (pointer_state.floating.drag && view) { 357 if (pointer_state.floating.drag && view) {
357 if (view->is_floating) { 358 if (view->is_floating) {
@@ -426,6 +427,91 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
426 } 427 }
427 } 428 }
428 } 429 }
430 }
431 } else if (pointer_state.tiling.resize && view) {
432 if (!view->is_floating) {
433 // Handle layout resizes -- Find the biggest parent container then apply resizes to that
434 // and its bordering siblings
435 swayc_t *parent = view;
436 double dx = mouse_origin.x - prev_pos.x;
437 double dy = mouse_origin.y - prev_pos.y;
438 if (pointer_state.lock.top) {
439 while (parent->type != C_WORKSPACE) {
440 // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better
441 // way of doing this.
442 if (fabs(parent->parent->y + parent->parent->height - (view->y + view->height)) <= 1) {
443 parent = parent->parent;
444 } else {
445 break;
446 }
447 }
448 if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
449 sway_log(L_DEBUG, "Top is locked, found biggest valid parent at: %p", parent);
450 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN);
451 if (sibling) {
452 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
453 recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM);
454 recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP);
455 }
456 }
457 } else {
458 while (parent->type != C_WORKSPACE) {
459 if (fabs(parent->parent->y - view->y) <= 1) {
460 parent = parent->parent;
461 } else {
462 break;
463 }
464 }
465 if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
466 sway_log(L_DEBUG, "Bot is locked, found biggest valid parent at: %p", parent);
467 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP);
468 if (sibling) {
469 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
470 recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP);
471 recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM);
472 }
473 }
474 }
475
476 parent = view;
477 if (pointer_state.lock.left) {
478 while (parent->type != C_WORKSPACE) {
479 if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) {
480 parent = parent->parent;
481 } else {
482 sway_log(L_DEBUG, "view: %f vs parent: %f", view->x + view->width, parent->parent->x + parent->parent->width);
483 break;
484 }
485 }
486 sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent);
487 if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
488 sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent);
489 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT);
490 if (sibling) {
491 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
492 recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT);
493 recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT);
494 }
495 }
496 } else {
497 while (parent->type != C_WORKSPACE) {
498 if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) {
499 parent = parent->parent;
500 } else {
501 break;
502 }
503 }
504 if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
505 sway_log(L_DEBUG, "Right is locked, found biggest valid parent at: %p", parent);
506 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT);
507 if (sibling) {
508 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
509 recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT);
510 recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT);
511 }
512 }
513 }
514 arrange_windows(active_workspace, -1, -1);
429 } 515 }
430 } 516 }
431 if (config->focus_follows_mouse && prev_handle != handle) { 517 if (config->focus_follows_mouse && prev_handle != handle) {
@@ -472,7 +558,16 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
472 pointer_state.r_held = true; 558 pointer_state.r_held = true;
473 } 559 }
474 swayc_t *pointer = container_under_pointer(); 560 swayc_t *pointer = container_under_pointer();
475 set_focused_container(pointer); 561 if (pointer) {
562 set_focused_container(pointer);
563 int midway_x = pointer->x + pointer->width/2;
564 int midway_y = pointer->y + pointer->height/2;
565 pointer_state.lock.bottom = origin->y < midway_y;
566 pointer_state.lock.top = !pointer_state.lock.bottom;
567 pointer_state.lock.right = origin->x < midway_x;
568 pointer_state.lock.left = !pointer_state.lock.right;
569 }
570
476 if (pointer->is_floating) { 571 if (pointer->is_floating) {
477 int i; 572 int i;
478 for (i = 0; i < pointer->parent->floating->length; i++) { 573 for (i = 0; i < pointer->parent->floating->length; i++) {
@@ -484,19 +579,14 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
484 } 579 }
485 arrange_windows(pointer->parent, -1, -1); 580 arrange_windows(pointer->parent, -1, -1);
486 if (modifiers->mods & config->floating_mod) { 581 if (modifiers->mods & config->floating_mod) {
487 int midway_x = pointer->x + pointer->width/2;
488 int midway_y = pointer->y + pointer->height/2;
489
490 pointer_state.floating.drag = pointer_state.l_held; 582 pointer_state.floating.drag = pointer_state.l_held;
491 pointer_state.floating.resize = pointer_state.r_held; 583 pointer_state.floating.resize = pointer_state.r_held;
492 pointer_state.lock.bottom = origin->y < midway_y;
493 pointer_state.lock.top = !pointer_state.lock.bottom;
494 pointer_state.lock.right = origin->x < midway_x;
495 pointer_state.lock.left = !pointer_state.lock.right;
496 start_floating(pointer); 584 start_floating(pointer);
497 } 585 }
498 // Dont want pointer sent to window while dragging or resizing 586 // Dont want pointer sent to window while dragging or resizing
499 return (pointer_state.floating.drag || pointer_state.floating.resize); 587 return (pointer_state.floating.drag || pointer_state.floating.resize);
588 } else {
589 pointer_state.tiling.resize = pointer_state.r_held;
500 } 590 }
501 return (pointer && pointer != focused); 591 return (pointer && pointer != focused);
502 } else { 592 } else {
@@ -508,6 +598,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
508 if (button == M_RIGHT_CLICK) { 598 if (button == M_RIGHT_CLICK) {
509 pointer_state.r_held = false; 599 pointer_state.r_held = false;
510 pointer_state.floating.resize = false; 600 pointer_state.floating.resize = false;
601 pointer_state.tiling.resize = false;
511 pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; 602 pointer_state.lock = (struct pointer_lock){false ,false ,false ,false};
512 } 603 }
513 } 604 }