From cc53f7be1ccde78cc2d338297a00352b4fe545cf Mon Sep 17 00:00:00 2001 From: snailed Date: Thu, 9 Feb 2023 09:23:22 +0000 Subject: [PATCH 1/4] Clean up remapd I found a much better way of doing this, without a potentially too short sleep. This script waits for an input to be added, and then waits for a usb device to be bound. The remaps script can be run as soon as the USB device is bound. These changes should improve the reliability of the script and maybe even decrease latency. --- .local/bin/remapd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.local/bin/remapd b/.local/bin/remapd index cf67428..f2edb4f 100755 --- a/.local/bin/remapd +++ b/.local/bin/remapd @@ -2,8 +2,10 @@ # Rerun the remaps script whenever a new input device is added. -while : ; do - remaps - dmesg -W -f kern | grep "input:" -q - sleep 1 +trap "rm -f /tmp/udev_pipe" HUP INT QUIT ILL TRAP BUS TERM +mkfifo -m 600 /tmp/udev_pipe +udevadm monitor -u -t seat -s input -s usb >>/tmp/udev_pipe & +while :; do + grep -q "add" /tmp/udev_pipe && grep -q " bind" /tmp/udev_pipe + remaps us:dvorak done From ec1914e0b96c7b85be2197289e45852f08b95579 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 9 Feb 2023 15:39:31 +0100 Subject: [PATCH 2/4] fix broken trap --- .local/bin/remapd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.local/bin/remapd b/.local/bin/remapd index f2edb4f..2d87eae 100755 --- a/.local/bin/remapd +++ b/.local/bin/remapd @@ -2,7 +2,7 @@ # Rerun the remaps script whenever a new input device is added. -trap "rm -f /tmp/udev_pipe" HUP INT QUIT ILL TRAP BUS TERM +trap "rm -f /tmp/udev_pipe; exit" HUP INT QUIT ILL TRAP BUS TERM mkfifo -m 600 /tmp/udev_pipe udevadm monitor -u -t seat -s input -s usb >>/tmp/udev_pipe & while :; do From 457539c043cc8645eb75e92ff6b0f31182b114d7 Mon Sep 17 00:00:00 2001 From: Luca Bilke Date: Thu, 9 Feb 2023 17:11:16 +0100 Subject: [PATCH 3/4] remove complexity --- .local/bin/remapd | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.local/bin/remapd b/.local/bin/remapd index 2d87eae..14ae239 100755 --- a/.local/bin/remapd +++ b/.local/bin/remapd @@ -2,10 +2,9 @@ # Rerun the remaps script whenever a new input device is added. -trap "rm -f /tmp/udev_pipe; exit" HUP INT QUIT ILL TRAP BUS TERM -mkfifo -m 600 /tmp/udev_pipe -udevadm monitor -u -t seat -s input -s usb >>/tmp/udev_pipe & while :; do - grep -q "add" /tmp/udev_pipe && grep -q " bind" /tmp/udev_pipe + udevadm monitor -u -t seat -s input -s usb | grep --line-buffer -m1 -P '[^un]bind' + sleep 1 remaps us:dvorak done + From 88477d849770561382157667e8d804e3ed8addfc Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Thu, 9 Feb 2023 11:52:47 -0500 Subject: [PATCH 4/4] use bash procsub --- .local/bin/remapd | 8 +++----- .local/bin/remaps | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.local/bin/remapd b/.local/bin/remapd index 14ae239..ee4cf39 100755 --- a/.local/bin/remapd +++ b/.local/bin/remapd @@ -1,10 +1,8 @@ -#!/bin/sh +#!/bin/bash # Rerun the remaps script whenever a new input device is added. while :; do - udevadm monitor -u -t seat -s input -s usb | grep --line-buffer -m1 -P '[^un]bind' - sleep 1 - remaps us:dvorak + remaps + grep -qP -m1 '[^un]bind.+\/[^:]+\(usb\)' <(udevadm monitor -u -t seat -s input -s usb) done - diff --git a/.local/bin/remaps b/.local/bin/remaps index c95ac84..6d7d54e 100755 --- a/.local/bin/remaps +++ b/.local/bin/remaps @@ -8,4 +8,4 @@ setxkbmap -option caps:super,altwin:menu_win # When caps lock is pressed only once, treat it as escape. killall xcape 2>/dev/null ; xcape -e 'Super_L=Escape' # Turn off caps lock if on since there is no longer a key for it. -xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock +xset -q | grep -q "Caps Lock:\s*on" && xdotool key Caps_Lock