diff options
author | kitty piapiac <kcp@bsd.computer> | 2020-07-28 05:56:10 -0700 |
---|---|---|
committer | kitty piapiac <kcp@bsd.computer> | 2020-07-28 05:56:10 -0700 |
commit | ed17aeb7079b329ec3c7e66792484660bcf6b3ef (patch) | |
tree | 6117917ce833da64a9df91e0f4760d6a1b6f6027 /src | |
parent | 679401626886be97a546f18d54a8d1842011f564 (diff) |
(。ヘ°) keybindings
initShortcutKeys -> TODO, rename to initKeybindings ?
they're not exactly shortcut keys but here i am commiting anyway
Diffstat (limited to 'src')
-rw-r--r-- | src/config.nim | 20 | ||||
-rw-r--r-- | src/types.nim | 10 | ||||
-rw-r--r-- | src/windowmanager.nim | 58 |
3 files changed, 61 insertions, 27 deletions
diff --git a/src/config.nim b/src/config.nim index 23bd093..bd7d6ae 100644 --- a/src/config.nim +++ b/src/config.nim @@ -1,11 +1,13 @@ -import types +import + types, + x11/[x, keysym] # settings, or something along those lines # currently unused const # default mod key, run xmodmap to see what the mod keys are on your current keyboard layout # Mod1 is alt and Mod4 is super - modifier* = "mod1" + modifier* = Mod1Mask # if it isn't obvious, hex values go here colours* = ( @@ -16,14 +18,14 @@ const # store keybindings here keybindings*: seq[Key] = @[ closeWindow.initKey( - keys = @["c"], - mods = @[modifier, "shift"]), + key = XK_c, + mods = modifier), nextWindow.initKey( - keys = @["tab"], - mods = @[modifier]), + key = XK_Tab, + mods = modifier), spawnCustom.initKey( - keys = @["return"], - mods = @[modifier], - "st")]
\ No newline at end of file + key = XK_Return, + mods = modifier, + command = "st")]
\ No newline at end of file diff --git a/src/types.nim b/src/types.nim index 0352fc2..3eb6fc0 100644 --- a/src/types.nim +++ b/src/types.nim @@ -1,3 +1,5 @@ +import x11/[x] + type KeyFunc* = enum closeWindow, @@ -5,14 +7,14 @@ type spawnCustom Key* = object - mods*: seq[string] - keys*: seq[string] + mods*: int + key*: KeySym keyfunc*: KeyFunc command*: string -proc initKey* (keyfunc: KeyFunc, mods: seq[string], keys: seq[string], command = ""): Key = +proc initKey* (keyfunc: KeyFunc, mods: int, key: KeySym, command = ""): Key = return Key( mods: mods, - keys: keys, + key: key, command: command, keyfunc: keyfunc)
\ No newline at end of file diff --git a/src/windowmanager.nim b/src/windowmanager.nim index e90ec94..d371442 100644 --- a/src/windowmanager.nim +++ b/src/windowmanager.nim @@ -1,5 +1,6 @@ import x11/[x, xlib], + config, /types, logging, /logger type @@ -7,27 +8,32 @@ type display: PDisplay root: Window +# Initialiazation stuff +proc initShortcutKeys (wm: WindowManager) + # Error Handlers proc onWMDetected (display: PDisplay, e: PXErrorEvent): cint{.cdecl.} proc onXError (display: PDisplay, e: PXErrorEvent): cint{.cdecl.} # Events -proc onCreateNotify (wm: WindowManager, e: PXCreateWindowEvent): void -proc onDestroyNotify (wm: WindowManager, e: PXDestroyWindowEvent): void -proc onReparentNotify (wm: WindowManager, e: PXReparentEvent): void -proc onMapNotify (wm: WindowManager, e: PXMapEvent): void -proc onUnmapNotify (wm: WindowManager, e: PXUnmapEvent): void -proc onConfigureNotify (wm: WindowManager, e: PXConfigureEvent): void -proc onMapRequest (wm: WindowManager, e: PXMapRequestEvent): void -proc onConfigureRequest (wm: WindowManager, e: PXConfigureRequestEvent): void -proc onButtonPress (wm: WindowManager, e: PXButtonEvent): void -proc onButtonRelease (wm: WindowManager, e: PXButtonEvent): void -proc onMotionNotify (wm: WindowManager, e: PXMotionEvent): void -proc onKeyPress (wm: WindowManager, e: PXKeyEvent): void -proc onKeyRelease (wm: WindowManager, e: PXKeyEvent): void +proc onCreateNotify (wm: WindowManager, e: PXCreateWindowEvent) +proc onDestroyNotify (wm: WindowManager, e: PXDestroyWindowEvent) +proc onReparentNotify (wm: WindowManager, e: PXReparentEvent) +proc onMapNotify (wm: WindowManager, e: PXMapEvent) +proc onUnmapNotify (wm: WindowManager, e: PXUnmapEvent) +proc onConfigureNotify (wm: WindowManager, e: PXConfigureEvent) +proc onMapRequest (wm: WindowManager, e: PXMapRequestEvent) +proc onConfigureRequest (wm: WindowManager, e: PXConfigureRequestEvent) +proc onButtonPress (wm: WindowManager, e: PXButtonEvent) +proc onButtonRelease (wm: WindowManager, e: PXButtonEvent) +proc onMotionNotify (wm: WindowManager, e: PXMotionEvent) +proc onKeyPress (wm: WindowManager, e: PXKeyEvent) +proc onKeyRelease (wm: WindowManager, e: PXKeyEvent) # Run window manager proc run* (wm: WindowManager) = + initShortcutKeys wm + discard XSetErrorHandler onWMDetected # Temporary error handler if there is another window manager running discard wm.display.XSelectInput(wm.root, SubstructureNotifyMask or SubstructureRedirectMask) @@ -66,6 +72,17 @@ proc createWindowManager*: WindowManager = display: display, root: display.DefaultRootWindow()) +# Initialization Stuff +proc initShortcutKeys (wm: WindowManager) = + for key in config.keybindings: + discard wm.display.XGrabKey( + cint wm.display.XKeysymToKeycode(key.key), + cuint key.mods, + wm.root, + XBool true, + GrabModeAsync, + GrabModeAsync) + # Error Handlers proc onWMDetected (display: PDisplay, e: PXErrorEvent): cint{.cdecl.} = if e.theType == BadAccess: @@ -98,7 +115,20 @@ proc onMapNotify (wm: WindowManager, e: PXMapEvent) = return proc onUnmapNotify (wm: WindowManager, e: PXUnmapEvent) = return proc onConfigureNotify (wm: WindowManager, e: PXConfigureEvent) = return proc onMapRequest (wm: WindowManager, e: PXMapRequestEvent) = return -proc onConfigureRequest (wm: WindowManager, e: PXConfigureRequestEvent) = return + +proc onConfigureRequest (wm: WindowManager, e: PXConfigureRequestEvent) = + var changes: PXWindowChanges + + changes.x = e.x + changes.y = e.y + changes.width = e.width + changes.height = e.height + changes.border_width = e.border_width + changes.sibling = e.above + changes.stack_mode = e.detail + + discard wm.display.XConfigureWindow(e.window, cuint e.value_mask, changes) + proc onButtonPress (wm: WindowManager, e: PXButtonEvent) = return proc onButtonRelease (wm: WindowManager, e: PXButtonEvent) = return proc onMotionNotify (wm: WindowManager, e: PXMotionEvent) = return |