Skip to content

Match the remote's Caps Lock and Num Lock to the client's - #143

Open
Unayung wants to merge 2 commits into
omacom:mainfrom
Unayung:fix/send-lock-state
Open

Unayung wants to merge 2 commits into
omacom:mainfrom
Unayung:fix/send-lock-state

Conversation

@Unayung

@Unayung Unayung commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #138.

Problem

The server's virtual keyboard starts from a fresh KeyState with no locked modifiers, and nothing told it the client's. With Num Lock on locally (Omarchy's numlock_by_default), the keypad typed navigation keys on the remote. A Num Lock press toggles both ends, so they stayed opposite.

Fix

  • gliff-proto: new ClientMsg::Locks { caps, num } (variant 17) and the feature lock-state in FEATURES. Following the rules in msg.rs, the client sends Locks only to a server that lists the feature, so an older server never sees it. An older client simply never sends it.
  • Client: send_locks reads Caps Lock and Num Lock from the GDK seat keyboard (is_caps_locked, is_num_locked) and sends them whenever the keyboard starts going to a session: on connect, when the picture takes focus, and when that session's tab is shown.
  • Server: Locks becomes InputCmd::SetLocks. KeyState::set_locks sets or clears only the Lock and Mod2 bits, keeps the other locked modifiers, the depressed and latched ones and the layout, and the new state goes to the virtual keyboard as a modifiers request.

The client does not send on every lock change. The lock key itself is forwarded and toggles both ends, and a message sent from the GDK notify could arrive before or after that key event, which would invert the lock again.

Testing

scripts/check.sh passes, with a new test keymap::tests::set_locks_sets_num_lock_and_a_lock_key_still_toggles_it: Num Lock set while Ctrl is held keeps Ctrl, setting it again changes nothing, and a forwarded Num Lock press still toggles it off. A second test, set_locks_clears_and_leaves_other_locks_and_the_layout, sets and then clears both locks with Mod5 and the second layout locked, and checks those survive.

In a nested Hyprland with numlock_by_default = true, the server logged client locks caps=false num=true on each focus of the picture. I did not verify keypad typing end to end: with client and server on one compositor, the server's keys come back to the client window. The first Locks at connect said num=false, because a second window had keyboard focus at that moment. The send on focus corrected it before any key could be typed.

The change was written with Claude Opus 5.5.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UCs6nfZCNssaXtUYR7cpHg

The server's virtual keyboard starts with no locked modifiers, and the
first modifier change it sends clears the locks Hyprland gave it. With Num
Lock on locally (Omarchy's default), the keypad typed navigation keys on
the remote, and toggling Num Lock flipped both ends, so they stayed
opposite.

The client now sends its Caps Lock and Num Lock in a new Locks message
when the keyboard starts going to a session: on connect, when the picture
takes focus, and when the session's tab is shown. The server sets them on
the virtual keyboard's state. It goes only to a server that lists the new
lock-state feature.

Fixes omacom#138.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCs6nfZCNssaXtUYR7cpHg
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous test gap addressed and no new findings.

Summary

The PR matches the remote keyboard’s Caps Lock and Num Lock to the client’s when a session connects or gains focus.

  • Remote sessions now start with the client's Caps Lock and Num Lock state.

Reviews (2) · Last reviewed commit: "Test clearing locks and keeping the othe..." · Reviewed by Greptile

Comment thread crates/hypr-input/src/keymap.rs Resolved
set_locks clears Caps Lock and Num Lock as well as setting them, and
leaves another locked modifier and the locked layout as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UCs6nfZCNssaXtUYR7cpHg
@wynandt

wynandt commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

We reproduced this from a Windows client (gliff-win) against stock gliff-server 0.4.3. On a new session the keypad types digits correctly, so the virtual keyboard does start with Num Lock on. After the first Caps Lock press is forwarded, the remote's Num Lock turns off, and keypad 1 2 3 8 then arrives as End, Down, PgDn and Up. Forwarding Num Lock once restores it. Caps Lock also drifts out of step with the client. A client-reported lock state like this PR adds would fix both for us. Happy to test once it lands.

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.

Num Lock is inverted on the remote: the client's lock state is never sent

2 participants