Skip to content

Commit 4a9ea0a

Browse files
authored
Merge pull request #1 from fox0430/devel
v0.0.1
2 parents ecd6745 + c29a298 commit 4a9ea0a

File tree

3 files changed

+69
-46
lines changed

3 files changed

+69
-46
lines changed

nimWM.nimble

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author = "fox0430"
55
description = "simple window manager"
66
license = "MIT"
77
srcDir = "src"
8-
bin = @["nimWM"]
8+
bin = @["nimwm"]
99

1010
# Dependencies
1111

src/nimWM.nim

-45
This file was deleted.

src/nimwm.nim

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
type XWindowInfo = object
8+
display*: PDisplay
9+
attr*: TXWindowAttributes
10+
start*: TXButtonEvent
11+
ev*: TXEvent
12+
13+
proc initXWIndowInfo(winInfo: var XWindowInfo): XWIndowInfo =
14+
winInfo.display = XOpenDisplay(nil)
15+
if winInfo.display == nil:
16+
quit "Failed to open display"
17+
18+
discard XGrabKey(winInfo.display, XKeysymToKeycode(winInfo.display, XStringToKeysym("F1")), Mod1Mask,
19+
DefaultRootWindow(winInfo.display), true, GrabModeAsync, GrabModeAsync)
20+
discard XGrabButton(winInfo.display, 1, Mod1Mask, DefaultRootWindow(winInfo.display), true,
21+
ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None)
22+
discard XGrabButton(winInfo.display, 3, Mod1Mask, DefaultRootWindow(winInfo.display), true,
23+
ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None)
24+
25+
winInfo.start.subwindow = None
26+
27+
return winInfo
28+
29+
when isMainModule:
30+
31+
var winInfo: XWindowInfo
32+
33+
winInfo = initXWIndowInfo(winInfo)
34+
35+
while true:
36+
discard XNextEvent(winInfo.display, winInfo.ev.addr)
37+
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
56+
var
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+
65+
elif winInfo.ev.theType == ButtonRelease:
66+
discard XUngrabPointer(winInfo.display, CurrentTime)
67+
else:
68+
continue

0 commit comments

Comments
 (0)