From 2025ebe1d91525c69b4b7d486da3a5d2f4278617 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 13 Mar 2022 18:17:43 +0100 Subject: Use interception-tools for mapping keys --- intcp-mapper.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 intcp-mapper.nix (limited to 'intcp-mapper.nix') 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 +#include +#include + +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 + ''; +} -- cgit v1.2.3