#define INCLUDE_DEFS
#include "config.h"
+#define BARHEIGHT(x) \
+ ((x)->font->height + 3)
+
typedef struct Client {
struct Client *next, *prev;
Window win;
XConf X = {0};
Client* Clients = NULL;
Cursor Move_Cursor;
+int StartY = 0;
/* configuration */
uint32_t BorderWidth = 1;
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) {
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);
}
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;