From e44f1b2355c61c2c8c7930f5c4b879bf55ec31a3 Mon Sep 17 00:00:00 2001 From: kitty piapiac Date: Fri, 31 Jul 2020 04:39:41 -0700 Subject: =?UTF-8?q?(/=E3=83=BB=E3=83=BB)=E3=83=8E=20=20closes=20windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - small bugfix - updated readme.md to include config section - updated .gitignore to ignore config.nim - added config.def.nim --- .gitignore | 1 + README.md | 4 +++- TODO | 2 +- src/config.def.nim | 40 ++++++++++++++++++++++++++++++++++++++++ src/config.nim | 16 +++++++++++----- src/windowmanager.nim | 11 ++++++++--- 6 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 src/config.def.nim diff --git a/.gitignore b/.gitignore index 72497fc..4b91cf9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.kra* +config.nim kauw \ No newline at end of file diff --git a/README.md b/README.md index b9d9953..9ac352e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ i have a few goals in mind while writing this project - be small and fairly minimalist - help myself learn nim and get around x11 - +## config +the default config is [src/config.def.nim]; you can duplicate it (and be sure to rename it to config.nim) and make changes to your liking + ## development clone using ``` diff --git a/TODO b/TODO index 2ce1ecf..3728873 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,4 @@ Todo: [ ] Literally everything!! [ ] Support for multiple modifiers on keybinding [ ] Optional title bars? - [ ] Documentation \ No newline at end of file + [ ] Documentation diff --git a/src/config.def.nim b/src/config.def.nim new file mode 100644 index 0000000..638b04b --- /dev/null +++ b/src/config.def.nim @@ -0,0 +1,40 @@ +import /keys, x11/x + +# settings, or something along those lines +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* = Mod1Mask + + # if it isn't obvious, hex values go here + colours* = ( + focused: "#fbfdff", + unfocused: "#295eb3", + background: "#232323") + + init* = @[ + "xsetroot -solid \"" & colours.background & "\""] + + # in pixels + frameWidth* = 2 + + # store keybindings here + keybindings*: seq[Key] = @[ + # alt + shift + q will close the focused window + initKey( + closeWindow, + key = "q", + mods = modifier or ShiftMask), + + # alt + tab will cycle the focus through the windows + initKey( + nextWindow, + key = "Tab", + mods = modifier), + + # alt + return will open st, you can replace this with whatever your preferred terminal is + initKey( + spawnCustom, + key = "Return", + mods = modifier, + command = "st")] \ No newline at end of file diff --git a/src/config.nim b/src/config.nim index db02b1f..638b04b 100644 --- a/src/config.nim +++ b/src/config.nim @@ -20,15 +20,21 @@ const # store keybindings here keybindings*: seq[Key] = @[ - closeWindow.initKey( - key = "c", + # alt + shift + q will close the focused window + initKey( + closeWindow, + key = "q", mods = modifier or ShiftMask), - nextWindow.initKey( + # alt + tab will cycle the focus through the windows + initKey( + nextWindow, key = "Tab", mods = modifier), - spawnCustom.initKey( + # alt + return will open st, you can replace this with whatever your preferred terminal is + initKey( + spawnCustom, key = "Return", mods = modifier, - command = "st")] \ No newline at end of file + command = "st")] \ No newline at end of file diff --git a/src/windowmanager.nim b/src/windowmanager.nim index 4e5ca26..6053aa0 100644 --- a/src/windowmanager.nim +++ b/src/windowmanager.nim @@ -64,7 +64,7 @@ proc createWindowManager*: WindowManager = root: display.DefaultRootWindow(), clients: @[], - focused: -1, + focused: 0, keys: initTable[cuint, keys.Key](1)) # Run window manager @@ -138,7 +138,11 @@ proc initCommands (wm: WindowManager) = for cmd in config.init: discard execShellCmd cmd -proc λcloseWindow (wm: WindowManager) = return +proc λcloseWindow (wm: WindowManager) = + var n = wm.clients.len + if n > 0: + discard wm.display.XDestroyWindow wm.clients[wm.focused] + proc λnextWindow (wm: WindowManager) = var n = wm.clients.high if n > 0: @@ -230,7 +234,8 @@ proc onReparentNotify (wm: WindowManager, e: PXReparentEvent) = return proc onMapNotify (wm: WindowManager, e: PXMapEvent) = return proc onUnmapNotify (wm: WindowManager, e: PXUnmapEvent) = if wm.focused == wm.clients.high: wm.focused -= 1 - wm.clients.delete wm.clients.find(e.window) + let index = wm.clients.find(e.window) + if index > -1: wm.clients.delete index wm.tileWindows() proc onConfigureNotify (wm: WindowManager, e: PXConfigureEvent) = return -- cgit v1.2.3