Skip to content

feat: add keyboard layout indicator to bar - #130

Open
flathead wants to merge 3 commits into
Axenide:devfrom
flathead:feature/keyboard-layout-indicator
Open

feat: add keyboard layout indicator to bar#130
flathead wants to merge 3 commits into
Axenide:devfrom
flathead:feature/keyboard-layout-indicator

Conversation

@flathead

@flathead flathead commented Mar 25, 2026

Copy link
Copy Markdown

Adds a keyboard layout indicator button to the bar that shows the active XKB layout and lets users switch between configured layouts.

What was added

New files

modules/services/KeyboardLayoutService.qml -- singleton service that:

  • Detects the main keyboard and its configured layouts via hyprctl devices -j
  • Tracks the active layout index and keymap name in real time
  • Listens for activelayout>> events on the Hyprland socket for instant updates
  • Polls hyprctl devices -j every 500ms as a fallback for key combos like grp:alt_shift_toggle that do not emit socket events
  • Loads layout display names dynamically from /usr/share/X11/xkb/rules/evdev.lst (no hardcoded language table)
  • Overrides XKB names with Hyprland active_keymap values as layouts are activated
  • Provides switchLayout() (next), setLayout(index), and getDisplayName(code)

modules/bar/KeyboardLayoutIndicator.qml -- bar button that:

  • Displays a 2-letter uppercase layout code (e.g. "EN", "RU", "DE")
  • Left click cycles to the next layout
  • Right click opens a BarPopup with all available layouts as selectable buttons
  • Each popup entry shows a globe icon and the full layout name
  • Active layout is highlighted with the primary variant
  • Tooltip shows the full keymap name from Hyprland
  • Follows the same structure as ControlsButton and other bar items (radius props, shadow, hover, animations)

Modified files

config/Config.qml -- added showKeyboardLayout: true to the bar JsonAdapter.

modules/bar/BarContent.qml -- added KeyboardLayoutIndicator in both horizontal and vertical layouts, placed between ControlsButton and BatteryIndicator. Wrapped in a Loader with visibility condition:

  • Config.bar.showKeyboardLayout must be true (default)
  • KeyboardLayoutService.availableLayouts.length > 1 (auto-hides when only one layout is configured)

modules/widgets/dashboard/controls/ShellPanel.qml -- added a "Show Keyboard Layout" toggle in the Bar settings section, between "Enable Firefox Player" and the Auto-hide separator.

modules/widgets/dashboard/controls/SettingsIndex.qml -- added a search index entry for "Keyboard Layout" with keywords: language, input, switch, layout, keyboard, locale, xkb.

Behavior

  • Systems with 2+ layouts: indicator is visible by default
  • Systems with 1 layout: indicator is auto-hidden regardless of the toggle
  • Users can disable it in Settings > Ambxst > Bar > "Show Keyboard Layout"

Dependencies

  • ncat (from nmap) for Hyprland socket listening
  • /usr/share/X11/xkb/rules/evdev.lst for layout name resolution

Demo

2026-04-01T21-19-29-730Z.mp4

Install as a mod

Requires the native manager from PR #230. Paste the package link into Settings → Mods → Package source:

https://github.com/flathead/ambxst-mods/tree/main/packages/keyboard-layout-indicator

The package needs community.i18n (PR #134) for its Settings strings. The details pane marks that requirement as missing, disabled, or ready, and Install required mods fetches i18n, enables it first, and leaves this package for you to enable. The same steps from the CLI:

ambxst mods install https://github.com/flathead/ambxst-mod-i18n.git
ambxst mods enable community.i18n
ambxst mods install https://github.com/flathead/ambxst-mods/tree/main/packages/keyboard-layout-indicator
ambxst mods enable community.keyboard-layout-indicator
ambxst reload

The packaged version targets the current dev base and includes the follow-up startup fix: it uses Quickshell.Hyprland events and a retrying device query, so it no longer needs ncat or a polling loop.

Merge into Ambxst core

For core review, take this PR's branch: the feature as ordinary Ambxst source on dev.

The package patch is a separate artifact. It targets a tree that already carries the mod manager from PR #230 and the community.i18n package, because that is the only tree a mod can be installed on. To reproduce exactly what the manager composes:

git remote add flathead https://github.com/flathead/Ambxst.git
git fetch flathead feature/mod-manager
git switch -c mods/keyboard-layout-indicator flathead/feature/mod-manager
git apply --3way ambxst-mod-i18n/patches/feature.patch
git apply --3way ambxst-mods/packages/keyboard-layout-indicator/patches/feature.patch
go test ./...
go vet ./...

It adds KeyboardLayoutService.qml and KeyboardLayoutIndicator.qml, registers the indicator in both bar orientations, and adds its Config, Settings, and search-index entries. If i18n is not part of the core plan, this PR's branch carries the same feature with plain English strings. Either way the result is ordinary Ambxst source; the mod path adds no adapter that has to be rewritten for core.

Package parity

The package in flathead/ambxst-mods and this branch now carry the same feature code: KeyboardLayoutService.qml and KeyboardLayoutIndicator.qml are byte-identical, including the Hyprland-event rewrite. config/Config.qml, modules/bar/BarContent.qml, ShellPanel.qml, and SettingsIndex.qml differ only in their registration lines, because the package is generated on a tree that also carries the mod manager and community.i18n.

@flathead
flathead changed the base branch from main to dev March 25, 2026 23:20
Add a bar button that displays the active XKB layout code and allows
switching between configured layouts. Includes a popup for direct
layout selection and a toggle in Settings > Ambxst > Bar.

New files:
- modules/services/KeyboardLayoutService.qml
- modules/bar/KeyboardLayoutIndicator.qml

Modified files:
- modules/bar/BarContent.qml
- config/Config.qml
- modules/widgets/dashboard/controls/ShellPanel.qml
- modules/widgets/dashboard/controls/SettingsIndex.qml
@Axenide

Axenide commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Nice, please add some screenshots. :)

@flathead

flathead commented Apr 1, 2026

Copy link
Copy Markdown
Author

Nice, please add some screenshots. :)

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants