aboutsummaryrefslogtreecommitdiff
path: root/sway/resize.c
diff options
context:
space:
mode:
authortaiyu <taiyu.len@gmail.com>2015-08-22 21:03:45 -0700
committertaiyu <taiyu.len@gmail.com>2015-08-22 21:03:45 -0700
commit42d5d9a17779710e83f4ebb2d7e8c893ad91dfe6 (patch)
treea323f619fa2a2254fd642dd5f285019510b28632 /sway/resize.c
parente139de0857a1ba015fa324dcc662a39eca88761b (diff)
mouse tile resize mode done
Diffstat (limited to 'sway/resize.c')
-rw-r--r--sway/resize.c261
1 files changed, 0 insertions, 261 deletions
diff --git a/sway/resize.c b/sway/resize.c
index 31cd66e8..22d520af 100644
--- a/sway/resize.c
+++ b/sway/resize.c
@@ -6,267 +6,6 @@
#include "input_state.h"
#include "handlers.h"
-bool mouse_resize_tiled(struct wlc_origin prev_pos) {
- swayc_t *view = container_under_pointer();
- bool valid = true;
- bool changed_tiling = false;
- double dx = pointer_state.origin.x - prev_pos.x;
- double dy = pointer_state.origin.y - prev_pos.y;
- if (view != pointer_state.tiling.init_view) {
- changed_tiling = true;
- valid = false;
- if (view->type != C_WORKSPACE) {
- if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_LEFT) == view) {
- pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20;
- pointer_state.lock.temp_left = true;
- } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_RIGHT) == view) {
- pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20;
- pointer_state.lock.temp_right = true;
- } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_UP) == view) {
- pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20;
- pointer_state.lock.temp_up = true;
- } else if (get_swayc_in_direction(pointer_state.tiling.init_view, MOVE_DOWN) == view) {
- pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20;
- pointer_state.lock.temp_down = true;
- }
- }
- }
-
- if ((dx < 0 || pointer_state.origin.x < pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_left) {
- changed_tiling = true;
- valid = false;
- } else if (dx > 0 && pointer_state.lock.temp_left) {
- pointer_state.lock.temp_left = false;
- pointer_state.tiling.lock_pos.x = 0;
- }
-
- if ((dx > 0 || pointer_state.origin.x > pointer_state.tiling.lock_pos.x) && pointer_state.lock.temp_right) {
- changed_tiling = true;
- valid = false;
- } else if (dx < 0 && pointer_state.lock.temp_right) {
- pointer_state.lock.temp_right = false;
- pointer_state.tiling.lock_pos.x = 0;
- }
-
- if ((dy < 0 || pointer_state.origin.y < pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_up) {
- changed_tiling = true;
- valid = false;
- } else if (dy > 0 && pointer_state.lock.temp_up) {
- pointer_state.lock.temp_up = false;
- pointer_state.tiling.lock_pos.y = 0;
- }
-
- if ((dy > 0 || pointer_state.origin.y > pointer_state.tiling.lock_pos.y) && pointer_state.lock.temp_down) {
- changed_tiling = true;
- valid = false;
- } else if (dy < 0 && pointer_state.lock.temp_down) {
- pointer_state.lock.temp_down = false;
- pointer_state.tiling.lock_pos.y = 0;
- }
-
- if (!view->is_floating && valid) {
- // Handle layout resizes -- Find the biggest parent container then apply resizes to that
- // and its bordering siblings
- swayc_t *parent = view;
- if (!pointer_state.lock.bottom) {
- while (parent->type != C_WORKSPACE) {
- // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better
- // way of doing this.
- if (fabs(parent->parent->y + parent->parent->height - (view->y + view->height)) <= 1) {
- parent = parent->parent;
- } else {
- break;
- }
- }
- if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
- swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN);
- if (sibling) {
- if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) {
- recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM);
- recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP);
- changed_tiling = true;
- } else {
- if (parent->height < min_sane_h) {
- //pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20;
- pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20;
- pointer_state.lock.temp_up = true;
- } else if (sibling->height < min_sane_h) {
- pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20;
- pointer_state.lock.temp_down = true;
- }
- }
- }
- }
- } else if (!pointer_state.lock.top) {
- while (parent->type != C_WORKSPACE) {
- if (fabs(parent->parent->y - view->y) <= 1) {
- parent = parent->parent;
- } else {
- break;
- }
- }
- if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) {
- swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP);
- if (sibling) {
- if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) {
- recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP);
- recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM);
- changed_tiling = true;
- } else {
- if (parent->height < min_sane_h) {
- //pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + pointer_state.tiling.init_view->height - 20;
- pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20;
- pointer_state.lock.temp_down = true;
- } else if (sibling->height < min_sane_h) {
- pointer_state.tiling.lock_pos.y = pointer_state.tiling.init_view->y + 20;
- pointer_state.lock.temp_up = true;
- }
- }
- }
- }
- }
-
- parent = view;
- if (!pointer_state.lock.right) {
- while (parent->type != C_WORKSPACE) {
- if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) {
- parent = parent->parent;
- } else {
- sway_log(L_DEBUG, "view: %f vs parent: %f", view->x + view->width, parent->parent->x + parent->parent->width);
- break;
- }
- }
- if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
- swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT);
- if (sibling) {
- if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) {
- recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT);
- recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT);
- changed_tiling = true;
- } else {
- if (parent->width < min_sane_w) {
- pointer_state.lock.temp_left = true;
- pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20;
- } else if (sibling->width < min_sane_w) {
- pointer_state.lock.temp_right = true;
- pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + pointer_state.tiling.init_view->width - 20;
- }
- }
- }
- }
- } else if (!pointer_state.lock.left) {
- while (parent->type != C_WORKSPACE) {
- if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) {
- parent = parent->parent;
- } else {
- break;
- }
- }
- if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) {
- swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT);
- if (sibling) {
- if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) {
- recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT);
- recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT);
- changed_tiling = true;
- } else {
- if (parent->width < min_sane_w) {
- pointer_state.lock.temp_right = true;
- pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20;
- } else if (sibling->width < min_sane_w) {
- pointer_state.lock.temp_left = true;
- pointer_state.tiling.lock_pos.x = pointer_state.tiling.init_view->x + 20;
- }
- }
- }
- }
- }
- arrange_windows(swayc_active_workspace(), -1, -1);
- }
- return changed_tiling;
-}
-
-bool resize_floating(struct wlc_origin prev_pos) {
- bool changed = false;
- swayc_t *view = container_under_pointer();
- uint32_t edge = 0;
- int dx = pointer_state.origin.x - prev_pos.x;
- int dy = pointer_state.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 (!pointer_state.lock.right) {
- if (view->width > min_sane_w) {
- changed = true;
- view->width += dx;
- edge += WLC_RESIZE_EDGE_RIGHT;
- }
- } else if (pointer_state.origin.x < midway_x && !pointer_state.lock.left) {
- changed = true;
- view->x += dx;
- view->width -= dx;
- edge += WLC_RESIZE_EDGE_LEFT;
- }
- } else if (dx > 0) {
- if (pointer_state.origin.x > midway_x && !pointer_state.lock.right) {
- changed = true;
- view->width += dx;
- edge += WLC_RESIZE_EDGE_RIGHT;
- } else if (!pointer_state.lock.left) {
- if (view->width > min_sane_w) {
- changed = true;
- view->x += dx;
- view->width -= dx;
- edge += WLC_RESIZE_EDGE_LEFT;
- }
- }
- }
-
- if (dy < 0) {
- if (!pointer_state.lock.bottom) {
- if (view->height > min_sane_h) {
- changed = true;
- view->height += dy;
- edge += WLC_RESIZE_EDGE_BOTTOM;
- }
- } else if (pointer_state.origin.y < midway_y && !pointer_state.lock.top) {
- changed = true;
- view->y += dy;
- view->height -= dy;
- edge += WLC_RESIZE_EDGE_TOP;
- }
- } else if (dy > 0) {
- if (pointer_state.origin.y > midway_y && !pointer_state.lock.bottom) {
- changed = true;
- view->height += dy;
- edge += WLC_RESIZE_EDGE_BOTTOM;
- } else if (!pointer_state.lock.top) {
- if (view->height > min_sane_h) {
- changed = true;
- view->y += dy;
- view->height -= dy;
- edge += WLC_RESIZE_EDGE_TOP;
- }
- }
- }
- if (changed) {
- struct wlc_geometry geometry = {
- .origin = {
- .x = view->x,
- .y = view->y
- },
- .size = {
- .w = view->width,
- .h = view->height
- }
- };
- wlc_view_set_geometry(view->handle, edge, &geometry);
- }
- return changed;
-}
-
bool resize_tiled(int amount, bool use_width) {
swayc_t *parent = get_focused_view(swayc_active_workspace());
swayc_t *focused = parent;