diff options
-rw-r--r-- | include/input_state.h | 8 | ||||
-rw-r--r-- | sway/handlers.c | 76 | ||||
-rw-r--r-- | sway/input_state.c | 2 |
3 files changed, 69 insertions, 17 deletions
diff --git a/include/input_state.h b/include/input_state.h index 000996e0..04fde42d 100644 --- a/include/input_state.h +++ b/include/input_state.h | |||
@@ -37,13 +37,19 @@ extern struct pointer_state { | |||
37 | struct pointer_tiling { | 37 | struct pointer_tiling { |
38 | bool resize; | 38 | bool resize; |
39 | swayc_t *init_view; | 39 | swayc_t *init_view; |
40 | struct wlc_origin *lock_pos; | 40 | struct wlc_origin lock_pos; |
41 | } tiling; | 41 | } tiling; |
42 | struct pointer_lock { | 42 | struct pointer_lock { |
43 | // Lock movement for certain edges | ||
43 | bool left; | 44 | bool left; |
44 | bool right; | 45 | bool right; |
45 | bool top; | 46 | bool top; |
46 | bool bottom; | 47 | bool bottom; |
48 | // Lock movement in certain directions | ||
49 | bool temp_left; | ||
50 | bool temp_right; | ||
51 | bool temp_up; | ||
52 | bool temp_down; | ||
47 | } lock; | 53 | } lock; |
48 | } pointer_state; | 54 | } pointer_state; |
49 | 55 | ||
diff --git a/sway/handlers.c b/sway/handlers.c index 78f8927d..7188092a 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -421,16 +421,42 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
421 | } | 421 | } |
422 | } | 422 | } |
423 | } else if (pointer_state.tiling.resize && view) { | 423 | } else if (pointer_state.tiling.resize && view) { |
424 | if (view != pointer_state.tiling.init_view) { | 424 | bool valid = true; |
425 | // Quit out of the resize | 425 | double dx = mouse_origin.x - prev_pos.x; |
426 | //pointer_state.tiling.init_view = NULL; | 426 | double dy = mouse_origin.y - prev_pos.y; |
427 | |||
428 | if ((dx < 0 || mouse_origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) { | ||
429 | changed_tiling = true; | ||
430 | valid = false; | ||
431 | } else if (dx > 0 && pointer_state.lock.temp_left) { | ||
432 | pointer_state.lock.temp_left = false; | ||
427 | } | 433 | } |
428 | if (!view->is_floating && view == pointer_state.tiling.init_view) { | 434 | |
435 | if ((dx > 0 || mouse_origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) { | ||
436 | changed_tiling = true; | ||
437 | valid = false; | ||
438 | } else if (dx < 0 && pointer_state.lock.temp_right) { | ||
439 | pointer_state.lock.temp_right = false; | ||
440 | } | ||
441 | |||
442 | if ((dy < 0 || mouse_origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) { | ||
443 | changed_tiling = true; | ||
444 | valid = false; | ||
445 | } else if (dy > 0 && pointer_state.lock.temp_up) { | ||
446 | pointer_state.lock.temp_up = false; | ||
447 | } | ||
448 | |||
449 | if ((dy > 0 || mouse_origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) { | ||
450 | changed_tiling = true; | ||
451 | valid = false; | ||
452 | } else if (dy < 0 && pointer_state.lock.temp_down) { | ||
453 | pointer_state.lock.temp_down = false; | ||
454 | } | ||
455 | |||
456 | if (!view->is_floating && valid) { | ||
429 | // Handle layout resizes -- Find the biggest parent container then apply resizes to that | 457 | // Handle layout resizes -- Find the biggest parent container then apply resizes to that |
430 | // and its bordering siblings | 458 | // and its bordering siblings |
431 | swayc_t *parent = view; | 459 | swayc_t *parent = view; |
432 | double dx = mouse_origin.x - prev_pos.x; | ||
433 | double dy = mouse_origin.y - prev_pos.y; | ||
434 | if (!pointer_state.lock.bottom) { | 460 | if (!pointer_state.lock.bottom) { |
435 | while (parent->type != C_WORKSPACE) { | 461 | while (parent->type != C_WORKSPACE) { |
436 | // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better | 462 | // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better |
@@ -442,14 +468,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
442 | } | 468 | } |
443 | } | 469 | } |
444 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { | 470 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { |
445 | sway_log(L_DEBUG, "Top is locked, found biggest valid parent at: %p", parent); | ||
446 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); | 471 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); |
447 | if (sibling) { | 472 | if (sibling) { |
448 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
449 | if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { | 473 | if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { |
450 | recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); | 474 | recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); |
451 | recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); | 475 | recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); |
452 | changed_tiling = true; | 476 | changed_tiling = true; |
477 | } else { | ||
478 | pointer_state.tiling.lock_pos.y = mouse_origin.y; | ||
479 | if (parent->height < min_sane_h) { | ||
480 | pointer_state.lock.temp_up = true; | ||
481 | } else if (sibling->height < min_sane_h) { | ||
482 | pointer_state.lock.temp_down = true; | ||
483 | } | ||
453 | } | 484 | } |
454 | } | 485 | } |
455 | } | 486 | } |
@@ -462,14 +493,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
462 | } | 493 | } |
463 | } | 494 | } |
464 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { | 495 | if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { |
465 | sway_log(L_DEBUG, "Bot is locked, found biggest valid parent at: %p", parent); | ||
466 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); | 496 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); |
467 | if (sibling) { | 497 | if (sibling) { |
468 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
469 | if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { | 498 | if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { |
470 | recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); | 499 | recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); |
471 | recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); | 500 | recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); |
472 | changed_tiling = true; | 501 | changed_tiling = true; |
502 | } else { | ||
503 | pointer_state.tiling.lock_pos.y = mouse_origin.y; | ||
504 | if (parent->height < min_sane_h) { | ||
505 | pointer_state.lock.temp_down = true; | ||
506 | } else if (sibling->height < min_sane_h) { | ||
507 | pointer_state.lock.temp_up = true; | ||
508 | } | ||
473 | } | 509 | } |
474 | } | 510 | } |
475 | } | 511 | } |
@@ -486,14 +522,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
486 | } | 522 | } |
487 | } | 523 | } |
488 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { | 524 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { |
489 | sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent); | ||
490 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); | 525 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); |
491 | if (sibling) { | 526 | if (sibling) { |
492 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
493 | if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { | 527 | if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { |
494 | recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); | 528 | recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); |
495 | recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); | 529 | recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); |
496 | changed_tiling = true; | 530 | changed_tiling = true; |
531 | } else { | ||
532 | pointer_state.tiling.lock_pos.x = mouse_origin.x; | ||
533 | if (parent->width < min_sane_w) { | ||
534 | pointer_state.lock.temp_left = true; | ||
535 | } else if (sibling->width < min_sane_w) { | ||
536 | pointer_state.lock.temp_right = true; | ||
537 | } | ||
497 | } | 538 | } |
498 | } | 539 | } |
499 | } | 540 | } |
@@ -506,14 +547,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
506 | } | 547 | } |
507 | } | 548 | } |
508 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { | 549 | if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { |
509 | sway_log(L_DEBUG, "Right is locked, found biggest valid parent at: %p", parent); | ||
510 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); | 550 | swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); |
511 | if (sibling) { | 551 | if (sibling) { |
512 | sway_log(L_DEBUG, "Found sibling at: %p", sibling); | ||
513 | if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { | 552 | if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { |
514 | recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); | 553 | recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); |
515 | recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); | 554 | recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); |
516 | changed_tiling = true; | 555 | changed_tiling = true; |
556 | } else { | ||
557 | pointer_state.tiling.lock_pos.x = mouse_origin.x; | ||
558 | if (parent->width < min_sane_w) { | ||
559 | pointer_state.lock.temp_right = true; | ||
560 | } else if (sibling->width < min_sane_w) { | ||
561 | pointer_state.lock.temp_left = true; | ||
562 | } | ||
517 | } | 563 | } |
518 | } | 564 | } |
519 | } | 565 | } |
@@ -611,7 +657,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
611 | pointer_state.floating.resize = false; | 657 | pointer_state.floating.resize = false; |
612 | pointer_state.tiling.resize = false; | 658 | pointer_state.tiling.resize = false; |
613 | pointer_state.tiling.init_view = NULL; | 659 | pointer_state.tiling.init_view = NULL; |
614 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; | 660 | pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false}; |
615 | } | 661 | } |
616 | } | 662 | } |
617 | return false; | 663 | return false; |
diff --git a/sway/input_state.c b/sway/input_state.c index 5119930a..61c1e4ba 100644 --- a/sway/input_state.c +++ b/sway/input_state.c | |||
@@ -48,7 +48,7 @@ void release_key(keycode key) { | |||
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}}; | 51 | struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, {0, 0}}, {0, 0, 0, 0, 0, 0, 0, 0}}; |
52 | 52 | ||
53 | static struct wlc_geometry saved_floating; | 53 | static struct wlc_geometry saved_floating; |
54 | 54 | ||