Alexays / Waybar

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

hyprland/language active keymap does not update #2137

Closed xadips closed 5 months ago

xadips commented 1 year ago

The module fails to initialize with my keyboard and I can't seem to get it to work. Current module config.

"hyprland/language": {
        "format": "test {}",
        "format-us": "us",
        "format-lt": "lt",
        "keyboard-name": "duckychannel-international-co.,-ltd.-ducky-keyboard"
}

Waybar logs

Apr 24 14:01:52 ducky waybar[15926]: [2023-04-24 14:01:52.020] [error] Hyprland IPC: Couldn't get host (2)
Apr 24 14:01:52 ducky waybar[15926]: [2023-04-24 14:01:52.020] [error] hyprland language initLanguage failed with basic_string::substr: __pos (which is 50) > this->size() (which is 0)
Apr 24 14:01:52 ducky waybar[15926]: ../glib/gobject/gsignal.c:2088: type 'GtkWindow' is already overridden for signal id '73'
Apr 24 14:01:52 ducky waybar[15926]: ../glib/gobject/gsignal.c:2088: type 'GtkWindow' is already overridden for signal id '72'
Apr 24 14:01:52 ducky waybar[15926]: [2023-04-24 14:01:52.028] [error] Hyprland IPC: Couldn't get host (2)
Apr 24 14:01:52 ducky waybar[15926]: [2023-04-24 14:01:52.028] [error] hyprland language initLanguage failed with basic_string::substr: __pos (which is 50) > this->size() (which is 0)

I'm not sure whether this is an issue with waybar module or hyprland handling keyboards, there's currently multiple keyboards detected probably because of my keyboard firmware hyprctl devices

    Keyboard at fb166560:
        duckychannel-international-co.,-ltd.-ducky-keyboard-system-control
            rules: r "", m "", l "us, lt", v "", o "grp:alt_shift_toggle"
            active keymap: English (US)
            main: no
    Keyboard at fb1e01c0:
        duckychannel-international-co.,-ltd.-ducky-keyboard
            rules: r "", m "", l "us, lt", v "", o "grp:alt_shift_toggle"
            active keymap: Lithuanian
            main: no
    Keyboard at fb12cea0:
        duckychannel-international-co.,-ltd.-ducky-keyboard-1
            rules: r "", m "", l "us, lt", v "", o "grp:alt_shift_toggle"
            active keymap: English (US)
            main: no
    Keyboard at fb21e100:
        duckychannel-international-co.,-ltd.-ducky-keyboard-consumer-control
            rules: r "", m "", l "us, lt", v "", o "grp:alt_shift_toggle"
            active keymap: English (US)
            main: yes

But only a single one gets its keymap changed when I use the keymap toggle keybind, I've tried setting the keyboard name to all of the above restarting waybar but still got the same error with all of them.

d4r1us-drk commented 1 year ago

Mine gets initialized, but when I change the layout with the keybinding, the indicator doesn't change.

config:

  "hyprland/language": {
    "format": "{} \udb80\udf0c",
    "format-en": "US",
    "format-es": "ES",
    "keyboard-name": "at-translated-set-2-keyboard",
    "on-click": "hyprctl switchxkblayout at-translated-set-2-keyboard next"
  },

The logs don't show anything useful as far as I can see, it shows when I change the layout, but that's it:

[2023-04-25 04:30:03.776] [debug] Try expanding: $XDG_CONFIG_HOME/waybar/config
[2023-04-25 04:30:03.776] [debug] Try expanding: $XDG_CONFIG_HOME/waybar/config.jsonc
[2023-04-25 04:30:03.776] [debug] Try expanding: $HOME/.config/waybar/config
[2023-04-25 04:30:03.776] [debug] Found config file: $HOME/.config/waybar/config
[2023-04-25 04:30:03.776] [info] Using configuration file /home/drk/.config/waybar/config
[2023-04-25 04:30:03.776] [debug] Try expanding: $XDG_CONFIG_HOME/waybar/style.css
[2023-04-25 04:30:03.776] [debug] Try expanding: $HOME/.config/waybar/style.css
[2023-04-25 04:30:03.776] [debug] Found config file: $HOME/.config/waybar/style.css
[2023-04-25 04:30:03.776] [info] Using CSS file /home/drk/.config/waybar/style.css
[2023-04-25 04:30:03.780] [debug] Output detection done: eDP-1 (LG Display 0x05FD)
[2023-04-25 04:30:03.780] [debug] Workspace group 1 created
[2023-04-25 04:30:03.781] [debug] Workspace 1 created
[2023-04-25 04:30:03.781] [debug] Workspace 2 created
[2023-04-25 04:30:03.781] [debug] Workspace 3 created
[2023-04-25 04:30:03.781] [debug] Output 0x56332ab46b00 assigned to 1 group
[2023-04-25 04:30:03.781] [debug] Workspace 1 changed to state 0
[2023-04-25 04:30:03.781] [debug] Workspace 2 changed to state 1
[2023-04-25 04:30:03.781] [debug] Workspace 3 changed to state 0
[2023-04-25 04:30:03.781] [info] Hyprland IPC starting
[2023-04-25 04:30:03.808] [debug] hyprland language initLanguage found US 󰌌
[2023-04-25 04:30:03.811] [warning] As using a timezone, some format args may be missing as the date library haven't got a release since 2018.
[2023-04-25 04:30:03.811] [debug] network: new default route via 10.0.0.1 on if3 metric 600
[2023-04-25 04:30:03.812] [debug] network: wlp0s20f3, new addr 10.0.0.239/24
[2023-04-25 04:30:03.830] [debug] GTK widget tree:
window#waybar.background.top.eDP-1..mode-default:dir(ltr)
  decoration:dir(ltr)
  box.horizontal:dir(ltr)
    box.horizontal.modules-left:dir(ltr)
      widget:dir(ltr)
        box#workspaces.horizontal:dir(ltr)
          button.flat:dir(ltr)
            box.horizontal:dir(ltr)
              label:dir(ltr)
          button.flat.active:dir(ltr)
            box.horizontal:dir(ltr)
              label:dir(ltr)
          button.flat:dir(ltr)
            box.horizontal:dir(ltr)
              label:dir(ltr)
    box.horizontal.modules-center:dir(ltr)
    box.horizontal.modules-right:dir(ltr)
      widget:dir(ltr)
        label#idle_inhibitor:dir(ltr)
      widget:dir(ltr)
        label#language:dir(ltr)
      widget:dir(ltr)
        label#pulseaudio:dir(ltr)
      widget:dir(ltr)
        label#backlight:dir(ltr)
      widget:dir(ltr)
        label#battery:dir(ltr)
      widget:dir(ltr)
        label#network:dir(ltr)
      widget:dir(ltr)
        label#clock:dir(ltr)

[2023-04-25 04:30:03.842] [info] Bar configured (width: 1920, height: 41) for output: eDP-1
[2023-04-25 04:30:03.843] [debug] hyprland IPC received openlayer>>waybar
[2023-04-25 04:30:07.313] [debug] hyprland IPC received activelayout>>at-translated-set-2-keyboard,Spanish
[2023-04-25 04:30:08.124] [debug] hyprland IPC received activelayout>>at-translated-set-2-keyboard,English (US)
[2023-04-25 04:30:10.076] [debug] hyprland IPC received activelayout>>at-translated-set-2-keyboard,Spanish
[2023-04-25 04:30:10.608] [debug] hyprland IPC received activelayout>>at-translated-set-2-keyboard,English (US)

Using waybar-hyprland version 0.9.17

xadips commented 1 year ago

After getting the newest commit I can see the indicator but have the same issue of the keymap not changing when I change it with my keybind grp:alt_shift_toggle

xadips commented 1 year ago

using version 0.9.17.r161.g757f20fc-1 The keymap only updates on waybar restart and stays the same no matter @d4r1us-drk try using the latest commit, for some people it helped, same as https://github.com/Alexays/Waybar/issues/1989

d4r1us-drk commented 1 year ago

I installed waybar-hyprland-git-0.9.17.r161.g757f20fc-1 from the AUR and now the indicator changes with the keybind, which is weird. I forgot to say that the previous behavior was the same as @xadips's situation, the indicator only updates on restart and then stays the same. But now weirdly enough I installed the latest commit and it's working fine.

Also when I first installed waybar-hyprland (last Saturday I think), I installed the git version from the AUR and the module failed to initialize, but when I changed the layout with the keybind, it fixed itself. So I installed the version 0.9.17 and the problem was gone, then the thing stopped updating the keymap and the rest is what I did right now.

d4r1us-drk commented 1 year ago

After further testing, I realized this has something to do with the "keyboard-name" variable, when I deleted it, the issue was fixed on version 0.9.17 (not the latest git), I guess now the module now picks whatever keyboard is set to default, which is better for me actually, because I use external keyboards on my laptop. Maybe this issue was all about we setting one specific keyboard with this variable, in which case it's obvious that the indicator will not change if another keyboard is connected and set by default by Hyprland.

xadips commented 1 year ago

Version 0.9.17 core dumps for me, can't really check, but it could be to hyprland setting the wrong main keyboard as my keyboard is detected as multiple keyboards currently.

❯ waybar
[2023-04-27 10:16:10.370] [info] Using configuration file /home/spidax/.config/waybar/config
[2023-04-27 10:16:10.370] [info] Using CSS file /home/spidax/.config/waybar/style.css
[2023-04-27 10:16:10.373] [info] Hyprland IPC starting
[2023-04-27 10:16:10.379] [warning] As using a timezone, some format args may be missing as the date library haven't got a release since 2018.
C 10:16:10.384583       GLib-GObject (null):(null):(null): ../glib/gobject/gsignal.c:2088: type 'GtkWindow' is already overridden for signal id '73'
C 10:16:10.384588       GLib-GObject (null):(null):(null): ../glib/gobject/gsignal.c:2088: type 'GtkWindow' is already overridden for signal id '72'
E 10:16:10.390807               GLib (null):(null):(null): g_log_set_writer_func() called multiple times
zsh: trace trap (core dumped)  waybar
xadips commented 1 year ago

Sadly still doesn't work just wrote myself a custom script to grep the current layout for my keyboard name as a band-aid workaround for now, will revisit if there's any updates to this module.

#!/bin/bash
LAYOUT=$(hyprctl devices | rg -A 2 'duckychannel-international-co.,-ltd.-ducky-keyboard-1' | grep keymap | awk '{ print $3 }')
[[ "$LAYOUT" == "English" ]] && echo "us" || echo "lt"
"custom/keymap": {
        "format": "{}",
        "exec": "bash ~/.config/waybar/scripts/keymap.sh",
        "interval": 1
    }
archdron commented 1 year ago

After further testing, I realized this has something to do with the "keyboard-name" variable, when I deleted it, the issue was fixed on version 0.9.17 (not the latest git), I guess now the module now picks whatever keyboard is set to default, which is better for me actually, because I use external keyboards on my laptop. Maybe this issue was all about we setting one specific keyboard with this variable, in which case it's obvious that the indicator will not change if another keyboard is connected and set by default by Hyprland.

Bumping up, as I have the same situation with multiple keyboards. Perhaps, it has something to do with the module not accepting an array of values for a variable: if you pass it in brackets like in module lists (["keyboard 1", "keybopard2"]), you get:

[warning] module hyprland/language: Disabling module "hyprland/language", Type is not convertible to string

xadips commented 1 year ago

@Alexays #2424 only fixed capslock,numlock toggle issues in keyboard state module, hyprland/language still has issues when it finds multiple keyboards as in language doesn't change when switching, please re-open.

s1syph0s commented 10 months ago

I have the same problem.. After diving in the hyprland language module source code and looking at my debug logs, I might found out that the dispatcher delimiter is , and in our keyboard name, there is a comma.. that means, that the event is parsed incorrectly:

my debug log:

[2023-12-19 11:03:31.793] [debug] hyprland IPC received activelayout>>hp,-inc-hyperx-alloy-origins,English (US)
#                                                                       ^ not delimiter           ^ the delimiter

language.cpp:

void Language::onEvent(const std::string& ev) {
  std::lock_guard<std::mutex> lg(mutex_);
  std::string kbName(begin(ev) + ev.find_last_of('>') + 1, begin(ev) + ev.find_first_of(','));
  //                                                                                     ^ this tries to find the delimiter
  // in my case, kbName will be 'hp' instead of 'hp,-inc-hyperx-alloy-origins
  auto layoutName = ev.substr(ev.find_first_of(',') + 1);

  if (config_.isMember("keyboard-name") && kbName != config_["keyboard-name"].asString())
    return;  // ignore

  layoutName = waybar::util::sanitize_string(layoutName);

  layout_ = getLayout(layoutName);

  spdlog::debug("hyprland language onevent with {}", layoutName);

  dp.emit();
}

Please note that i haven't really try to fix the code or really debug the source code, since i haven't pulled the wayland source code and mess with it. But I think that we need to adjust the delimiter to be ; instead of , to prevent this problem. I also haven't figured out how to adjust the format of the IPC..

s1syph0s commented 9 months ago

@Alexays I would like to fix this issue by changing the find_first_of method.. is there any reason why find_first_of method is used and not find_last_of?

holisticode commented 2 weeks ago

Sorry but I am not sure I understand how multiple keyboards need to be handled. The ticket is closed but I still have the issue that I have two keyboards, and only one seems to be supported by the widget.

That is, when I try to add both (comma-separated?), the widget doesn't work, and it never changes the content. So currently I have just one keyboard (the external one) enabled, but if I disconnect the laptop to use standalone, of course it doesn't work anymore.

Thanks for clarifying how to have the widget work for both keyboards.