summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ptrmath.nim19
-rw-r--r--src/windowmanager.nim29
2 files changed, 47 insertions, 1 deletions
diff --git a/src/ptrmath.nim b/src/ptrmath.nim
new file mode 100644
index 0000000..7de2fa6
--- /dev/null
+++ b/src/ptrmath.nim
@@ -0,0 +1,19 @@
+# from http://forum.nim-lang.org/t/1188#7366
+
+template `+`*[T](p: ptr T, off: int): ptr T =
+ cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[]))
+
+template `+=`*[T](p: ptr T, off: int) =
+ p = p + off
+
+template `-`*[T](p: ptr T, off: int): ptr T =
+ cast[ptr type(p[])](cast[ByteAddress](p) -% off * sizeof(p[]))
+
+template `-=`*[T](p: ptr T, off: int) =
+ p = p - off
+
+template `[]`*[T](p: ptr T, off: int): T =
+ (p + off)[]
+
+template `[]=`*[T](p: ptr T, off: int, val: T) =
+ (p + off)[] = val \ No newline at end of file
diff --git a/src/windowmanager.nim b/src/windowmanager.nim
index a4e2058..409b06a 100644
--- a/src/windowmanager.nim
+++ b/src/windowmanager.nim
@@ -2,7 +2,7 @@ import
x11/[x, xlib],
config, /types,
logging, /logger,
- tables, os
+ tables, os, ptrmath
type
WindowManager* = ref object
@@ -28,6 +28,9 @@ proc funcSpawnCustom (wm: WindowManager)
proc onWMDetected (display: PDisplay, e: PXErrorEvent): cint{.cdecl.}
proc onXError (display: PDisplay, e: PXErrorEvent): cint{.cdecl.}
+# Main Loop
+proc tileWindows (wm: WindowManager)
+
# Events
proc onCreateNotify (wm: WindowManager, e: PXCreateWindowEvent)
proc onDestroyNotify (wm: WindowManager, e: PXDestroyWindowEvent)
@@ -80,6 +83,8 @@ proc run* (wm: WindowManager) =
var e: XEvent
discard wm.display.XNextEvent(addr e)
+ tileWindows wm
+
case e.theType:
of CreateNotify: wm.onCreateNotify addr e.xcreatewindow
of DestroyNotify: wm.onDestroyNotify addr e.xdestroywindow
@@ -173,6 +178,28 @@ proc onXError (display: PDisplay, e: PXErrorEvent): cint{.cdecl.} =
return 0
+# Main Loop
+proc tileWindows (wm: WindowManager) =
+ var
+ parent: Window
+ children: PWindow
+ n: cuint
+ w = cuint wm.display.XDisplayWidth 0
+ h = cuint wm.display.XDisplayHeight 0
+
+ discard wm.display.XQueryTree(wm.root, addr wm.root, addr parent, addr children, addr n)
+
+ if n == 1:
+ # only 1 window, keep it fullscreen
+ discard wm.display.XMoveResizeWindow(children[0], 0, 0, w, h)
+ else:
+ # resize master window to take up half the screen
+ discard wm.display.XMoveResizeWindow(children[0], 0, 0, cuint (w div 2), h)
+
+ # maths, sort of explained here: https://i.imgur.com/fGxdfDh.png
+ for i in 1..n-1:
+ discard wm.display.XMoveResizeWindow(children[int i], cint w div 2, cint (i-1) * (h div (n-1)), w div 2, h div (n-1))
+
# Events
proc onCreateNotify (wm: WindowManager, e: PXCreateWindowEvent) = return
proc onDestroyNotify (wm: WindowManager, e: PXDestroyWindowEvent) = return