]> git.mdlowis.com Git - proto/anvil.git/commitdiff
added logic to resize existing windows
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 11 Mar 2020 17:02:34 +0000 (13:02 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 11 Mar 2020 17:02:34 +0000 (13:02 -0400)
anvil.c
anvil.h
client.c

diff --git a/anvil.c b/anvil.c
index b32b1a0c1fa3f93e3b91a0afd0f98e354a62374e..e74254bc6ed3b44f26831b08083cf80786fc51d6 100644 (file)
--- a/anvil.c
+++ b/anvil.c
@@ -19,13 +19,17 @@ static void xbtnpress(XEvent* e)
     {
         if (ev->button == Button1) {
            client_raise(c);
-           if (ev->y < (TITLE_HEIGHT + BORDER_WIDTH)) {
-                X.start_x = ev->x_root;
-                X.start_y = ev->y_root;
-            }
-            else
+            X.start_x = ev->x_root;
+            X.start_y = ev->y_root;
+            if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))
             {
-                /* TODO: warp the pointer and resize the window*/
+                X.reshaping = 1;
+                XWarpPointer(X.disp, None, ev->window, 0, 0, 0, 0,
+                    c->w + 2*BORDER_WIDTH,
+                    c->h + 2*BORDER_WIDTH + TITLE_HEIGHT
+                );
+                X.start_x = c->x + c->w + 2*BORDER_WIDTH;
+                X.start_y = c->y + c->h + 2*BORDER_WIDTH + TITLE_HEIGHT;
             }
         } else if (ev->button == Button2) {
             client_close(c);
@@ -38,6 +42,12 @@ static void xbtnpress(XEvent* e)
 static void xbtnrelease(XEvent* e)
 {
     (void)e;
+    X.reshaping = 0;
+}
+
+static inline int PRESSED(int mods, int btn)
+{
+    return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
 }
 
 static void xbtnmotion(XEvent* e)
@@ -47,7 +57,17 @@ static void xbtnmotion(XEvent* e)
     if (c && (ev->window == c->frame))
     {
         /* TODO: only move window if Button1 held */
-        client_move(c, ev->x_root - X.start_x, ev->y_root - X.start_y);
+        if (PRESSED(ev->state, Button1))
+        {
+            if (!X.reshaping)
+            {
+                client_move(c, ev->x_root - X.start_x, ev->y_root - X.start_y);
+            }
+            else
+            {
+                client_resize(c, ev->x_root - X.start_x, ev->y_root - X.start_y);
+            }
+        }
     }
     X.start_x = ev->x_root;
     X.start_y = ev->y_root;
diff --git a/anvil.h b/anvil.h
index 3988f323ea77fb426cd6f9e358adbba53f43699b..ed2354098b59dd75384c6a2f9085df29042b5c59 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -20,6 +20,7 @@ typedef struct {
     Window root;
     unsigned long black, white, gray;
     int start_x, start_y;
+    int reshaping;
     void (*eventfns[LASTEvent])(XEvent*);
 } XConf;
 
@@ -70,6 +71,7 @@ Client* client_get(Window w);
 void client_raise(Client* c);
 void client_lower(Client* c);
 void client_move(Client* c, int xdiff, int ydiff);
+void client_resize(Client* c, int xdiff, int ydiff);
 void client_close(Client* c);
 void client_focus(Client* c);
 
index fe98ed5a9b80a1c8feb21c7920dd0b2ebec9f3a1..88a3afedbd85b3943c55d9e9d6bcbf64232a02c0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -119,6 +119,18 @@ void client_move(Client* c, int xdiff, int ydiff)
     XSync(X.disp, False);
 }
 
+void client_resize(Client* c, int xdiff, int ydiff)
+{
+    c->w += xdiff;
+    c->h += ydiff;
+    if (c->w < 50) c->w = 50;
+    if (c->h < 50) c->h = 50;
+    XResizeWindow(X.disp, c->win, c->w, c->h);
+    XResizeWindow(X.disp, c->frame,
+        c->w + 2*BORDER_WIDTH,
+        c->h + 2*BORDER_WIDTH + TITLE_HEIGHT);
+}
+
 void client_close(Client* c)
 {
     /* TODO: handle wm_delete client message here */