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 10:52:01 -0500
commitdd8ff4a1505e914b6ab9b2de11a4a55f7a4bb61d (patch)
tree0c069255e99c83dec6d98d8cddb3c73506bb25f0
parentFixed config loading (diff)
downloadsway-dd8ff4a1505e914b6ab9b2de11a4a55f7a4bb61d.tar.gz
sway-dd8ff4a1505e914b6ab9b2de11a4a55f7a4bb61d.tar.zst
sway-dd8ff4a1505e914b6ab9b2de11a4a55f7a4bb61d.zip
Added in resize locking
-rw-r--r--sway/handlers.c136
1 files changed, 84 insertions, 52 deletions
diff --git a/sway/handlers.c b/sway/handlers.c
index 3ae33294..306c8abf 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -23,8 +23,10 @@ static bool m1_held = false;
23static bool dragging = false; 23static bool dragging = false;
24static bool m2_held = false; 24static bool m2_held = false;
25static bool resizing = false; 25static bool resizing = false;
26static bool lock_left, lock_right, lock_top, lock_bottom = false;
26 27
27static bool floating_mod_pressed(void) { 28static bool floating_mod_pressed(void) {
29 return true;
28 int i = 0; 30 int i = 0;
29 while (i < keys_pressed_length) { 31 while (i < keys_pressed_length) {
30 if (keys_pressed[i++] == config->floating_mod) 32 if (keys_pressed[i++] == config->floating_mod)
@@ -370,61 +372,89 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct
370 // Do checks to determine if proper keys are being held 372 // Do checks to determine if proper keys are being held
371 swayc_t *view = get_focused_view(active_workspace); 373 swayc_t *view = get_focused_view(active_workspace);
372 uint32_t edge = 0; 374 uint32_t edge = 0;
373 if (dragging && view && view->is_floating) { 375 if (dragging && view) {
374 int dx = mouse_origin.x - prev_pos.x; 376 if (view->is_floating) {
375 int dy = mouse_origin.y - prev_pos.y; 377 int dx = mouse_origin.x - prev_pos.x;
376 view->x += dx; 378 int dy = mouse_origin.y - prev_pos.y;
377 view->y += dy; 379 view->x += dx;
378 changed_floating = true; 380 view->y += dy;
379 } else if (resizing && view && view->is_floating) {
380 int dx = mouse_origin.x - prev_pos.x;
381 int dy = mouse_origin.y - prev_pos.y;
382
383 // Move and resize the view based on the dx/dy and mouse position
384 int midway_x = view->x + view->width/2;
385 int midway_y = view->y + view->height/2;
386 if (dx < 0) {
387 changed_floating = true;
388 if (mouse_origin.x > midway_x) {
389 view->width += dx;
390 edge += WLC_RESIZE_EDGE_RIGHT;
391 } else {
392 view->x += dx;
393 view->width -= dx;
394 edge += WLC_RESIZE_EDGE_LEFT;
395 }
396 } else if (dx > 0){
397 changed_floating = true; 381 changed_floating = true;
398 if (mouse_origin.x > midway_x) {
399 view->width += dx;
400 edge += WLC_RESIZE_EDGE_RIGHT;
401 } else {
402 view->x += dx;
403 view->width -= dx;
404 edge += WLC_RESIZE_EDGE_LEFT;
405 }
406 } 382 }
407 383 } else if (resizing && view) {
408 if (dy < 0) { 384 if (view->is_floating) {
409 changed_floating = true; 385 int dx = mouse_origin.x - prev_pos.x;
410 if (mouse_origin.y > midway_y) { 386 int dy = mouse_origin.y - prev_pos.y;
411 view->height += dy; 387 int min_sane_w = 100;
412 edge += WLC_RESIZE_EDGE_BOTTOM; 388 int min_sane_h = 60;
413 } else { 389
414 view->y += dy; 390 // Move and resize the view based on the dx/dy and mouse position
415 view->height -= dy; 391 int midway_x = view->x + view->width/2;
416 edge += WLC_RESIZE_EDGE_TOP; 392 int midway_y = view->y + view->height/2;
393 if (dx < 0) {
394 if (mouse_origin.x > midway_x && !lock_right) {
395 if (view->width > min_sane_w) {
396 lock_left = true;
397 changed_floating = true;
398 view->width += dx;
399 edge += WLC_RESIZE_EDGE_RIGHT;
400 }
401 } else if (mouse_origin.x < midway_x && !lock_left) {
402 lock_right = true;
403 changed_floating = true;
404 view->x += dx;
405 view->width -= dx;
406 edge += WLC_RESIZE_EDGE_LEFT;
407 }
408 } else if (dx > 0){
409 if (mouse_origin.x > midway_x && !lock_right) {
410 lock_left = true;
411 changed_floating = true;
412 view->width += dx;
413 edge += WLC_RESIZE_EDGE_RIGHT;
414 if (view->width > min_sane_w) {
415 lock_left = false;
416 }
417 } else if (mouse_origin.x < midway_x && !lock_left) {
418 if (view->width > min_sane_w) {
419 lock_right = true;
420 changed_floating = true;
421 view->x += dx;
422 view->width -= dx;
423 edge += WLC_RESIZE_EDGE_LEFT;
424 }
425 }
417 } 426 }
418 } else if (dy > 0) { 427
419 changed_floating = true; 428 if (dy < 0) {
420 if (mouse_origin.y > midway_y) { 429 if (mouse_origin.y > midway_y && !lock_bottom) {
421 view->height += dy; 430 if (view->height > min_sane_h) {
422 edge += WLC_RESIZE_EDGE_BOTTOM; 431 lock_top = true;
423 } else { 432 changed_floating = true;
424 edge = WLC_RESIZE_EDGE_BOTTOM; 433 view->height += dy;
425 view->y += dy; 434 edge += WLC_RESIZE_EDGE_BOTTOM;
426 view->height -= dy; 435 }
427 edge += WLC_RESIZE_EDGE_TOP; 436 } else if (mouse_origin.y < midway_y && !lock_top) {
437 lock_bottom = true;
438 changed_floating = true;
439 view->y += dy;
440 view->height -= dy;
441 edge += WLC_RESIZE_EDGE_TOP;
442 }
443 } else if (dy > 0) {
444 if (mouse_origin.y > midway_y && !lock_bottom) {
445 lock_top = true;
446 changed_floating = true;
447 view->height += dy;
448 edge += WLC_RESIZE_EDGE_BOTTOM;
449 } else if (mouse_origin.y < midway_y && !lock_top) {
450 if (view->height > min_sane_h) {
451 lock_bottom = true;
452 changed_floating = true;
453 view->y += dy;
454 view->height -= dy;
455 edge += WLC_RESIZE_EDGE_TOP;
456 }
457 }
428 } 458 }
429 } 459 }
430 } 460 }
@@ -494,10 +524,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w
494 if (button == 272) { 524 if (button == 272) {
495 m1_held = false; 525 m1_held = false;
496 dragging = false; 526 dragging = false;
527 lock_top = lock_bottom = lock_left = lock_right = false;
497 } 528 }
498 if (button == 273) { 529 if (button == 273) {
499 m2_held = false; 530 m2_held = false;
500 resizing = false; 531 resizing = false;
532 lock_top = lock_bottom = lock_left = lock_right = false;
501 } 533 }
502 } 534 }
503 return false; 535 return false;