@@ -35,21 +35,34 @@ when isMainModule:
35
35
while true :
36
36
discard XNextEvent (winInfo.display, winInfo.ev.addr )
37
37
38
- if winInfo.ev.theType == KeyPress and winInfo.ev.xkey.subwindow != None :
39
- discard XRaiseWindow (winInfo.display, winInfo.ev.xkey.subwindow);
40
- elif winInfo.ev.theType == ButtonPress and winInfo.ev.xkey.subwindow != None :
41
- discard XGetWindowAttributes (winInfo.display, winInfo.ev.xbutton.subwindow, winInfo.attr.addr );
42
- winInfo.start = winInfo.ev.xbutton;
43
- elif winInfo.ev.theType == MotionNotify and winInfo.start.subwindow != None :
38
+ if winInfo.ev.theType == KeyPress :
39
+ var kev = cast [PXKeyEvent ](winInfo.ev.addr )[]
40
+ if not kev.subwindow.addr .isNil:
41
+ discard XLowerWindow (winInfo.display, kev.subwindow)
42
+
43
+ elif winInfo.ev.theType == ButtonPress :
44
+ var bev = cast [PXButtonEvent ](winInfo.ev.addr )[]
45
+ if not bev.subwindow.addr .isNil:
46
+ discard XGrabPointer (winInfo.display, bev.subwindow, true ,
47
+ PointerMotionMask or ButtonReleaseMask , GrabModeAsync ,
48
+ GrabModeAsync , None , None , CurrentTime )
49
+ discard XGetWindowAttributes (winInfo.display, bev.subwindow, winInfo.attr.addr );
50
+ winInfo.start = bev;
51
+ elif winInfo.ev.theType == MotionNotify :
52
+ var mnev = cast [PXMotionEvent ](winInfo.ev.addr )[]
53
+ var bev = cast [PXButtonEvent ](winInfo.ev.addr )[]
54
+ while XCheckTypedEvent (winInfo.display, MotionNotify , winInfo.ev.addr ):
55
+ continue
44
56
var
45
- xdiff = winInfo.ev.xbutton.x_root - winInfo.start.x_root
46
- ydiff = winInfo.ev.xbutton.y_root - winInfo.start.y_root
47
-
48
- discard XMoveResizeWindow (winInfo.display, winInfo.start.subwindow,
49
- winInfo.attr.x + (if winInfo.start.button == 1 : xdiff else : 0 ),
50
- winInfo.attr.y + (if winInfo.start.button == 1 : ydiff else : 0 ),
51
- max (1 , winInfo.attr.width + (if winInfo.start.button == 3 : xdiff else : 0 )),
52
- max (1 , winInfo.attr.height + (if winInfo.start.button == 3 : ydiff else : 0 )))
53
-
57
+ xdiff = bev.x_root - winInfo.start.x_root
58
+ ydiff = bev.y_root - winInfo.start.y_root
59
+ discard XMoveResizeWindow (winInfo.display, mnev.window,
60
+ winInfo.attr.x + (if winInfo.start.button== 1 : xdiff else : 0 ),
61
+ winInfo.attr.y + (if winInfo.start.button== 1 : ydiff else : 0 ),
62
+ max (1 , winInfo.attr.width + (if winInfo.start.button== 3 : xdiff else : 0 )),
63
+ max (1 , winInfo.attr.height + (if winInfo.start.button== 3 : ydiff else : 0 )))
64
+
54
65
elif winInfo.ev.theType == ButtonRelease :
55
- winInfo.start.subwindow = None
66
+ discard XUngrabPointer (winInfo.display, CurrentTime )
67
+ else :
68
+ continue
0 commit comments