-
Notifications
You must be signed in to change notification settings - Fork 476
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
Conversation
It'd simplify this code if Also, this adds a way to read the variant. |
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().
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... |
Thanks! |
Glad to help! |
* 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
Closes #1384
If you set the xkbmap layout to a multilingual string with variants, such as:
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 becausei3status-rust
uses the commandsetxkbmap -query
to get the current layout.This pull request uses
xkb-switch
to read the current layout and keyboard variant.Example usage