Skip to content

Commit 03e6f10

Browse files
authored
feat(keyboard): ability to display and switch kb layout (#836)
This extends the existing `keys` module to be able to show the current keyboard layout, and cycle between layouts (using the `next` command) by clicking. The `keys` module has been renamed to `keyboard` to more accurately reflect its extended featureset.
1 parent ee19176 commit 03e6f10

File tree

15 files changed

+552
-202
lines changed

15 files changed

+552
-202
lines changed

Diff for: Cargo.toml

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ default = [
1818
"focused",
1919
"http",
2020
"ipc",
21-
"keys",
21+
"keyboard+all",
2222
"launcher",
2323
"music+all",
2424
"network_manager",
@@ -56,7 +56,10 @@ clock = ["chrono"]
5656

5757
focused = []
5858

59-
keys = ["dep:input", "dep:evdev-rs", "dep:libc", "dep:nix"]
59+
keyboard = ["dep:input", "dep:evdev-rs", "dep:libc", "dep:nix"]
60+
"keyboard+all" = ["keyboard", "keyboard+sway", "keyboard+hyprland"]
61+
"keyboard+sway" = ["keyboard", "sway"]
62+
"keyboard+hyprland" = ["keyboard", "hyprland"]
6063

6164
launcher = []
6265

@@ -137,7 +140,7 @@ cairo-rs = { version = "0.18.5", optional = true, features = ["png"] }
137140
# clock
138141
chrono = { version = "0.4.39", optional = true, default-features = false, features = ["clock", "unstable-locales"] }
139142

140-
# keys
143+
# keyboard
141144
input = { version = "0.9.1", optional = true }
142145
evdev-rs = { version = "0.6.1", optional = true }
143146
libc = { version = "0.2.164", optional = true }
@@ -161,17 +164,15 @@ upower_dbus = { version = "0.3.2", optional = true }
161164
# volume
162165
libpulse-binding = { version = "2.28.2", optional = true }
163166

164-
# workspaces
165-
swayipc-async = { version = "2.0.1", optional = true }
166-
hyprland = { version = "0.4.0-alpha.3", features = ["silent"], optional = true }
167-
168167
# shared
169168
futures-lite = { version = "2.6.0", optional = true } # network_manager, upower, workspaces
170169
nix = { version = "0.29.0", optional = true, features = ["event", "fs", "poll"] } # clipboard, input
171170
regex = { version = "1.11.1", default-features = false, features = [
172171
"std",
173172
], optional = true } # music, sys_info
174173
zbus = { version = "3.15.2", default-features = false, features = ["tokio"], optional = true } # network_manager, notifications, upower
174+
swayipc-async = { version = "2.0.1", optional = true } # workspaces, keyboard
175+
hyprland = { version = "0.4.0-alpha.3", features = ["silent"], optional = true } # workspaces, keyboard
175176

176177
# schema
177178
schemars = { version = "0.8.21", optional = true }

Diff for: docs/Compiling.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pacman -S openssl
2626
pacman -S libdbusmenu-gtk3
2727
# for volume support
2828
pacman -S libpulse
29-
# for keys support
29+
# for keyboard support
3030
pacman -S libinput
3131
# for lua/cairo support
3232
pacman -S luajit lua51-lgi
@@ -42,7 +42,7 @@ apt install libssl-dev
4242
apt install libdbusmenu-gtk3-dev
4343
# for volume support
4444
apt install libpulse-dev
45-
# for keys support
45+
# for keyboard support
4646
apt install libinput-dev
4747
# for lua/cairo support
4848
apt install luajit-dev lua-lgi
@@ -58,7 +58,7 @@ dnf install openssl-devel
5858
dnf install libdbusmenu-gtk3-devel
5959
# for volume support
6060
dnf install pulseaudio-libs-devel
61-
# for keys support
61+
# for keyboard support
6262
dnf install libinput-devel
6363
# for lua/cairo support
6464
dnf install luajit-devel lua-lgi
@@ -85,7 +85,7 @@ cargo build --release --no-default-features \
8585
> ⚠ Make sure you enable at least one `config` feature otherwise you will not be able to start the bar!
8686
8787
| Feature | Description |
88-
|---------------------|-----------------------------------------------------------------------------------|
88+
| ------------------- | --------------------------------------------------------------------------------- |
8989
| **Core** | |
9090
| http | Enables HTTP features. Currently this includes the ability to load remote images. |
9191
| ipc | Enables the IPC server. |
@@ -101,6 +101,10 @@ cargo build --release --no-default-features \
101101
| clipboard | Enables the `clipboard` module. |
102102
| clock | Enables the `clock` module. |
103103
| focused | Enables the `focused` module. |
104+
| keyboard | Enables the `keyboard` module without keyboard layout support. |
105+
| keyboard+all | Enables the `keyboard` module with keyboard layout support for all compositors. |
106+
| keyboard+sway | Enables the `keyboard` module with keyboard layout support for Sway. |
107+
| keyboard+hyprland | Enables the `keyboard` module with keyboard layout support for Hyprland. |
104108
| launcher | Enables the `launcher` module. |
105109
| music+all | Enables the `music` module with support for all player types. |
106110
| music+mpris | Enables the `music` module with MPRIS support. |

Diff for: docs/_Sidebar.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
- [Clock](clock)
3030
- [Custom](custom)
3131
- [Focused](focused)
32-
- [Keys](keys)
32+
- [Keyboard](keyboard)
3333
- [Label](label)
3434
- [Launcher](launcher)
3535
- [Music](music)

Diff for: docs/modules/Keyboard.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
> [!NOTE]
2+
> This module requires your user is in the `input` group.
3+
4+
> [!IMPORTANT]
5+
> The keyboard layout feature is only available on Sway and Hyprland.
6+
7+
Displays the toggle state of the capslock, num lock and scroll lock keys, and the current keyboard layout.
8+
9+
![Screenshot of keyboard widget](https://f.jstanger.dev/github/ironbar/keys.png)
10+
11+
## Configuration
12+
13+
> Type: `keyboard`
14+
15+
| Name | Type | Default | Description |
16+
| ------------------ | ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------- |
17+
| `show_caps` | `boolean` | `true` | Whether to show capslock indicator. |
18+
| `show_num` | `boolean` | `true` | Whether to show num lock indicator. |
19+
| `show_scroll` | `boolean` | `true` | Whether to show scroll lock indicator. |
20+
| `icon_size` | `integer` | `32` | Size to render icon at (image icons only). |
21+
| `icons.caps_on` | `string` or [image](images) | `󰪛` | Icon to show for enabled capslock indicator. |
22+
| `icons.caps_off` | `string` or [image](images) | `''` | Icon to show for disabled capslock indicator. |
23+
| `icons.num_on` | `string` or [image](images) | `` | Icon to show for enabled num lock indicator. |
24+
| `icons.num_off` | `string` or [image](images) | `''` | Icon to show for disabled num lock indicator. |
25+
| `icons.scroll_on` | `string` or [image](images) | `` | Icon to show for enabled scroll lock indicator. |
26+
| `icons.scroll_off` | `string` or [image](images) | `''` | Icon to show for disabled scroll lock indicator. |
27+
| `icons.layout_map` | `Map<string, string or image>` | `{}` | Map of icons or labels to show for a particular keyboard layout. Layouts use their actual name if not present in the map. |
28+
| `seat` | `string` | `seat0` | ID of the Wayland seat to attach to. |
29+
30+
<details>
31+
<summary>JSON</summary>
32+
33+
```json
34+
{
35+
"end": [
36+
{
37+
"type": "keyboard",
38+
"show_scroll": false,
39+
"icons": {
40+
"caps_on": "󰪛",
41+
"layout_map": {
42+
"English (US)": "🇺🇸",
43+
"Ukrainian": "🇺🇦"
44+
}
45+
}
46+
}
47+
]
48+
}
49+
```
50+
51+
</details>
52+
53+
<details>
54+
<summary>TOML</summary>
55+
56+
```toml
57+
[[end]]
58+
type = "keyboard"
59+
show_scroll = false
60+
61+
[end.icons]
62+
caps_on = "󰪛"
63+
64+
[end.icons.layout_map]
65+
"English (US)" = "🇺🇸"
66+
Ukrainian = "🇺🇦"
67+
```
68+
69+
</details>
70+
71+
<details>
72+
<summary>YAML</summary>
73+
74+
```yaml
75+
end:
76+
- type: keyboard
77+
show_scroll: false
78+
icons:
79+
caps_on: 󰪛
80+
layout_map:
81+
"English (US)": 🇺🇸
82+
Ukrainian: 🇺🇦
83+
84+
```
85+
86+
</details>
87+
88+
<details>
89+
<summary>Corn</summary>
90+
91+
```corn
92+
{
93+
end = [
94+
{
95+
type = "keyboard"
96+
show_scroll = false
97+
icons.caps_on = "󰪛"
98+
icons.layout_map.'English (US)' = "🇺🇸"
99+
icons.layout_map.Ukrainian = "🇺🇦"
100+
}
101+
]
102+
}
103+
```
104+
105+
</details>
106+
107+
## Styling
108+
109+
| Selector | Description |
110+
| -------------------------- | ------------------------------------------ |
111+
| `.keyboard` | Keys box container widget. |
112+
| `.keyboard .key` | Individual key indicator container widget. |
113+
| `.keyboard .key.enabled` | Key indicator where key is toggled on. |
114+
| `.keyboard .key.caps` | Capslock key indicator. |
115+
| `.keyboard .key.num` | Num lock key indicator. |
116+
| `.keyboard .key.scroll` | Scroll lock key indicator. |
117+
| `.keyboard .key.image` | Key indicator image icon. |
118+
| `.keyboard .key.text-icon` | Key indicator textual icon. |
119+
| `.keyboard .layout` | Keyboard layout indicator. |
120+
121+
For more information on styling, please see the [styling guide](styling-guide).

Diff for: docs/modules/Keys.md

-102
This file was deleted.

Diff for: nix/default.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
++ lib.optionals (hasFeature "tray") [ libdbusmenu-gtk3 ]
6565
++ lib.optionals (hasFeature "volume")[ libpulseaudio ]
6666
++ lib.optionals (hasFeature "cairo") [ luajit ]
67-
++ lib.optionals (hasFeature "keys") [ libinput libevdev ];
67+
++ lib.optionals (hasFeature "keyboard") [ libinput libevdev ];
6868

6969
propagatedBuildInputs = [ gtk3 ];
7070

0 commit comments

Comments
 (0)