Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ is missing or empty.
- The lock and login screen have a new look: a large clock over the
wallpaper, six PIN slots and the shell's own keypad, and a wrong PIN shown
in red without anything moving.
- The Home button responds to every press: it no longer depends on what the
keyboard is doing.

## [0.3.2] - 2026-11-19

Expand Down
70 changes: 16 additions & 54 deletions desktop/shell/bin/omarchy-home-button
Original file line number Diff line number Diff line change
@@ -1,78 +1,40 @@
#!/bin/bash

# omarchy:summary=The iPad's Home button: open the launcher, or the overview when pressed twice; close the overview; nothing if the press took a screenshot or woke the screen
# omarchy:summary=The iPad's Home button: open the launcher, or the overview when pressed twice; close the overview
# omarchy:hidden=true

# labwc runs this when Home comes up. omarchy-powerd saw the same press and
# knows whether Home was pressed together with Power (a screenshot), or
# woke a dark screen: in the grace before the lock the session is still
# unlocked, so this binding runs, but the press was only the wake.
# omarchy-powerd runs this when Home comes up after a press alone on a lit
# screen: it reads the button itself, so a press that woke the screen or
# was half of Home + Power (a screenshot) never gets here, and no keyboard
# state or compositor binding stands in between.
runtime="${XDG_RUNTIME_DIR:-/run/user/$UID}"
stamp="$runtime/omarchy-home-press"
# When the press happened, in ms, from bash's own clock (no fork).
now=$(( ${EPOCHREALTIME/[.,]/} / 1000 ))

# omarchy-powerd's answer is a Python round trip, slow to start on a tablet,
# so it is asked at once and runs while this press waits for a second one.
answer_file=$(mktemp "$runtime/omarchy-home-answer.XXXXXX")
trap 'rm -f "$answer_file"' EXIT
# Each press also leaves its verdict, as soon as it is known, for a second
# press that comes before this one has finished: a press that only woke the
# screen does not make the next one a double press.
verdict="$runtime/omarchy-home-verdict-$now"
{
/usr/libexec/omarchy-powerctl home >"$answer_file" 2>&1
case $(<"$answer_file") in combo | wake) echo taken ;; *) echo pressed ;; esac >"$verdict"
} &
asker=$!
# Verdicts nobody read (no second press came) go after a few seconds.
for old in "$runtime"/omarchy-home-verdict-*; do
[[ -e $old && ${old##*-} =~ ^[0-9]+$ ]] && (( now - ${old##*-} > 5000 )) && rm -f "$old"
done

# True when the press opens nothing: half of Home + Power (a screenshot),
# or the press that woke a dark screen.
press_taken() {
wait "$asker"
local answer
answer=$(<"$answer_file")
[[ $answer == combo || $answer == wake ]]
}
# A locked session's Home is the lock screen's (waking is omarchy-powerd's).
[[ $(omarchy-shell lock status 2>/dev/null) == *'"secure":true'* ]] && exit 0

# In the overview Home goes back to the desktop (omarchy-overview-changed
# keeps the note). labwc leaves Home to this script even then, so that
# Home + Power can take a screenshot of the overview.
# keeps the note).
if [[ -e $runtime/omarchy-overview-open ]]; then
press_taken && exit 0
rm -f "$stamp" "$answer_file"
rm -f "$stamp"
exec labwc --overview
fi

# Two presses open the overview of all windows, and must not flash the
# launcher on the way. So one press waits a moment for a second: the launcher
# opens only once it is certain that the press stays alone.
# opens only once it is certain that the press stays alone. The stamp is
# this press's at once, so the first one, still waiting, will not open the
# launcher meanwhile.
last=$(cat "$stamp" 2>/dev/null)
# A second press, unless the first only woke the screen or took a
# screenshot: then this one is a press of its own (asked up to 1.5 s).
first_taken() {
local file="$runtime/omarchy-home-verdict-$1" tries=0
while [[ ! -s $file ]] && (( tries++ < 75 )); do sleep 0.02; done
[[ $(cat "$file" 2>/dev/null) == taken ]]
}
# The stamp is this press's at once, so the first one, still waiting, will
# not open the launcher meanwhile.
echo "$now" >"$stamp"
if [[ $last =~ ^[0-9]+$ ]] && (( now - last < 300 )) && ! first_taken "$last"; then
press_taken && exit 0
rm -f "$stamp" "$answer_file"
if [[ $last =~ ^[0-9]+$ ]] && (( now - last < 300 )); then
rm -f "$stamp"
exec labwc --overview
fi
sleep 0.3
if press_taken; then
[[ $(cat "$stamp" 2>/dev/null) == "$now" ]] && rm -f "$stamp"
exit 0
fi
# A second press has taken the stamp; an older, slower one may have left its own.
# A second press has taken the stamp.
[[ $(cat "$stamp" 2>/dev/null) == "$now" ]] || exit 0
rm -f "$stamp" "$answer_file"
rm -f "$stamp"
exec omarchy-shell omarchy.dock apps
17 changes: 8 additions & 9 deletions desktop/shell/labwc-rc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
Four fingers up, Home pressed twice (omarchy-home-button) or Super+Tab.
Opening it puts the app drawer and the keyboard away. It opens with no
window as well: the dimmed desktop, which a tap or Home closes.
Home closes it: labwc leaves that key to omarchy-home-button, which
knows from these commands that the overview is open. -->
Home closes it: omarchy-home-button (run by omarchy-powerd) knows
from these commands that the overview is open. -->
<overview swipe="yes"
openCommand="omarchy-overview-changed opened"
closeCommand="omarchy-overview-changed closed" />
Expand Down Expand Up @@ -60,13 +60,12 @@
<keybind key="Super_R" onRelease="yes">
<action name="Execute" command="omarchy-shell omarchy.dock apps" />
</keybind>
<!-- J71b Home emits KEY_HOMEPAGE (172), not navigation KEY_HOME. Only this home
action is the session's, and only unlocked; waking is omarchy-powerd's.
A Home press that was part of Home + Power took a screenshot instead;
a second press right after the first opens the overview, which is
why the drawer waits a moment after one press. -->
<keybind key="XF86HomePage" onRelease="yes">
<action name="Execute" command="omarchy-home-button" />
<!-- J71b Home emits KEY_HOMEPAGE (172), not navigation KEY_HOME. Its action
comes from omarchy-powerd, which reads the button itself and runs
omarchy-home-button: no keyboard state stands in between. Here it is
only kept from the focused app (a browser would go to its home page). -->
<keybind key="XF86HomePage">
<action name="Execute" command="/usr/bin/true" />
</keybind>
<!-- Keyboard shortcuts for a Bluetooth keyboard, after upstream Omarchy (W = Super).
labwc has no directional focus, so Super+arrows cycle windows; Super+Shift+arrows
Expand Down
26 changes: 26 additions & 0 deletions desktop/shell/migrations/1795120948.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
echo "Home's action comes from the button itself"

# omarchy-powerd now runs omarchy-home-button when Home is let go, so
# labwc's Home binding only keeps the key from the focused app. An existing
# rc.xml still runs the script from labwc as well (two runs would read as a
# double press and open the overview).
rc="$HOME/.config/labwc/rc.xml"
if [[ -f $rc ]] && grep -q '<keybind key="XF86HomePage" onRelease="yes">' "$rc"; then
python3 - "$rc" <<'PY'
import sys
path = sys.argv[1]
text = open(path).read()
old = ''' <keybind key="XF86HomePage" onRelease="yes">
<action name="Execute" command="omarchy-home-button" />
</keybind>'''
new = ''' <keybind key="XF86HomePage">
<action name="Execute" command="/usr/bin/true" />
</keybind>'''
if old in text:
open(path + '.new', 'w').write(text.replace(old, new, 1))
import os
os.replace(path + '.new', path)
PY
labwc=${LABWC_PID:-$(pgrep -u "$(id -u)" -x labwc | head -1 || true)}
[[ -z $labwc ]] || kill -HUP "$labwc"
fi
16 changes: 9 additions & 7 deletions docs/power-and-lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ orchard `docs/bring-up/suspend.md`); this model decides when.
1. Power, released after a short press on its own, requests lock and eases the
backlight to dark over 240 ms. Home and Power pressed together on a lit
screen take a screenshot (`omarchy-capture-screenshot fullscreen`) when the
first of them comes up within 1.5 s; Home then does not open the dock
(`omarchy-home-button` asks `omarchy-powerctl home`). Held longer (the DFU
first of them comes up within 1.5 s; Home then does not open the dock.
Held longer (the DFU
and restart combination), they do nothing. Sleep follows
only after the screen stayed dark for a short while. Idle
screen-off has an eight-second grace period before requesting lock.
Expand All @@ -40,11 +40,13 @@ times inside resume cannot measure this (printk showed 133 ms for what ktime
measured as 3.36 s); the key timestamps can. It:

- reads the `gpio-keys` input device itself (Power, Home), with kernel
timestamps on `CLOCK_MONOTONIC`. No process per press. labwc no longer binds
Power; labwc's Home binding is only the session's home action and does not
fire while locked. A Home press that woke a dark screen (in the grace before
the lock, when the session is still unlocked) opens nothing either:
`omarchy-powerctl home` answers `wake`. Volume stays with labwc, `allowWhenLocked`, and never
timestamps on `CLOCK_MONOTONIC`. labwc binds neither Power nor Home (Home
only so that the focused app does not get it). Home let go after a press
alone on a lit screen starts `omarchy-home-button` in the session at once:
the action comes from the button, so no keyboard state, held modifier or
compositor binding can swallow it. A press that woke a dark screen (also in
the grace before the lock) or was half of Home + Power starts nothing, and
the script leaves a locked session alone. Volume stays with labwc, `allowWhenLocked`, and never
touches the panel or the state;
- reads every input device that reports `SW_MACHINE_COVER` (the iPad
Smart Cover; the kernel names two hall sensors, each its own device). The
Expand Down
52 changes: 44 additions & 8 deletions system/overlay/usr/libexec/omarchy-powerd
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ class Buttons:
after a short press alone. Home and Power pressed together on a lit
screen take a screenshot when the first of them comes up, if that is
soon: held (the DFU and restart combination), they do nothing, and a
restart never releases them at all.
restart never releases them at all. Home let go after a press alone on a
lit screen is 'home-up': the session's Home action (omarchy-home-button).
It comes from the button itself, so no keyboard state, compositor
binding or held modifier stands between the press and the action.
"""

def __init__(self):
Expand Down Expand Up @@ -420,9 +423,12 @@ class Buttons:
if self.held is not None:
self._start_combo(when)
return 'home'
pressed = self.home_down is not None
self.home_down = None
event = self._end_combo(when)
self._both_up()
if event is None and pressed and not self.home_in_combo and not self.home_woke:
return 'home-up'
return event
if down:
if not lit:
Expand Down Expand Up @@ -460,9 +466,21 @@ def session_user():
return pwd.getpwnam(fields['Name'])


def user_env(user):
return {'HOME': user.pw_dir, 'USER': user.pw_name, 'XDG_RUNTIME_DIR': f'/run/user/{user.pw_uid}',
'OMARCHY_PATH': SHELL_ROOT, 'PATH': '/usr/local/bin:/usr/bin'}


def spawn_as_user(user, *argv, env=None):
"""Start ARGV as the user and return at once (as_user waits for it)."""
return subprocess.Popen(('setpriv', f'--reuid={user.pw_uid}', f'--regid={user.pw_gid}', '--init-groups', '--',
*argv), env={**user_env(user), **(env or {})}, cwd='/',
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
start_new_session=True)


def as_user(user, *argv, timeout=5):
env = {'HOME': user.pw_dir, 'USER': user.pw_name, 'XDG_RUNTIME_DIR': f'/run/user/{user.pw_uid}',
'OMARCHY_PATH': SHELL_ROOT, 'PATH': '/usr/local/bin:/usr/bin'}
env = user_env(user)
# setpriv looks the groups up in the child. In here, os.getgrouplist holds
# Python's interpreter lock through NSS, and nss-systemd (group merges
# with it) answers only once systemd has finished a sleep: the whole
Expand Down Expand Up @@ -892,6 +910,26 @@ class Daemon:
if job == 'lock':
self.post('lock-failed')

def home_action(self, when):
"""Home let go after a press alone: the session's Home, at once.

Started, not waited for: the script tells one press from two by
when each starts. Only on a lit screen (a wake's press was handled
above); the script itself leaves a locked session alone.
"""
if self.machine.state != ON:
log(f't={when:.6f} home-up: {self.machine.state}, nothing')
return
try:
user = session_user()
if user is None:
return
labwc = command('pgrep', '-u', str(user.pw_uid), '-x', 'labwc').stdout.split()
spawn_as_user(user, 'omarchy-home-button', env={'LABWC_PID': labwc[0]} if labwc else None)
log(f't={when:.6f} home-up: omarchy-home-button')
except (OSError, KeyError, ValueError, subprocess.SubprocessError) as error:
log(f'home: {error}')

def lock_session(self, user):
if as_user(user, 'omarchy-shell', 'lock', 'lock').stdout.strip() != 'ok':
return False
Expand Down Expand Up @@ -931,11 +969,6 @@ class Daemon:
if self.machine.state == GRACE:
self.feed('wake')
connection.sendall(b'lit\n' if self.machine.state == ON else b'dark\n')
elif request == 'home':
# labwc's Home binding asks: a Home press that took a screenshot or
# woke the screen (dark in the grace before the lock) opens nothing.
answer = 'combo' if self.buttons.home_in_combo else 'wake' if self.buttons.home_woke else 'alone'
connection.sendall(answer.encode() + b'\n')
elif request == 'unlocked':
# The lock screen let the user in: new USB devices work again.
usb_new_devices(True)
Expand Down Expand Up @@ -1106,6 +1139,9 @@ class Daemon:
log(f't={when:.6f} screenshot')
self.session_jobs.put('screenshot')
continue
if name == 'home-up':
self.home_action(when)
continue
# Pressed before this wake's panel lit: that wake took care of it.
if self.machine.inflight and self.lit_at is not None and when <= self.lit_at:
log(f't={when:.6f} {name}: consumed by the wake')
Expand Down
12 changes: 7 additions & 5 deletions tests/test_bluetooth_pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ def test_named_release_bindings_and_brightness_repeat(self):
('XF86HomePage', 'omarchy-shell omarchy.dock apps')):
bindings = tree.findall("./keyboard/keybind[@key='%s']" % key)
self.assertEqual(len(bindings), 1)
self.assertEqual(bindings[0].get('onRelease'), 'yes')
if key == 'XF86HomePage':
# The dock, unless the press was part of Home + Power (a screenshot).
self.assertEqual(bindings[0].find('action').get('command'), 'omarchy-home-button')
# Home's action comes from omarchy-powerd (the button itself);
# labwc only keeps the key from the focused app.
self.assertIsNone(bindings[0].get('onRelease'))
self.assertEqual(bindings[0].find('action').get('command'), '/usr/bin/true')
self.assertIn(command, (PROJECT / 'desktop/shell/bin/omarchy-home-button').read_text())
else:
self.assertEqual(bindings[0].find('action').get('command'), command)
continue
self.assertEqual(bindings[0].get('onRelease'), 'yes')
self.assertEqual(bindings[0].find('action').get('command'), command)
for key in ('XF86AudioRaiseVolume', 'XF86AudioLowerVolume'):
self.assertIsNone(tree.find("./keyboard/keybind[@key='%s']" % key).get('onRelease'))

Expand Down
9 changes: 4 additions & 5 deletions tests/test_keyboard_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ def test_overview_triggers(self):
# One press waits for a second before the drawer opens: two presses
# must not flash the drawer on the way to the overview.
self.assertLess(home.index('sleep'), home.index('omarchy-shell omarchy.dock apps'))
# Home closes the overview from the script, not inside labwc: a Home
# that is half of Home + Power must leave the overview on screen.
self.assertLess(home.index('combo'), home.index('omarchy-overview-open'))
# A press that woke the screen in the grace before the lock opens nothing.
self.assertLess(home.index('== wake'), home.index('omarchy-overview-open'))
# A locked session's Home is the lock screen's. (A press that woke the
# screen or was half of Home + Power never starts the script: see
# omarchy-powerd's 'home-up'.)
self.assertLess(home.index('lock status'), home.index('omarchy-overview-open'))
self.assertIn('omarchy-overview-open"', changed)
self.assertIn('omarchy-overview-open', (PROJECT / 'desktop/shell/default/labwc/autostart').read_text())
# The greeter has nothing to switch between.
Expand Down
30 changes: 22 additions & 8 deletions tests/test_powerd.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,16 @@ def test_user_commands_look_groups_up_in_the_child(self):
def test_a_home_press_that_wakes_the_screen_opens_nothing(self):
buttons = powerd.Buttons()
self.assertEqual(buttons.edge('home', True, 1.0, False), 'home')
buttons.edge('home', False, 1.1, True)
self.assertIsNone(buttons.edge('home', False, 1.1, True))
self.assertTrue(buttons.home_woke)
buttons.edge('home', True, 5.0, True)
self.assertFalse(buttons.home_woke)

def test_home_let_go_after_a_press_alone_is_the_home_action(self):
self.assertEqual(self.events([('home', True, 1.0), ('home', False, 1.1)]), ['home', 'home-up'])
# A release whose press was not seen (powerd started meanwhile) is not one.
self.assertEqual(self.events([('home', False, 1.1)]), [])

def test_power_alone_still_darkens_after_a_screenshot(self):
edges = [('power', True, 1.0), ('home', True, 1.1), ('home', False, 1.3), ('power', False, 1.4),
('power', True, 3.0), ('power', False, 3.2)]
Expand Down Expand Up @@ -868,13 +873,22 @@ def ask(self, request):
connection.sendall(request.encode() + b'\n')
return connection.recv(64).decode().strip()

def test_home_socket_reports_combo_after_screenshot_chord(self):
when = time.monotonic()
event = powerd.INPUT_EVENT.pack
os.write(self.key_write, b''.join(event(int(when+i/10), int((when+i/10)%1*1e6), 1, code, down)
for i, (code, down) in enumerate(((116, 1), (172, 1), (172, 0), (116, 0)))))
self.wait(lambda: self.daemon.buttons.home_in_combo)
self.assertEqual(self.ask('home'), 'combo')
def test_home_alone_starts_the_home_action_and_a_screenshot_chord_does_not(self):
# The action comes from the button: no labwc binding or keyboard
# state in between. Half of Home + Power starts nothing.
user = pwd.struct_passwd(('tablet', 'x', 1000, 1000, '', '/home/tablet', '/bin/bash'))
spawned = []
with patch.object(powerd, 'session_user', lambda: user), \
patch.object(powerd, 'spawn_as_user', lambda *argv, **options: spawned.append((argv, options))):
when = time.monotonic()
event = powerd.INPUT_EVENT.pack
os.write(self.key_write, b''.join(event(int(when+i/10), int((when+i/10)%1*1e6), 1, code, down)
for i, (code, down) in enumerate(((116, 1), (172, 1), (172, 0), (116, 0)))))
self.wait(lambda: self.daemon.buttons.home_in_combo)
self.assertEqual(spawned, [])
self.press(172)
self.wait(lambda: spawned)
self.assertEqual(spawned[0][0][1:], ('omarchy-home-button',))
self.assertEqual(self.ask('status'), 'ON')

def test_idle_dim_restore_and_manual_brightness_supersedes_dim(self):
Expand Down
Loading