Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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: 1 addition & 1 deletion packages/omamobile-settings/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pkgdesc="Native mobile Settings framework and device information"
arch=(aarch64 x86_64)
url="https://github.com/derekross/omarchy-mobile"
license=(MIT)
depends=(omarchy bash coreutils systemd brightnessctl polkit python qt6-base qt6-declarative qt6-svg)
depends=(omarchy 'omamobile-omarchy>=0.1.49' bash coreutils systemd brightnessctl polkit python qt6-base qt6-declarative qt6-svg)
makedepends=(gcc make)
checkdepends=(dbus python)

Expand Down
43 changes: 41 additions & 2 deletions packages/omamobile-settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,47 @@ This package contains the read-only foundation and one settings page, Display
(brightness and, where the monitor lists more than one, the refresh rate; the
refresh rate changes the running session only: turning the phone makes
auto-rotate apply the monitor's preferred mode again, and a session restart or a
reload of Hyprland's config does too). The page runs
`backends/display.sh` through a fixed-argument runner, with no shell string.
reload of Hyprland's config does too) and the screen lock. The page runs
`backends/display.sh` and `backends/lock.sh` through a fixed-argument runner,
with no shell string. When Settings is started from a login outside the
graphical session (for example over SSH), display.sh finds Hyprland's instance
signature from `$XDG_RUNTIME_DIR/hypr/*/.socket.sock` (the newest live one) and
sets the brightness through the user's graphical session (loginctl Display).

"Lock screen after" (30 s, 1, 2, 3 or 5 min) sets `idle.lock` in
`~/.config/omarchy/shell.json`, the one timer Omarchy's idle service has: the
phone locks after that long without input and the lock turns the screen off a
few seconds later, so lock and screen off are the same timer. There is no
Never: a phone that never locks by itself isn't offered one tap away. A 0 set
by hand in shell.json still means no idle lock, and the page says so.
"Lock after 30 minutes while a keyboard is connected" writes 1800 there while
a Bluetooth or USB keyboard (udev `ID_INPUT_KEYBOARD=1`, bus 0005, or bus 0003
outside `/devices/virtual/input`, with the letter keys and space, a name, and
not a known security token or barcode scanner) is connected, and the chosen
time back when it goes. The user unit
`omamobile-lock-keyboard.service` follows `udevadm monitor` for input devices
and runs `lock.sh apply`. It is not enabled by the package: turning the toggle
on enables and starts it, turning it off stops and disables it (opening the
page puts the unit in line with a saved choice, e.g. after an upgrade), and when it
stops `lock.sh restore` writes the chosen time back. The 1800 is only written
while that unit runs; a failed apply (a broken `shell.json`) is logged once and
retried on the next input change instead of restarting the unit. After a write
the running shell is told with `omarchy-shell shell reloadConfig`, as
Omarchy's `omarchy-shell-config` does; if that fails the page shows an error
and the reload is tried again on the next change, even one that writes
nothing. If the watcher cannot be started the toggle goes back to off.
Stay awake and idle on/off are never touched. The choice lives in
`~/.config/omamobile/lock.json`, saved (only when it changed) before
`shell.json` with a flag saying whether the 1800 in force is the keyboard's,
kept until the chosen time is back in `shell.json`, so a crash at any point
never turns it into the owner's choice. A value changed in Omarchy's
own settings is adopted. Nothing is
written until the user picks something on the page, and nothing at all if the
user's `shell.json` does not parse. Both files are written under one `flock`.
Known limits: a USB receiver, dock or KVM that exposes a full keyboard
interface counts even with no keyboard behind it; a Bluetooth keyboard that
goes to sleep disconnects, so the timer comes back until it wakes.

A second page, Battery, sets the charge limit (80, 85, 90, 95 or 100 %), only
on a phone whose device package declares one in
`/usr/share/omamobile/charge-limit.conf` (a line `supply=NAME`;
Expand Down
75 changes: 70 additions & 5 deletions packages/omamobile-settings/app/DisplayPage.qml
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
// SPDX-License-Identifier: MIT
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "."
ColumnLayout {
// Scrolls like the About page, so the keyboard text at the end can be read
// on a short screen.
ScrollView {
id: page
spacing: 14
contentWidth: availableWidth
clip: true
property int brightness: -1
property int refresh: -1
property var rates: []
property string status: qsTr("Reading the display...")
property bool busy: true
property int reqId: -1
readonly property var levels: [10, 25, 50, 75, 100]
// Screen lock (backends/lock.sh): one timer locks and then turns the screen off
property int lockAfter: -1
property bool keyboardAwake: false
property bool keyboard: false
property bool lockBusy: true
property int lockReq: -1
property string lockError: ""
readonly property var lockChoices: [{s: 30, t: qsTr("30 s")}, {s: 60, t: qsTr("1 min")}, {s: 120, t: qsTr("2 min")},
{s: 180, t: qsTr("3 min")}, {s: 300, t: qsTr("5 min")}]
function applyLock(r) {
lockBusy = false
// a saved value with an error (the shell did not reload, the watcher did not start) shows both
if (r.lock !== undefined) { lockAfter = r.lock; keyboardAwake = !!r.keyboardAwake; keyboard = !!r.keyboard }
if (r.error) { lockError = r.error; return }
if (r.lock === undefined) { lockError = qsTr("The lock backend gave no values."); return }
lockError = ""
}
function apply(r) {
busy = false
if (r.error) { status = r.error; return }
Expand All @@ -20,8 +41,17 @@ ColumnLayout {
status = rates.length > 1 ? qsTr("Tap a value; it applies at once. The refresh rate lasts until the phone is turned or the session restarts.")
: qsTr("Tap a value; it applies at once.")
}
Connections { target: actions; function onFinished(tool, r, id) { if (tool === "display" && id === page.reqId) page.apply(r) } }
Component.onCompleted: reqId = actions.run("display", ["get"])
Connections {
target: actions
function onFinished(tool, r, id) {
if (tool === "display" && id === page.reqId) page.apply(r)
else if (tool === "lock" && id === page.lockReq) page.applyLock(r)
}
}
Component.onCompleted: { reqId = actions.run("display", ["get"]); lockReq = actions.run("lock", ["get"]) }
ColumnLayout {
width: page.availableWidth
spacing: 14
SettingsLabel { text: qsTr("Brightness"); font.weight: Font.DemiBold; color: backend.foreground; Layout.fillWidth: true }
Flow {
Layout.fillWidth: true; spacing: 8
Expand Down Expand Up @@ -51,5 +81,40 @@ ColumnLayout {
}
}
SettingsLabel { text: page.status; color: backend.muted; font.pixelSize: SettingsStyle.fontPx(13); wrapMode: Text.Wrap; Layout.fillWidth: true }
Item { Layout.fillHeight: true }
SettingsLabel { text: qsTr("Lock screen after"); font.weight: Font.DemiBold; color: backend.foreground; Layout.fillWidth: true; Layout.topMargin: 8 }
Flow {
Layout.fillWidth: true; spacing: 8
Repeater {
model: page.lockChoices
delegate: SettingsButton {
required property var modelData
text: modelData.t; highlighted: page.lockAfter === modelData.s; enabled: !page.lockBusy
onClicked: { page.lockBusy = true; page.lockReq = actions.run("lock", ["set", "lock", String(modelData.s)]) }
}
}
}
SettingsLabel {
text: page.lockError !== "" ? page.lockError
: page.lockAfter === 0 ? qsTr("The lock time is off in Omarchy's settings file: the phone stays unlocked until you press the power key. Pick a time above to turn it back on.")
: qsTr("With no touch for this long the phone locks, and the screen turns off a few seconds later. Locking and screen off are the same timer.")
color: backend.muted; font.pixelSize: SettingsStyle.fontPx(13); wrapMode: Text.Wrap; Layout.fillWidth: true
}
SettingsLabel { text: qsTr("Lock after 30 minutes while a keyboard is connected"); font.weight: Font.DemiBold; color: backend.foreground; wrapMode: Text.Wrap; Layout.fillWidth: true; Layout.topMargin: 8 }
Flow {
Layout.fillWidth: true; spacing: 8
Repeater {
model: [{on: false, t: qsTr("Off")}, {on: true, t: qsTr("On")}]
delegate: SettingsButton {
required property var modelData
text: modelData.t; highlighted: page.lockAfter >= 0 && page.keyboardAwake === modelData.on; enabled: !page.lockBusy
onClicked: { page.lockBusy = true; page.lockReq = actions.run("lock", ["set", "keyboard", modelData.on ? "on" : "off"]) }
}
}
}
SettingsLabel {
text: (page.keyboard ? qsTr("A keyboard is connected now. ") : qsTr("No keyboard is connected now. "))
+ qsTr("Any Bluetooth or USB keyboard counts, a dock or receiver too. While one is connected the phone locks and the screen turns off after 30 minutes without input instead of the time above. A Bluetooth keyboard that goes to sleep counts as disconnected.")
color: backend.muted; font.pixelSize: SettingsStyle.fontPx(13); wrapMode: Text.Wrap; Layout.fillWidth: true
}
}
}
2 changes: 1 addition & 1 deletion packages/omamobile-settings/app/actionrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ActionRunner::post(const QString &tool, const QVariantMap &result, int id)

int ActionRunner::run(const QString &tool, const QStringList &args) {
static const QRegularExpression word("\\A[a-z0-9]{1,16}\\z");
static const QStringList tools = {"display", "charge"};
static const QStringList tools = {"display", "charge", "lock"};
const int id = ++m_next;
auto fail = [this, &tool, id](const QString &why) { post(tool, {{"error", why}}, id); return id; };
if (!tools.contains(tool) || args.size() > 3) return fail("unknown action");
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-settings/app/actionrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QVariantMap>
#include <QStringList>

// Runs the source-owned backend scripts (display, charge) with a fixed argument list and no shell. Pages call run();
// Runs the source-owned backend scripts (display, charge, lock) with a fixed argument list and no shell. Pages call run();
// the JSON the script prints comes back through finished(), always from the event loop and never before run()
// has returned its id.
class ActionRunner : public QObject {
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-settings/app/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"id": "display",
"title": "Display",
"detail": "Brightness and refresh rate",
"detail": "Brightness, refresh rate and screen lock",
"icon": "display",
"page": "display"
},
Expand Down
36 changes: 34 additions & 2 deletions packages/omamobile-settings/backends/display.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ fail() { printf '{"error":"%s"}\n' "$1"; exit 2; }
fake=''
[[ -z $fake || -r $fake ]] || fail "cannot read the test file"

# Settings started from a login outside the graphical session (for example over SSH) runs without
# HYPRLAND_INSTANCE_SIGNATURE, and hyprctl then finds no Hyprland: no refresh rates. Take it from $XDG_RUNTIME_DIR/hypr/<sig>/.socket.sock, the
# newest socket by mtime if there are several (a crashed Hyprland's stale socket file is not told apart).
find_hypr() {
[[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]] && return 0
local d best='' sig
for d in "${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"/hypr/*/; do
[[ -S $d.socket.sock ]] || continue
if [[ -z $best || $d.socket.sock -nt $best.socket.sock ]]; then best=$d; fi
done
[[ -n $best ]] || return 0
sig=${best%/}; sig=${sig##*/}
export HYPRLAND_INSTANCE_SIGNATURE=$sig
}
find_hypr

get_brightness() {
local v dev
if [[ -n $fake ]]; then v=$(sed -n 1p "$fake")
Expand All @@ -35,8 +51,24 @@ get_brightness() {
set_brightness() {
local dev
dev=$(omarchy-hw-display 2>/dev/null || true)
if [[ -n $dev ]]; then brightnessctl -d "$dev" --quiet set "${1}%" >/dev/null 2>&1
else brightnessctl --class=backlight --quiet set "${1}%" >/dev/null 2>&1; fi
if [[ -n $dev ]]; then brightnessctl -d "$dev" --quiet set "${1}%" >/dev/null 2>&1 && return 0
else brightnessctl --class=backlight --quiet set "${1}%" >/dev/null 2>&1 && return 0; fi
set_brightness_session "$1" "$dev"
}

# brightnessctl asks logind for the caller's own session. When Settings is started from a login outside
# the graphical session (for example over SSH), that is not the session owning the screen and logind
# refuses; ask for the user's graphical session.
set_brightness_session() {
local pct=$1 dev=$2 sid path max
[[ -n $dev ]] || dev=$(ls /sys/class/backlight 2>/dev/null | head -n1)
[[ -n $dev && -r /sys/class/backlight/$dev/max_brightness ]] || return 1
max=$(cat "/sys/class/backlight/$dev/max_brightness") || return 1
sid=$(loginctl show-user "$(id -un)" -p Display --value 2>/dev/null) || return 1
[[ -n $sid ]] || return 1
path=$(busctl call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager GetSession s "$sid" 2>/dev/null | awk '{print $2}' | tr -d '"') || return 1
[[ $path == /org/freedesktop/login1/session/* ]] || return 1
busctl call org.freedesktop.login1 "$path" org.freedesktop.login1.Session SetBrightness ssu backlight "$dev" $(( max * pct / 100 )) >/dev/null 2>&1
}
monitors_json() {
if [[ -n $fake ]]; then sed -n 2p "$fake"; else hyprctl monitors -j 2>/dev/null; fi
Expand Down
Loading
Loading