summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2022-03-13 18:17:43 +0100
committerJulian T <julian@jtle.dk>2022-03-13 18:17:43 +0100
commit2025ebe1d91525c69b4b7d486da3a5d2f4278617 (patch)
tree0900f26d108f7410c4e536f0a4c865b131f44e7d
parent70c847f1a716df9c91c48d625d9f510cd37d5fd9 (diff)
Use interception-tools for mapping keys
-rw-r--r--desktop.nix31
-rw-r--r--intcp-mapper.nix46
2 files changed, 68 insertions, 9 deletions
diff --git a/desktop.nix b/desktop.nix
index 2f293d4..a170eaf 100644
--- a/desktop.nix
+++ b/desktop.nix
@@ -63,17 +63,30 @@
# Enable CUPS to print documents.
printing.enable = true;
- postgresql = {
- enable = false;
- initialScript = pkgs.writeText "backend-initScript" ''
- CREATE ROLE julian WITH LOGIN PASSWORD 'hejmeddig' CREATEDB;
- CREATE DATABASE julian;
- GRANT ALL PRIVILEGES ON DATABASE julian TO julian;
- '';
- };
-
blueman.enable = true;
+ interception-tools =
+ let mappings = [
+ { from = "KEY_CAPSLOCK"; to = "KEY_LEFTCTRL"; }
+ { from = "KEY_LEFTALT"; to = "KEY_LEFTMETA"; }
+ { from = "KEY_102ND"; to = "KEY_LEFTALT"; }
+ ];
+ mapper = pkgs.callPackage ./intcp-mapper.nix { inherit mappings; };
+ intercept = pkgs.interception-tools;
+ in {
+ enable = true;
+ # We will just use our own here
+ plugins = [];
+
+ udevmonConfig = ''
+ - JOB: "${intercept}/bin/intercept -g $DEVNODE | ${mapper}/bin/mapper | ${intercept}/bin/uinput -d $DEVNODE"
+ DEVICE:
+ EVENTS:
+ EV_KEY: ${builtins.toJSON (map (m: m.from) mappings) }
+ '';
+ };
+
+
udev.packages = [ pkgs.yubikey-personalization ];
};
diff --git a/intcp-mapper.nix b/intcp-mapper.nix
new file mode 100644
index 0000000..5863f85
--- /dev/null
+++ b/intcp-mapper.nix
@@ -0,0 +1,46 @@
+{ lib, stdenv, writeText, mappings ? [] }:
+
+stdenv.mkDerivation rec {
+ name = "intcp-mapper";
+
+ src = writeText "intcp-mapper.c" ''
+#include <stdio.h>
+#include <stdlib.h>
+#include <linux/input.h>
+
+int main(void) {
+ setbuf(stdin, NULL), setbuf(stdout, NULL);
+
+ struct input_event event;
+ while (fread(&event, sizeof(event), 1, stdin) == 1) {
+ /* Example
+ if (event.type == EV_KEY && event.code == KEY_X) {
+ event.code = KEY_Y;
+ }
+ */
+
+ if (event.type == EV_KEY) {
+ ${ lib.concatStrings (map (m: ''
+ if (event.code == ${m.from}) {
+ event.code = ${m.to};
+ }
+ '') mappings) }
+ }
+
+ fwrite(&event, sizeof(event), 1, stdout);
+ };
+}
+ '';
+
+ dontUnpack = true;
+
+ buildPhase = ''
+ cat $src
+ gcc $src -o mapper
+ '';
+
+ installPhase = ''
+ mkdir -p $out/bin
+ install -m 555 mapper $out/bin/mapper
+ '';
+}