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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ release is checked here and released on by hand.
about 18 MiB more free memory on every board, with the same behaviour
(tcballard).

- Lock, idle and brightness commands answer faster: the power control
command is a small C program instead of Python (tcballard).

- Upstream's commands show their texts instead of raw keys like
`webapp.intro`, in every language upstream has, and Install > Browser
gets past its browser policy step (jannyg).
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# make install DESTDIR=<root> OMARCHY=<upstream Omarchy at desktop/upstream.lock> DBUS_NEXT=<unpacked dbus-next 0.2.3 wheel>
#
# The compiles are the on-screen keyboard (wvkbd with this repository's
# patches), the startup cursor helper (wtype), the mute-switch helper and the power daemon
# patches), the startup cursor helper (wtype), the mute-switch and power-control helpers and the power daemon
# (omarchy-powerd, against libsystemd's sd-bus: the recipe's makedepends);
# desktop/install-tree puts every file in place.

Expand All @@ -15,7 +15,7 @@ CC ?= cc
CFLAGS ?= -O2
PKG_CONFIG ?= pkg-config

all: $(BUILD)/wvkbd-mobintl $(BUILD)/wtype $(BUILD)/omarchy-powerd $(BUILD)/omarchy-mute-switch
all: $(BUILD)/wvkbd-mobintl $(BUILD)/wtype $(BUILD)/omarchy-powerd $(BUILD)/omarchy-mute-switch $(BUILD)/omarchy-powerctl

$(BUILD)/omarchy-powerd: desktop/configuration/powerd.c
mkdir -p $(BUILD)
Expand All @@ -26,6 +26,10 @@ $(BUILD)/omarchy-mute-switch: desktop/configuration/mute-switch.c
mkdir -p $(BUILD)
$(CC) $(CPPFLAGS) $(CFLAGS) -Wall -Wextra -std=c99 desktop/configuration/mute-switch.c $(LDFLAGS) -o $@

$(BUILD)/omarchy-powerctl: desktop/configuration/powerctl.c
mkdir -p $(BUILD)
$(CC) $(CPPFLAGS) $(CFLAGS) -Wall -Wextra -std=c99 desktop/configuration/powerctl.c $(LDFLAGS) -o $@

$(BUILD)/wvkbd-mobintl:
@test -d "$(WVKBD)" || { echo 'Set WVKBD to the wvkbd v0.20 source' >&2; exit 1; }
@grep -q preferred_buffer_scale /usr/include/wayland-client-protocol.h || \
Expand Down
105 changes: 105 additions & 0 deletions desktop/configuration/powerctl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* omarchy-powerctl: tell omarchy-powerd about the session (idle, wake, lock,
* dim, undim, unlocked) or query it (input, status).
*
* input: exit 0 while the panel is lit, 3 while it is dark (a dark screen
* ignores taps), 1 on unknown or error. See docs/power-and-lock.md.
*/
#define _POSIX_C_SOURCE 200809L

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <unistd.h>

#define DEFAULT_SOCK "/run/omarchy-powerd.sock"
#define TIMEOUT_SEC 3

int main(int argc, char *argv[]) {
if (argc < 2 || !argv[1][0]) {
fprintf(stderr, "omarchy-powerctl: missing command\n");
return 1;
}

const char *sock_path = getenv("OMARCHY_POWERD_SOCK");
if (!sock_path || !*sock_path)
sock_path = DEFAULT_SOCK;

struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
if (strlen(sock_path) >= sizeof(addr.sun_path)) {
fprintf(stderr, "omarchy-powerctl: socket path too long\n");
return 1;
}
memcpy(addr.sun_path, sock_path, strlen(sock_path) + 1);

int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
fprintf(stderr, "omarchy-powerctl: %s\n", strerror(errno));
return 1;
}

struct timeval tv = { .tv_sec = TIMEOUT_SEC, .tv_usec = 0 };
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));

if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
fprintf(stderr, "omarchy-powerctl: %s\n", strerror(errno));
close(fd);
return 1;
}

size_t len = strlen(argv[1]);
char msg[256];
if (len + 1 >= sizeof(msg)) {
fprintf(stderr, "omarchy-powerctl: command too long\n");
close(fd);
return 1;
}
memcpy(msg, argv[1], len);
msg[len] = '\n';

size_t sent = 0;
while (sent < len + 1) {
ssize_t n = send(fd, msg + sent, (len + 1) - sent, MSG_NOSIGNAL);
if (n < 0) {
if (errno == EINTR)
continue;
fprintf(stderr, "omarchy-powerctl: %s\n", strerror(errno));
close(fd);
return 1;
}
sent += (size_t)n;
}

char buf[65];
ssize_t r;
do {
r = recv(fd, buf, 64, 0);
} while (r < 0 && errno == EINTR);
close(fd);
if (r < 0) {
fprintf(stderr, "omarchy-powerctl: %s\n", strerror(errno));
return 1;
}
buf[r] = '\0';

char *start = buf;
while (*start == ' ' || *start == '\t' || *start == '\r' || *start == '\n')
start++;
char *end = start + strlen(start);
while (end > start && (end[-1] == ' ' || end[-1] == '\t' || end[-1] == '\r' || end[-1] == '\n'))
*--end = '\0';

printf("%s\n", start);
if (strcmp(start, "dark") == 0)
return 3;
if (strcmp(start, "unknown") == 0)
return 1;
return 0;
}
7 changes: 4 additions & 3 deletions desktop/install-tree
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ here=$(cd "$(dirname "$0")" && pwd)
project=$(dirname "$here")
shell=$here/shell config=$here/configuration
omarchy=$root/usr/share/omarchy
for input in "$build/wvkbd-mobintl" "$build/wtype" "$build/wtype.LICENSE" "$build/omarchy-mute-switch" "$build/omarchy-powerd" "$upstream/themes" "$upstream/bin" \
for input in "$build/wvkbd-mobintl" "$build/wtype" "$build/wtype.LICENSE" "$build/omarchy-powerctl" "$build/omarchy-mute-switch" "$build/omarchy-powerd" "$upstream/themes" "$upstream/bin" \
"$upstream/themes/jade-horse/colors.toml" "$upstream/icons/papercraft" "$upstream/applications/foot.desktop" "$upstream/default/hypr/toggles/bar-glassy.lua" \
"$upstream/default/i18n/en/cli.json" "$upstream/install/helpers/as-root.sh" "$upstream/install/helpers/browser-policy.sh" \
"$upstream/default/chromium/policies/omarchy.json" "$upstream/default/firefox/policies.json" "$upstream/config/chromium-flags.conf" \
Expand Down Expand Up @@ -107,13 +107,14 @@ for set in "$omarchy"/icons/*/; do
if [[ -f $set/btop.svg.tpl && ! -e $set/omactivity.svg.tpl ]]; then ln -s btop.svg.tpl "$set/omactivity.svg.tpl"; fi
done

# The keyboard, the startup cursor helper, the power daemon and the hardware
# mute-switch helper.
# The keyboard, the startup cursor helper, the power daemon, and the
# power-control and hardware mute-switch helpers.
put "$build/wvkbd-mobintl" "$omarchy/trials/wvkbd-mobintl-v0.20-font18-special15-state" 755
put "$build/wtype" "$root/usr/libexec/omarchy-wtype" 755
put "$build/wtype.LICENSE" "$root/usr/share/licenses/omarchy-wtype/LICENSE"
put "$build/omarchy-powerd" "$root/usr/libexec/omarchy-powerd" 755
put "$build/omarchy-mute-switch" "$root/usr/libexec/omarchy-mute-switch" 755
put "$build/omarchy-powerctl" "$root/usr/libexec/omarchy-powerctl" 755

# The Bluetooth helper's D-Bus library, from its wheel.
(cd "$dbus_next" && find dbus_next -type f -name '*.py' | LC_ALL=C sort) | while read -r file; do
Expand Down
1 change: 1 addition & 0 deletions release/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
HELPERS = {'usr/libexec/omarchy-wtype': 'startup cursor helper',
'usr/libexec/omarchy-powerd': 'power, lock and sleep daemon',
'usr/libexec/omarchy-mute-switch': 'mute switch helper',
'usr/libexec/omarchy-powerctl': 'power control client',
'usr/share/omarchy/trials/wvkbd-mobintl-v0.20-font18-special15-state': 'on-screen keyboard'}

def private_firmware(orchard=None):
Expand Down
20 changes: 0 additions & 20 deletions system/overlay/usr/libexec/omarchy-powerctl

This file was deleted.

2 changes: 1 addition & 1 deletion tests/package_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def inputs(base):
"""BUILD, OMARCHY and DBUS_NEXT for install-tree, under BASE."""
build, upstream, wheel = base / 'build', base / 'omarchy', base / 'wheel'
build.mkdir()
for name in ('wvkbd-mobintl', 'wtype', 'omarchy-powerd', 'omarchy-mute-switch'):
for name in ('wvkbd-mobintl', 'wtype', 'omarchy-powerd', 'omarchy-mute-switch', 'omarchy-powerctl'):
(build / name).write_bytes(elf())
(build / 'wtype.LICENSE').write_text('MIT\n')
(upstream / 'themes/jade-horse/backgrounds').mkdir(parents=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def test_the_compiled_helpers_are_of_the_roots_architecture(self):
self.assertEqual(set(audit.HELPERS), {'usr/libexec/omarchy-wtype',
'usr/libexec/omarchy-powerd',
'usr/libexec/omarchy-mute-switch',
'usr/libexec/omarchy-powerctl',
'usr/share/omarchy/trials/wvkbd-mobintl-v0.20-font18-special15-state'})
from release.architecture import check_elf
check_elf(elf('aarch64'), 'aarch64')
Expand Down
80 changes: 80 additions & 0 deletions tests/test_powerctl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""desktop/configuration/powerctl.c: native C omarchy-powerctl client tests."""
import os
from pathlib import Path
import shutil
import socket
import subprocess
import tempfile
import threading
import unittest

PROJECT = Path(__file__).resolve().parents[1]
SOURCE = PROJECT / 'desktop/configuration/powerctl.c'


@unittest.skipUnless(shutil.which('cc'), 'C compiler needed to test powerctl.c')
class PowerctlBinary(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls._tmp = tempfile.TemporaryDirectory()
cls.binary = Path(cls._tmp.name) / 'omarchy-powerctl'
subprocess.run(
['cc', '-O2', '-Wall', '-Wextra', '-Werror', '-std=c99', str(SOURCE), '-o', str(cls.binary)],
check=True,
)

@classmethod
def tearDownClass(cls):
cls._tmp.cleanup()

def run_against_reply(self, verb: str, reply: bytes):
with tempfile.TemporaryDirectory() as tmp:
sock_path = Path(tmp) / 'powerd.sock'
received = []
srv = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
srv.bind(str(sock_path))
srv.listen(1)

def serve():
conn, _ = srv.accept()
with conn:
received.append(conn.recv(256))
conn.sendall(reply)
srv.close()

t = threading.Thread(target=serve, daemon=True)
t.start()
env = dict(os.environ, OMARCHY_POWERD_SOCK=str(sock_path))
res = subprocess.run([str(self.binary), verb], env=env, capture_output=True, text=True, timeout=5)
t.join(timeout=5)
return res, received

def test_ok_dark_and_unknown_exit_codes(self):
res, rec = self.run_against_reply('input', b'ok\n')
self.assertEqual(res.returncode, 0)
self.assertEqual(res.stdout, 'ok\n')
self.assertEqual(rec, [b'input\n'])

res, rec = self.run_against_reply('input', b'dark\n')
self.assertEqual(res.returncode, 3)
self.assertEqual(res.stdout, 'dark\n')
self.assertEqual(rec, [b'input\n'])

res, rec = self.run_against_reply('bogus', b'unknown\n')
self.assertEqual(res.returncode, 1)
self.assertEqual(res.stdout, 'unknown\n')
self.assertEqual(rec, [b'bogus\n'])

def test_missing_arg_and_missing_socket_return_1(self):
res = subprocess.run([str(self.binary)], capture_output=True, text=True, timeout=5)
self.assertEqual(res.returncode, 1)
self.assertIn('omarchy-powerctl:', res.stderr)

env = dict(os.environ, OMARCHY_POWERD_SOCK='/tmp/nonexistent-omarchy-powerd-test.sock')
res = subprocess.run([str(self.binary), 'status'], env=env, capture_output=True, text=True, timeout=5)
self.assertEqual(res.returncode, 1)
self.assertIn('omarchy-powerctl:', res.stderr)


if __name__ == '__main__':
unittest.main()
Loading