dotfiles/nixos/systems/omen/inputplug.nix
magic_rb dc49ca69ab
omen: improve inputplug
Signed-off-by: magic_rb <magic_rb@redalder.org>
2024-11-09 22:17:18 +01:00

70 lines
2 KiB
Nix

{...}: {
home-manager.users."main" = {
pkgs,
lib,
...
}: let
script = pkgs.writeShellScript "inputplug.sh" ''
mkdir -p $HOME/.cache/inputplug
set -x
_event_type="$1"
_device_id="$2"
_device_type="$3"
_device_name="$4"
_keyboard_id=$(xinput list | grep "AT Translated Set 2 keyboard" | cut -f 2 -d $'\t' | cut -f 2 -d '=')
_property_id=$(xinput list-props 16 | grep "Device Enabled" | cut -f 2 | sed -E 's/^[^(]+\(([[:digit:]]*)\):$/\1/')
cat <<EOF
event_type: $_event_type
device_id: $_device_id
device_type: $_device_type
device_name: $_device_name
EOF
case "$_event_type" in
XIDeviceEnabled|XIDeviceDisabled)
case "$_device_type" in
XISlaveKeyboard)
if [ -f "$HOME/.cache/inputplug/$_device_id" ] ; then
_device_name="$(cat "$HOME/.cache/inputplug/$_device_id")"
rm "$HOME/.cache/inputplug/$_device_id"
fi
case "$_device_name" in
"YMDK Split75")
if [ "$_event_type" = "XIDeviceDisabled" ] ; then
xinput set-int-prop $_keyboard_id $_property_id 8 1
elif [ "$_event_type" = "XIDeviceEnabled" ] ; then
echo "$_device_name" >> "$HOME/.cache/inputplug/$_device_id"
xinput set-int-prop $_keyboard_id $_property_id 8 0
fi
;;
*)
;;
esac
;;
*)
;;
esac
;;
*)
;;
esac
'';
in {
systemd.user.services."inputplug" = {
Unit = {
After = ["graphical-session-pre.target"];
PartOf = ["graphical-session.target"];
};
Service = {
Type = "simple";
ExecStart = ''${lib.getExe pkgs.bash} -l -c "${lib.getExe pkgs.inputplug} -d -c ${script}"'';
};
Install = {WantedBy = ["graphical-session.target"];};
};
};
}