sway-xkb: {layout} is empty #51

Closed
opened 6 months ago by m1s4k1 · 5 comments
m1s4k1 commented 6 months ago

The sway-xkb module doesn't display {layout} for me. I created a custom script with jq but it would be nice to have a working module too.
Sway shows 2 inputs for my identifier so I have to check type == "keyboard" also. Could this be the reason?

Inputs:

  {
    "identifier": "1133:16419:Logitech_Wireless_Keyboard_PID:4023",
    "name": "Logitech Wireless Keyboard PID:4023",
    "vendor": 1133,
    "product": 16419,
    "type": "pointer",
    "libinput": {
      "send_events": "enabled",
      "natural_scroll": "disabled"
    }
  },
  {
    "identifier": "1133:16419:Logitech_Wireless_Keyboard_PID:4023",
    "name": "Logitech Wireless Keyboard PID:4023",
    "vendor": 1133,
    "product": 16419,
    "type": "keyboard",
    "xkb_layout_names": [
      "English (US)",
      "Russian"
    ],
    "xkb_active_layout_index": 0,
    "xkb_active_layout_name": "English (US)",
    "libinput": {
      "send_events": "enabled",
      "natural_scroll": "disabled"
    }
  }

Config:

    - script:
        path: /home/m1s4k1/.config/yambar/scripts/sway-xkb
        args: ["1133:16419:Logitech_Wireless_Keyboard_PID:4023"]
        content: {string: {text: "{layout}"}}
    - sway-xkb:
        identifiers: ["1133:16419:Logitech_Wireless_Keyboard_PID:4023"]
        content: {string: {text: "{id}: <<{layout}>>"}}

jq script:

#!/bin/bash -e

sleep 1

swaymsg -t get_inputs | jq -r --arg id "$1" '
    first(.[] | select(.identifier == $id and .type == "keyboard"))
    | .xkb_active_layout_name[0:2]
    | ascii_upcase
    | "layout|string|\(.)\n"'

swaymsg -mrt subscribe '["input"]' | jq -r --arg id "$1" --unbuffered '
    select(.change == "xkb_layout")
    | .input
    | select(.identifier == $id and .type == "keyboard")
    | .xkb_active_layout_name[0:2]
    | ascii_upcase
    | "layout|string|\(.)\n"'

@dnkl Also I'd like to thank you for both foot and yambar. I really like them :)

The sway-xkb module doesn't display `{layout}` for me. I created a custom script with jq but it would be nice to have a working module too. Sway shows 2 inputs for my identifier so I have to check `type == "keyboard"` also. Could this be the reason? Inputs: ```json { "identifier": "1133:16419:Logitech_Wireless_Keyboard_PID:4023", "name": "Logitech Wireless Keyboard PID:4023", "vendor": 1133, "product": 16419, "type": "pointer", "libinput": { "send_events": "enabled", "natural_scroll": "disabled" } }, { "identifier": "1133:16419:Logitech_Wireless_Keyboard_PID:4023", "name": "Logitech Wireless Keyboard PID:4023", "vendor": 1133, "product": 16419, "type": "keyboard", "xkb_layout_names": [ "English (US)", "Russian" ], "xkb_active_layout_index": 0, "xkb_active_layout_name": "English (US)", "libinput": { "send_events": "enabled", "natural_scroll": "disabled" } } ``` Config: ```yaml - script: path: /home/m1s4k1/.config/yambar/scripts/sway-xkb args: ["1133:16419:Logitech_Wireless_Keyboard_PID:4023"] content: {string: {text: "{layout}"}} - sway-xkb: identifiers: ["1133:16419:Logitech_Wireless_Keyboard_PID:4023"] content: {string: {text: "{id}: <<{layout}>>"}} ``` jq script: ```bash #!/bin/bash -e sleep 1 swaymsg -t get_inputs | jq -r --arg id "$1" ' first(.[] | select(.identifier == $id and .type == "keyboard")) | .xkb_active_layout_name[0:2] | ascii_upcase | "layout|string|\(.)\n"' swaymsg -mrt subscribe '["input"]' | jq -r --arg id "$1" --unbuffered ' select(.change == "xkb_layout") | .input | select(.identifier == $id and .type == "keyboard") | .xkb_active_layout_name[0:2] | ascii_upcase | "layout|string|\(.)\n"' ``` @dnkl Also I'd like to thank you for both foot and yambar. I really like them :)
dnkl added the
bug
label 6 months ago
Owner

Sway shows 2 inputs for my identifier so I have to check type == "keyboard" also. Could this be the reason?

That sounds very likely. I'm thinking yambar should simply ignore non-keyboards... Can you test the following patch?

diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c
index 114a361..83d4d10 100644
--- a/modules/sway-xkb.c
+++ b/modules/sway-xkb.c
@@ -99,6 +99,15 @@ handle_input_reply(int type, const struct json_object *json, void *_mod)
             return false;
 
         const char *id = json_object_get_string(identifier);
+
+        struct json_object *type;
+        if (!json_object_object_get_ex(obj, "type", &type))
+            return false;
+        if (strcmp(json_object_get_string(type), "keyboard") != 0) {
+            LOG_DBG("ignoring non-keyboard input '%s'", id);
+            continue;
+        }
+
         struct input *input = NULL;
         for (size_t i = 0; i < m->num_inputs; i++) {
             struct input *maybe_input = &m->inputs[i];

Also I'd like to thank you for both foot and yambar. I really like them :)

You're welcome :)

> Sway shows 2 inputs for my identifier so I have to check type == "keyboard" also. Could this be the reason? That sounds very likely. I'm thinking yambar should simply ignore non-keyboards... Can you test the following patch? ```diff diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index 114a361..83d4d10 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -99,6 +99,15 @@ handle_input_reply(int type, const struct json_object *json, void *_mod) return false; const char *id = json_object_get_string(identifier); + + struct json_object *type; + if (!json_object_object_get_ex(obj, "type", &type)) + return false; + if (strcmp(json_object_get_string(type), "keyboard") != 0) { + LOG_DBG("ignoring non-keyboard input '%s'", id); + continue; + } + struct input *input = NULL; for (size_t i = 0; i < m->num_inputs; i++) { struct input *maybe_input = &m->inputs[i]; ``` > Also I'd like to thank you for both foot and yambar. I really like them :) You're welcome :)
Poster

@dnkl Could you please push it to a new branch?

@dnkl Could you please push it to a new branch?
Owner

Sure, I just pushed to the sway-xkb-ignore-non-keyboards branch.

Sure, I just pushed to the `sway-xkb-ignore-non-keyboards` branch.
Poster

It's working with the fix now. Thanks!

It's working with the fix now. Thanks!
dnkl closed this issue 6 months ago
Owner

Awesome! Thanks for testing :)

Awesome! Thanks for testing :)
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.