]> git.mdlowis.com Git - projs/tide.git/commitdiff
resize based on titlebar
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 18 Jun 2019 01:37:08 +0000 (21:37 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 18 Jun 2019 01:37:08 +0000 (21:37 -0400)
src/anvil.c

index a9c100c4d27403bea9fcf99bd769144c6c396ff7..0e28a3fcd6c98a18eaad649acc3cc1a83986de82 100644 (file)
@@ -11,6 +11,9 @@
 #define INCLUDE_DEFS
 #include "config.h"
 
+#define BARHEIGHT(x) \
+    ((x)->font->height + 3)
+
 typedef struct Client {
     struct Client *next, *prev;
     Window win;
@@ -23,6 +26,7 @@ typedef struct Client {
 XConf X = {0};
 Client* Clients = NULL;
 Cursor Move_Cursor;
+int StartY = 0;
 
 /* configuration */
 uint32_t BorderWidth = 1;
@@ -60,11 +64,15 @@ void client_del(Client* c) {
     if (Clients == c) Clients = c->next;
 }
 
+void client_reconfig(XConf* xs, Client* c) {
+    int height = xs->font->height + 3;
+    XMoveResizeWindow(xs->display, c->frame, c->x, c->y,          c->w - 2, height);
+    XMoveResizeWindow(xs->display, c->win,   c->x, c->y + height, c->w - 2, c->h - height - 2);
+}
+
 void client_config(XConf* xs, Client* c, int x, int y, int w, int h) {
     c->x = x, c->y = y, c->w = w, c->h = h;
-    int height = xs->font->height + 3;
-    XMoveResizeWindow(xs->display, c->frame, x, y, c->w-2, height);
-    XMoveResizeWindow(xs->display, c->win,   x, y + height, c->w - 2, c->h - height - 2);
+    client_reconfig(xs, c);
 }
 
 void client_raise(XConf* x, Client* c) {
@@ -145,29 +153,59 @@ void client_redraw(XConf* x, Client* c) {
     XftColorFree(x->display, x->visual, x->colormap, &clr);
 }
 
+void client_resize(XConf* x, Client* c, int dir) {
+    if (!c->prev) return;
+    Client* prev = c->prev;
+
+    int sh = HeightOfScreen(DefaultScreenOfDisplay(x->display));
+    int miny = prev->y + BARHEIGHT(x);
+    int maxy = (c->next ? c->next->y : sh) - BARHEIGHT(x);
+    int newy = min(max(miny, (c->y + dir)), maxy);
+
+    prev->h = newy - prev->y;
+    if (c->next)
+        c->h = c->next->y - newy;
+    else
+        c->h = sh - newy;
+    c->y = newy;
+
+    client_reconfig(x, prev);
+    client_reconfig(x, c);
+}
+
 /* X11 Event Handling
  *****************************************************************************/
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-parameter"
-Cursor cursor;
+
+/*
+    * B1 Grow window a little
+    * B1 Drag: Resize vertically or  move to column
+    * B2: Stack windows with titlebars visible but only one window expanded
+    * B3: Maximize in column
+    * B1+B2: Kill window
+    * Shift+B1: Move one column to the left
+    * Shift+B1: Move one column to the right
+*/
+
 static void xbtnpress(XConf* x, XEvent* e) {
     printf("btn\n");
-    /*
-        * B1 Grow window a little
-        * B1 Drag: Resize vertically or  move to column
-        * B2: Stack windows with titlebars visible but only one window expanded
-        * B3: Maximize in column
-        * B1+B2: Kill window
-        * Shift+B1: Move one column to the left
-        * Shift+B1: Move one column to the right
-    */
     Client* c = client_find(e->xbutton.window);
     if (c && c->frame == e->xbutton.window) {
-        if (ButtonPress == e->type)
-            XDefineCursor(X.display, e->xbutton.window, Move_Cursor);
-        else
-            XUndefineCursor(X.display, e->xbutton.window);
+        XDefineCursor(X.display, e->xbutton.window, Move_Cursor);
+        StartY = e->xbutton.y;
+    }
+    XSync(X.display, False);
+}
+
+static void xbtnrelease(XConf* x, XEvent* e) {
+    printf("btn\n");
+    Client* c = client_find(e->xbutton.window);
+    if (c && c->frame == e->xbutton.window) {
+        XUndefineCursor(X.display, e->xbutton.window);
+        printf("moved: %d\n", e->xbutton.y - StartY);
+        client_resize(x, c, e->xbutton.y - StartY);
     }
     XSync(X.display, False);
 }
@@ -268,7 +306,7 @@ int main(void) {
 
     Move_Cursor = XCreateFontCursor(X.display, XC_draped_box);
     X.eventfns[ButtonPress] = xbtnpress;
-    X.eventfns[ButtonRelease] = xbtnpress;
+    X.eventfns[ButtonRelease] = xbtnrelease;
     X.eventfns[ConfigureRequest] = xconfigrequest;
     X.eventfns[MapRequest] = xmaprequest;
     X.eventfns[UnmapNotify] = xunmapnotify;