Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[
- Whim - Minimal floating window manager in Nim.
- Based off of https://github.com/mackstann/tinywm.
- ]#
- import
- std/strformat,
- std/tables,
- x11/xlib,
- x11/xutil,
- x11/x
- type
- KeyMapping* = ref object
- code: char
- modifiers: cuint
- Whim = object
- dpy: PDisplay
- keys: Table[KeyMapping, string]
- var
- wm = Whim()
- proc grabKeys*(self: Whim) =
- let root = DefaultRootWindow(self.dpy)
- for key, command in self.keys:
- discard XGrabKey(self.dpy,
- cast[cint](key.code),
- key.modifiers,
- root,
- 1,
- GrabModeAsync,
- GrabModeAsync)
- proc makeKeyMapping(xk: XKeyEvent): KeyMapping =
- KeyMapping(code: cast[char](xk.keycode), modifiers: xk.state)
- proc initX() =
- # open a connection to the display
- wm.dpy = XOpenDisplay(nil)
- wm.keys = initTable[KeyMapping, string]()
- proc mainLoop() =
- var event: XEvent
- while true:
- # Get the next event from X
- discard XNextEvent(wm.dpy, event.addr)
- if event.theType == KeyPress and event.xkey.subwindow != None:
- #let mapping = makeKeyMapping(event.xkey)
- if makeKeyMapping(event.xkey) in wm.keys: # error here
- echo "key was pressed"
- discard XRaiseWindow(wm.dpy, event.xkey.subwindow)
- when isMainModule:
- initX()
- mainLoop()
Advertisement
Add Comment
Please, Sign In to add comment