omen: improve inputplug

Signed-off-by: magic_rb <magic_rb@redalder.org>
This commit is contained in:
magic_rb 2024-11-09 22:17:18 +01:00
parent d3d59a8fb3
commit dc49ca69ab
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E

View file

@ -1,30 +1,70 @@
{...}: { {...}: {
home."main".modules = [ home-manager.users."main" = {
({
pkgs, pkgs,
lib, lib,
... ...
}: let }: let
inherit
(lib)
getExe
;
script = pkgs.writeShellScript "inputplug.sh" '' script = pkgs.writeShellScript "inputplug.sh" ''
mkdir -p $HOME/.cache/inputplug mkdir -p $HOME/.cache/inputplug
set -x
EVENT_TYPE="$1" _event_type="$1"
DEVICE_ID="$2" _device_id="$2"
DEVICE_TYPE="$3" _device_type="$3"
DEVICE_NAME="$4" _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 { in {
systemd.user.services."inputplug" = { systemd.user.services."inputplug" = {
Unit = {
After = ["graphical-session-pre.target"];
PartOf = ["graphical-session.target"];
};
Service = { Service = {
Type = "simple"; Type = "simple";
ExecStart = ''${getExe pkgs.inputplug} -c ${script}''; ExecStart = ''${lib.getExe pkgs.bash} -l -c "${lib.getExe pkgs.inputplug} -d -c ${script}"'';
};
Install = {WantedBy = ["graphical-session.target"];};
}; };
}; };
})
];
} }