Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up remapd #1265

Merged
merged 3 commits into from
Feb 9, 2023
Merged

Clean up remapd #1265

merged 3 commits into from
Feb 9, 2023

Conversation

ssnailed
Copy link
Contributor

@ssnailed ssnailed commented Feb 9, 2023

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. This way of doing things also doesn't require any changes to /etc/sysctl.conf.

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.
@LukeSmithxyz
Copy link
Owner

What's the purpose of the double grep?

Also when try to kill this script or shutting down will hang and cause memory leakage.

@LukeSmithxyz
Copy link
Owner

I.e. and the machine become mostly non-reponsive.

@LukeSmithxyz
Copy link
Owner

Also, I should add it didn't even more or remap the keys. Haven't bothered to troubleshoot.

@LukeSmithxyz
Copy link
Owner

It still doesn't actually remap the keys. It just sits there grepping output forever lol

@ssnailed
Copy link
Contributor Author

ssnailed commented Feb 9, 2023

Well this should work in all shells. The only way to get rid of the sleep seems to be using process substitution, but since process substitution isn't posix compliant I'm just gonna stick with a one second sleep.

Here's the non-posix compliant solution:

#!/bin/bash
while :; do
    grep -qP -m1 '[^un]bind.+\/[^:]+\(usb\)' <(udevadm monitor -u -t seat -s input -s usb)
	remaps us:dvorak
done

This version waits for the last bind event triggered by plugging in a keyboard rather than matching the first one (like the posix compliant version). The last bind event isn't followed by a newline until anything happens at all in udevadm. Unfortunately grep does not exit with -m1 until it reads a newline after that first match, so you have to use this esoteric process substitution to trick it into exiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants