mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 19:31:29 +00:00
Added in resize locking
This commit is contained in:
parent
0e4df85ba1
commit
dd8ff4a150
134
sway/handlers.c
134
sway/handlers.c
|
@ -23,8 +23,10 @@ static bool m1_held = false;
|
||||||
static bool dragging = false;
|
static bool dragging = false;
|
||||||
static bool m2_held = false;
|
static bool m2_held = false;
|
||||||
static bool resizing = false;
|
static bool resizing = false;
|
||||||
|
static bool lock_left, lock_right, lock_top, lock_bottom = false;
|
||||||
|
|
||||||
static bool floating_mod_pressed(void) {
|
static bool floating_mod_pressed(void) {
|
||||||
|
return true;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < keys_pressed_length) {
|
while (i < keys_pressed_length) {
|
||||||
if (keys_pressed[i++] == config->floating_mod)
|
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
|
// Do checks to determine if proper keys are being held
|
||||||
swayc_t *view = get_focused_view(active_workspace);
|
swayc_t *view = get_focused_view(active_workspace);
|
||||||
uint32_t edge = 0;
|
uint32_t edge = 0;
|
||||||
if (dragging && view && view->is_floating) {
|
if (dragging && view) {
|
||||||
int dx = mouse_origin.x - prev_pos.x;
|
if (view->is_floating) {
|
||||||
int dy = mouse_origin.y - prev_pos.y;
|
int dx = mouse_origin.x - prev_pos.x;
|
||||||
view->x += dx;
|
int dy = mouse_origin.y - prev_pos.y;
|
||||||
view->y += dy;
|
view->x += dx;
|
||||||
changed_floating = true;
|
view->y += dy;
|
||||||
} 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) {
|
|
||||||
changed_floating = true;
|
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) {
|
// Move and resize the view based on the dx/dy and mouse position
|
||||||
changed_floating = true;
|
int midway_x = view->x + view->width/2;
|
||||||
if (mouse_origin.y > midway_y) {
|
int midway_y = view->y + view->height/2;
|
||||||
view->height += dy;
|
if (dx < 0) {
|
||||||
edge += WLC_RESIZE_EDGE_BOTTOM;
|
if (mouse_origin.x > midway_x && !lock_right) {
|
||||||
} else {
|
if (view->width > min_sane_w) {
|
||||||
view->y += dy;
|
lock_left = true;
|
||||||
view->height -= dy;
|
changed_floating = true;
|
||||||
edge += WLC_RESIZE_EDGE_TOP;
|
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 (dy < 0) {
|
||||||
if (mouse_origin.y > midway_y) {
|
if (mouse_origin.y > midway_y && !lock_bottom) {
|
||||||
view->height += dy;
|
if (view->height > min_sane_h) {
|
||||||
edge += WLC_RESIZE_EDGE_BOTTOM;
|
lock_top = true;
|
||||||
} else {
|
changed_floating = true;
|
||||||
edge = WLC_RESIZE_EDGE_BOTTOM;
|
view->height += dy;
|
||||||
view->y += dy;
|
edge += WLC_RESIZE_EDGE_BOTTOM;
|
||||||
view->height -= dy;
|
}
|
||||||
edge += WLC_RESIZE_EDGE_TOP;
|
} 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) {
|
if (button == 272) {
|
||||||
m1_held = false;
|
m1_held = false;
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
lock_top = lock_bottom = lock_left = lock_right = false;
|
||||||
}
|
}
|
||||||
if (button == 273) {
|
if (button == 273) {
|
||||||
m2_held = false;
|
m2_held = false;
|
||||||
resizing = false;
|
resizing = false;
|
||||||
|
lock_top = lock_bottom = lock_left = lock_right = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue