2024-10-27 11:44:39 +01:00
|
|
|
{...}: {
|
2024-11-09 22:17:18 +01:00
|
|
|
home-manager.users."main" = {
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
script = pkgs.writeShellScript "inputplug.sh" ''
|
|
|
|
mkdir -p $HOME/.cache/inputplug
|
|
|
|
set -x
|
2024-10-27 11:44:39 +01:00
|
|
|
|
2024-11-09 22:17:18 +01:00
|
|
|
_event_type="$1"
|
|
|
|
_device_id="$2"
|
|
|
|
_device_type="$3"
|
|
|
|
_device_name="$4"
|
2024-10-27 11:44:39 +01:00
|
|
|
|
2024-11-09 22:17:18 +01:00
|
|
|
_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"];
|
2024-10-27 11:44:39 +01:00
|
|
|
};
|
2024-11-09 22:17:18 +01:00
|
|
|
|
|
|
|
Service = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = ''${lib.getExe pkgs.bash} -l -c "${lib.getExe pkgs.inputplug} -d -c ${script}"'';
|
|
|
|
};
|
|
|
|
|
|
|
|
Install = {WantedBy = ["graphical-session.target"];};
|
|
|
|
};
|
|
|
|
};
|
2024-10-27 11:44:39 +01:00
|
|
|
}
|