diff options
| author | Patrick <devnull@mailinator.com> | 2015-10-15 15:38:05 +0800 |
|---|---|---|
| committer | Patrick <devnull@mailinator.com> | 2015-10-15 15:38:05 +0800 |
| commit | 00195baff8d1c3bea711a37852d26fc04edf0b2d (patch) | |
| tree | b4428090feb5e90ed7bba233dcb90ef8ac6941c3 /x-move-resize.c | |
| parent | 72197fa6a8a48682d54bd81d41ab5a00d56fd167 (diff) | |
switch to defined style standard
Diffstat (limited to 'x-move-resize.c')
| -rw-r--r-- | x-move-resize.c | 138 |
1 files changed, 70 insertions, 68 deletions
diff --git a/x-move-resize.c b/x-move-resize.c index bb673ac..45bbf9a 100644 --- a/x-move-resize.c +++ b/x-move-resize.c @@ -33,87 +33,89 @@ extern void exit(int code); // fun on down void configure(Display *d, Window *w, XWindowAttributes *wa) { - XConfigureEvent ce; - - ce.type = ConfigureNotify; - ce.display = d; - ce.event = *w; - ce.window = *w; - ce.x = wa->x; - ce.y = wa->y; - ce.width = wa->width; - ce.height = wa->height; - ce.border_width = 0; - ce.above = None; - ce.override_redirect = False; - XSendEvent(d, *w, False, StructureNotifyMask, (XEvent *)&ce); + XConfigureEvent ce; + + ce.type = ConfigureNotify; + ce.display = d; + ce.event = *w; + ce.window = *w; + ce.x = wa->x; + ce.y = wa->y; + ce.width = wa->width; + ce.height = wa->height; + ce.border_width = 0; + ce.above = None; + ce.override_redirect = False; + XSendEvent(d, *w, False, StructureNotifyMask, (XEvent *)&ce); } void die(Display *dpy, int return_value) { - XUngrabPointer(dpy, CurrentTime); - XFreeCursor (dpy, cursor); - XSync (dpy, DefaultRootWindow(dpy)); - XCloseDisplay(dpy); - exit(return_value); + XUngrabPointer(dpy, CurrentTime); + XFreeCursor (dpy, cursor); + XSync (dpy, DefaultRootWindow(dpy)); + XCloseDisplay(dpy); + exit(return_value); } void buttonpress(Display *dpy, XEvent *e) { - XEvent ev = *e; - Window root = DefaultRootWindow(dpy); - if (ev.xbutton.subwindow == None) - return; - XUngrabPointer(dpy, root); - XSync(dpy, root); - if (XGrabPointer (dpy, ev.xbutton.subwindow, False, (PointerMotionMask | ButtonReleaseMask), - GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) - die(dpy, 1); - XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr); - start = ev.xbutton; + XEvent ev = *e; + Window root = DefaultRootWindow(dpy); + if (ev.xbutton.subwindow == None) + return; + XUngrabPointer(dpy, root); + XSync(dpy, root); + if (XGrabPointer (dpy, ev.xbutton.subwindow, False, (PointerMotionMask | ButtonReleaseMask), + GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) + die(dpy, 1); + XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr); + start = ev.xbutton; } void motionnotify(Display *dpy, XEvent *e) { - int xdiff, ydiff; - XEvent ev = *e; - - while (XCheckTypedEvent(dpy, MotionNotify, &ev)); - xdiff = ev.xbutton.x_root - start.x_root; - ydiff = ev.xbutton.y_root - start.y_root; - XMoveResizeWindow(dpy, ev.xmotion.window, - attr.x + (start.button==1 ? xdiff : 0), - attr.y + (start.button==1 ? ydiff : 0), - MAX(1, attr.width + (start.button==3 ? xdiff : 0)), - MAX(1, attr.height + (start.button==3 ? ydiff : 0))); - if (start.button == 1) - return; + int xdiff, ydiff; + XEvent ev = *e; + + while (XCheckTypedEvent(dpy, MotionNotify, &ev)); + xdiff = ev.xbutton.x_root - start.x_root; + ydiff = ev.xbutton.y_root - start.y_root; + XMoveResizeWindow(dpy, ev.xmotion.window, + attr.x + (start.button==1 ? xdiff : 0), + attr.y + (start.button==1 ? ydiff : 0), + MAX(1, attr.width + (start.button==3 ? xdiff : 0)), + MAX(1, attr.height + (start.button==3 ? ydiff : 0))); + if (start.button == 1) + return; } void buttonrelease(Display *dpy, XEvent *e) { - die(dpy, 0); + die(dpy, 0); } int main() { - Display * dpy; - Window root; - XEvent ev; - void (*handler[LASTEvent]) (Display *d, XEvent *) = { - [ButtonPress] = buttonpress, - [ButtonRelease] = buttonrelease, - [MotionNotify] = motionnotify, - }; - int cursor_shape = XC_plus; - start.button = 0; start.x_root = 0; start.y_root = 0; - - if(!(dpy = XOpenDisplay(0x0))) return 1; - - root = DefaultRootWindow(dpy); - cursor = XCreateFontCursor(dpy, cursor_shape); - if (XGrabPointer (dpy, root, False, (ButtonPressMask), - GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) - die(dpy, 1); - - for(;;) { - XNextEvent(dpy, &ev); - if(handler[ev.type]) - handler[ev.type](dpy, &ev); - } + Display * dpy; + Window root; + XEvent ev; + void (*handler[LASTEvent]) (Display *d, XEvent *) = { + [ButtonPress] = buttonpress, + [ButtonRelease] = buttonrelease, + [MotionNotify] = motionnotify, + }; + int cursor_shape = XC_plus; + start.button = 0; + start.x_root = 0; + start.y_root = 0; + + if(!(dpy = XOpenDisplay(0x0))) return 1; + + root = DefaultRootWindow(dpy); + cursor = XCreateFontCursor(dpy, cursor_shape); + if (XGrabPointer (dpy, root, False, (ButtonPressMask), + GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess) + die(dpy, 1); + + for(;;) { + XNextEvent(dpy, &ev); + if(handler[ev.type]) + handler[ev.type](dpy, &ev); + } } |
