Tiny Core Linux
Tiny Core Base => CorePlus => Topic started by: Santos on February 04, 2022, 06:45:49 PM
-
Hello
In fact is microcore build up with so many extensions that is not microcore anymore. Anyways, I'm aware of:
/home/tc/home/.X.d/
Which works when Xorg is properly closed and reopened. However, what I'm trying to get is a "persistent" setxkbmap configuration. When keyboard is unplugged, automatically setxkbmap reverts itself back to defaults (en). So I have to open a new terminal and type in:
setxkbmap es
Every single time I disconnect the keyboard, which happens quite often.
Is it possible to change the default keyboard layout so it always be: es?
Thank you.
-
Hi Santos
I think this can be done with udev.
Create a file called /etc/udev/rules.d/98-keyboard-map.rules containing the following:
ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_KEYBOARD}=="?*", RUN+="/usr/local/bin/setxkbmap es"
Now make udev aware of the new rules file:
sudo udevadm control --reload-rules
Unplug your keyboard, count to 3, and plug it back in. See if the keyboard is correctly programmed.
If it looks correct, add the .rules file you created to your backup. Add the udevadm control --reload-rules
command to your bootlocal.sh file.
-
Have you tried to set the correct keyboard layout for X11.
Like this threads:
http://forum.tinycorelinux.net/index.php/topic,20065.msg124906.html#msg124906
http://forum.tinycorelinux.net/index.php/topic,24864.msg158216.html#msg158216
-
Hi Santos
... Create a file called /etc/udev/rules.d/98-keyboard-map.rules containing the following:
ACTION=="add", SUBSYSTEM=="input", ENV{ID_INPUT_KEYBOARD}=="?*", RUN+="/usr/local/bin/setxkbmap es"
...
It's possible you may have to do the RUN part a little differently:
Sorry, see attachment, forum error.
-
Hello
...
It's possible you may have to do the RUN part a little differently:
Sorry, see attachment, forum error.
Thank you Rich. I did tried the first udev rule you shared. But didn't worked. I will try to test it again with the corrections. To have an alternative way of doing it.
Have you tried to set the correct keyboard layout for X11.
Like this threads:
http://forum.tinycorelinux.net/index.php/topic,20065.msg124906.html#msg124906
http://forum.tinycorelinux.net/index.php/topic,24864.msg158216.html#msg158216
Thank you patrikg. It worked. The configuration file does make the keyboard layout persistent across Xorg soft and hard reset (exiting out) same with window manager or plugging keyboard in/out.
Thread can be marked as solved.
-
Hi Santos
... I will try to test it again with the corrections. To have an alternative way of doing it. ...
I look forward to hearing whether it works or not. Remember to disable the Xorg keyboard config file and restart
Xorg prior to trying it.
The thread has been marked as solved.
-
Hello Rich.
Today I tried with the corrections you made (.txt file downloaded and checked out). But still, no change. Counted up to 3 (even tried up to ten) with keyboard unplugged, Xorg keyboard config file removed and Xorg restarted.
Am I missing something?
-
Hi Santos
... Am I missing something?
Maybe. Or maybe I missed something. Or maybe we both missed something. :)
OK, I decided to test this out on one of my machines. I changed RUN+= to:
RUN+="/bin/ash -c 'touch /home/tc/KBD'"
Make udev aware of the new rules file:
sudo udevadm control --reload-rules
I unplugged and replugged the keyboard. When I checked my home directory, there was an empty file called KBD, so
the rule did run. I also noticed it remembered that NumLock was on.
I use a US keyboard so have no need for setxkbmap , but I have numlockx.tcz installed and used that for the
next test. I changed RUN+= to:
RUN+="/bin/ash -c 'DISPLAY=:0 /usr/local/bin/numlockx off'"
I unplugged and replugged the keyboard. The NumLock LED briefly lit up before numlockx turned NumLock off.
So running an X application to change the keyboard works too.
Remember to run the udevadm command when you first copy the file to /etc/udev/rules.d/
When editing the file, don't forget to hit Save before testing it again.
Watch your spelling, punctuation, and capitalization when making changes.
... (.txt file downloaded ...
On the off chance you changed it, I think the filenames have to end in .rule
-
Hello Rich
Followed each step very carefully, triple checked the punctuation, spelling, capitalization and saved all changes on file before closing it. And ran command to update rules.
... On the off chance you changed it, I think the filenames have to end in .rule
Fear not. I downloaded the .txt file just to look at the content. I didn't blindly downloaded and put it in the directory. :-)
I did tested the same way you have done it. With a test file generated by touch . So I'm confident it is running the desired command, but maybe it is a quirk of setxkbmap?
You can try by just changing your kbmap to something else and try to put it back on: en. With the udev rule.
-
Hi Santos
OK, I think I cracked it. Run the following command:
udevadm monitor --env
Then unplug and replug the keyboard. You'll see udev print a bunch of messages. The last group is the bind command
for the keyboard. You want the values for SUBSYSTEM, ID_VENDOR_ID, and ID_MODEL_ID listed there.
Place the following in your .rules file with the values you found for SUBSYSTEM, ID_VENDOR_ID, and ID_MODEL_ID.
ACTION=="bind", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="413c", ENV{ID_MODEL_ID}=="2005" RUN+="/bin/ash -c 'DISPLAY=:0 /usr/local/bin/setxkbmap es'"
-
Isn't there a script that can read the id code of the keyboard and run the necessary command accordingly!?
-
Hi xor
I'm not aware of any such script.
The op said:
His keyboard sometimes becomes unplugged and forgets its settings.
When he plugs it back in, he wants it to automatically be detected and reconfigured.
If it did exist, how would you make that script run automatically?
-
Hello
...
OK, I think I cracked it. Run the following command:
udevadm monitor --env
...
Yes, you did. It worked this time.
Main advantage of this udev rule over the config file is there is no need to close Xorg. But is specific for each keyboard, sometimes I do change keyboards.
So, second question. Can this be more universal? Meaning: to work with any keyboard being plugged in. I just want to know whether is possible or not, with some kind of glob expanding or regex. I want to check on this myself.
Thank you.
-
Hi Santos
I can think of a few possibilities:
You can have multiple lines in the .rules file each with a different ID_VENDOR_ID and ID_MODEL_ID
It will only execute the line that matches your keyboard.
Using udevadm monitor --env
Check the ID_MODEL and ID_SERIAL fields for your keyboards. If either field contains the word Keyboard for
all of your keyboards, you can use that field instead of ID_VENDOR_ID and ID_MODEL_ID like this:
ENV{ID_MODEL}=="*?eyboar?*"
The second ? is there to prevent the forum error, you can replace it with the letter d if you wish.
-
Amazing, thank you Rich. You've answered all my questions.
-
Hi Santos
You are welcome. It was an interesting problem. The Internet is littered with others who tried to do
this using udev only to be told to use an Xorg config file when they failed. The clue came from a post
on the Archlinux forum that suggested the command was being run too early.
Running udevadm monitor --env confirmed this. Unlike a USB thumb drive whose last action is "add"
when it gets plugged in, the last action is "bind" when a keyboard gets plugged in.
-
Hello
Thank you Rich. The feature of running too early will be of my special interest. And your answer will be very helpful and is super handy right now because I always wondered how to execute a specific command based on events. But I was still searching for options, one of it was to install a monitor that gets triggered based on dmesg, based on what I now know udev seem a lot easier to set up and manage.
Will be for another post (if a run into issues). Thanks again.
-
Hi Santos
Running too early was what tripped everyone else up. Every example I saw used ACTION=="add" which is why
they failed. Someone on the Archlinux forum found a solution that launched a couple of scripts with delays, but
that was a kludge that no longer worked.