From dd8ff4a1505e914b6ab9b2de11a4a55f7a4bb61d Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 10:52:01 -0500 Subject: [PATCH 1/5] Added in resize locking --- sway/handlers.c | 134 ++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 51 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; static bool dragging = false; static bool m2_held = false; static bool resizing = false; +static bool lock_left, lock_right, lock_top, lock_bottom = false; static bool floating_mod_pressed(void) { + return true; int i = 0; while (i < keys_pressed_length) { if (keys_pressed[i++] == config->floating_mod) @@ -370,61 +372,89 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct // Do checks to determine if proper keys are being held swayc_t *view = get_focused_view(active_workspace); uint32_t edge = 0; - if (dragging && view && view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - view->x += dx; - view->y += dy; - changed_floating = true; - } else if (resizing && view && view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - - // Move and resize the view based on the dx/dy and mouse position - int midway_x = view->x + view->width/2; - int midway_y = view->y + view->height/2; - if (dx < 0) { + if (dragging && view) { + if (view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + view->x += dx; + view->y += dy; changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } else if (dx > 0){ - changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } } + } else if (resizing && view) { + if (view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + int min_sane_w = 100; + int min_sane_h = 60; - if (dy < 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; + // Move and resize the view based on the dx/dy and mouse position + int midway_x = view->x + view->width/2; + int midway_y = view->y + view->height/2; + if (dx < 0) { + if (mouse_origin.x > midway_x && !lock_right) { + if (view->width > min_sane_w) { + lock_left = true; + changed_floating = true; + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + } + } else if (mouse_origin.x < midway_x && !lock_left) { + lock_right = true; + changed_floating = true; + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } else if (dx > 0){ + if (mouse_origin.x > midway_x && !lock_right) { + lock_left = true; + changed_floating = true; + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + if (view->width > min_sane_w) { + lock_left = false; + } + } else if (mouse_origin.x < midway_x && !lock_left) { + if (view->width > min_sane_w) { + lock_right = true; + changed_floating = true; + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } } - } else if (dy > 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - edge = WLC_RESIZE_EDGE_BOTTOM; - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; + + if (dy < 0) { + if (mouse_origin.y > midway_y && !lock_bottom) { + if (view->height > min_sane_h) { + lock_top = true; + changed_floating = true; + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } + } else if (mouse_origin.y < midway_y && !lock_top) { + lock_bottom = true; + changed_floating = true; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } else if (dy > 0) { + if (mouse_origin.y > midway_y && !lock_bottom) { + lock_top = true; + changed_floating = true; + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } else if (mouse_origin.y < midway_y && !lock_top) { + if (view->height > min_sane_h) { + lock_bottom = true; + changed_floating = true; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } } } } @@ -494,10 +524,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (button == 272) { m1_held = false; dragging = false; + lock_top = lock_bottom = lock_left = lock_right = false; } if (button == 273) { m2_held = false; resizing = false; + lock_top = lock_bottom = lock_left = lock_right = false; } } return false; From 0b23962564a52dff8dd70488f33bc08eeb5aef03 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 11:23:27 -0500 Subject: [PATCH 2/5] Resolved merge conflicts --- sway/handlers.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index 306c8abf..92d9b6af 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -26,13 +26,7 @@ static bool resizing = false; static bool lock_left, lock_right, lock_top, lock_bottom = false; static bool floating_mod_pressed(void) { - return true; - int i = 0; - while (i < keys_pressed_length) { - if (keys_pressed[i++] == config->floating_mod) - return true; - } - return false; + return key_modifiers & config->floating_mod; } static bool pointer_test(swayc_t *view, void *_origin) { From 9542f8746ae691b867ed127a7897dd5e8c7f4305 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 10:52:01 -0500 Subject: [PATCH 3/5] Added in resize locking --- sway/handlers.c | 133 +++++++++++++++++++++++++++++------------------- 1 file changed, 82 insertions(+), 51 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; static bool dragging = false; static bool m2_held = false; static bool resizing = false; +static bool lock_left, lock_right, lock_top, lock_bottom = false; static bool floating_mod_pressed(void) { return key_modifiers & config->floating_mod; @@ -368,61 +369,89 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct // Do checks to determine if proper keys are being held swayc_t *view = get_focused_view(active_workspace); uint32_t edge = 0; - if (dragging && view && view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - view->x += dx; - view->y += dy; - changed_floating = true; - } else if (resizing && view && view->is_floating) { - int dx = mouse_origin.x - prev_pos.x; - int dy = mouse_origin.y - prev_pos.y; - - // Move and resize the view based on the dx/dy and mouse position - int midway_x = view->x + view->width/2; - int midway_y = view->y + view->height/2; - if (dx < 0) { + if (dragging && view) { + if (view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + view->x += dx; + view->y += dy; changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } - } else if (dx > 0){ - changed_floating = true; - if (mouse_origin.x > midway_x) { - view->width += dx; - edge += WLC_RESIZE_EDGE_RIGHT; - } else { - view->x += dx; - view->width -= dx; - edge += WLC_RESIZE_EDGE_LEFT; - } } + } else if (resizing && view) { + if (view->is_floating) { + int dx = mouse_origin.x - prev_pos.x; + int dy = mouse_origin.y - prev_pos.y; + int min_sane_w = 100; + int min_sane_h = 60; - if (dy < 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; + // Move and resize the view based on the dx/dy and mouse position + int midway_x = view->x + view->width/2; + int midway_y = view->y + view->height/2; + if (dx < 0) { + if (mouse_origin.x > midway_x && !lock_right) { + if (view->width > min_sane_w) { + lock_left = true; + changed_floating = true; + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + } + } else if (mouse_origin.x < midway_x && !lock_left) { + lock_right = true; + changed_floating = true; + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } else if (dx > 0){ + if (mouse_origin.x > midway_x && !lock_right) { + lock_left = true; + changed_floating = true; + view->width += dx; + edge += WLC_RESIZE_EDGE_RIGHT; + if (view->width > min_sane_w) { + lock_left = false; + } + } else if (mouse_origin.x < midway_x && !lock_left) { + if (view->width > min_sane_w) { + lock_right = true; + changed_floating = true; + view->x += dx; + view->width -= dx; + edge += WLC_RESIZE_EDGE_LEFT; + } + } } - } else if (dy > 0) { - changed_floating = true; - if (mouse_origin.y > midway_y) { - view->height += dy; - edge += WLC_RESIZE_EDGE_BOTTOM; - } else { - edge = WLC_RESIZE_EDGE_BOTTOM; - view->y += dy; - view->height -= dy; - edge += WLC_RESIZE_EDGE_TOP; + + if (dy < 0) { + if (mouse_origin.y > midway_y && !lock_bottom) { + if (view->height > min_sane_h) { + lock_top = true; + changed_floating = true; + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } + } else if (mouse_origin.y < midway_y && !lock_top) { + lock_bottom = true; + changed_floating = true; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } else if (dy > 0) { + if (mouse_origin.y > midway_y && !lock_bottom) { + lock_top = true; + changed_floating = true; + view->height += dy; + edge += WLC_RESIZE_EDGE_BOTTOM; + } else if (mouse_origin.y < midway_y && !lock_top) { + if (view->height > min_sane_h) { + lock_bottom = true; + changed_floating = true; + view->y += dy; + view->height -= dy; + edge += WLC_RESIZE_EDGE_TOP; + } + } } } } @@ -492,10 +521,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (button == 272) { m1_held = false; dragging = false; + lock_top = lock_bottom = lock_left = lock_right = false; } if (button == 273) { m2_held = false; resizing = false; + lock_top = lock_bottom = lock_left = lock_right = false; } } return false; From 745031e6f97b871de0c37572b085aea4eae855a8 Mon Sep 17 00:00:00 2001 From: Ezra Date: Wed, 19 Aug 2015 11:29:32 -0500 Subject: [PATCH 4/5] More merge resolution. --- sway/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/handlers.c b/sway/handlers.c index 92d9b6af..00f10a0c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -26,7 +26,7 @@ static bool resizing = false; static bool lock_left, lock_right, lock_top, lock_bottom = false; static bool floating_mod_pressed(void) { - return key_modifiers & config->floating_mod; + return key_modifiers & config->floating_mod; } static bool pointer_test(swayc_t *view, void *_origin) { From daea22bc8920fea1d6fba923169173a2bbdc75f9 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Wed, 19 Aug 2015 12:06:00 -0500 Subject: [PATCH 5/5] Resize lock fixes --- sway/handlers.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/sway/handlers.c b/sway/handlers.c index faade5eb..5e8e05b8 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -388,15 +388,13 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct int midway_x = view->x + view->width/2; int midway_y = view->y + view->height/2; if (dx < 0) { - if (mouse_origin.x > midway_x && !lock_right) { + if (!lock_right) { if (view->width > min_sane_w) { - lock_left = true; changed_floating = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; } } else if (mouse_origin.x < midway_x && !lock_left) { - lock_right = true; changed_floating = true; view->x += dx; view->width -= dx; @@ -404,16 +402,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } else if (dx > 0){ if (mouse_origin.x > midway_x && !lock_right) { - lock_left = true; changed_floating = true; view->width += dx; edge += WLC_RESIZE_EDGE_RIGHT; + } else if (!lock_left) { if (view->width > min_sane_w) { - lock_left = false; - } - } else if (mouse_origin.x < midway_x && !lock_left) { - if (view->width > min_sane_w) { - lock_right = true; changed_floating = true; view->x += dx; view->width -= dx; @@ -423,15 +416,13 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } if (dy < 0) { - if (mouse_origin.y > midway_y && !lock_bottom) { + if (!lock_bottom) { if (view->height > min_sane_h) { - lock_top = true; changed_floating = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; } } else if (mouse_origin.y < midway_y && !lock_top) { - lock_bottom = true; changed_floating = true; view->y += dy; view->height -= dy; @@ -439,13 +430,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } else if (dy > 0) { if (mouse_origin.y > midway_y && !lock_bottom) { - lock_top = true; changed_floating = true; view->height += dy; edge += WLC_RESIZE_EDGE_BOTTOM; - } else if (mouse_origin.y < midway_y && !lock_top) { + } else if (!lock_top) { if (view->height > min_sane_h) { - lock_bottom = true; changed_floating = true; view->y += dy; view->height -= dy; @@ -511,6 +500,12 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (floating_mod_pressed()) { dragging = m1_held; resizing = m2_held; + int midway_x = pointer->x + pointer->width/2; + int midway_y = pointer->y + pointer->height/2; + lock_bottom = origin->y < midway_y; + lock_top = !lock_bottom; + lock_right = origin->x < midway_x; + lock_left = !lock_right; } //Dont want pointer sent to window while dragging or resizing return (dragging || resizing);