Module hyprland/language cannot be configured to be usable
I started trying to configure the hyprland/language module and came up absolutely flat. The only string I can get out of it is the full long description from the keyboard layout, and that is useless
- For two of the layouts I use it is so long as to take up half the bar
- It includes spaces, dashes, and other characters that I can't seem to match in the config so I can't even add a per-layout override in the config file
- There is no short option as in the sway equivalent
- There is no flag option as in the sway equivalent
The final output I want is a flag, but the flag option probably won't help me even if implemented correctly because, for example, I want the Kazakh flag for my Russian layout. What I really need I think is just the short identifier used to set the layout in the first place. That's a simple code I can use in the config to add custom label string per-layout.
I looked into fixing it myself, but the C++ involved is going to be out of my league especially considering the comparable Sway module is also reported not to work properly so I can't just copy bits (#1501, #1909, #1536)
Just a little more info looking into this, lets take one of my layouts as an example: My dvp layout (that's the short key used to set it, whether with setxkbmap or hyprctl) reports its full name as "USA - Programmer Dvorak`.
Since there are no options other than {} for the format string that's the only string I have to work with, but the format-* key that could be used to customize this is using the "brief" name behind the scenes. The brief layout is always being reported as an empty string by the hyprland/language module.
I can actually change the string with this:
"format-": "DVP",
But that of course changes it for all of my layouts because they all parse to an empty string for brief.
I ended up using a custom module with a very stupid script instead of the language module:
#!/bin/sh
echo "?"
nc -U /home/user/tmp/.hypr2.sock | while IFS='>,' read event noop dev layout; do
if [ "$event" = "activelayout" ]; then
case "$layout" in
Czech*) echo "π¨πΏ";;
English*) echo "πΊπΈ";;
esac
fi
done
it requires the hyprland ipc socket2 to be available at ~/tmp/.hypr2.sock (I link it there from the default location by other script). It could probably leverage IPC from waybar somehow but I haven't investigated that far, this works for me (tm)
Thanks for the hack. I might cobble something together for my use case too because this still isn't fixed and the status-quo is not usable in the slightest.
This works for me:
"hyprland/language": {
"format": "{}",
"format-en": "πΊπΈ",
"format-de": "π©πͺ",
},
So my ugly script stopped working some time ago so I gave the module a chance again and managed to configure it to behave as I want it to using this settings:
"hyprland/language": {
"format": "{}",
"format-cs": "π¨πΏ",
"format-en": "πΊπΈ",
"keyboard-name": "at-translated-set-2-keyboard"
},
Not sure if the keyboar-name key is needed and I had hard time figuring out the "short suffix" after format-. It's confusing, in hyprland config I've got us,cz(sic!)* layout but here for some reason I must use en for the US layout. Found out basically by trial and error :/
Maybe this is now more of a documentation issue? It would help to update the wiki, adding a way to find out what the "short" name for a layout is - I couldn't find it anywhere.
*) in fact my layouts in hyprland config are us_insert,cz_insert because I've got some custom key mapping. Which makes things even more confusing...
@jficz I've had the same issue with trial and error. I noticed after your comment that using waybar --log-level debug will show the correct matching keyboard name to use, but not the right short code to use in the language. I added some more debug outputs (and hence identified that my bespoke keyboard layouts don't even have short codes) that show a lot more about what is going on.