Skip to content

Commit

Permalink
change the cursor to alert the user
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Haller committed Feb 28, 2011
1 parent 4cf1b3a commit df9f187
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions x-move-resize.c
@@ -1,3 +1,7 @@
/* I lifted the move-resize code from tinywm and
* added an extra pointer grab to set the cursor
*/

/* TinyWM is written by Nick Welch <mack AT incise.org>, 2005. /* TinyWM is written by Nick Welch <mack AT incise.org>, 2005.
* *
* This software is in the public domain * This software is in the public domain
Expand Down Expand Up @@ -43,52 +47,45 @@ static int interruptibleXNextEvent(Display *dpy, XEvent *event) {
} }
} }


int die(Display *dpy, int return_value) { int die(Display *dpy, Cursor *cursor, int return_value) {
XUngrabPointer(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime);
XFreeCursor (dpy, *cursor);
XSync (dpy, DefaultRootWindow(dpy));
XCloseDisplay(dpy); XCloseDisplay(dpy);
return return_value; return return_value;
} }


int main() int main()
{ {
Display * dpy; Display * dpy;
Window root; Window root;
XWindowAttributes attr; XWindowAttributes attr;
XButtonEvent start; XButtonEvent start;
XEvent ev; XEvent ev;
Cursor cursor; Cursor cursor;
int cursor_shape = XC_X_cursor; int cursor_shape = XC_plus;
start.button = 0; start.x_root = 0; start.y_root = 0; start.button = 0; start.x_root = 0; start.y_root = 0;


if(!(dpy = XOpenDisplay(0x0))) return 1; if(!(dpy = XOpenDisplay(0x0))) return 1;

root = DefaultRootWindow(dpy);

XGrabButton(dpy, 1, 0, root, True, ButtonPressMask, GrabModeAsync,
GrabModeAsync, None, None);
XGrabButton(dpy, 3, 0, root, True, ButtonPressMask, GrabModeAsync,
GrabModeAsync, None, None);



root = DefaultRootWindow(dpy);
cursor = XCreateFontCursor(dpy, cursor_shape); cursor = XCreateFontCursor(dpy, cursor_shape);
XDefineCursor(dpy, root, cursor); if (XGrabPointer (dpy, root, False, (ButtonPressMask),
XSync (dpy, root); /* give xterm a chance */
if (XGrabPointer (dpy, root, False, (ButtonPressMask | PointerMotionMask | ButtonReleaseMask),
GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
return die(dpy, 1); return die(dpy, &cursor, 1);


for(;;) for(;;) {
{
if (! interruptibleXNextEvent(dpy, &ev)) if (! interruptibleXNextEvent(dpy, &ev))
continue; continue;
switch(ev.type) { switch(ev.type) {
case ButtonPress: case ButtonPress:
if (ev.xbutton.subwindow == None) if (ev.xbutton.subwindow == None)
break; break;
if( XGrabPointer(dpy, ev.xbutton.subwindow, False, XUngrabPointer(dpy, root);
PointerMotionMask|ButtonReleaseMask, GrabModeAsync, XSync(dpy, root);
GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) if (XGrabPointer (dpy, ev.xbutton.subwindow, False, (PointerMotionMask | ButtonReleaseMask),
return die(dpy, 1); GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
return die(dpy, &cursor, 1);
XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr); XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
start = ev.xbutton; start = ev.xbutton;
break; break;
Expand All @@ -105,8 +102,8 @@ int main()
} }
break; break;
case ButtonRelease: case ButtonRelease:
return die(dpy, 0); return die(dpy, &cursor, 0);
break; break;
} }
} }
} }

0 comments on commit df9f187

Please sign in to comment.