Repository navigation
Conversation
keyboard.sh edits only the live kb_layout, kb_variant and the grp: part of kb_options in ~/.config/hypr/input.lua (backup, flock, abort if the file changed), applies it live with hyprctl eval instead of a reload, and writes the same list to the input-sources gsettings key for the OSK. Test uses fake input.lua files, a fake hyprctl and gsettings.
keyboard.sh gets a list verb (layouts and grp: switch keys from the xkb rules file). The action runner allows the keyboard tool with its wider argument set and reads up to 32 KiB of output.
next/set/lock switch every real keyboard (never squeekboard's virtual one) through hyprctl switchxkblayout and put the same layout, by name, first in the on-screen keyboard's list. A user service listens for activelayout so the xkb switch key moves the OSK too. Super+Alt+Shift+Space runs next on hardware keyboards (Super+Space is Omarchy's menu). The Settings page no longer offers grp:win_space_toggle for the same reason.
Shows EN/GR... for the main hardware keyboard when kb_layout has more than one layout, re-read on activelayout and configreloaded. The call chip anchors to the label, or to the clock when the label is hidden.
The stock file has kb_layout and kb_options only in comments. get now reports Hyprland's effective values, and set adds one hl.config() block at the end instead of failing.
…ards, bar rereads The main keyboard is now the real one marked main, else the first real one with more than one layout, else the first real one, in the bar and the switch tool. radio-control and gpio-keys count as pseudo-keyboards. A device name with a space, ; or quote is left out of the hyprctl --batch string. listen brings the other real keyboards to the index of the one switched. The bar reruns its devices read when an event comes while one is running.
gsettings is merged instead of replaced: the OSK's own languages and its
current entry stay, new hardware layouts are added (only ones squeekboard has a
file for), removed ones dropped, and a switch-key change leaves it alone. It is
written before the live apply so the layout follower never reads the old list.
A list whose first layout is not Latin is refused; the page stops it before
sending and reads the state again after a failed set. Only kb_* inside an
input = { } table are edited, a symlinked input.lua keeps its link, get uses
Hyprland's options like set does, the keyword fallback is one batch, and the
main keyboard follows the same rule as the shell.
The xkb grp: option never switched layouts on the phone (Hyprland 0.57.0), and writing gsettings on a hardware switch made squeekboard resend its keymap, so apps got Latin letters. Settings now writes ~/.config/hypr/omamobile-keyboard.lua (Alt+Shift, Ctrl+Shift, Caps Lock or none, both key orders, every keyboard but squeekboard's), phone.lua loads it, and grp: options are dropped from kb_options. omamobile-keyboard-switch only runs switchxkblayout on real keyboards; the follower service is gone. The layout picker is a search field instead of the full list.
…ected omamobile-osk-guard becomes the one writer of screen-keyboard-enabled: false while a real BT/USB keyboard is connected (same rule as the lock backend), true otherwise, while locked with a password, or in the card's show mode. Keyboards are listed per uniq in osk-hwkbd.json with a 5 s grace. A true written by the screensaver restore over a connected keyboard goes straight back off. The shade gets a keyboard card with Show/Hide on-screen keyboard and Disconnect for Bluetooth ones.
…overs any lock - Alt+Shift / Ctrl+Shift switch binds fire on release, non-consuming, so Alt+Shift+Tab, Ctrl+Shift+C/V keep working. Every switch key is bound once and only the chosen one is enabled; no hl.unbind on key strings. - phone.lua binds the default (Alt+Shift) when Settings never wrote the file. - The switch script does nothing with one layout. - osk-guard: any lock keeps auto-show on (unknown isLocked output counts as locked), no auto-show written over a running screensaver, grace counted from the removal, one process per lock poll (slower with the screen off), setting followed from gsettings monitor, exits when a monitor dies, clears the keyboard list on exit, drops bad state entries. - Keyboard card: no binding loop on the shade's room, reload timer only while the shade is open. Not tested on the phone yet.
Measured on the 8 Pro (Hyprland 0.57.0): the release binds missed 9 of 17 presses and fired ~110 ms late, press binds running switchxkblayout current next switched 11/11, a code:66 bind never fired and grp:caps_toggle switched 12/12. Caps now goes into kb_options (compose:caps dropped then), get reports caps from the effective options, and keyboard-switch next reads devices once.
…only if it was there
…compose marker on a failed write phone.lua reads input:kb_options with hl.get_config and leaves every default Alt+Shift/Ctrl+Shift bind off when it has a grp: switch, so one press doesn't switch twice; get reports none then. keyboard.sh puts the compose-caps marker on disk before input.lua loses compose:caps. Tests for both, known limits in the header.
On the 8 Pro (Hyprland 0.57.0-3.2, Dell KB7120W, 2026-11-18) grp:alt_shift_toggle switched 20/20 in both key orders, 1-2 ms after the second key, and grp:ctrl_shift_toggle 19/19; an Alt+Shift press bind on top of the option switched twice per press. So every switch key is a grp: option in kb_options (caps stays grp:caps_toggle,grp_led:caps with the compose:caps marker) and phone.lua binds nothing. get reads the choice from the effective kb_options; a fresh phone has no grp: option until one is picked. The old bind file is no longer loaded; while there is no grp: option get reports its choice and the next save writes it as xkb (old binds stay until hyprctl reload). A save that needs Hyprland's effective kb_layout/kb_options writes nothing when getoption fails.
…witch key and comes back after Later Omarchy sets Compose on Shift+Caps through omarchy:shift_caps_compose, which redefines the whole Caps Lock key, so a Caps switch key would not switch with it left in. It is handled like compose:caps: removed while caps holds the key and put back when caps lets go. The state file says which one to put back; a bare restore line from before still means compose:caps.
…failed save restores the old marker The marker named only the first Compose option it found, so with both compose:caps and omarchy:shift_caps_compose set only compose:caps came back after caps, and an option added by hand while caps was on replaced the one the marker held. It now names every option that was there or is there now, and leaving caps adds back each one that is missing. When input.lua cannot be written after the marker changed, fail() puts the old marker back instead of removing it. The header's counts now match the logged runs.
65bf593 to
3aac25f
Compare
derekross
left a comment
There was a problem hiding this comment.
Thank you, Lef. A second layout on a real keyboard is something the phone should have, and a lot of care went into this: the editor leaves comments and other options alone, keeps a backup, refuses when the file changed under it, and the tests cover the stock file, a symlink and the failure paths. I ran the backend's test, the guard's test and the two model tests here on a merge with today's main, and they pass. The measurement of the three switch keys, and the finding that a bind on top of the xkb option switches twice, are exactly the kind of evidence I like to see.
It isn't close to merging yet, though, and I'd rather say why now than after another week of work on it.
1. Omarchy 4.5 already has a store for this, and the page overrides it. You built and measured this on 4.0.6. In 4.5.0-3, which every phone is on, omarchy-setup-keyboard saves the layouts to ~/.config/omarchy/keyboard-layouts, and Omarchy's default input.lua builds kb_layout, kb_variant and kb_options from that file, puts us first when a non-Latin layout leads, and adds grp:alts_toggle. I ran your backend on 4.5's stock input.lua: the first save appends an hl.config({ input = { kb_layout = "us,gr", kb_options = "omarchy:shift_caps_compose" } }) block to the user's file. From then on Omarchy's own file is ignored and its picker fails with "Your personal keyboard layout override takes precedence over this selection". I understand why you can't call Omarchy's tool (it reloads Hyprland, which resets the refresh rate here, and it goes through Fcitx). But I'd like the page to write Omarchy's file for the layouts, apply them live with the hyprctl eval you already have, and touch input.lua only for the switch key, which Omarchy has no store for. Most of the Lua editing then goes away.
2. The Latin rule. With your list of 35 layouts, jp,us, al,us, vn,us, mt,us and kr,us are refused as not Latin, and a phone whose first layout is jp can't save anything on the page; while us:rus and us:chr are accepted. Omarchy keeps the opposite list, the 29 layouts that can't type Latin plus those two us variants (default/hypr/input.lua). Please use that one, in the backend only, and let the page ask the backend.
3. Three pull requests instead of one. (a) the Settings page and its backend; (b) the layout label in the bar; (c) the on-screen keyboard staying down while a hardware keyboard is connected, with the shade card. Each can be tested and merged on its own, and (c) is a different kind of change: it rewrites the on-screen keyboard's safety net, about 40 lines of bash that every phone depends on, into a Python daemon ten times that size, and changes a default for everyone. I read it through and the fail-safe directions are right (unknown lock state counts as locked, a stop or crash turns the keyboard back on). For (c) I'd want: a plan section with a runbook in docs/TOUCH-PLAN.md next to 0.5 (the "OSK-HWKBD-PLAN" the code cites isn't in the repository); the slow 10 s lock poll chosen only after a poll has answered "locked" (as it is, a poll that lands between the backlight going to 0 and the lock being taken schedules the next one 10 s out; I read that from the code and have not reproduced it); a word on USB receivers and docks that present a full keyboard with none attached; and a run on my Pixel 7 Pro before it merges, since it runs there at every login.
4. It has to have run. As you say yourself, the page writing the switch keys hasn't been tried on the phone, nothing has run on 4.5, and the code has six "UNVERIFIED on the phone" notes, including the live apply through hyprctl eval and the bar's event names on Hyprland 0.57. For each part: uname -r, pacman -Q omarchy quickshell hyprland and the two packages, a tools/phone-smoke report, and each UNVERIFIED note turned into a dated result or removed together with its code.
5. The on-screen keyboard's language list. omamobile-keyboard-languages and the language sheet own that list today (docs/KEYBOARD-LAYOUTS.md). Your sync_osk removes from it whatever is removed on the page, including the language the on-screen keyboard is showing, and can write it empty. Since you want the two lists separate, please only ever add, and do it through omamobile-keyboard-languages so there is one writer.
Smaller things, for when you rework it:
- The four pictures under
docs/screenshots/keyboard/aren't used by any document; please attach them to the pull request instead of committing them. The numbers in the chart belong in the plan's results. - Please take out what only your own phone ever had: the migration from the earlier bind file in
keyboard.sh, and the test lines about the old bind and the layout follower. Andomamobile-keyboard-switch, which nothing calls yet, can come with the lock-screen reset that needs it. - The backend leaves three files in
~/.config/hypr(backup, lock, state);~/.local/state/omamobile/is the place for state. - The bar starts
hyprctl -j devicesafter everyactivelayoutevent on every phone. Omarchy 4.5's own bar widget (KeyboardLayoutModel.js) reads the layout from the event itself; have a look before the next version, and a count of those events during ordinary typing on the on-screen keyboard would tell us whether it matters. - The tests that grep
KeyboardPage.qmlandBar.qmlfor a line of source pin the spelling, not the behaviour. #866 loads its page against a stub runner in the core tests; the same would work here. - Versions: you were right to leave them. Settings 0.1.3 goes to #860 and 0.1.4 to #866, so the page is 0.1.5 at the earliest; I'll set the shell's number when each part merges.
- #896 puts the choice of on-screen keyboard under Omarchy's Setup > Keyboard. It doesn't conflict with this in git, but the two of you should agree where an owner looks for what.
If you'd like to start with one part, (b) is the smallest and (a) the most useful. I'm happy to look at a sketch of (a) on Omarchy's file before you write the tests for it.
|
@derekross thanks, that's fair, and better now than in a week. I'll split it in three and redo the page on Omarchy's file. I'd take your offer and start with the sketch of (a) before I write any tests. I read the 4.5.0-3 files on the 8 Pro today (read only, nothing run yet). Short version:
Questions before I write it:
Order: once the sketch is agreed I'd send (b) first since it's small (with the I'll also talk to the author of #896 about where an owner looks for what. The full sketch, with file:line for everything I read on the phone: Sketch of (a)Sketch for part (a): Keyboard page + backend on Omarchy 4.5's storeDate: 2026-11-18. Answers the review of #892 Marks: [V] = read on the Pixel 8 Pro today (omarchy 4.5.0-3, hyprland 0.57.0-3.3, read only, file:line given). 1. What Omarchy 4.5 does (facts)
2. Data flowOn the next Hyprland start Omarchy's 3. Files written
Nothing else in 4. The switch keyOmarchy has no store for it, so it lives in the user's
Consequences to be honest about:
What is left of the Lua editing: find or replace one marked block, and detect a live 5. Live apply
[G] that 0.57 rebuilds the keymap of already connected keyboards on this eval. This is the first thing 6. Latin rule
Where the list comes from: a copy in the backend, plus a test that reads the installed 7. On-screen keyboard list: add only
8. Removed from today's backend
Kept: 9. Test planOn the phone (Pixel 8 Pro, Omarchy 4.5.0-3; each with
In the repo: the backend test against a fake 10. Open questions
|
This adds a Keyboard page to Settings for using a real keyboard with the phone, Bluetooth or USB, plus a layout label in the bar and a small keyboard card in the shade. I type Greek and English, and until now the only way to get a second layout on a hardware keyboard was editing input.lua by hand.
It builds on the Settings app @marselnenaj started in #526, it's a great app to have on the phone so I'd rather keep adding pages to it. The input.lua handling follows what I did in my desktop plugin, https://github.com/Somnius/Keyboard-Layout-for-Omarchy.
What the page does:
The bar gets a small label right of the clock (EN, GR, ...) for the hardware keyboard's layout. It only shows with more than one layout, so with one layout the bar looks the same as before.
While a keyboard is connected the on-screen keyboard doesn't pop up on every text field, and the shade gets a card with Show, Hide and Disconnect:
How it saves: layouts go into
~/.config/hypr/input.lua, the same file Omarchy uses on the desktop. The backend only replaces the live kb_layout, kb_variant and kb_options strings and leaves comments and other options alone. It takes a lock, keeps a backup next to the file, writes through a temp file and rename, follows a symlink instead of replacing it, and aborts if the file changed meanwhile. Omarchy's stock input.lua only has those keys in a commented template, so then it appends one smallhl.config({ input = { ... } })block and edits that next time. The change goes in live withhyprctl eval(falling back tohyprctl keyword), neverhyprctl reload, since a reload re-runs phone.lua and resets the refresh rate. squeekboard's list follows: a new layout is added if squeekboard has a layout file for it, and a layout removed on the page is removed there too. Languages that are only on the OSK stay. Switching layouts never writes gsettings, because that made squeekboard send its keymap again and apps got Latin letters while Hyprland said Greek.The switch key is a plain xkb option:
grp:alt_shift_toggle,grp:ctrl_shift_toggle, orgrp:caps_toggle,grp_led:caps. phone.lua binds nothing. Caps Lock takes the Caps key, socompose:caps(Omarchy 4.0) oromarchy:shift_caps_compose(4.5) comes out while Caps is the switch key and goes back when another switch key is picked, but only if it was there before.What I measured on my Pixel 8 Pro (Hyprland 0.57.0, Dell KB7120W over Bluetooth, 11-17 and 11-18), with a small logger on the keyboard's evdev node and Hyprland's socket2:
One trade-off with the chord keys: xkb switches on Ctrl+Shift or Alt+Shift even when they're part of a longer chord. With Ctrl+Shift picked, Ctrl+Shift+V in foot still pasted, but the layout also flipped to Greek on the same press. Alt+Shift does the same on Alt+Shift+Tab. So with a chord switch key, shortcuts on that chord flip the layout as a side effect. Caps Lock doesn't have that problem, which is why I use it.
Known limits:
omamobile-keyboard-switch lockis there for it but I haven't found the right place in Omarchy's lock flow to call it fromTesting: test/all passes for omamobile-settings and omamobile-shell on my desktop after rebasing on today's main. The backend tests cover the stock commented input.lua, edited files, a symlink, missing keys, hyprctl and gsettings failures, the compose marker for both Omarchy names and both at once, and a failed backup or marker write. Putting the old marker back when input.lua itself can't be written has no test of its own yet. On the phone, on Omarchy 4.0.6, I measured all three switch keys with the xkb options set in input.lua by hand. The page and the bar label ran from an earlier build of this branch, from before the xkb-only change, so the page writing these switch keys hasn't been tried on the phone yet. The phone moved to Omarchy 4.5.0 this evening, and its default input.lua does set
omarchy:shift_caps_compose, but the Caps handling for it is only covered by the tests so far.This touches the same Settings files as #866 (catalog.json, actionrunner, install, test/all, core tests), so whichever lands second needs a rebase. I didn't bump versions here because of that, I'll set them after the rebase.