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

From: Kris Maglione <jg_AT_suckless.org>
Date: Wed Feb 21 00:30:22 2007

changeset: 1916:b6ac1ecb0246
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Feb 20 18:29:16 2007 -0500
summary: Change the window cursor when over the border for resizal (the border is still too small for this to be useful

diff -r b8b3e0112a1e -r b6ac1ecb0246 client.c
--- a/client.c Tue Feb 20 17:33:26 2007 -0500
+++ b/client.c Tue Feb 20 18:29:16 2007 -0500
@@ -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 -r b8b3e0112a1e -r b6ac1ecb0246 event.c
--- a/event.c Tue Feb 20 17:33:26 2007 -0500
+++ b/event.c Tue Feb 20 18:29:16 2007 -0500
@@ -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 @@ void (*handler[LASTEvent]) (XEvent *) =
 void (*handler[LASTEvent]) (XEvent *) = {
         [ButtonPress] = buttonpress,
         [ButtonRelease] = buttonrelease,
- [ConfigureRequest]= configurerequest,
+ [ConfigureRequest]=configurerequest,
         [DestroyNotify] = destroynotify,
         [EnterNotify] = enternotify,
+ [Expose] = expose,
+ [FocusIn] = focusin,
+ [FocusOut] = focusout,
+ [KeyPress] = keypress,
         [LeaveNotify] = leavenotify,
- [Expose] = expose,
- [KeyPress] = keypress,
+ [MapRequest] = maprequest,
         [MappingNotify] = mappingnotify,
- [MapRequest] = maprequest,
+ [MotionNotify] = motionnotify,
         [PropertyNotify]= propertynotify,
         [UnmapNotify] = unmapnotify,
- [FocusIn] = focusin,
- [FocusOut] = focusout
+
 };
 
 void
diff -r b8b3e0112a1e -r b6ac1ecb0246 geom.c
--- a/geom.c Tue Feb 20 17:33:26 2007 -0500
+++ b/geom.c Tue Feb 20 18:29:16 2007 -0500
@@ -25,6 +25,22 @@ quadofcoord(XRectangle *rect, int x, int
                 ret |= SOUTH;
 
         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> */
diff -r b8b3e0112a1e -r b6ac1ecb0246 main.c
--- a/main.c Tue Feb 20 17:33:26 2007 -0500
+++ b/main.c Tue Feb 20 18:29:16 2007 -0500
@@ -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 -r b8b3e0112a1e -r b6ac1ecb0246 mouse.c
--- a/mouse.c Tue Feb 20 17:33:26 2007 -0500
+++ b/mouse.c Tue Feb 20 18:29:16 2007 -0500
@@ -332,7 +332,7 @@ do_mouse_resize(Client *c, Bool grabbox,
         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,
         }
 
         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 -r b8b3e0112a1e -r b6ac1ecb0246 wmii.h
--- a/wmii.h Tue Feb 20 17:33:26 2007 -0500
+++ b/wmii.h Tue Feb 20 18:29:16 2007 -0500
@@ -91,7 +91,8 @@ enum { Coldefault, Colstack, Colmax };
 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 unmap_client(Client *c, int
 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);
Received on Wed Feb 21 2007 - 00:30:22 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:55:34 UTC