Skip to content

omamobile-shell: keyboard layout label in the bar, read from the activelayout event - #949

Draft
Somnius wants to merge 5 commits into
derekross:mainfrom
Somnius:kbd-split-b-1120
Draft

Somnius wants to merge 5 commits into
derekross:mainfrom
Somnius:kbd-split-b-1120

Conversation

@Somnius

@Somnius Somnius commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@derekross part (b) of the split of #892: the keyboard layout label in the bar, beside the clock. It only shows while the hardware keyboard has more than one layout, so with one layout the bar looks like before.

I looked at Omarchy 4.5's KeyboardLayoutModel.js like you suggested. The label now comes from the activelayout event itself (keyboard name and description) with the same brief rules, so a switch doesn't start hyprctl at all, and events from squeekboard's virtual keyboard are ignored. hyprctl -j devices runs at start, after a config reload, and when a layout event comes from a keyboard it hasn't read yet, so a keyboard connected later gets its label too. xkbcli list runs once, when a label is first needed. Labels follow Omarchy's briefs now instead of my old rule, Greek is still GR and English EN.

It doesn't depend on (a) or (c), the three can merge in any order. Tests are in test/status-model.js.

I haven't put a version bump in, you said you set the shell's number when each part merges.

Tested on my desktop: test/all for omamobile-shell and tools/pr-check origin/main. Not run on the phone. That also means I don't know yet that Quickshell hands over event.data the way the code expects, that the event names are right on Hyprland 0.57, that a newly connected keyboard sends an activelayout when it appears, or that xkbcli is on the phone image (on my desktop it comes with libxkbcommon). I also haven't counted the events while typing on the on-screen keyboard, which you asked for. All of that comes from the 8 Pro next, with uname, pacman and a phone-smoke report added here before I ask for a merge. Please treat it as a draft until then.

…ut event

Same label rules as Omarchy 4.5's KeyboardLayoutModel.js; hyprctl devices
only at start and on configreloaded, squeekboard's events ignored.
…ected later

Hyprland has no device-added event, so a keyboard plugged in after the
bar started never got a label. A layout event from a typed keyboard the
last read didn't have now starts one more hyprctl read.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Lef. This is the split I asked for, and the rework is the one I hoped for: the layout comes from the event, hyprctl runs only at start, after a reload and for a keyboard it hasn't seen, and the labels are xkb's briefs like Omarchy's own widget. I compared your functions with KeyboardLayoutModel.js in the 4.5.0-3 package and the label rules match. CI is green.

Two things I'd change before you take it to the phone, so the run tests the final shape:

  1. Which devices count as a keyboard. Hyprland lists the phone's own key devices as keyboards too, each carrying the seat's layout list. You exclude gpio-keys by name; I don't know that the power key and the other input nodes on our phones all go by names in your list, and if one doesn't, a phone with two layouts set and no keyboard attached shows the label all the time. Could you post hyprctl -j devices | jq -r '.keyboards[] | "\(.name) \(.layout)"' from the 8 Pro with no keyboard connected? I'll read the same on my 7 Pro. Your #866 already decides "a real keyboard is connected" by bus and key capabilities; I'd like the two to agree.

  2. The label when the keyboard goes away. Nothing re-reads the devices on a disconnect, so after a Bluetooth keyboard drops the count stays above one and the label stays until the shell restarts. A slow re-read only while the label is showing would be enough.

Smaller: a devices read that started before a switch can finish after it and put the old layout back; and Omarchy's widget takes the event's fields with event.parse(2) where it exists, which is worth copying since a layout's description can contain a comma.

Your own list of what hasn't run is the right one (the event's fields on Quickshell, the names on Hyprland 0.57, whether a new keyboard sends activelayout, xkbcli on the image, the event count while typing on the on-screen keyboard). With those, uname -r, pacman -Q omarchy quickshell hyprland omamobile-shell, a tools/phone-smoke report and a screenshot of the bar with a call up, I'll look again. I set the number when it merges.

… shows

Which keyboards count now follows derekross#866's rule: a new omamobile-keyboards
lists the input devices udev marks as keyboards on Bluetooth or real USB
with the letter keys and space, and only Hyprland keyboards with those
names count. The 8 Pro with nothing attached lists gpio-keys and
squeekboard, both us,gr; neither counts.

While the label shows, the devices are read again every 10 s, so it goes
away when a keyboard disconnects. A read that started before a switch no
longer puts the old layout back, and the event's fields come from
event.parse(2) where Quickshell has it (a description can hold a comma).
@Somnius

Somnius commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@derekross fixed, all four. How:

  • devices: it now counts the same keyboards as omamobile-settings: lock screen timeout, and lock after 30 minutes while a keyboard is connected #866's bus/key check, and the real-keyboard match follows Hyprland's naming (a comma or newline becomes -, and a repeated name gets -1, -2), so name or name-N both match. Tests for those.
  • disconnect: while the label is showing it re-reads the devices slowly, so it goes away when the keyboard does.
  • the stale read racing a switch is fixed, and it uses event.parse(2) now.
  • from the 8 Pro with nothing attached, hyprctl -j devices keyboards are only gpio-keys us,gr and hl-virtual-keyboard-squeekboard us,gr.

Two smaller things are still open and I'll do them next: the event path still only looks at the name list, and a missing omamobile-keyboards gives no label without saying why. status-model tests pass; not run on the phone yet.

…ile-keyboards fails

A switch event now sets the label only for a keyboard the last devices
read found real (derekross#866's bus/key rule), not by the name list alone, so a
phone key device the list misses can't set it. An event from a device
the last read hasn't seen at all still starts a read.

When omamobile-keyboards is missing or fails, no keyboard counts (the
phone's own keys must never show the label) and the bar logs why, once.
@Somnius

Somnius commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@derekross the two smaller things I said I'd do next are in be0939f. How:

  • the event path: a switch event now sets the label only when it comes from a keyboard the last devices read found real (the same omamobile-settings: lock screen timeout, and lock after 30 minutes while a keyboard is connected #866 bus/key rule), not from the name list alone. An event from a device the last read hasn't seen at all still starts a read, so a keyboard connected later is picked up, and one from a device it saw but didn't count starts one no sooner than 10 s after the last read, deferred rather than dropped (in case udev hadn't tagged the keyboard yet at the first read).
  • a missing omamobile-keyboards: if it's missing or fails, no keyboard counts (so the phone's own keys still never show the label) and the bar logs once why there is no label.

Tests for the model side of both in test/status-model.js (the QML wiring itself has no test); it and test/keyboards.py pass in a container. Not run on the phone yet, the run list above still stands.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Lef, for working through all four so carefully. Counting only the keyboards that pass #866's rule, matched by Hyprland's own spelling of the names, answers the first one properly, and with your 8 Pro list (gpio-keys and squeekboard only) I'm reassured; I'll read the same list on my 7 Pro with nothing attached and post it here. The slow re-read while the label shows, the switch counter that keeps an older read from winning, and event.parse(2) are all as I'd hoped.

One question I want to settle before this leaves draft, and it's mine as much as yours: omamobile-keyboards and the Python in #866's lock.sh are now the same rule written twice. If one changes, the bar and the lock page will disagree about whether a keyboard is connected. I'd rather have one copy: either #866 calls the shell's omamobile-keyboards, or a test keeps the two equal. I'll say which on #866 too, so you don't have to choose alone.

The rest is the phone run in your list. Two small things for it: top once while the label is showing, since the bar then reads the devices every 10 s, and the version, which the branch doesn't bump yet; I'll set the number and push it at merge. Heads-up: #1010 and #1014 both add to the end of StatusModel.js and its test, so whichever of you lands later will need a small rebase that keeps both sets of functions.

@derekross

Copy link
Copy Markdown
Owner

Decision on keyboard detection: one writer, the Settings package (#866). The shell only reads what Settings decided, so please drop the second copy in omamobile-keyboards and read the shared state instead.

@Somnius

Somnius commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @derekross, understood: one writer, #866 (#866).

How I'd do it, tell me if this is what you mean by shared state. The rule (ID_INPUT_KEYBOARD on Bluetooth or USB, the letter keys and space, no tokens or scanners) lives only in omamobile-settings. Settings writes what it found to a small state file under $XDG_RUNTIME_DIR, the real keyboards by name, each time it checks: lock.sh and the watcher already run on every input change while the toggle is on, and a small udev-triggered user unit would keep it current when the toggle is off. The bar here only reads that file and drops omamobile-keyboards and its test. No file, or Settings not installed, means no keyboard counts, so the phone's own keys still never show the label.

The other way would be a read-only command in Settings that the bar calls. That's one copy of the code but not one writer, so I'd go with the file unless you'd rather have the command.

Either way it touches #866, and you're about to run #866 on your 7 Pro. I don't want to move its head under that run, so I'll do the #866 part once your run is done (or now, if you'd rather run the final shape). This PR then follows on top. Nothing pushed for this yet.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Lef. Yes: a small state file that Settings writes and the bar only reads is what I meant by shared state, and "no file means no keyboard" keeps the phone's own keys from ever showing the label.

Three things to build in. A udev-started user unit runs when a keyboard appears, not when it goes, so the file also needs rewriting on removal, or the label outlives the keyboard again. Write it to a temporary name and rename it, so the bar never reads half a file. On the order, I lean towards leaving #866 as it is while my run of it is pending, and putting the writer in its own small pull request on top of #866, with this one following it; that keeps my run valid and gives the writer its own review. I'll confirm here.

I still owe you the 7 Pro's device list with nothing attached; I'll post it with my #866 run.

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