Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2010
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1. /* TinyWM is written by Nick Welch <mack@incise.org>, 2005.
  2.  *
  3.  * This software is in the public domain
  4.  * and is provided AS IS, with NO WARRANTY. */
  5.  
  6. #include <X11/Xlib.h>
  7.  
  8. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  9.  
  10. int main()
  11. {
  12.     Display * dpy;
  13.     Window root;
  14.     XWindowAttributes attr;
  15.     XButtonEvent start;
  16.     XEvent ev;
  17.  
  18.     if(!(dpy = XOpenDisplay(0x0))) return 1;
  19.  
  20.     root = DefaultRootWindow(dpy);
  21.  
  22.     XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("F1")), Mod1Mask, root,
  23.              True, GrabModeAsync, GrabModeAsync);
  24.     XGrabButton(dpy, 1, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync,
  25.                 GrabModeAsync, None, None);
  26.     XGrabButton(dpy, 3, Mod1Mask, root, True, ButtonPressMask, GrabModeAsync,
  27.                 GrabModeAsync, None, None);
  28.  
  29.     for(;;)
  30.     {
  31.         XNextEvent(dpy, &ev);
  32.         if(ev.type == KeyPress && ev.xkey.subwindow != None)
  33.             XRaiseWindow(dpy, ev.xkey.subwindow);
  34.         else if(ev.type == ButtonPress && ev.xbutton.subwindow != None)
  35.         {
  36.             XGrabPointer(dpy, ev.xbutton.subwindow, True,
  37.                          PointerMotionMask|ButtonReleaseMask, GrabModeAsync,
  38.                          GrabModeAsync, None, None, CurrentTime);
  39.             XGetWindowAttributes(dpy, ev.xbutton.subwindow, &attr);
  40.             start = ev.xbutton;
  41.         }
  42.         else if(ev.type == MotionNotify)
  43.         {
  44.             int xdiff, ydiff;
  45.             while(XCheckTypedEvent(dpy, MotionNotify, &ev));
  46.             xdiff = ev.xbutton.x_root - start.x_root;
  47.             ydiff = ev.xbutton.y_root - start.y_root;
  48.             XMoveResizeWindow(dpy, ev.xmotion.window,
  49.                               attr.x + (start.button==1 ? xdiff : 0),
  50.                               attr.y + (start.button==1 ? ydiff : 0),
  51.                               MAX(1, attr.width + (start.button==3 ? xdiff : 0)),
  52.                               MAX(1, attr.height + (start.button==3 ? ydiff : 0)));
  53.         }
  54.         else if(ev.type == ButtonRelease)
  55.             XUngrabPointer(dpy, CurrentTime);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement