|
| 1 | +import xlib, x |
| 2 | +converter toCint(x: TKeyCode): cint = x.cint |
| 3 | +converter int32toCUint(x: int32): cuint = x.cuint |
| 4 | +converter toTBool(x: bool): TBool = x.TBool |
| 5 | +converter toBool(x: TBool): bool = x.bool |
| 6 | + |
| 7 | +var |
| 8 | + attr: TXWindowAttributes |
| 9 | + start:TXButtonEvent |
| 10 | + ev:TXEvent |
| 11 | + |
| 12 | +var display = XOpenDisplay(nil) |
| 13 | +if display == nil: |
| 14 | + quit "Failed to open display" |
| 15 | + |
| 16 | +discard XGrabKey(display, XKeysymToKeycode(display, XStringToKeysym("F1")), Mod1Mask, |
| 17 | + DefaultRootWindow(display), true, GrabModeAsync, GrabModeAsync) |
| 18 | +discard XGrabButton(display, 1, Mod1Mask, DefaultRootWindow(display), true, |
| 19 | + ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None) |
| 20 | +discard XGrabButton(display, 3, Mod1Mask, DefaultRootWindow(display), true, |
| 21 | + ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None) |
| 22 | + |
| 23 | +start.subwindow = None |
| 24 | + |
| 25 | +while true: |
| 26 | + discard XNextEvent(display,ev.addr) |
| 27 | + |
| 28 | + if ev.theType == KeyPress and ev.xkey.subwindow != None: |
| 29 | + discard XRaiseWindow(display, ev.xkey.subwindow); |
| 30 | + elif ev.theType == ButtonPress and ev.xkey.subwindow != None: |
| 31 | + discard XGetWindowAttributes(display, ev.xbutton.subwindow, attr.addr); |
| 32 | + start = ev.xbutton; |
| 33 | + elif ev.theType == MotionNotify and start.subwindow != None: |
| 34 | + var |
| 35 | + xdiff = ev.xbutton.x_root - start.x_root |
| 36 | + ydiff = ev.xbutton.y_root - start.y_root |
| 37 | + |
| 38 | + discard XMoveResizeWindow(display, start.subwindow, |
| 39 | + attr.x + (if start.button==1: xdiff else: 0), |
| 40 | + attr.y + (if start.button==1: ydiff else: 0), |
| 41 | + max(1, attr.width + (if start.button==3: xdiff else: 0)), |
| 42 | + max(1, attr.height + (if start.button==3: ydiff else: 0))) |
| 43 | + |
| 44 | + elif ev.theType == ButtonRelease: |
| 45 | + start.subwindow = None |
0 commit comments