]> git.lizzy.rs Git - bspwm.git/commitdiff
New 'grab_pointer' argument: 'resize_side'
authorBastien Dejean <nihilhill@gmail.com>
Thu, 28 Feb 2013 11:27:26 +0000 (12:27 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Thu, 28 Feb 2013 11:27:26 +0000 (12:27 +0100)
The 'resize' argument is now called 'resize_corner'.

README.md
bspwm.1
events.c
messages.c
types.h

index cb84e30db52157620acdb87bb3e6880402aa8d9a..fcc6b60e566d72b8587b79ec58571ed954c01bda 100644 (file)
--- a/README.md
+++ b/README.md
@@ -115,7 +115,7 @@ The following messages are handled:
 
 - `circulate forward|backward` — Circulate the leaves in the given direction.
 
-- `grab_pointer move|resize|focus|move_tiled|resize_tiled` — Begin the specified pointer action.
+- `grab_pointer move|resize_corner|resize_side|focus|move_tiled|resize_tiled` — Begin the specified pointer action.
 
 - `track_pointer ROOT_X ROOT_Y` — Pass the pointer root coordinates for the current pointer action.
 
diff --git a/bspwm.1 b/bspwm.1
index 84125f2f4d399047e8daf215741351c4352da777..811a44337e29c800f7775261be5bb9a66bd11214 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -159,7 +159,7 @@ Focus the nearest window matching the given constraints.
 .BI circulate " forward|backward"
 Circulate the leaves in the given direction.
 .TP
-.BI grab_pointer " move|resize|focus|move_tiled|resize_tiled"
+.BI grab_pointer " move|resize_corner|resize_side|focus|move_tiled|resize_tiled"
 Begin the specified pointer action.
 .TP
 .BI track_pointer " ROOT_X ROOT_Y"
index d9f7290fbb1eed6be8d0a6e57ade515e5ed22c20..7847a93fd9b4fd820bb09fce138c741048acfcfd 100644 (file)
--- a/events.c
+++ b/events.c
@@ -299,7 +299,8 @@ void grab_pointer(pointer_action_t pac)
                 focus_node(loc.monitor, loc.desktop, loc.node, true);
                 break;
             case ACTION_MOVE:
-            case ACTION_RESIZE:
+            case ACTION_RESIZE_SIDE:
+            case ACTION_RESIZE_CORNER:
                 if (is_tiled(c)) {
                     loc.node->client->floating_rectangle = c->tiled_rectangle;
                     toggle_floating(loc.node);
@@ -309,20 +310,41 @@ void grab_pointer(pointer_action_t pac)
                     return;
                 }
                 frozen_pointer->rectangle = c->floating_rectangle;
-                if (pac == ACTION_RESIZE) {
+
+                if (pac == ACTION_RESIZE_SIDE) {
+                    float W = c->floating_rectangle.width;
+                    float H = c->floating_rectangle.height;
+                    float ratio = W / H;
+                    float x = pos.x - c->floating_rectangle.x;
+                    float y = pos.y - c->floating_rectangle.y;
+                    float diag_a = ratio * y;
+                    float diag_b = c->floating_rectangle.width - diag_a;
+
+                    if (x < diag_a) {
+                        if (x < diag_b)
+                            frozen_pointer->side = SIDE_LEFT;
+                        else
+                            frozen_pointer->side = SIDE_BOTTOM;
+                    } else {
+                        if (x < diag_b)
+                            frozen_pointer->side = SIDE_TOP;
+                        else
+                            frozen_pointer->side = SIDE_RIGHT;
+                    }
+                } else if (pac == ACTION_RESIZE_CORNER) {
                     int16_t mid_x, mid_y;
                     mid_x = c->floating_rectangle.x + (c->floating_rectangle.width / 2);
                     mid_y = c->floating_rectangle.y + (c->floating_rectangle.height / 2);
                     if (pos.x > mid_x) {
                         if (pos.y > mid_y)
-                            frozen_pointer->corner = BOTTOM_RIGHT;
+                            frozen_pointer->corner = CORNER_BOTTOM_RIGHT;
                         else
-                            frozen_pointer->corner = TOP_RIGHT;
+                            frozen_pointer->corner = CORNER_TOP_RIGHT;
                     } else {
                         if (pos.y > mid_y)
-                            frozen_pointer->corner = BOTTOM_LEFT;
+                            frozen_pointer->corner = CORNER_BOTTOM_LEFT;
                         else
-                            frozen_pointer->corner = TOP_LEFT;
+                            frozen_pointer->corner = CORNER_TOP_LEFT;
                     }
                 }
                 break;
@@ -379,27 +401,60 @@ void track_pointer(int root_x, int root_y)
             y = rect.y + delta_y;
             window_move(win, x, y);
             break;
-        case ACTION_RESIZE:
+        case ACTION_RESIZE_SIDE:
+            switch (frozen_pointer->side) {
+                case SIDE_TOP:
+                    x = rect.x;
+                    y = rect.y + delta_y;
+                    w = rect.width;
+                    h = rect.height - delta_y;
+                    break;
+                case SIDE_RIGHT:
+                    x = rect.x;
+                    y = rect.y;
+                    w = rect.width + delta_x;
+                    h = rect.height;
+                    break;
+                case SIDE_BOTTOM:
+                    x = rect.x;
+                    y = rect.y;
+                    w = rect.width;
+                    h = rect.height + delta_y;
+                    break;
+                case SIDE_LEFT:
+                    x = rect.x + delta_x;
+                    y = rect.y;
+                    w = rect.width - delta_x;
+                    h = rect.height;
+                    break;
+            }
+            width = MAX(1, w);
+            height = MAX(1, h);
+            window_move_resize(win, x, y, width, height);
+            c->floating_rectangle = (xcb_rectangle_t) {x, y, width, height};
+            window_draw_border(n, d->focus == n, mon == m);
+            break;
+        case ACTION_RESIZE_CORNER:
             switch (frozen_pointer->corner) {
-                case TOP_LEFT:
+                case CORNER_TOP_LEFT:
                     x = rect.x + delta_x;
                     y = rect.y + delta_y;
                     w = rect.width - delta_x;
                     h = rect.height - delta_y;
                     break;
-                case TOP_RIGHT:
+                case CORNER_TOP_RIGHT:
                     x = rect.x;
                     y = rect.y + delta_y;
                     w = rect.width + delta_x;
                     h = rect.height - delta_y;
                     break;
-                case BOTTOM_LEFT:
+                case CORNER_BOTTOM_LEFT:
                     x = rect.x + delta_x;
                     y = rect.y;
                     w = rect.width - delta_x;
                     h = rect.height + delta_y;
                     break;
-                case BOTTOM_RIGHT:
+                case CORNER_BOTTOM_RIGHT:
                     x = rect.x;
                     y = rect.y;
                     w = rect.width + delta_x;
index 530670451a9d4d97080f8ae8d6f1c22d95670aa6..c1442c8600f8c8998737ec08f9b6f53588908514 100644 (file)
@@ -759,8 +759,11 @@ bool parse_pointer_action(char *s, pointer_action_t *a)
     if (strcmp(s, "move") == 0) {
         *a = ACTION_MOVE;
         return true;
-    } else if (strcmp(s, "resize") == 0) {
-        *a = ACTION_RESIZE;
+    } else if (strcmp(s, "resize_corner") == 0) {
+        *a = ACTION_RESIZE_CORNER;
+        return true;
+    } else if (strcmp(s, "resize_side") == 0) {
+        *a = ACTION_RESIZE_SIDE;
         return true;
     } else if (strcmp(s, "focus") == 0) {
         *a = ACTION_FOCUS;
diff --git a/types.h b/types.h
index 683ca8b4cb98c70833b8290d6fdfb7c049bb48d0..6477aa1b790f12df572c45a281030cfc3589a1e0 100644 (file)
--- a/types.h
+++ b/types.h
@@ -94,16 +94,24 @@ typedef enum {
 } direction_t;
 
 typedef enum {
-    TOP_LEFT,
-    TOP_RIGHT,
-    BOTTOM_LEFT,
-    BOTTOM_RIGHT
+    CORNER_TOP_LEFT,
+    CORNER_TOP_RIGHT,
+    CORNER_BOTTOM_LEFT,
+    CORNER_BOTTOM_RIGHT
 } corner_t;
 
+typedef enum {
+    SIDE_LEFT,
+    SIDE_TOP,
+    SIDE_RIGHT,
+    SIDE_BOTTOM
+} side_t;
+
 typedef enum {
     ACTION_NONE,
     ACTION_MOVE,
-    ACTION_RESIZE,
+    ACTION_RESIZE_CORNER,
+    ACTION_RESIZE_SIDE,
     ACTION_FOCUS,
     ACTION_MOVE_TILED,
     ACTION_RESIZE_TILED
@@ -203,6 +211,7 @@ typedef struct {
     client_t *client;
     xcb_window_t window;
     corner_t corner;
+    side_t side;
 } pointer_state_t;
 
 typedef struct {