From b4af703fdf4de92ee767afe653808a647b931a61 Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Sat, 6 Apr 2024 10:42:07 -0400 Subject: [PATCH] meta: Merge dual-function-keys with hardware Seems like an alright categorization for now since dual-function-keys can be used without a desktop environment, although realistically the tty is impractical for things like CJK. --- default.nix | 1 + modules/dual-function-keys.nix | 66 --------------------------------- modules/hardware.nix | 67 ++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 69 deletions(-) delete mode 100644 modules/dual-function-keys.nix diff --git a/default.nix b/default.nix index 61ed5e8d..8224269e 100644 --- a/default.nix +++ b/default.nix @@ -14,6 +14,7 @@ in modules = { hardware = { + keyboardBinds = true; disableLaptopKeyboard = true; lidIgnore = true; powerIgnore = true; diff --git a/modules/dual-function-keys.nix b/modules/dual-function-keys.nix deleted file mode 100644 index ae24df52..00000000 --- a/modules/dual-function-keys.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ pkgs, lib, ... }: - -let - inherit (lib) getExe singleton; - inherit (builtins) toJSON; - inherit (pkgs) interception-tools; - inherit (pkgs.interception-tools-plugins) dual-function-keys; - - configFile = "dual-function-keys.yaml"; -in -{ - services.interception-tools = { - enable = true; - plugins = [ dual-function-keys ]; - - udevmonConfig = toJSON (singleton { - JOB = /* bash */ '' - ${interception-tools}/bin/intercept -g $DEVNODE | - ${getExe dual-function-keys} -c /etc/${configFile} | - ${interception-tools}/bin/uinput -d $DEVNODE - ''; - - DEVICE = { - EVENTS = { - EV_KEY = [ "KEY_CAPSLOCK" "KEY_ESC" ]; - }; - }; - }); - }; - - environment.etc.${configFile}.text = toJSON { - TIMING = [ - { TAP_MILLISEC = 1000; } - { DOUBLE_TAP_MILLISEC = 0; } - { SYNTHETIC_KEYS_PAUSE_MILLISEC = 0; } - ]; - - MAPPINGS = [ - { - KEY = "KEY_CAPSLOCK"; - TAP = "KEY_ESC"; - HOLD = "KEY_LEFTCTRL"; - } - { - KEY = "KEY_SYSRQ"; - TAP = "KEY_SYSRQ"; - HOLD = "KEY_RIGHTMETA"; - } - { - KEY = "KEY_LEFTMETA"; - TAP = [ "KEY_LEFTMETA" "KEY_F1" ]; - HOLD = "KEY_LEFTMETA"; - } - { - KEY = "KEY_RIGHTSHIFT"; - TAP = [ "KEY_LEFTMETA" "KEY_F2" ]; - HOLD = "KEY_RIGHTSHIFT"; - } - { - KEY = "KEY_RIGHTALT"; - TAP = "KEY_GRAVE"; - HOLD = "KEY_RIGHTALT"; - } - ]; - }; -} diff --git a/modules/hardware.nix b/modules/hardware.nix index 538ca6a4..252c32f4 100644 --- a/modules/hardware.nix +++ b/modules/hardware.nix @@ -1,20 +1,26 @@ { pkgs, config, lib, ... }: let - inherit (lib) mkEnableOption mkIf; - inherit (pkgs) piper; + inherit (builtins) toJSON; + inherit (lib) mkEnableOption mkIf getExe singleton; + inherit (pkgs) piper interception-tools; + inherit (pkgs.interception-tools-plugins) dual-function-keys; + inherit (cfg) mouseSettings disableLaptopKeyboard lidIgnore powerIgnore keyboardBinds; + + dualFunctionKeysConfig = "dual-function-keys.yaml"; cfg = config.modules.hardware; in { options.modules.hardware = { + keyboardBinds = mkEnableOption "start button for rofi, caps lock as escape, etc."; mouseSettings = mkEnableOption "piper for gaming mice"; disableLaptopKeyboard = mkEnableOption "udev rule to disable laptop keyboard"; lidIgnore = mkEnableOption "ignoring the laptop lid on close"; powerIgnore = mkEnableOption "ignoring the power button on press"; }; - config = with cfg; { + config = { services = { ratbagd.enable = mkIf mouseSettings true; @@ -26,8 +32,63 @@ in lidSwitch = mkIf lidIgnore "ignore"; extraConfig = mkIf powerIgnore "HandlePowerKey=ignore"; }; + + interception-tools = { + enable = mkIf keyboardBinds true; + plugins = [ dual-function-keys ]; + + udevmonConfig = toJSON (singleton { + JOB = /* bash */ '' + ${interception-tools}/bin/intercept -g $DEVNODE | + ${getExe dual-function-keys} -c /etc/${dualFunctionKeysConfig} | + ${interception-tools}/bin/uinput -d $DEVNODE + ''; + + DEVICE = { + EVENTS = { + EV_KEY = [ "KEY_CAPSLOCK" "KEY_ESC" ]; + }; + }; + }); + }; }; environment.systemPackages = mkIf mouseSettings [ piper ]; + + environment.etc.${dualFunctionKeysConfig}.text = toJSON { + TIMING = [ + { TAP_MILLISEC = 1000; } + { DOUBLE_TAP_MILLISEC = 0; } + { SYNTHETIC_KEYS_PAUSE_MILLISEC = 0; } + ]; + + MAPPINGS = [ + { + KEY = "KEY_CAPSLOCK"; + TAP = "KEY_ESC"; + HOLD = "KEY_LEFTCTRL"; + } + { + KEY = "KEY_SYSRQ"; + TAP = "KEY_SYSRQ"; + HOLD = "KEY_RIGHTMETA"; + } + { + KEY = "KEY_LEFTMETA"; + TAP = [ "KEY_LEFTMETA" "KEY_F1" ]; + HOLD = "KEY_LEFTMETA"; + } + { + KEY = "KEY_RIGHTSHIFT"; + TAP = [ "KEY_LEFTMETA" "KEY_F2" ]; + HOLD = "KEY_RIGHTSHIFT"; + } + { + KEY = "KEY_RIGHTALT"; + TAP = "KEY_GRAVE"; + HOLD = "KEY_RIGHTALT"; + } + ]; + }; }; }