]> git.lizzy.rs Git - bspwm.git/commitdiff
Use absolute coordinates when resizing manually
authorBastien Dejean <nihilhill@gmail.com>
Fri, 29 Dec 2017 14:31:15 +0000 (15:31 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Fri, 29 Dec 2017 14:31:15 +0000 (15:31 +0100)
Fixes #752.

src/messages.c
src/pointer.c
src/window.c
src/window.h

index 3f80f9db7c19cd97f7df744acae46e536f9a87b8..ce0721a05c3ac301b1670863c37e1bd2dc64ae7f 100644 (file)
@@ -412,7 +412,7 @@ void cmd_node(char **args, int num, FILE *rsp)
                                if (sscanf(*args, "%i", &dx) == 1) {
                                        num--, args++;
                                        if (sscanf(*args, "%i", &dy) == 1) {
-                                               if (!resize_client(&trg, rh, dx, dy)) {
+                                               if (!resize_client(&trg, rh, dx, dy, true)) {
                                                        fail(rsp, "");
                                                        break;
                                                }
index baf979c68526c3423531a9ed35bcfb30856ad69d..c3f370866aafa0e9a7d1e9520c5eb7d12a22868c 100644 (file)
@@ -282,7 +282,7 @@ void track_pointer(coordinates_t loc, pointer_action_t pac, xcb_point_t pos)
                        if (pac == ACTION_MOVE) {
                                move_client(&loc, dx, dy);
                        } else {
-                               resize_client(&loc, rh, dx, dy);
+                               resize_client(&loc, rh, e->root_x, e->root_y, false);
                        }
                        last_motion_x = e->root_x;
                        last_motion_y = e->root_y;
index a330e8f91a3721460d6ed66dc4abea1dcf270020..22e20f75d7a9c84342bc8e8c74bdc9468856822a 100644 (file)
@@ -529,7 +529,7 @@ bool move_client(coordinates_t *loc, int dx, int dy)
        return true;
 }
 
-bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy)
+bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy, bool relative)
 {
        node_t *n = loc->node;
        if (n == NULL || n->client == NULL || n->client->state == STATE_FULLSCREEN) {
@@ -554,21 +554,45 @@ bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy)
                        return false;
                }
                if (vertical_fence != NULL) {
-                       double sr = vertical_fence->split_ratio + (double) dx / vertical_fence->rectangle.width;
+                       double sr = 0.0;
+                       if (relative) {
+                               sr = vertical_fence->split_ratio + (double) dx / (double) vertical_fence->rectangle.width;
+                       } else {
+                               sr = (double) (dx - vertical_fence->rectangle.x) / (double) vertical_fence->rectangle.width;
+                       }
                        sr = MAX(0, sr);
                        sr = MIN(1, sr);
                        vertical_fence->split_ratio = sr;
                }
                if (horizontal_fence != NULL) {
-                       double sr = horizontal_fence->split_ratio + (double) dy / horizontal_fence->rectangle.height;
+                       double sr = 0.0;
+                       if (relative) {
+                               sr = horizontal_fence->split_ratio + (double) dy / (double) horizontal_fence->rectangle.height;
+                       } else {
+                               sr = (double) (dy - horizontal_fence->rectangle.y) / (double) horizontal_fence->rectangle.height;
+                       }
                        sr = MAX(0, sr);
                        sr = MIN(1, sr);
                        horizontal_fence->split_ratio = sr;
                }
                arrange(loc->monitor, loc->desktop);
        } else {
-               int w = width + dx * (rh & HANDLE_LEFT ? -1 : (rh & HANDLE_RIGHT ? 1 : 0));
-               int h = height + dy * (rh & HANDLE_TOP ? -1 : (rh & HANDLE_BOTTOM ? 1 : 0));
+               int w = width, h = height;
+               if (relative) {
+                       w += dx * (rh & HANDLE_LEFT ? -1 : (rh & HANDLE_RIGHT ? 1 : 0));
+                       h += dy * (rh & HANDLE_TOP ? -1 : (rh & HANDLE_BOTTOM ? 1 : 0));
+               } else {
+                       if (rh & HANDLE_LEFT) {
+                               w = x + width - dx;
+                       } else if (rh & HANDLE_RIGHT) {
+                               w = dx - x;
+                       }
+                       if (rh & HANDLE_TOP) {
+                               h = y + height - dy;
+                       } else if (rh & HANDLE_BOTTOM) {
+                               h = dy - y;
+                       }
+               }
                width = MAX(1, w);
                height = MAX(1, h);
                apply_size_hints(n->client, &width, &height);
index 9cad0fdd01edfb1787ad7bd7f49a77c8c05f1cb5..7b5376ef1265aca1953d639441b963de7659b0ed 100644 (file)
@@ -50,7 +50,7 @@ uint32_t get_border_color(bool focused_node, bool focused_monitor);
 void initialize_floating_rectangle(node_t *n);
 xcb_rectangle_t get_window_rectangle(node_t *n);
 bool move_client(coordinates_t *loc, int dx, int dy);
-bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy);
+bool resize_client(coordinates_t *loc, resize_handle_t rh, int dx, int dy, bool relative);
 void apply_size_hints(client_t *c, uint16_t *width, uint16_t *height);
 void query_pointer(xcb_window_t *win, xcb_point_t *pt);
 void update_motion_recorder(void);