mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-26 01:56:13 +01:00
omen
: improve inputplug
Signed-off-by: magic_rb <magic_rb@redalder.org>
This commit is contained in:
parent
d3d59a8fb3
commit
dc49ca69ab
|
@ -1,30 +1,70 @@
|
|||
{...}: {
|
||||
home."main".modules = [
|
||||
({
|
||||
home-manager.users."main" = {
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit
|
||||
(lib)
|
||||
getExe
|
||||
;
|
||||
|
||||
script = pkgs.writeShellScript "inputplug.sh" ''
|
||||
mkdir -p $HOME/.cache/inputplug
|
||||
set -x
|
||||
|
||||
EVENT_TYPE="$1"
|
||||
DEVICE_ID="$2"
|
||||
DEVICE_TYPE="$3"
|
||||
DEVICE_NAME="$4"
|
||||
_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 = ''${getExe pkgs.inputplug} -c ${script}'';
|
||||
ExecStart = ''${lib.getExe pkgs.bash} -l -c "${lib.getExe pkgs.inputplug} -d -c ${script}"'';
|
||||
};
|
||||
|
||||
Install = {WantedBy = ["graphical-session.target"];};
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue