Waybar icon indicating copy to clipboard operation
Waybar copied to clipboard

(hyprland/language) "format-<shortcode>" doesn't resolve if two variants of the same language is used

Open guttermonk opened this issue 2 years ago • 11 comments

I'm having an issue using two english variants (qwerty and colemak-dh) and getting the customized icons and "US" and "DH" names to display.

        "hyprland/language" = {
          format = "{}";
          format-en = "  us";
          format-en = "  dh";
          keyboard-name = "apple-inc.-apple-internal-keyboard-/-trackpad";
          on-click = "hyprctl switchxkblayout apple-inc.-apple-internal-keyboard-/-trackpad next";
        };

I get the following error when I try to use the above configuration in NixOS: error: attribute 'format-en' already defined at /nix/store/jcw0hy1dz7lxpvrccnl0c9gdcq34qyj6-source/home/system/waybar/default.nix:174:11

As suggested above, I tried including the variant on the second format-en (i.e. format-en_colemak_dh), but that didn't work either.

When I don't specify format-en at all, they appear in waybar as English (US) and English (Colemak-DH), which is little too verbose for a toolbar. Any suggestions on how to use two variants of the same language? Thanks in advance to anyone that can help.

guttermonk avatar Oct 11 '24 00:10 guttermonk

I have the same issue. Once the layout is used, the details are detected, but using it twice produces an empty output.

Waybar config

  "hyprland/language": {
    "format": "{}",
    "format-en": "🇺🇸 us",
    "format-es": "🇪🇸 es",
    "on-click": "hyprctl switchxkblayout current next"
  }

Hyprland config

input {
    kb_layout = us,us,es
    kb_variant = ,intl,
}

Waybar debug (when switching layout)

...
[2024-11-25 10:41:45.901] [debug] hyprland language update with full name Spanish
[2024-11-25 10:41:45.901] [debug] hyprland language update with short name es
[2024-11-25 10:41:45.901] [debug] hyprland language update with short description es
[2024-11-25 10:41:45.901] [debug] hyprland language update with variant
[2024-11-25 10:41:45.901] [debug] hyprland language formatted layout name 🇪🇸 es
[2024-11-25 10:41:45.904] [debug] hyprland IPC received activelayout>>keychron-k2,English (US)
...
[2024-11-25 10:41:46.914] [debug] hyprland language update with full name English (US)
[2024-11-25 10:41:46.914] [debug] hyprland language update with short name us
[2024-11-25 10:41:46.914] [debug] hyprland language update with short description en
[2024-11-25 10:41:46.914] [debug] hyprland language update with variant
[2024-11-25 10:41:46.914] [debug] hyprland language formatted layout name 🇺🇸 us
[2024-11-25 10:41:46.917] [debug] hyprland IPC received activelayout>>keychron-k2,English (US, intl., with dead keys)
...
[2024-11-25 10:41:46.927] [debug] hyprland language didn't find matching layout
[2024-11-25 10:41:46.927] [debug] hyprland language onevent with  with dead keys)
[2024-11-25 10:41:46.927] [debug] hyprland language update with full name
[2024-11-25 10:41:46.927] [debug] hyprland language update with short name
[2024-11-25 10:41:46.927] [debug] hyprland language update with short description
[2024-11-25 10:41:46.927] [debug] hyprland language update with variant
[2024-11-25 10:41:46.927] [debug] hyprland language formatted layout name

I'm using this workaround right now in my Waybar config:

  "hyprland/language": {
    "format": "{}",
    "format-": "🇺🇸 intl",
    "format-en": "🇺🇸 us",
    "format-es": "🇪🇸 es",
    "on-click": "hyprctl switchxkblayout current next"
  },

aerz avatar Nov 25 '24 09:11 aerz

This issue may be related: https://github.com/Alexays/Waybar/issues/3696

guttermonk avatar Nov 26 '24 00:11 guttermonk

I created a $50 bounty for this bug that is claimable after I've verified the PR. This is my first time trying boss-bounty so bear with me.

guttermonk avatar Mar 01 '25 20:03 guttermonk

@Alexays, I'd love to see this fixed. Does the bug bounty help bump this? Thanks for the time.

guttermonk avatar Mar 12 '25 00:03 guttermonk

@guttermonk I moved to hyprland this week and faced the same problem. So I created the PR that fixed the problem for me : Rimsoo:patch-1

Rimsoo avatar Apr 22 '25 09:04 Rimsoo

I tried applying the patch, but I'm struggling to figure out how I would configure the "hyprland/language" module differently to get the customized icons and "US" and "DH" names (shown in the below Waybar config) to display. Here are my configs (w/NixOS formatting).

Hyprland config:

      input = {
        kb_layout = "us,us";
        kb_variant = "colemak_dh,";
        kb_options = "grp:shifts_toggle";
        follow_mouse = 1;
        numlock_by_default = 1;

        touchpad = {
          natural_scroll = true;
          tap-to-click = true;
          drag_lock = true;
          disable_while_typing = true;
          middle_button_emulation = false;
        };
      };

Waybar config:

        "hyprland/language" = {
          format-en = "󰼭   us"; # tried en1 & en2 - don't work, and either do en & dh
          format-colemak_dh = "   dh";
          keyboard-name = "apple-inc.-apple-internal-keyboard-/-trackpad";
          on-click = "hyprctl switchxkblayout apple-inc.-apple-internal-keyboard-/-trackpad next";
          tooltip = false; # tooltips not working with this module
          tooltip-format = "{}";
        };

Currently waybar uses "format-{shortDescription}" when it should probably optionally use "format-{shortDescription}-{variant}".

guttermonk avatar Apr 23 '25 02:04 guttermonk

The "format-{shortDescription}-{variant}" is working fine on my side with the following config:

Hyprland:

input {
    kb_layout = us,us
    kb_variant = colemak_dh,
    kb_options = grp:win_space_toggle
    numlock_by_default = true
    follow_mouse = 1
}

Waybar:

  "hyprland/language": {
    "format-en": "󰼭   us",
    "format-en-colemak_dh": "   dh",
    "on-click": "hyprctl switchxkblayout current next",
  },

Runing waybar in debug shows the formated layout name:

$ waybar -l debug -c ~/.config/hypr/waybar/config.jsonc -s ~/.config/hypr/waybar/style.css

[2025-04-23 10:47:48.928] [debug] hyprland IPC received activelayout>>sinowealth-gaming-kb-,English (Colemak-DH)
[2025-04-23 10:47:48.941] [debug] hyprland language onevent with English (Colemak-DH)
[2025-04-23 10:47:48.941] [debug] hyprland language update with full name English (Colemak-DH)
[2025-04-23 10:47:48.941] [debug] hyprland language update with short name us
[2025-04-23 10:47:48.941] [debug] hyprland language update with short description en
[2025-04-23 10:47:48.941] [debug] hyprland language update with variant colemak_dh
[2025-04-23 10:47:48.941] [debug] hyprland language formatted layout name    dh
[2025-04-23 10:47:49.538] [debug] Received SIGCHLD in signalThread
[2025-04-23 10:47:49.538] [debug] Cmd exited with code 0
[2025-04-23 10:47:49.548] [debug] hyprland IPC received activelayout>>sinowealth-gaming-kb-,English (US)
[2025-04-23 10:47:49.560] [debug] hyprland language onevent with English (US)
[2025-04-23 10:47:49.560] [debug] hyprland language update with full name English (US)
[2025-04-23 10:47:49.560] [debug] hyprland language update with short name us
[2025-04-23 10:47:49.560] [debug] hyprland language update with short description en
[2025-04-23 10:47:49.560] [debug] hyprland language update with variant 
[2025-04-23 10:47:49.560] [debug] hyprland language formatted layout name 󰼭   us

If still doesn't work, could you share what your debug logs gives ?

Rimsoo avatar Apr 23 '25 09:04 Rimsoo

That worked for me. Thank you so much. My UI looks so much better with this fix, and what an elegant solution. Please feel free to claim the bounty and I'll do whatever I need to on my end to make sure it goes through. Thanks again for the clean fix.

guttermonk avatar Apr 23 '25 12:04 guttermonk

Thank you so much, I’m really glad the solution worked well for you—this was actually my first time fixing an issue, so your feedback means a lot! I’ll wait for the maintainers to merge the PR before handling the bounty claim. Thanks again for your support.

Rimsoo avatar Apr 23 '25 14:04 Rimsoo

I do not know if this is not two separate problems. I can't attest for the "format-" doesn't resolve if two variants of the same language are used"; but it most certainly does not resolve when the layout description has a comma:

[2025-06-07 11:57:16.316] [debug] hyprland IPC received activelayout>>keyboard-k380-keyb
oard,Catalan (Spain, with middle-dot L)
[2025-06-07 11:57:16.328] [debug] hyprland language didn't find matching layout
[2025-06-07 11:57:16.328] [debug] hyprland language onevent with  with middle-dot L)
[2025-06-07 11:57:16.329] [debug] hyprland language update with full name 
[2025-06-07 11:57:16.329] [debug] hyprland language update with short name 
[2025-06-07 11:57:16.329] [debug] hyprland language update with short description 
[2025-06-07 11:57:16.329] [debug] hyprland language update with variant 
[2025-06-07 11:57:16.329] [debug] hyprland language formatted layout name 
[2025-06-07 11:57:16.339] [debug] hyprland language didn't find matching layout
[2025-06-07 11:57:16.339] [debug] hyprland language onevent with  with middle-dot L)
[2025-06-07 11:57:16.339] [debug] hyprland language update with full name 
[2025-06-07 11:57:16.339] [debug] hyprland language update with short name 
[2025-06-07 11:57:16.339] [debug] hyprland language update with short description 
[2025-06-07 11:57:16.339] [debug] hyprland language update with variant 
[2025-06-07 11:57:16.339] [debug] hyprland language formatted layout name 

This shows how the name "Catalan (Spain, with middle-dot L)" having a comma breaks the description up, seemingly getting the faulty layout description "Catalan (Spain" and the rest " with middle-dot L)" as an event, I can surmise by the "onevent with with middle-dot L)" line.

At first I thought this was some unescaped comma error when read as a CSV, but looking at it more carefully it seems as though something else is going on.

It seems something similar happened to @aerz with the layout "English (US, intl., with dead keys)"

Waybar debug (when switching layout)

...
[2024-11-25 10:41:46.917] [debug] hyprland IPC received activelayout>>keychron-k2,English (US, intl., with dead keys)
...
[2024-11-25 10:41:46.927] [debug] hyprland language didn't find matching layout
[2024-11-25 10:41:46.927] [debug] hyprland language onevent with  with dead keys)
[2024-11-25 10:41:46.927] [debug] hyprland language update with full name
[2024-11-25 10:41:46.927] [debug] hyprland language update with short name
[2024-11-25 10:41:46.927] [debug] hyprland language update with short description
[2024-11-25 10:41:46.927] [debug] hyprland language update with variant
[2024-11-25 10:41:46.927] [debug] hyprland language formatted layout name

since the layout description string contains not only one but two strings of which only the last final bit is extracted " with dead keys)".

I'd have to look at the code to fully understand the behavior, but it seems as though some regex /.*,(.*)/ is going on, which should be non-greedy on the first ".*".


Edit: I see @Rimsoo already spotted and fixed the bug. Sorry.

albertbarba avatar Jun 07 '25 11:06 albertbarba

Thank you so much, I’m really glad the solution worked well for you—this was actually my first time fixing an issue, so your feedback means a lot! I’ll wait for the maintainers to merge the PR before handling the bounty claim. Thanks again for your support.

@Rimsoo looks like this has been merged. Feel free to claim the bounty if you are interested: https://github.com/Alexays/Waybar/issues/3676#issuecomment-2692397691

Thanks again! Also, I have another bounty posted on a related issue: https://github.com/Alexays/Waybar/issues/3693

guttermonk avatar Jul 31 '25 00:07 guttermonk