return ((mods & (1 << (btn + 7))) == (1 << (btn + 7)));
}
+static void warp_mouse(Client* c)
+{
+ XWarpPointer(X.disp, None, c->frame, 0, 0, 0, 0,
+ c->w + 2*BORDER_WIDTH - BORDER_WIDTH/2,
+ c->h + 2*BORDER_WIDTH + TITLE_HEIGHT - BORDER_WIDTH/2
+ );
+ X.start_x = c->x + c->w + 4;
+ X.start_y = c->y + c->h + 4;
+}
+
static void xbtnpress(XEvent* e)
{
XButtonEvent* ev = &(e->xbutton);
if (ev->y > (TITLE_HEIGHT + BORDER_WIDTH))
{
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;
+ warp_mouse(c);
}
} else if (ev->button == Button2) {
client_close(c);
static void xbtnmotion(XEvent* e)
{
+ /* make sure we get just the latest event */
XMotionEvent *ev = &e->xmotion;
- while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e))
- {
- /* Keep grabbing them till we have no more to grab */
- }
-
+ while (XCheckTypedWindowEvent(X.disp, ev->window, ev->type, e));
Client* c = client_get(ev->window);
if (c && (ev->window == c->frame))
{
- /* TODO: only move window if Button1 held */
if (PRESSED(ev->state, Button1))
{
if (!X.reshaping)
c->w = wc.width;
c->h = wc.height;
client_resize(c, 0, 0);
+ if (X.reshaping && Focused == c)
+ {
+ warp_mouse(c);
+ }
}
}
int main(void)
{
- XColor color, exact;
-
+ XColor color, red, white, exact;
/* Initialize X server*/
check( (X.disp = XOpenDisplay(0)) != NULL,
"could not open display");
client_initall();
keys_init();
+ /* configure mouse cursors */
+ Colormap cmap = DefaultColormap(X.disp, X.screen);
+ X.csr_root = XCreateFontCursor(X.disp, XC_left_ptr);
+ XAllocNamedColor(X.disp, cmap, "red", &red, &exact);
+ XAllocNamedColor(X.disp, cmap, "white", &white, &exact);
+ X.csr_point = XCreateFontCursor(X.disp, XC_left_ptr);
+ XRecolorCursor(X.disp, X.csr_point, &red, &white);
+ XDefineCursor(X.disp, X.root, X.csr_root);
+
/* setup event handlers */
X.eventfns[ButtonPress] = xbtnpress;
X.eventfns[ButtonRelease] = xbtnrelease;