diff options
author | taiyu <taiyu-len@users.noreply.github.com> | 2015-08-19 10:25:36 -0700 |
---|---|---|
committer | taiyu <taiyu-len@users.noreply.github.com> | 2015-08-19 10:25:36 -0700 |
commit | 8686142351cdb9b1a5eb63f7d82a32e81474d9fa (patch) | |
tree | 28cd4da4237cc587dc94be81465fd0ec1f23f952 | |
parent | removed debug which shouldnt be there (diff) | |
parent | Fixed conflicts (diff) | |
download | sway-8686142351cdb9b1a5eb63f7d82a32e81474d9fa.tar.gz sway-8686142351cdb9b1a5eb63f7d82a32e81474d9fa.tar.zst sway-8686142351cdb9b1a5eb63f7d82a32e81474d9fa.zip |
Merge pull request #87 from Luminarys/master
Added in resize locking
-rw-r--r-- | sway/handlers.c | 130 |
1 files changed, 78 insertions, 52 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index 670569cb..5e8e05b8 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -25,6 +25,7 @@ static bool m1_held = false; | |||
25 | static bool dragging = false; | 25 | static bool dragging = false; |
26 | static bool m2_held = false; | 26 | static bool m2_held = false; |
27 | static bool resizing = false; | 27 | static bool resizing = false; |
28 | static bool lock_left, lock_right, lock_top, lock_bottom = false; | ||
28 | 29 | ||
29 | static bool floating_mod_pressed(void) { | 30 | static bool floating_mod_pressed(void) { |
30 | return key_modifiers & config->floating_mod; | 31 | return key_modifiers & config->floating_mod; |
@@ -368,61 +369,78 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct | |||
368 | // Do checks to determine if proper keys are being held | 369 | // Do checks to determine if proper keys are being held |
369 | swayc_t *view = get_focused_view(active_workspace); | 370 | swayc_t *view = get_focused_view(active_workspace); |
370 | uint32_t edge = 0; | 371 | uint32_t edge = 0; |
371 | if (dragging && view && view->is_floating) { | 372 | if (dragging && view) { |
372 | int dx = mouse_origin.x - prev_pos.x; | 373 | if (view->is_floating) { |
373 | int dy = mouse_origin.y - prev_pos.y; | 374 | int dx = mouse_origin.x - prev_pos.x; |
374 | view->x += dx; | 375 | int dy = mouse_origin.y - prev_pos.y; |
375 | view->y += dy; | 376 | view->x += dx; |
376 | changed_floating = true; | 377 | view->y += dy; |
377 | } else if (resizing && view && view->is_floating) { | ||
378 | int dx = mouse_origin.x - prev_pos.x; | ||
379 | int dy = mouse_origin.y - prev_pos.y; | ||
380 | |||
381 | // Move and resize the view based on the dx/dy and mouse position | ||
382 | int midway_x = view->x + view->width/2; | ||
383 | int midway_y = view->y + view->height/2; | ||
384 | if (dx < 0) { | ||
385 | changed_floating = true; | ||
386 | if (mouse_origin.x > midway_x) { | ||
387 | view->width += dx; | ||
388 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
389 | } else { | ||
390 | view->x += dx; | ||
391 | view->width -= dx; | ||
392 | edge += WLC_RESIZE_EDGE_LEFT; | ||
393 | } | ||
394 | } else if (dx > 0){ | ||
395 | changed_floating = true; | 378 | changed_floating = true; |
396 | if (mouse_origin.x > midway_x) { | ||
397 | view->width += dx; | ||
398 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
399 | } else { | ||
400 | view->x += dx; | ||
401 | view->width -= dx; | ||
402 | edge += WLC_RESIZE_EDGE_LEFT; | ||
403 | } | ||
404 | } | 379 | } |
405 | 380 | } else if (resizing && view) { | |
406 | if (dy < 0) { | 381 | if (view->is_floating) { |
407 | changed_floating = true; | 382 | int dx = mouse_origin.x - prev_pos.x; |
408 | if (mouse_origin.y > midway_y) { | 383 | int dy = mouse_origin.y - prev_pos.y; |
409 | view->height += dy; | 384 | int min_sane_w = 100; |
410 | edge += WLC_RESIZE_EDGE_BOTTOM; | 385 | int min_sane_h = 60; |
411 | } else { | 386 | |
412 | view->y += dy; | 387 | // Move and resize the view based on the dx/dy and mouse position |
413 | view->height -= dy; | 388 | int midway_x = view->x + view->width/2; |
414 | edge += WLC_RESIZE_EDGE_TOP; | 389 | int midway_y = view->y + view->height/2; |
390 | if (dx < 0) { | ||
391 | if (!lock_right) { | ||
392 | if (view->width > min_sane_w) { | ||
393 | changed_floating = true; | ||
394 | view->width += dx; | ||
395 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
396 | } | ||
397 | } else if (mouse_origin.x < midway_x && !lock_left) { | ||
398 | changed_floating = true; | ||
399 | view->x += dx; | ||
400 | view->width -= dx; | ||
401 | edge += WLC_RESIZE_EDGE_LEFT; | ||
402 | } | ||
403 | } else if (dx > 0){ | ||
404 | if (mouse_origin.x > midway_x && !lock_right) { | ||
405 | changed_floating = true; | ||
406 | view->width += dx; | ||
407 | edge += WLC_RESIZE_EDGE_RIGHT; | ||
408 | } else if (!lock_left) { | ||
409 | if (view->width > min_sane_w) { | ||
410 | changed_floating = true; | ||
411 | view->x += dx; | ||
412 | view->width -= dx; | ||
413 | edge += WLC_RESIZE_EDGE_LEFT; | ||
414 | } | ||
415 | } | ||
415 | } | 416 | } |
416 | } else if (dy > 0) { | 417 | |
417 | changed_floating = true; | 418 | if (dy < 0) { |
418 | if (mouse_origin.y > midway_y) { | 419 | if (!lock_bottom) { |
419 | view->height += dy; | 420 | if (view->height > min_sane_h) { |
420 | edge += WLC_RESIZE_EDGE_BOTTOM; | 421 | changed_floating = true; |
421 | } else { | 422 | view->height += dy; |
422 | edge = WLC_RESIZE_EDGE_BOTTOM; | 423 | edge += WLC_RESIZE_EDGE_BOTTOM; |
423 | view->y += dy; | 424 | } |
424 | view->height -= dy; | 425 | } else if (mouse_origin.y < midway_y && !lock_top) { |
425 | edge += WLC_RESIZE_EDGE_TOP; | 426 | changed_floating = true; |
427 | view->y += dy; | ||
428 | view->height -= dy; | ||
429 | edge += WLC_RESIZE_EDGE_TOP; | ||
430 | } | ||
431 | } else if (dy > 0) { | ||
432 | if (mouse_origin.y > midway_y && !lock_bottom) { | ||
433 | changed_floating = true; | ||
434 | view->height += dy; | ||
435 | edge += WLC_RESIZE_EDGE_BOTTOM; | ||
436 | } else if (!lock_top) { | ||
437 | if (view->height > min_sane_h) { | ||
438 | changed_floating = true; | ||
439 | view->y += dy; | ||
440 | view->height -= dy; | ||
441 | edge += WLC_RESIZE_EDGE_TOP; | ||
442 | } | ||
443 | } | ||
426 | } | 444 | } |
427 | } | 445 | } |
428 | } | 446 | } |
@@ -482,6 +500,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
482 | if (floating_mod_pressed()) { | 500 | if (floating_mod_pressed()) { |
483 | dragging = m1_held; | 501 | dragging = m1_held; |
484 | resizing = m2_held; | 502 | resizing = m2_held; |
503 | int midway_x = pointer->x + pointer->width/2; | ||
504 | int midway_y = pointer->y + pointer->height/2; | ||
505 | lock_bottom = origin->y < midway_y; | ||
506 | lock_top = !lock_bottom; | ||
507 | lock_right = origin->x < midway_x; | ||
508 | lock_left = !lock_right; | ||
485 | } | 509 | } |
486 | //Dont want pointer sent to window while dragging or resizing | 510 | //Dont want pointer sent to window while dragging or resizing |
487 | return (dragging || resizing); | 511 | return (dragging || resizing); |
@@ -492,10 +516,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w | |||
492 | if (button == 272) { | 516 | if (button == 272) { |
493 | m1_held = false; | 517 | m1_held = false; |
494 | dragging = false; | 518 | dragging = false; |
519 | lock_top = lock_bottom = lock_left = lock_right = false; | ||
495 | } | 520 | } |
496 | if (button == 273) { | 521 | if (button == 273) { |
497 | m2_held = false; | 522 | m2_held = false; |
498 | resizing = false; | 523 | resizing = false; |
524 | lock_top = lock_bottom = lock_left = lock_right = false; | ||
499 | } | 525 | } |
500 | } | 526 | } |
501 | return false; | 527 | return false; |