{
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);
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)
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;
Window root;
unsigned long black, white, gray;
int start_x, start_y;
+ int reshaping;
void (*eventfns[LASTEvent])(XEvent*);
} XConf;
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);
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 */