From: Samir Benmendil Date: Sun, 14 May 2023 22:10:29 +0000 (+0100) Subject: xprofile: reload xkb layout on usb connection X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/dfbc6b99b7b48b31997e57b4804352be9536a43d?ds=sidebyside xprofile: reload xkb layout on usb connection Uses inputplug to trigger xkbload on input event, this matches the kinesis advantage for now and reloads the layout for it. --- diff --git a/bin/xkbload b/bin/xkbload new file mode 100755 index 0000000..607385b --- /dev/null +++ b/bin/xkbload @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# This script is meant to be called by inputplug when a new input device event happened. + +xkb_config=$XDG_CONFIG_HOME/xkb +xkb_file=$xkb_config/default.xkb +[[ -f $xkb_config/$(hostname).xkb ]] && xkb_file=$(hostname) + +XIDeviceEnabled() +{ + kinadv2="Kinesis Advantage2 Keyboard" + if [[ "$device_name" == "$kinadv2" ]]; then + # HACK: if I don't sleep, capslock is enabled on reconnect + sleep 0.1 + echo "xkbcomp default.xkb" + xkbcomp -w0 -I$xkb_config $xkb_file $DISPLAY -i $device_id + fi +} + +call_event_handler() +{ + case $(type -t $event_type) in + function) $event_type ;; + *) echo "No handler for event '$event_type'" ;; + esac +} + +if [[ $# -eq 4 ]]; then + # See inputplug(1) + event_type=$1 + device_id=$2 + device_type=$3 + device_name=$4 + call_event_handler +else + # if not called with four args, loop over all devices + event_type=XIDeviceEnabled + for device_id in $(xinput list --id-only); do + device_name="$(xinput list --name-only $device_id)" + device_type="UnknownTODO" # don't know how to get this easily + call_event_handler + done +fi diff --git a/xprofile.d/10-xkb.sh b/xprofile.d/10-xkb.sh index 1606d1d..7e00da1 100755 --- a/xprofile.d/10-xkb.sh +++ b/xprofile.d/10-xkb.sh @@ -1,5 +1,3 @@ #!/usr/bin/env bash -xkb_file=default -[[ -f $XDG_CONFIG_HOME/xkb/$(hostname).xkb ]] && xkb_file=$(hostname) -xkbcomp -I$XDG_CONFIG_HOME/xkb $XDG_CONFIG_HOME/xkb/$xkb_file.xkb $DISPLAY +inputplug -0c xkbload