summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-08-21 10:28:49 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-08-21 10:28:49 -0700
commit5a67628ad91d42d737acea659ed2782ec344933e (patch)
treef11e9d3032fd59060b9044bd2a7ed0009655bbf2
parentbugfixes, renames (diff)
parentRemoved ugly intializer for pointer_state (diff)
downloadsway-5a67628ad91d42d737acea659ed2782ec344933e.tar.gz
sway-5a67628ad91d42d737acea659ed2782ec344933e.tar.zst
sway-5a67628ad91d42d737acea659ed2782ec344933e.zip
Merge branch 'master' of https://github.com/SirCmpwn/sway
merge
-rw-r--r--include/input_state.h8
-rw-r--r--sway/handlers.c76
-rw-r--r--sway/input_state.c6
3 files changed, 71 insertions, 19 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 8dc409e1..07247b1c 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -419,16 +419,42 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
419 } 419 }
420 } 420 }
421 } else if (pointer_state.tiling.resize && view) { 421 } else if (pointer_state.tiling.resize && view) {
422 if (view != pointer_state.tiling.init_view) { 422 bool valid = true;
423 // Quit out of the resize 423 double dx = mouse_origin.x - prev_pos.x;
424 //pointer_state.tiling.init_view = NULL; 424 double dy = mouse_origin.y - prev_pos.y;
425
426 if ((dx < 0 || mouse_origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) {
427 changed_tiling = true;
428 valid = false;
429 } else if (dx > 0 && pointer_state.lock.temp_left) {
430 pointer_state.lock.temp_left = false;
425 } 431 }
426 if (!view->is_floating && view == pointer_state.tiling.init_view) { 432
433 if ((dx > 0 || mouse_origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) {
434 changed_tiling = true;
435 valid = false;
436 } else if (dx < 0 && pointer_state.lock.temp_right) {
437 pointer_state.lock.temp_right = false;
438 }
439
440 if ((dy < 0 || mouse_origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) {
441 changed_tiling = true;
442 valid = false;
443 } else if (dy > 0 && pointer_state.lock.temp_up) {
444 pointer_state.lock.temp_up = false;
445 }
446
447 if ((dy > 0 || mouse_origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) {
448 changed_tiling = true;
449 valid = false;
450 } else if (dy < 0 && pointer_state.lock.temp_down) {
451 pointer_state.lock.temp_down = false;
452 }
453
454 if (!view->is_floating && valid) {
427 // Handle layout resizes -- Find the biggest parent container then apply resizes to that 455 // Handle layout resizes -- Find the biggest parent container then apply resizes to that
428 // and its bordering siblings 456 // and its bordering siblings
429 swayc_t *parent = view; 457 swayc_t *parent = view;
430 double dx = mouse_origin.x - prev_pos.x;
431 double dy = mouse_origin.y - prev_pos.y;
432 if (!pointer_state.lock.bottom) { 458 if (!pointer_state.lock.bottom) {
433 while (parent->type != C_WORKSPACE) { 459 while (parent->type != C_WORKSPACE) {
434 // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better 460 // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better
@@ -440,14 +466,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
440 } 466 }
441 } 467 }
442 if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { 468 if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
443 sway_log(L_DEBUG, "Top is locked, found biggest valid parent at: %p", parent);
444 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); 469 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN);
445 if (sibling) { 470 if (sibling) {
446 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
447 if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { 471 if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) {
448 recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); 472 recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM);
449 recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); 473 recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP);
450 changed_tiling = true; 474 changed_tiling = true;
475 } else {
476 pointer_state.tiling.lock_pos.y = mouse_origin.y;
477 if (parent->height < min_sane_h) {
478 pointer_state.lock.temp_up = true;
479 } else if (sibling->height < min_sane_h) {
480 pointer_state.lock.temp_down = true;
481 }
451 } 482 }
452 } 483 }
453 } 484 }
@@ -460,14 +491,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
460 } 491 }
461 } 492 }
462 if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { 493 if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
463 sway_log(L_DEBUG, "Bot is locked, found biggest valid parent at: %p", parent);
464 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); 494 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP);
465 if (sibling) { 495 if (sibling) {
466 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
467 if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { 496 if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) {
468 recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); 497 recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP);
469 recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); 498 recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM);
470 changed_tiling = true; 499 changed_tiling = true;
500 } else {
501 pointer_state.tiling.lock_pos.y = mouse_origin.y;
502 if (parent->height < min_sane_h) {
503 pointer_state.lock.temp_down = true;
504 } else if (sibling->height < min_sane_h) {
505 pointer_state.lock.temp_up = true;
506 }
471 } 507 }
472 } 508 }
473 } 509 }
@@ -484,14 +520,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
484 } 520 }
485 } 521 }
486 if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { 522 if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
487 sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent);
488 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); 523 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT);
489 if (sibling) { 524 if (sibling) {
490 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
491 if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { 525 if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) {
492 recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); 526 recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT);
493 recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); 527 recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT);
494 changed_tiling = true; 528 changed_tiling = true;
529 } else {
530 pointer_state.tiling.lock_pos.x = mouse_origin.x;
531 if (parent->width < min_sane_w) {
532 pointer_state.lock.temp_left = true;
533 } else if (sibling->width < min_sane_w) {
534 pointer_state.lock.temp_right = true;
535 }
495 } 536 }
496 } 537 }
497 } 538 }
@@ -504,14 +545,19 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
504 } 545 }
505 } 546 }
506 if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { 547 if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
507 sway_log(L_DEBUG, "Right is locked, found biggest valid parent at: %p", parent);
508 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); 548 swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT);
509 if (sibling) { 549 if (sibling) {
510 sway_log(L_DEBUG, "Found sibling at: %p", sibling);
511 if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { 550 if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) {
512 recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); 551 recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT);
513 recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); 552 recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT);
514 changed_tiling = true; 553 changed_tiling = true;
554 } else {
555 pointer_state.tiling.lock_pos.x = mouse_origin.x;
556 if (parent->width < min_sane_w) {
557 pointer_state.lock.temp_right = true;
558 } else if (sibling->width < min_sane_w) {
559 pointer_state.lock.temp_left = true;
560 }
515 } 561 }
516 } 562 }
517 } 563 }
@@ -609,7 +655,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
609 pointer_state.floating.resize = false; 655 pointer_state.floating.resize = false;
610 pointer_state.tiling.resize = false; 656 pointer_state.tiling.resize = false;
611 pointer_state.tiling.init_view = NULL; 657 pointer_state.tiling.init_view = NULL;
612 pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; 658 pointer_state.lock = (struct pointer_lock){false ,false ,false ,false, false, false, false, false};
613 } 659 }
614 } 660 }
615 return false; 661 return false;
diff --git a/sway/input_state.c b/sway/input_state.c
index 5119930a..e2f3c754 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
51struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}}; 51struct pointer_state pointer_state;
52 52
53static struct wlc_geometry saved_floating; 53static struct wlc_geometry saved_floating;
54 54
@@ -69,6 +69,6 @@ void reset_floating(swayc_t *view) {
69 view->height = saved_floating.size.h; 69 view->height = saved_floating.size.h;
70 arrange_windows(view->parent, -1, -1); 70 arrange_windows(view->parent, -1, -1);
71 } 71 }
72 pointer_state.floating = (struct pointer_floating){0,0}; 72 pointer_state.floating = (struct pointer_floating){0, 0};
73 pointer_state.lock = (struct pointer_lock){0,0,0,0}; 73 pointer_state.lock = (struct pointer_lock){0, 0, 0, 0, 0, 0, 0, 0};
74} 74}