Skip to content

input: keyboard.numLock (on, off, restore) - #239

Open
sachahjkl wants to merge 1 commit into
bea4dev:mainfrom
sachahjkl:feat/keyboard-num-lock
Open

sachahjkl wants to merge 1 commit into
bea4dev:mainfrom
sachahjkl:feat/keyboard-num-lock

Conversation

@sachahjkl

Copy link
Copy Markdown
Contributor

The compositor owns the xkb state and never sets Num Lock, so every session starts with it off. Hyprland has numlock_by_default, KDE "Num Lock on startup", and Windows restores the last state.

This adds numLock?: "on" | "off" | "restore" to the keyboard input config (global only: there is one seat keyboard state).

  • "on" / "off": set once when the session starts, never again on a config reload or a new device, so the user's own toggling is kept.
  • "restore": the state is saved when it changes to $XDG_STATE_HOME/shoji_wm/num-lock (next to the logs), and put back at the next session start. Reading and writing happen off the event loop (a reader thread answering through a calloop channel; one writer thread that writes only the latest state, through a temp file and a rename). A missing file leaves the state as it is.
  • A keymap change (set_xkb_config / set_keymap_from_string create a new xkb::State) keeps the Num Lock state when the option is set, instead of resetting it.
  • Setting the state uses KeyboardHandle::set_modifier_state, then advertises the modifiers to the focused client and updates the LEDs (led_state_changed), which set_modifier_state alone does not do.

Note: smithay's set_modifier_state masks the layout index with STATE_LAYOUT_* flags, which would switch a multi-layout user back to layout 0; the active layout is read first and put back.

Docs: configuration/input.md (EN and JA).

Tests:

  • unit tests for parsing and merging the option, the state file path, a round trip of the state file, and the "set once" / "save only changes" rules;
  • in a nested session, with wev as the focused client: with "on" the client's first modifiers event has locked: Mod2; with "restore" and no file the state is left off, and a press of Num Lock writes on to the file.
    I have not tested it on a DRM session with a hardware LED yet.

sachahjkl added a commit to sachahjkl/ShojiWM that referenced this pull request Nov 13, 2026
The compositor owns the xkb state and never set Num Lock, so every session
started with it off. The global keyboard config's numLock sets it once when
the session starts (on, off), or puts back the state saved at the end of the
last session (restore: $XDG_STATE_HOME/shoji_wm/num-lock, read and written
off the event loop). A keymap change keeps the Num Lock state instead of
resetting it, and setting it updates the LEDs and the focused client.
@sachahjkl
sachahjkl force-pushed the feat/keyboard-num-lock branch from 9c2d5e5 to fd7a358 Compare November 16, 2026 22:10

This branch has not been deployed

No deployments
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.

1 participant