summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-19 10:52:01 -0500
committerLibravatar Luminarys <kizunanohikari@gmail.com>2015-08-19 11:28:04 -0500
commit9542f8746ae691b867ed127a7897dd5e8c7f4305 (patch)
treee942388505e81de16ce4910a722cded47d8ffe4b
parentremoved debug which shouldnt be there (diff)
downloadsway-9542f8746ae691b867ed127a7897dd5e8c7f4305.tar.gz
sway-9542f8746ae691b867ed127a7897dd5e8c7f4305.tar.zst
sway-9542f8746ae691b867ed127a7897dd5e8c7f4305.zip
Added in resize locking
-rw-r--r--sway/handlers.c135
1 files changed, 83 insertions, 52 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 670569cb..faade5eb 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -25,6 +25,7 @@ static bool m1_held = false;
25static bool dragging = false; 25static bool dragging = false;
26static bool m2_held = false; 26static bool m2_held = false;
27static bool resizing = false; 27static bool resizing = false;
28static bool lock_left, lock_right, lock_top, lock_bottom = false;
28 29
29static bool floating_mod_pressed(void) { 30static bool floating_mod_pressed(void) {
30 return key_modifiers & config->floating_mod; 31 return key_modifiers & config->floating_mod;
@@ -368,61 +369,89 @@ 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 (mouse_origin.x > midway_x && !lock_right) {
392 if (view->width > min_sane_w) {
393 lock_left = true;
394 changed_floating = true;
395 view->width += dx;
396 edge += WLC_RESIZE_EDGE_RIGHT;
397 }
398 } else if (mouse_origin.x < midway_x && !lock_left) {
399 lock_right = true;
400 changed_floating = true;
401 view->x += dx;
402 view->width -= dx;
403 edge += WLC_RESIZE_EDGE_LEFT;
404 }
405 } else if (dx > 0){
406 if (mouse_origin.x > midway_x && !lock_right) {
407 lock_left = true;
408 changed_floating = true;
409 view->width += dx;
410 edge += WLC_RESIZE_EDGE_RIGHT;
411 if (view->width > min_sane_w) {
412 lock_left = false;
413 }
414 } else if (mouse_origin.x < midway_x && !lock_left) {
415 if (view->width > min_sane_w) {
416 lock_right = true;
417 changed_floating = true;
418 view->x += dx;
419 view->width -= dx;
420 edge += WLC_RESIZE_EDGE_LEFT;
421 }
422 }
415 } 423 }
416 } else if (dy > 0) { 424
417 changed_floating = true; 425 if (dy < 0) {
418 if (mouse_origin.y > midway_y) { 426 if (mouse_origin.y > midway_y && !lock_bottom) {
419 view->height += dy; 427 if (view->height > min_sane_h) {
420 edge += WLC_RESIZE_EDGE_BOTTOM; 428 lock_top = true;
421 } else { 429 changed_floating = true;
422 edge = WLC_RESIZE_EDGE_BOTTOM; 430 view->height += dy;
423 view->y += dy; 431 edge += WLC_RESIZE_EDGE_BOTTOM;
424 view->height -= dy; 432 }
425 edge += WLC_RESIZE_EDGE_TOP; 433 } else if (mouse_origin.y < midway_y && !lock_top) {
434 lock_bottom = true;
435 changed_floating = true;
436 view->y += dy;
437 view->height -= dy;
438 edge += WLC_RESIZE_EDGE_TOP;
439 }
440 } else if (dy > 0) {
441 if (mouse_origin.y > midway_y && !lock_bottom) {
442 lock_top = true;
443 changed_floating = true;
444 view->height += dy;
445 edge += WLC_RESIZE_EDGE_BOTTOM;
446 } else if (mouse_origin.y < midway_y && !lock_top) {
447 if (view->height > min_sane_h) {
448 lock_bottom = true;
449 changed_floating = true;
450 view->y += dy;
451 view->height -= dy;
452 edge += WLC_RESIZE_EDGE_TOP;
453 }
454 }
426 } 455 }
427 } 456 }
428 } 457 }
@@ -492,10 +521,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
492 if (button == 272) { 521 if (button == 272) {
493 m1_held = false; 522 m1_held = false;
494 dragging = false; 523 dragging = false;
524 lock_top = lock_bottom = lock_left = lock_right = false;
495 } 525 }
496 if (button == 273) { 526 if (button == 273) {
497 m2_held = false; 527 m2_held = false;
498 resizing = false; 528 resizing = false;
529 lock_top = lock_bottom = lock_left = lock_right = false;
499 } 530 }
500 } 531 }
501 return false; 532 return false;