Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the xkb-switch keyboard layout reader. #1386

Merged
merged 3 commits into from
Jan 8, 2022
Merged

Add support for the xkb-switch keyboard layout reader. #1386

merged 3 commits into from
Jan 8, 2022

Conversation

roguh
Copy link
Contributor

@roguh roguh commented Jan 2, 2022

Closes #1384

If you set the xkbmap layout to a multilingual string with variants, such as:

setxkbmap -layout us,es,ru
setxkbmap -variant dvorak,,phonetic

the keyboard_layout block will not show the current layout nor the current variant. It will only show the entire multilingual layout string. This is because i3status-rust uses the command setxkbmap -query to get the current layout.

$ setxkbmap -query                 ☸ 0007-04
rules:      evdev
model:      pc105
layout:     us,es,ru
variant:    dvorak,,phonetic
options:    grp:ctrls_toggle

This pull request uses xkb-switch to read the current layout and keyboard variant.

Example usage

[[block]]
block = "keyboard_layout"
driver = "xkbswitch"
format = "{layout} {variant}"
on_click = "xkb-switch -n"
interval = 1

@roguh
Copy link
Contributor Author

roguh commented Jan 2, 2022

It'd simplify this code if xkb-switch had a way to show the variant and layout separately. I opened an issue for this: sergei-mironov/xkb-switch#63

Also, this adds a way to read the variant. xkb-switch doesn't return a value for the variant if you're using the default variant. I'm just setting the variant to "" in this case. I could also set it to "default" or a user-defined value.

roguh added 3 commits January 3, 2022 11:17
Closes #1384 at #1384

If you set the xkbmap layout to a multilingual string with variants, such as:

```
setxkbmap -layout us,es,ru
setxkbmap -variant dvorak,,phonetic
```

the `keyboard_layout` block will not show the current layout nor the current variant. It will only show the entire multilingual layout string. This is because `i3status-rust` uses the command [`setxkbmap -query`](https://github.com/greshake/i3status-rust/blob/b6e1b0b755de9f4520f1ecf17086d62fc5f190fe/src/blocks/keyboard_layout.rs#L63) to get the current layout.

```
$ setxkbmap -query                 ☸ 0007-04
rules:      evdev
model:      pc105
layout:     us,es,ru
variant:    dvorak,,phonetic
options:    grp:ctrls_toggle
```

This commit uses [`xkb-switch`](https://github.com/grwlf/xkb-switch) to read the current layout and keyboard variant.

Example usage:

```
[[block]]
block = "keyboard_layout"
driver = "xkbswitch"
format = "{layout} {variant}"
interval = 1
```
- Less newlines.
- Use unwrap_or_else instead of running unwrap_or with a function call.
  This improves efficiency by making the function call lazy.
- Use a character instead of a single-character string for split().
@ammgws
Copy link
Collaborator

ammgws commented Jan 6, 2022

I guess this has come up often enough that we may as well add it. IIRC the alternative was pulling in all the X bindings just to get the layout info...

@ammgws
Copy link
Collaborator

ammgws commented Jan 8, 2022

Thanks!

@ammgws ammgws merged commit 6b8ee2a into greshake:master Jan 8, 2022
@roguh
Copy link
Contributor Author

roguh commented Jan 8, 2022

Glad to help!

MaxVerevkin pushed a commit to MaxVerevkin/i3status-rust that referenced this pull request Jan 16, 2022
* Add support for the xkb-switch keyboard layout reader.

Closes greshake#1384 at greshake#1384

If you set the xkbmap layout to a multilingual string with variants, such as:

```
setxkbmap -layout us,es,ru
setxkbmap -variant dvorak,,phonetic
```

the `keyboard_layout` block will not show the current layout nor the current variant. It will only show the entire multilingual layout string. This is because `i3status-rust` uses the command [`setxkbmap -query`](https://github.com/greshake/i3status-rust/blob/b6e1b0b755de9f4520f1ecf17086d62fc5f190fe/src/blocks/keyboard_layout.rs#L63) to get the current layout.

```
$ setxkbmap -query                 ☸ 0007-04
rules:      evdev
model:      pc105
layout:     us,es,ru
variant:    dvorak,,phonetic
options:    grp:ctrls_toggle
```

This commit uses [`xkb-switch`](https://github.com/grwlf/xkb-switch) to read the current layout and keyboard variant.

Example usage:

```
[[block]]
block = "keyboard_layout"
driver = "xkbswitch"
format = "{layout} {variant}"
interval = 1
```

* Fix formatting and linter errors.

- Less newlines.
- Use unwrap_or_else instead of running unwrap_or with a function call.
  This improves efficiency by making the function call lazy.
- Use a character instead of a single-character string for split().

* Add documentation
@ammgws ammgws mentioned this pull request Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setxkbmap command does not show current layout for multilingual layout string
3 participants