wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 16cdf68c70b7813cf8d7d68e6023421f43be6cb4
parent 7199cfcaeb11b4ae760f534c3c0690893fb5bf94
Author: Kris Maglione <jg@suckless.org>
Date:   Tue, 20 Feb 2007 18:29:16 -0500

Change the window cursor when over the border for resizal (the border is still too small for this to be useful

Diffstat:
client.c | 11+++++++++++
event.c | 27++++++++++++++++++++++-----
geom.c | 16++++++++++++++++
main.c | 5++++-
mouse.c | 26+++++++++++++++-----------
wmii.h | 6+++++-
6 files changed, 73 insertions(+), 18 deletions(-)

diff --git a/client.c b/client.c @@ -251,6 +251,17 @@ unmap_client(Client *c, int state) { } void +set_cursor(Client *c, Cursor cur) { + XSetWindowAttributes wa; + + if(c->cursor != cur) { + c->cursor = cur; + wa.cursor = cur; + XChangeWindowAttributes(blz.dpy, c->framewin, CWCursor, &wa); + } +} + +void map_frame(Client *c) { if(!c->frame_mapped) { XMapWindow(blz.dpy, c->framewin); diff --git a/event.c b/event.c @@ -251,6 +251,21 @@ maprequest(XEvent *e) { } static void +motionnotify(XEvent *e) { + XMotionEvent *ev = &e->xmotion; + Cursor cur; + Frame *f; + + if((f = frame_of_win(ev->window))) { + if(!ispointinrect(ev->x, ev->y, &f->titlebar)) { + cur = cursor_of_quad(quadofcoord(&f->rect, ev->x_root, ev->y_root)); + set_cursor(f->client, cur); + }else + set_cursor(f->client, cursor[CurNormal]); + } +} + +static void propertynotify(XEvent *e) { XPropertyEvent *ev = &e->xproperty; Client *c; @@ -344,18 +359,20 @@ focusout(XEvent *e) { void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, [ButtonRelease] = buttonrelease, - [ConfigureRequest]= configurerequest, + [ConfigureRequest]=configurerequest, [DestroyNotify] = destroynotify, [EnterNotify] = enternotify, - [LeaveNotify] = leavenotify, [Expose] = expose, + [FocusIn] = focusin, + [FocusOut] = focusout, [KeyPress] = keypress, - [MappingNotify] = mappingnotify, + [LeaveNotify] = leavenotify, [MapRequest] = maprequest, + [MappingNotify] = mappingnotify, + [MotionNotify] = motionnotify, [PropertyNotify]= propertynotify, [UnmapNotify] = unmapnotify, - [FocusIn] = focusin, - [FocusOut] = focusout + }; void diff --git a/geom.c b/geom.c @@ -27,6 +27,22 @@ quadofcoord(XRectangle *rect, int x, int y) { return ret; } +Cursor +cursor_of_quad(BlitzAlign align) { + switch(align) { + case NEAST: + return cursor[CurNECorner]; + case NWEST: + return cursor[CurNWCorner]; + case SEAST: + return cursor[CurSECorner]; + case SWEST: + return cursor[CurSWCorner]; + default: + return cursor[CurMove]; + } +} + /* Syntax: <x> <y> <width> <height> */ int strtorect(XRectangle *r, const char *val) { diff --git a/main.c b/main.c @@ -119,7 +119,10 @@ init_cursors() { pix = XCreateBitmapFromData(blz.dpy, blz.root, (char[]){0}, 1, 1); cursor[CurNormal] = XCreateFontCursor(blz.dpy, XC_left_ptr); - cursor[CurResize] = XCreateFontCursor(blz.dpy, XC_sizing); + cursor[CurNECorner] = XCreateFontCursor(blz.dpy, XC_top_right_corner); + cursor[CurNWCorner] = XCreateFontCursor(blz.dpy, XC_top_left_corner); + cursor[CurSECorner] = XCreateFontCursor(blz.dpy, XC_bottom_right_corner); + cursor[CurSWCorner] = XCreateFontCursor(blz.dpy, XC_bottom_left_corner); cursor[CurMove] = XCreateFontCursor(blz.dpy, XC_fleur); cursor[CurInput] = XCreateFontCursor(blz.dpy, XC_xterm); cursor[CurInvisible] = XCreatePixmapCursor(blz.dpy, pix, pix, &black, &black, 0, 0); diff --git a/mouse.c b/mouse.c @@ -332,7 +332,7 @@ do_mouse_resize(Client *c, Bool grabbox, BlitzAlign align) { f = c->sel; floating = f->area->floating; origin = frect = f->rect; - cur = cursor[CurResize]; + cur = cursor_of_quad(align); if(floating) { rects = rects_of_view(f->area->view, &num, (grabbox ? c->frame : nil)); snap = screen->rect.height / 66; @@ -342,23 +342,27 @@ do_mouse_resize(Client *c, Bool grabbox, BlitzAlign align) { } if(align == CENTER) { - if(grabbox) - cur = cursor[CurMove]; - else + if(!grabbox) cur = cursor[CurInvisible]; - } - - if(!floating && (align == CENTER)) { - do_managed_move(c); - return; + if(!floating) + do_managed_move(c); } XQueryPointer(blz.dpy, c->framewin, &dummy, &dummy, &i, &i, &pt_x, &pt_y, &di); rx = (float)pt_x / frect.width; ry = (float)pt_y / frect.height; - if(XGrabPointer(blz.dpy, c->framewin, False, MouseMask, GrabModeAsync, GrabModeAsync, - None, cur, CurrentTime) != GrabSuccess) + if(XGrabPointer( + /* display */ blz.dpy, + /* window */ c->framewin, + /* owner_events */ False, + /* event_mask */ MouseMask, + /* pointer_mode */ GrabModeAsync, + /* keyboard_mode */ GrabModeAsync, + /* confine_to */ None, + /* cursor */ cur, + /* time */ CurrentTime + ) != GrabSuccess) return; XQueryPointer(blz.dpy, blz.root, &dummy, &dummy, &i, &i, &pt_x, &pt_y, &di); diff --git a/wmii.h b/wmii.h @@ -91,7 +91,8 @@ enum { NetSupported, NetWMName, NetLast }; enum { Coldefault, Colstack, Colmax }; /* Cursor */ -enum { CurNormal, CurResize, CurMove, CurInput, CurInvisible, CurLast }; +enum { CurNormal, CurNECorner, CurNWCorner, CurSECorner, CurSWCorner, + CurMove, CurInput, CurInvisible, CurLast }; enum { NCOL = 16 }; enum { WM_PROTOCOL_DELWIN = 1 }; @@ -164,6 +165,7 @@ struct Client { Window win; Window trans; Window framewin; + Cursor cursor; XRectangle rect; XSizeHints size; GC gc; @@ -293,6 +295,7 @@ extern void map_client(Client *c); extern void unmap_client(Client *c, int state); extern void map_frame(Client *c); extern void unmap_frame(Client *c); +extern void set_cursor(Client *c, Cursor cur); extern void focus_frame(Frame *f, Bool restack); extern void reparent_client(Client *c, Window w, int x, int y); extern void manage_client(Client *c); @@ -368,6 +371,7 @@ extern void write_event(char *format, ...); /* geom.c */ extern Bool ispointinrect(int x, int y, XRectangle * r); extern BlitzAlign quadofcoord(XRectangle *rect, int x, int y); +extern Cursor cursor_of_quad(BlitzAlign align); extern int strtorect(XRectangle *r, const char *val); extern BlitzAlign get_sticky(XRectangle *src, XRectangle *dst); extern int r_east(XRectangle *r);