Skip to content

The side mute switch follows its position; keyboards' Mute keys still toggle - #104

Open
ricktav wants to merge 2 commits into
OrchardLinux:mainfrom
ricktav:mute-switch
Open

ricktav wants to merge 2 commits into
OrchardLinux:mainfrom
ricktav:mute-switch

Conversation

@ricktav

@ricktav ricktav commented Nov 24, 2026

Copy link
Copy Markdown

The side mute switch follows its position

On the iPhone and the older iPads the kernel reports the ring/silent switch the way Apple's device trees in mainline do: as KEY_MUTE of the gpio-keys input device, held down while the switch is on silent. labwc takes it for a Mute key. It runs omarchy-volume mute-toggle on every repeat while the key is held, so with the switch on silent the mute turns on and off for about five seconds and the volume OSD flickers. This happens again after every boot and every wake, because the input core releases held keys at suspend and gpio-keys reports them again at resume. A toggle is also the wrong behaviour for a switch: the mute should follow the switch's position, not flip each time it moves.

The kernel's convention (KEY_MUTE held as the switch's state) is the same across Apple's device trees, so this is fixed in the session, not in the kernel.

What changes

  • omarchy-mute-switch (desktop/configuration/mute-switch, installed as /usr/libexec/omarchy-mute-switch and started from the labwc autostart). It is a small Python helper that uses only the standard library.
    • It follows every gpio-keys device that has KEY_MUTE.
    • At login it reads the switch with EVIOCGKEY and sets the default output's mute quietly.
    • After that, a change is read back 0.3 s after the last event, and the mute is set only when the position differs from the one last set. That call is omarchy-volume mute-on|mute-off, which shows the OSD.
    • Repeats are ignored.
    • The release and press around a suspend are both read after the resume, so the switch reads back the same position: no unmute, no OSD.
    • Without such a device it exits at once. It ends with the compositor.
  • omarchy-volume:
    • new mute-on and mute-off.
    • new mute-key, which labwc's XF86AudioMute now runs. It does nothing while the helper follows a switch (its pid is in $XDG_RUNTIME_DIR/omarchy-mute-switch), and toggles as before otherwise.
    • labwc cannot tell the switch from a keyboard's Mute key. So on a device with the switch, the helper also follows the Mute keys of the other input devices: Bluetooth or USB keyboards, including ones that connect later, which it looks for every 2 s. Each press toggles the mute with the OSD (omarchy-volume mute-toggle); repeats change nothing.
  • Migration 1795508927.sh rewrites the shipped omarchy-volume mute-toggle binding in existing ~/.config/labwc/rc.xml files. A user's own bindings are left alone.
  • Tests:
    • tests/test_mute_switch.py: detection of switches and keyboards from a fake sysfs, the decisions, repeats, the suspend release and press, bounce, keyboard presses and toggling, the migration.
    • Additions to test_volume_keys.py and test_package_staging.py.
  • Docs: a short section in docs/tablet-sensors.md.

Tested

iPhone 6s Plus (N66) on omarchy-a 0.3.2. The helper was copied to ~/.local/bin, and the binding was pointed at that copy's mute-key:

Test Result
Login with the switch on silent muted, no OSD
Unlock and screen on, switch on silent no OSD (before: OSD flickering for ~5 s)
Sound from a web page with the switch on silent silent
Switch to ring, then back to silent one OSD each time; sound back, then gone
s2idle suspend and wake with Power, switch on silent no OSD, still silent
Bluetooth keyboard (Logitech MediaBoard Pro) connected its device is followed for KEY_MUTE

python -m unittest discover -s tests in a python:3.11 container set up like CI: 418 tests, OK (29 skipped).

Not tested:

  • A keyboard Mute key press on hardware. The Logitech keyboard declares KEY_MUTE but has no Mute key, and /dev/uinput needs root. The keyboard path is tested with unit tests, and with a simulation of the main loop over pipes: a keyboard that connects, presses Mute with repeats, presses again and disconnects gives exactly two toggles.
  • Any iPad with the switch. The older iPads have it in the same gpio-keys node.

Seen while testing: on the N66 speaker the mute is PipeWire's software mute. The speaker's ALSA route has no mute control, so wpctl get-volume does not show [MUTED], although the node is muted (softMute: true) and nothing is heard. As a result the OSD icon may stay volume-high when muting there. That comes from the route and is not part of this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFMaVf5sMxs7xEyPFZWGEj

ricktav and others added 2 commits November 24, 2026 10:06
The kernel reports the ring/silent switch (mainline Apple device trees) as
gpio-keys' KEY_MUTE, held down while on silent. labwc's XF86AudioMute
binding toggled the mute and repeated while the key was held, so the mute
flickered on and off for seconds with the OSD, again at every boot and
resume, and flipping the switch back toggled instead of following it.

omarchy-mute-switch (/usr/libexec, from the session's autostart) finds a
gpio-keys device with KEY_MUTE, sets the default output's mute to the
switch's position at login (quietly) and follows it with the volume OSD
(omarchy-volume mute-on|mute-off). Each change is read back from the
switch (EVIOCGKEY) after a short settle, so the release and press the
kernel reports around a suspend change nothing. It exits without such a
switch, looks for a lost one again, and ends with labwc.

The Mute key binding becomes omarchy-volume mute-key, which toggles only
while no switch is followed (the helper's pid in $XDG_RUNTIME_DIR). labwc
cannot tell the switch from a keyboard's Mute key, so on such a device the
helper also follows the Mute keys of the other input devices (Bluetooth or
USB keyboards, also ones that connect later): a press toggles the mute with
the OSD, repeats change nothing. A migration rewrites the shipped binding
in existing users' rc.xml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFMaVf5sMxs7xEyPFZWGEj
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFMaVf5sMxs7xEyPFZWGEj
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