Repository navigation
Add set_caps_lock_led to complex modifications - #4571
Conversation
|
Thanks for the PR! This looks good, so I plan to merge it. |
71497f6 to
2f3c242
Compare
|
Thanks! No rush at all. Heads-up that the branch had drifted into a merge conflict, so I've rebased it onto current The only conflict was in Re-ran the affected suites on the rebased branch, all green:
|
2f3c242 to
b4a3c28
Compare
Add a new `to` event that controls the caps lock LED independently of
the caps lock state:
"to": [ { "set_caps_lock_led": "on" } ]
"on" and "off" force the LED, "auto" removes the override so that the
LED follows the caps lock state again.
The caps lock LED is driven by Karabiner-Core-Service, so the event is
handled in the daemon by a new caps_lock_led_override_manager rather
than being forwarded to Karabiner-Console-User-Server. This follows the
same path as set_notification_message.
device_grabber::update_caps_lock_led now prefers the override over
last_caps_lock_state_, and refreshes the LED whenever the override
changes.
Closes pqrs-org#3493
b4a3c28 to
744de99
Compare
|
Thank you for your patience. |
Closes #3493 (originally requested in #1257).
What this adds
A new
toevent that controls the caps lock LED independently of the caps lock state:{ "description": "Use the caps lock LED as a layer indicator", "manipulators": [ { "type": "basic", "from": { "key_code": "caps_lock" }, "to": [ { "set_variable": { "name": "layer", "value": 1 } }, { "set_caps_lock_led": "on" } ], "to_after_key_up": [ { "set_variable": { "name": "layer", "value": 0 } }, { "set_caps_lock_led": "auto" } ] } ] }"on""off""auto"The override is sticky: it stays in effect until another
set_caps_lock_ledchanges it. This is what makes the layer-indicator and mic-mute-indicator use cases in #3493 and #1257 work —"on"on key down,"auto"on key up.Why it is handled in the daemon
The caps lock LED is owned by
Karabiner-Core-Service:device_grabberholds thehid_keyboard_caps_lock_led_state_managerfor every grabbed device.software_functionevents are executed inKarabiner-Console-User-Server, soset_caps_lock_ledwould have to round-trip out of the process that actually owns the LED.Instead this follows the
set_notification_messagepath, which has the same shape:post_event_to_virtual_devices::manipulatecalls a daemon-side manager directly instead of pushing the event to the console user server.Implementation
src/share/types/caps_lock_led_value.hpp— newon/off/automaticenum withto_json/from_json, modelled onsticky_modifier_type.src/share/caps_lock_led_override_manager.hpp— new dispatcher-backed manager holding thestd::optional<led_state>override and emittingoverride_changed, modelled onnotification_message_manager. It deliberately does not signal when the value is unchanged, so repeatingset_caps_lock_ledon key repeat does not churn the LED.event_definition/event_queue::event— new type, variant alternative, JSON handling, factory,TO_C_STRING/TO_TYPE.post_event_to_virtual_devices— takes astd::weak_ptr<caps_lock_led_override_manager>and applies the value onkey_downonly.device_grabber::update_caps_lock_led— prefers the override overlast_caps_lock_state_, and refreshes the LED whenever the override changes.to_event_definitionaccepts it;from_event_definitionrejects it, like the otherto-only events.Tests
tests/src/caps_lock_led_override_manager/— new test directory for the manager (initial state, on/off,autoclearing the override,async_clear_override, and no signal on unchanged values).tests/src/manipulator_types/— parsing"on"/"off"/"auto", conversion toevent_queue::event,to_json/make_from_jsonround-trip, plus error cases for a non-string and an unknown value.tests/src/post_event_to_virtual_devices/— drivesmanipulate()and asserts the override changes onkey_downand is left alone onkey_up.cd tests && makepasses in full (39 suites).device_grabber.hppwas syntax-checked separately with-std=c++23 -Wall -Werror; I could not run a fullmakeofsrc/apps/CoreServicehere because it fails on anInfo.plistbuild-input error that also reproduces on a clean checkout ofmainon this machine, before any of my changes.Things you may want to decide differently
{"set_caps_lock_led": "on"}) to matchshell_command. An object ({"set_caps_lock_led": {"value": "on"}}) or an LED-keyed object ({"set_led": {"caps_lock": "on"}}, mirroringsticky_modifier) would leave more room for the Num Lock / Scroll Lock request in Controlling Caps Lock LED during Complex Modifications #1257. Happy to switch.toggle.sticky_modifierhas one, but for an LED it is ambiguous while no override is set, and the two-manipulator-with-conditions pattern already covers it. Easy to add later if you want it.The documentation for this lives in
pqrs-org/website; I am glad to open the companion PR there once the JSON shape is settled.