Alexays / Waybar

Highly customizable Wayland bar for Sway and Wlroots based compositors. :v: :tada:
MIT License
5.99k stars 673 forks source link

Module hyprland/language cannot be configured to be usable #2072

Open alerque opened 1 year ago

alerque commented 1 year ago

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

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)

alerque commented 1 year ago

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.

jficz commented 10 months ago

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)

alerque commented 10 months ago

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.

dann-merlin commented 5 months ago

This works for me:

    "hyprland/language": {
        "format": "{}",
        "format-en": "๐Ÿ‡บ๐Ÿ‡ธ",
        "format-de": "๐Ÿ‡ฉ๐Ÿ‡ช",
    },
jficz commented 1 month ago

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...

alerque commented 1 month ago

@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.