From ecc0e2661d632d52fd5a5ac247eb0386fe803d80 Mon Sep 17 00:00:00 2001 From: Jonas Hahn Date: Thu, 20 Nov 2025 23:42:53 +0100 Subject: [PATCH] Added kmonad --- gui/dot-config/hypr/hyprland.conf | 1 + home/dot-kmonad/default.kbd | 66 ++++++++++ home/dot-kmonad/main.kbd | 203 ++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 home/dot-kmonad/default.kbd create mode 100644 home/dot-kmonad/main.kbd diff --git a/gui/dot-config/hypr/hyprland.conf b/gui/dot-config/hypr/hyprland.conf index 203383f..2e5e338 100644 --- a/gui/dot-config/hypr/hyprland.conf +++ b/gui/dot-config/hypr/hyprland.conf @@ -94,6 +94,7 @@ misc { input { kb_layout = us + kb_options = compose:ralt follow_mouse = 1 touchpad { natural_scroll = false diff --git a/home/dot-kmonad/default.kbd b/home/dot-kmonad/default.kbd new file mode 100644 index 0000000..3b2962b --- /dev/null +++ b/home/dot-kmonad/default.kbd @@ -0,0 +1,66 @@ +(defcfg + input (device-file "/dev/input/by-id/usb-HyperX_Alloy_Elite_RGB_HyperX_Alloy_Elite_RGB-event-kbd") + + output (uinput-sink "Jonas kmonad modified output") + cmp-seq ralt + cmp-seq-delay 5 + key-seq-delay 5 + + fallthrough true + allow-cmd true + implicit-around around +) + +(defsrc + esc f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 ssrq slck pause + grv 1 2 3 4 5 6 7 8 9 0 - = bspc ins home pgup nlck kp/ kp* kp- + tab q w e r t y u i o p [ ] ret del end pgdn kp7 kp8 kp9 kp+ + caps a s d f g h j k l ; ' \ kp4 kp5 kp6 + lsft 102d z x c v b n m , . / rsft up kp1 kp2 kp3 kprt + lctl lmet lalt spc ralt rmet cmp rctl left down rght kp0 kp. +) + +(defalias + caps (tap-hold-next 300 esc lctl) + + symbols (layer-toggle symbols) + specials (layer-toggle specials) + neo (layer-switch neo) ;; Also inspired from enthium and graphite + default (layer-switch default) +) + +(deflayer default + @neo f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 XX XX XX + XX 1 2 3 4 5 6 7 8 9 0 XX XX bspc XX XX XX XX XX XX XX + tab q w e r t y u i o p XX XX ret XX XX XX XX XX XX XX + @caps a s d f g h j k l @symbols XX XX XX XX XX + lsft @specials z x c v b n m , . / rsft up XX XX XX XX + XX XX lmet spc ralt XX XX XX left down rght XX XX +) + +(deflayer neo + @default f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 XX XX XX + XX 1 2 3 4 5 6 7 8 9 0 XX XX bspc XX XX XX XX XX XX XX + tab b l d w z _ f o u j XX XX ret XX XX XX XX XX XX XX + @caps n r t s g y h a e l @symbols XX XX XX XX + lsft @specials q x m c v k p _ _ _ rsft up XX XX XX XX + XX XX lmet spc ralt XX XX XX left down rght XX XX +) + +(deflayer symbols + _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ \ / [ ] ^ ! < > ' _ _ _ _ _ _ _ _ _ _ _ + = : ; { } * ? \( \) @ _ _ _ _ _ _ + " - # $ | ~ ` + % _ _ _ _ _ _ _ _ _ + _ _ _ \_ _ _ _ _ _ _ _ _ _ +) + +(deflayer specials + _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ ü ö ü _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ +) diff --git a/home/dot-kmonad/main.kbd b/home/dot-kmonad/main.kbd new file mode 100644 index 0000000..caa62f4 --- /dev/null +++ b/home/dot-kmonad/main.kbd @@ -0,0 +1,203 @@ +(defcfg + ;; For Linux + input (device-file "/dev/input/by-id/usb-HyperX_Alloy_Elite_RGB_HyperX_Alloy_Elite_RGB-event-kbd") + output (uinput-sink "My KMonad output" + ;; To understand the importance of the following line, see the section on + ;; Compose-key sequences at the near-bottom of this file. + "sleep 1 && setxkbmap -option compose:ralt") + cmp-seq ralt ;; Set the compose key to `RightAlt' + cmp-seq-delay 5 ;; 5ms delay between each compose-key sequence press + key-seq-delay 5 ;; 5ms delay between each outputted key event + + ;; For Windows + ;; input (low-level-hook) + ;; output (send-event-sink) + + ;; For MacOS + ;; input (iokit-name "my-keyboard-product-string") + ;; output (kext) + + ;; Comment this if you want unhandled events not to be emitted + fallthrough true + + ;; Set this to false to disable any command-execution in KMonad + allow-cmd true + + ;; Set the implicit around to `around` + implicit-around around +) + + +#| -------------------------------------------------------------------------- + Necessary: at least 1 `defsrc` block + + It is difficult to explain the `defsrc` block without immediately going into + `deflayer` blocks as well. Essentially, KMonad maps input-events to various + internal actions, many of which generate output events. The `defsrc` block + explains the layout on which we specify our `deflayer`s down the line. + + It is important to realize that the `defsrc` block doesn't *necessarily* have + to coincide with your actual input keyboard. You can specify a full 100% + `defsrc` block, but only use a 40% keyboard. This will mean that every + `deflayer` you specify will also have to match your 100% `defsrc`, and that + your actual keyboard would be physically unable to trigger about 60% of your + keymap, but it would be perfectly valid syntax. + + The dual of this (and more useful) is that it is also perfectly valid to only + specify that part of your keyboard in `defsrc` that you want to remap. If you + use a 100% keyboard, but don't want to remap the numpad at all you can simply + leave the numpad out of your `defsrc`, and it should work just fine. In that + particular case you probably want to set `fallthrough` to `true` in your + `defcfg` block though. + + There is also support for named `defsrc` blocks. They contain `:name ` + as the first argument in their definition. + + The layouting in the `defsrc` block is completely free, whitespace simply gets + ignored. We strive to provide a name for every keycode that is no longer than + 4 characters, so we find that laying out your keymap in columns of 5 works out + quite nicely (although wider columns will allow for more informative aliases, + see below). + + You can also insert a placeholder button using `XX`. This is almost the same + as extra white space but you still need to bind a button to it. Said button is + never used. This is occasionally useful if you have buttons which don't emit a + keycode or have the same keycode multiple times on the same keyboard. In such + cases large chunks of whitespace may be more confusing then a placeholder + button. If you further want to specify which button this placeholder refers + to, you can use an alias (see below). + + Instead of keycodes directly you can also use an alias (see `defalias`). + The syntax for aliases is the same as described in `deflayer`. Keep in mind + that buttons, which won't work if you place them in `defsrc` directly, will + also not work if you use them via an alias. + + Most keycodes should be obvious. If you are unsure, check + './src/KMonad/Keyboard/Keycode.hs'. Every Keycode has a name corresponding to + its Keycode name, but all lower-case and with the 'Key' prefix removed. There + are also various aliases for Keycodes starting around line 350. If you are + trying to bind a key and there is not a 4-letter alias, please file an issue, + or better yet, a pull-request, and it will be added promptly. + + Also, you can consult './keymap/template/' for various input templates to use + directly or to look up keycodes by position. Here we use the input-template + for 'us_ansi_60.kbd' + + -------------------------------------------------------------------------- |# + +(defsrc + grv 1 2 3 4 5 6 7 8 9 0 - = bspc + tab q w e r t y u i o p [ ] \ + caps a s d f g h j k l ; ' ret + lsft z x c v b n m , . / rsft + lctl lmet lalt spc ralt rmet cmp rctl +) + +(deflayer capsasa + grv 1 2 3 4 5 6 7 8 9 0 - = bspc + tab q w e r t y u i o p [ ] \ + lctrl a s d f g h j k l ; ' ret + lsft z x c v b n m , . / rsft + lctl lmet lalt spc ralt rmet cmp rctl +) + +(defsrc :name numpad + nlck kp/ kp* kp- + kp7 kp8 kp9 kp+ + kp4 kp5 kp6 + kp1 kp2 kp3 kprt + kp0 kp. +) + +(defsrc :name with-aliases @foo @power) + + + +(defalias + num (layer-toggle numbers) ;; Bind num to a button that switches to a layer + kil C-A-del ;; Bind kil to a button that Ctrl-Alt-deletes + power XX ;; Placeholder for power button of keyboard + foo @bar ;; An alias with a forward reference to another alias + bar a +) + + +#| NOTE: The above code could just as easily have been written as: +(defalias num (layer-toggle numbers)) +(defalias kil C-A-del) + +(deflayer qwerty + grv 1 2 3 4 5 6 7 8 9 0 - = bspc + tab q w e r t y u i o p [ ] \ + caps a s d f g h j k l ; ' ret + lsft z x c v b n m , . / rsft + lctl @num lalt spc ralt rmet @sym @tst +) + +(deflayer phone :source numpad + :implicit-around disabled + nlck kp/ kp* kp- + kp1 kp2 kp3 kp+ + kp4 kp5 kp6 + kp7 kp8 kp9 kprt + kp0 kp. +) + + + +(deflayer numbers + _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ XX / 7 8 9 - _ _ _ + _ _ _ _ _ XX * 4 5 6 + _ _ + _ _ \( \) . XX 0 1 2 3 _ _ + _ _ _ _ _ _ _ _ +) + + + +(defalias + + ;; Something useful + cpy C-c + pst C-v + cut C-x + + ;; Something silly + md1 (around a (around b c)) ;; abc + md2 (around a (around-only lsft b)) ;; aB + md3 C-A-M-S-l + md4 (around % b) ;; BEWARE: %B, not %b, do you see why? + md5 (around-when-alone lctl c) +) + + +(defalias + ctl-lck (stepped (press-only lctl) (release-only lctl))) + + + +(deflayer modded-test + _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ @md4 _ _ _ _ _ _ _ _ _ _ _ + _ _ @md1 @md2 @md3 _ _ _ _ _ _ _ _ + _ _ @cut @cpy @pst _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ +) + + +(defalias + mc1 #(K M o n a d) + mc2 #(C-c P50 A-tab P50 C-v) ;; Careful, this might do something + mc3 #(P200 h P150 4 P100 > < P50 > < P20 0 r z 1 ! 1 ! !) + mc4 (tap-macro a (pause 50) @md2 (pause 50) c) + mc5 (tap-macro-release esc esc esc) + mc6 #(@mc3 spc @mc3 spc @mc3) +) + +(deflayer macro-test + _ @mc1 @mc2 @mc3 @mc4 @mc5 @mc6 _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ +)