From 6a2fb993e0123d119d9d7f2b77295f0851d6bebc Mon Sep 17 00:00:00 2001 From: Lef Date: Tue, 10 Nov 2026 19:16:12 +0200 Subject: [PATCH 1/2] omamobile-settings 0.1.1: a Display page, brightness and refresh rate The first settings page on the foundation, opened as the display page (org.omamobile.Settings.Open("display")). Brightness is the backlight through brightnessctl, on the device omarchy-hw-display names, in steps of 10, 25, 50, 75 and 100 percent (never below 10). The refresh rate lists the rates the built-in monitor offers at its current size and applies the one tapped live, through hyprctl eval hl.monitor with the monitor's own name, size, position, scale and transform; the page hides the rate buttons when there is only one. It changes the running session only. The page runs backends/display.sh through a small ActionRunner: a fixed tool list, at most three arguments of [a-z0-9] up to 16 characters, no shell string, a 20 s kill, and the result as one line of JSON delivered from the event loop. Values taken from hyprctl are checked before they reach the eval string. Tested on a Pixel 8 Pro: test/all passes on the phone (the new backend test included), the page renders, 60 and 120 Hz apply and read back, and brightness changes when the app is started by the compositor (from an ssh login the logind brightness call is refused, which is expected). Not tested on any other phone. Signed-off-by: Lef --- packages/omamobile-settings/PKGBUILD | 2 +- packages/omamobile-settings/README.md | 9 +- .../omamobile-settings/app/DisplayPage.qml | 54 +++++++++ packages/omamobile-settings/app/Main.qml | 7 +- .../omamobile-settings/app/actionrunner.cpp | 49 ++++++++ .../omamobile-settings/app/actionrunner.h | 20 ++++ packages/omamobile-settings/app/catalog.json | 11 ++ .../omamobile-settings/app/icons/display.svg | 1 + packages/omamobile-settings/app/main.cpp | 3 + packages/omamobile-settings/app/resources.qrc | 2 + .../omamobile-settings/backends/display.sh | 106 ++++++++++++++++++ packages/omamobile-settings/install | 1 + .../omamobile-settings/omamobile-settings.pro | 4 +- packages/omamobile-settings/test/all | 1 + .../test/display-backend.sh | 47 ++++++++ .../omamobile-settings/tests/core_tests.cpp | 5 +- .../omamobile-settings/tests/session_app.pro | 4 +- packages/omamobile-settings/version | 2 +- 18 files changed, 316 insertions(+), 12 deletions(-) create mode 100644 packages/omamobile-settings/app/DisplayPage.qml create mode 100644 packages/omamobile-settings/app/actionrunner.cpp create mode 100644 packages/omamobile-settings/app/actionrunner.h create mode 100644 packages/omamobile-settings/app/icons/display.svg create mode 100755 packages/omamobile-settings/backends/display.sh create mode 100755 packages/omamobile-settings/test/display-backend.sh diff --git a/packages/omamobile-settings/PKGBUILD b/packages/omamobile-settings/PKGBUILD index a99e7a27a..28ab9ed7f 100644 --- a/packages/omamobile-settings/PKGBUILD +++ b/packages/omamobile-settings/PKGBUILD @@ -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 qt6-base qt6-declarative qt6-svg) +depends=(omarchy bash brightnessctl python qt6-base qt6-declarative qt6-svg) makedepends=(gcc make) checkdepends=(dbus python) diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index e66e00a09..993b3734c 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -6,8 +6,11 @@ palette and a read-only About page. It shows the model, operating system, kernel architecture, memory, root-filesystem capacity and installed package versions. Unknown values remain unavailable. It opens from the desktop launcher. -This initial package contains the read-only foundation. Omarchy's existing tools -continue to provide settings changes. Network, wallpaper, app management and +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). The page runs +`backends/display.sh` through a fixed-argument runner, with no shell string. +Omarchy's existing tools continue to provide the other settings changes. Network, wallpaper, app management and recording controls are separate future contributions with their own runtime contracts and tests; this catalog does not offer those routes. @@ -23,7 +26,7 @@ the implemented detail page directly. The application reads the current theme's colors.toml and observes atomic theme replacements. Rounded corners follow Hyprland's read-only decoration:rounding -option. It does not change compositor settings. A session D-Bus service handles +option. Apart from the Display page's live refresh rate it does not change compositor settings. A session D-Bus service handles repeat launches. Copyright 2026 Marsel Nenaj, MIT; see LICENSE. Extracted from my own native diff --git a/packages/omamobile-settings/app/DisplayPage.qml b/packages/omamobile-settings/app/DisplayPage.qml new file mode 100644 index 000000000..b35beddd7 --- /dev/null +++ b/packages/omamobile-settings/app/DisplayPage.qml @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: MIT +import QtQuick +import QtQuick.Layouts +import "." +ColumnLayout { + id: page + spacing: 14 + 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] + function apply(r) { + busy = false + if (r.error) { status = r.error; return } + if (r.brightness === undefined || r.refresh === undefined) { status = qsTr("The display backend gave no values."); return } + brightness = r.brightness; refresh = r.refresh; rates = r.rates || [] + status = 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"]) + SettingsLabel { text: qsTr("Brightness"); font.weight: Font.DemiBold; color: backend.foreground; Layout.fillWidth: true } + Flow { + Layout.fillWidth: true; spacing: 8 + Repeater { + model: page.levels + delegate: SettingsButton { + required property int modelData + text: modelData + "%"; highlighted: page.brightness === modelData; enabled: !page.busy + onClicked: { page.busy = true; page.reqId = actions.run("display", ["set", "brightness", String(modelData)]) } + } + } + } + SettingsLabel { + visible: page.rates.length > 1 + text: qsTr("Refresh rate"); font.weight: Font.DemiBold; color: backend.foreground; Layout.fillWidth: true; Layout.topMargin: 8 + } + Flow { + visible: page.rates.length > 1 + Layout.fillWidth: true; spacing: 8 + Repeater { + model: page.rates + delegate: SettingsButton { + required property int modelData + text: modelData + " Hz"; highlighted: page.refresh === modelData; enabled: !page.busy + onClicked: { page.busy = true; page.reqId = actions.run("display", ["set", "refresh", String(modelData)]) } + } + } + } + SettingsLabel { text: page.status; color: backend.muted; font.pixelSize: SettingsStyle.fontPx(13); wrapMode: Text.Wrap; Layout.fillWidth: true } + Item { Layout.fillHeight: true } +} diff --git a/packages/omamobile-settings/app/Main.qml b/packages/omamobile-settings/app/Main.qml index a21321374..4d696f357 100644 --- a/packages/omamobile-settings/app/Main.qml +++ b/packages/omamobile-settings/app/Main.qml @@ -24,6 +24,8 @@ ApplicationWindow { if (backend.searching) search.clear() backend.back() } + readonly property var customPages: ({ display: "DisplayPage.qml" }) + readonly property string customSource: backend.searching ? "" : (customPages[backend.page] || "") readonly property bool showingAbout: backend.page === "about" && !backend.searching Connections { target: backend @@ -53,16 +55,17 @@ ApplicationWindow { id: search objectName: "settingsSearch" Layout.fillWidth: true; Layout.preferredHeight: 52 - visible: !window.showingAbout + visible: !window.showingAbout && window.customSource === "" placeholderText: qsTr("Search settings") color: backend.foreground; placeholderTextColor: backend.muted onTextEdited: backend.search(text) background: Rectangle { radius: Math.min(backend.radius, width / 2, height / 2); color: SettingsStyle.fill("normal") } } AboutPage { visible: window.showingAbout; Layout.fillWidth: true; Layout.fillHeight: true; controller: deviceInfo; colors: backend } + Loader { id: pageLoader; active: window.customSource !== ""; source: window.customSource; visible: active; Layout.fillWidth: true; Layout.fillHeight: true } ListView { id: list - visible: !window.showingAbout + visible: !window.showingAbout && window.customSource === "" Layout.fillWidth: true; Layout.fillHeight: true clip: true; model: backend.rows delegate: SettingsItemDelegate { diff --git a/packages/omamobile-settings/app/actionrunner.cpp b/packages/omamobile-settings/app/actionrunner.cpp new file mode 100644 index 000000000..a118095f2 --- /dev/null +++ b/packages/omamobile-settings/app/actionrunner.cpp @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +#include "actionrunner.h" +#include +#include +#include +#include +#include +#include +#include +#include + +// finished() is always emitted from the event loop, never before run() has returned its id. +void ActionRunner::post(const QString &tool, const QVariantMap &result, int id) { + QMetaObject::invokeMethod(this, [this, tool, result, id] { emit finished(tool, result, id); }, Qt::QueuedConnection); +} + +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"}; + 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"); + for (const auto &a : args) if (!word.match(a).hasMatch()) return fail("bad argument"); + const QString dir = "/usr/lib/omamobile-settings/backends"; + auto *p = new QProcess(this); + // bash would run a startup file named by these + auto env = QProcessEnvironment::systemEnvironment(); + env.remove("BASH_ENV"); + env.remove("ENV"); + p->setProcessEnvironment(env); + p->setProgram("/usr/bin/bash"); + p->setArguments(QStringList{dir + "/" + tool + ".sh"} + args); + connect(p, &QProcess::finished, this, [this, p, tool, id](int code, QProcess::ExitStatus st) { + const auto raw = p->readAllStandardOutput().left(4096); + p->readAllStandardError(); + auto obj = QJsonDocument::fromJson(raw).object(); + if (obj.isEmpty() || st != QProcess::NormalExit) + obj = QJsonObject{{"error", QStringLiteral("the backend failed (exit %1)").arg(code)}}; + post(tool, obj.toVariantMap(), id); + p->deleteLater(); + }); + connect(p, &QProcess::errorOccurred, this, [this, p, tool, id](QProcess::ProcessError e) { + if (e == QProcess::FailedToStart) { post(tool, {{"error", "cannot start the backend"}}, id); p->deleteLater(); } + }); + p->start(); + p->closeWriteChannel(); + QTimer::singleShot(20000, p, [p] { if (p->state() != QProcess::NotRunning) p->kill(); }); + return id; +} diff --git a/packages/omamobile-settings/app/actionrunner.h b/packages/omamobile-settings/app/actionrunner.h new file mode 100644 index 000000000..e56a52234 --- /dev/null +++ b/packages/omamobile-settings/app/actionrunner.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +#pragma once +#include +#include +#include + +// Runs the source-owned backend scripts (display) 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 { + Q_OBJECT +public: + explicit ActionRunner(QObject *parent = nullptr) : QObject(parent) {} + Q_INVOKABLE int run(const QString &tool, const QStringList &args); +signals: + void finished(const QString &tool, const QVariantMap &result, int id); +private: + void post(const QString &tool, const QVariantMap &result, int id); + int m_next = 0; +}; diff --git a/packages/omamobile-settings/app/catalog.json b/packages/omamobile-settings/app/catalog.json index 9cd019e4f..23efec22b 100644 --- a/packages/omamobile-settings/app/catalog.json +++ b/packages/omamobile-settings/app/catalog.json @@ -2,6 +2,13 @@ "root": { "title": "Settings", "rows": [ + { + "id": "display", + "title": "Display", + "detail": "Brightness and refresh rate", + "icon": "display", + "page": "display" + }, { "id": "about", "title": "About this device", @@ -14,5 +21,9 @@ "about": { "title": "About this device", "rows": [] + }, + "display": { + "title": "Display", + "rows": [] } } diff --git a/packages/omamobile-settings/app/icons/display.svg b/packages/omamobile-settings/app/icons/display.svg new file mode 100644 index 000000000..27abb70ce --- /dev/null +++ b/packages/omamobile-settings/app/icons/display.svg @@ -0,0 +1 @@ + diff --git a/packages/omamobile-settings/app/main.cpp b/packages/omamobile-settings/app/main.cpp index 5848e68ca..ab0826a12 100644 --- a/packages/omamobile-settings/app/main.cpp +++ b/packages/omamobile-settings/app/main.cpp @@ -2,6 +2,7 @@ // Copyright (c) 2026 Marsel Nenaj #include "backend.h" #include "deviceinfocontroller.h" +#include "actionrunner.h" #include #include #include @@ -62,9 +63,11 @@ int main(int argc, char **argv) { if (!bus.registerObject("/Settings", &backend, QDBusConnection::ExportScriptableSlots | QDBusConnection::ExportScriptableInvokables)) return 1; } + ActionRunner actions; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("backend", &backend); engine.rootContext()->setContextProperty("deviceInfo", &deviceInfo); + engine.rootContext()->setContextProperty("actions", &actions); engine.load(QUrl("qrc:/Main.qml")); if (engine.rootObjects().isEmpty()) return 1; return app.exec(); diff --git a/packages/omamobile-settings/app/resources.qrc b/packages/omamobile-settings/app/resources.qrc index 7d3fb01f4..0f18d70dc 100644 --- a/packages/omamobile-settings/app/resources.qrc +++ b/packages/omamobile-settings/app/resources.qrc @@ -3,6 +3,8 @@ Main.qml AboutPage.qml + DisplayPage.qml + icons/display.svg catalog.json icons/system.svg SettingsStyle.qml diff --git a/packages/omamobile-settings/backends/display.sh b/packages/omamobile-settings/backends/display.sh new file mode 100755 index 000000000..ce49290da --- /dev/null +++ b/packages/omamobile-settings/backends/display.sh @@ -0,0 +1,106 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Display settings for the Settings app: brightness (the backlight, through brightnessctl, on the device +# omarchy-hw-display names like the shell does) and the refresh rate (applied live through +# `hyprctl eval hl.monitor{...}` with the monitor's own name, size, position, scale and transform). +# Prints one line of JSON. +# display.sh get {"brightness":50,"refresh":120,"rates":[60,120]} +# display.sh set brightness N N is 10, 25, 50, 75 or 100 (never below 10, so the screen cannot go black) +# display.sh set refresh N N must be one of the rates the monitor lists at its current size +# The rates are the monitor's own availableModes at its current width and height. The change is live only: a +# restart of the session or a reload of Hyprland's config sets the configured mode again. The monitor is the +# built-in panel (DSI-* or eDP-*), else the only one, else the focused one. Without a monitor the brightness +# still works and "refresh" reads -1 with no rates. +# The test runs a copy of this script with `fake` set to a file holding the brightness (a number) and the monitor +# JSON (two lines): no tool is run then. Nothing in the environment sets it. +set -euo pipefail +set +x +verb=${1:-}; key=${2:-}; value=${3:-} +fail() { printf '{"error":"%s"}\n' "$1"; exit 2; } +fake='' +[[ -z $fake || -r $fake ]] || fail "cannot read the test file" + +get_brightness() { + local v dev + if [[ -n $fake ]]; then v=$(sed -n 1p "$fake") + else + dev=$(omarchy-hw-display 2>/dev/null || true) + if [[ -n $dev ]]; then v=$(brightnessctl -d "$dev" -m 2>/dev/null | head -n1 | awk -F, '{gsub("%","",$4); print $4}') + else v=$(brightnessctl --class=backlight -m 2>/dev/null | head -n1 | awk -F, '{gsub("%","",$4); print $4}'); fi + fi + [[ $v =~ ^[0-9]+$ ]] || return 1 + echo "$v" +} +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 +} +monitors_json() { + if [[ -n $fake ]]; then sed -n 2p "$fake"; else hyprctl monitors -j 2>/dev/null; fi +} +# prints: name width height x y scale transform refresh rates(comma separated); fails on anything odd, so +# nothing unchecked reaches the eval below +mon_info() { + monitors_json | /usr/bin/python3 -I -c ' +import sys, json, re +ms = json.load(sys.stdin) +pick = [m for m in ms if re.match(r"(DSI|eDP)-", m.get("name", ""))] +if not pick and len(ms) == 1: pick = ms +if not pick: pick = [m for m in ms if m.get("focused")] +m = pick[0] +w, h, x, y = (int(m[k]) for k in ("width", "height", "x", "y")) +name = m["name"] +scale = float(m["scale"]) +transform = int(m.get("transform", 0)) +if not re.fullmatch(r"[A-Za-z0-9_.-]{1,32}", name) or not 0 <= transform <= 7: raise SystemExit(1) +rates = set() +for mode in m.get("availableModes", []): + size, _, hz = mode.partition("@") + if size == "%dx%d" % (w, h): + try: + rates.add(int(round(float(hz.rstrip("Hz"))))) + except ValueError: + pass # a mode this parser does not know is left out +cur = int(round(float(m["refreshRate"]))) +rates.add(cur) +print(name, w, h, x, y, "%g" % scale, transform, cur, ",".join(str(r) for r in sorted(rates)))' 2>/dev/null +} +read_all() { + bright=$(get_brightness) || fail "cannot read the backlight" + if ! read -r name w h x y scale transform refresh rates < <(mon_info); then + name=""; refresh=-1; rates="" + fi +} +out() { printf '{"brightness":%s,"refresh":%s,"rates":[%s]}\n' "$bright" "$refresh" "$rates"; } + +case $verb in +get) + read_all; out ;; +set) + read_all + case $key in + brightness) + case $value in 10|25|50|75|100) ;; *) fail "bad value" ;; esac + if [[ -z $fake ]]; then set_brightness "$value" || fail "could not set the brightness"; fi + bright=$value ;; + refresh) + [[ $value =~ ^[0-9]{1,3}$ ]] || fail "bad value" + [[ -n $name ]] || fail "cannot read the monitor" + [[ ,$rates, == *",$value,"* ]] || fail "this display does not list that rate" + if [[ -z $fake ]]; then + res=$(hyprctl eval "hl.monitor({ output = \"$name\", mode = \"${w}x${h}@${value}\", position = \"${x}x${y}\", scale = $scale, transform = $transform })" 2>&1) \ + || fail "the screen did not accept the change" + [[ ${res,,} != *error* ]] || fail "the screen did not accept the change" + sleep 1 + read -r name w h x y scale transform refresh rates < <(mon_info) || fail "cannot read the monitor" + else + refresh=$value + fi ;; + *) fail "unknown key" ;; + esac + out ;; +*) + fail "usage: get|set" ;; +esac diff --git a/packages/omamobile-settings/install b/packages/omamobile-settings/install index 9458d0709..2963f0a8b 100755 --- a/packages/omamobile-settings/install +++ b/packages/omamobile-settings/install @@ -10,3 +10,4 @@ install -Dm755 "$build_dir/omamobile-settings" "$dest/usr/bin/omamobile-settings install -Dm644 "$source_dir/org.omamobile.Settings.desktop" "$dest/usr/share/applications/org.omamobile.Settings.desktop" install -Dm644 "$source_dir/org.omamobile.Settings.svg" "$dest/usr/share/icons/hicolor/scalable/apps/org.omamobile.Settings.svg" install -Dm644 "$source_dir/LICENSE" "$dest/usr/share/licenses/omamobile-settings/LICENSE" +install -Dm755 "$source_dir/backends/display.sh" "$dest/usr/lib/omamobile-settings/backends/display.sh" diff --git a/packages/omamobile-settings/omamobile-settings.pro b/packages/omamobile-settings/omamobile-settings.pro index b4e55810f..a06eeff4a 100644 --- a/packages/omamobile-settings/omamobile-settings.pro +++ b/packages/omamobile-settings/omamobile-settings.pro @@ -4,8 +4,8 @@ CONFIG += c++17 release no_include_pwd TEMPLATE = app TARGET = omamobile-settings INCLUDEPATH += $$PWD/app -HEADERS += app/backend.h app/deviceinfocontroller.h -SOURCES += app/main.cpp app/backend.cpp app/deviceinfocontroller.cpp +HEADERS += app/backend.h app/deviceinfocontroller.h app/actionrunner.h +SOURCES += app/main.cpp app/backend.cpp app/deviceinfocontroller.cpp app/actionrunner.cpp RESOURCES += app/resources.qrc include(version.pri) diff --git a/packages/omamobile-settings/test/all b/packages/omamobile-settings/test/all index 1d2ca963d..d0c6618eb 100755 --- a/packages/omamobile-settings/test/all +++ b/packages/omamobile-settings/test/all @@ -4,6 +4,7 @@ set -eu source_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) build_dir=${OMAMOBILE_SETTINGS_TEST_BUILD_DIR:-"$source_dir/build/tests"} "$source_dir/bin/build" +"$source_dir/test/display-backend.sh" mkdir -p "$build_dir" fixture=$(mktemp -d) trap 'rm -rf -- "$fixture"' EXIT HUP INT TERM diff --git a/packages/omamobile-settings/test/display-backend.sh b/packages/omamobile-settings/test/display-backend.sh new file mode 100755 index 000000000..83a61ec96 --- /dev/null +++ b/packages/omamobile-settings/test/display-backend.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# backends/display.sh against a fake brightness and monitor, in a copy of the script with `fake` set: no tool is run. +set -euo pipefail +src=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) +tmp=$(mktemp -d); trap 'rm -rf -- "$tmp"' EXIT +fake=$tmp/fake +cat > "$fake" <<'EOT' +50 +[{"name":"DSI-1","width":1344,"height":2992,"x":0,"y":0,"scale":3.2,"refreshRate":120.000,"availableModes":["1344x2992@120.00Hz","1344x2992@60.00Hz","1008x2244@120.00Hz"]}] +EOT +sed "s|^fake=.*|fake=$fake|" "$src/backends/display.sh" > "$tmp/display.sh" +grep -q "^fake=$fake" "$tmp/display.sh" +run() { bash "$tmp/display.sh" "$@" || true; } +eq() { [[ $1 == "$2" ]] || { echo "FAIL: got $1, want $2" >&2; exit 1; }; } + +eq "$(run get)" '{"brightness":50,"refresh":120,"rates":[60,120]}' +eq "$(run set brightness 25)" '{"brightness":25,"refresh":120,"rates":[60,120]}' +eq "$(run set brightness 5)" '{"error":"bad value"}' +eq "$(run set brightness 101)" '{"error":"bad value"}' +eq "$(run set refresh 60)" '{"brightness":50,"refresh":60,"rates":[60,120]}' +eq "$(run set refresh 90)" '{"error":"this display does not list that rate"}' +eq "$(run set refresh abc)" '{"error":"bad value"}' +eq "$(run set night on)" '{"error":"unknown key"}' +eq "$(run nonsense)" '{"error":"usage: get|set"}' + +# one rate only: the page hides the refresh rate buttons +sed -i '2s/.*/[{"name":"HDMI-A-1","width":1920,"height":1080,"x":0,"y":0,"scale":1,"refreshRate":60.0,"availableModes":["1920x1080@60.00Hz"]}]/' "$fake" +eq "$(run get)" '{"brightness":50,"refresh":60,"rates":[60]}' +# two monitors: the built-in panel is picked +sed -i '2s/.*/[{"name":"HDMI-A-1","width":1920,"height":1080,"x":0,"y":0,"scale":1,"refreshRate":60.0,"availableModes":["1920x1080@60.00Hz"]},{"name":"DSI-1","width":1344,"height":2992,"x":0,"y":0,"scale":3.2,"transform":1,"refreshRate":120.0,"availableModes":["1344x2992@120.00Hz","1344x2992@60.00Hz"]}]/' "$fake" +eq "$(run get)" '{"brightness":50,"refresh":120,"rates":[60,120]}' +# two external monitors and none focused: no monitor, but the brightness still works +sed -i '2s/.*/[{"name":"A-1","width":1,"height":1,"x":0,"y":0,"scale":1,"refreshRate":60.0},{"name":"B-1","width":1,"height":1,"x":0,"y":0,"scale":1,"refreshRate":60.0}]/' "$fake" +eq "$(run get)" '{"brightness":50,"refresh":-1,"rates":[]}' +eq "$(run set brightness 75)" '{"brightness":75,"refresh":-1,"rates":[]}' +eq "$(run set refresh 60)" '{"error":"cannot read the monitor"}' +# a monitor name that is not a plain connector name never reaches hyprctl +sed -i '2s/.*/[{"name":"X\"-1","width":1,"height":1,"x":0,"y":0,"scale":1,"refreshRate":60.0}]/' "$fake" +eq "$(run set refresh 60)" '{"error":"cannot read the monitor"}' +# one odd mode string does not take the others down +sed -i '2s/.*/[{"name":"DSI-1","width":1344,"height":2992,"x":0,"y":0,"scale":3.2,"refreshRate":120.0,"availableModes":["1344x2992@odd","1344x2992@60.00Hz","1344x2992@120.00Hz"]}]/' "$fake" +eq "$(run get)" '{"brightness":50,"refresh":120,"rates":[60,120]}' +# the monitor query failing leaves the brightness working +sed -i '2s/.*/not json/' "$fake" +eq "$(run get)" '{"brightness":50,"refresh":-1,"rates":[]}' +echo "display backend: ok" diff --git a/packages/omamobile-settings/tests/core_tests.cpp b/packages/omamobile-settings/tests/core_tests.cpp index f3f982a90..17c912394 100644 --- a/packages/omamobile-settings/tests/core_tests.cpp +++ b/packages/omamobile-settings/tests/core_tests.cpp @@ -18,7 +18,7 @@ private slots: void navigationRejectsUnknownAndHiddenActions() { Backend backend; QVERIFY(backend.catalogProblems().isEmpty()); - QCOMPARE(backend.rows().size(), 1); + QCOMPARE(backend.rows().size(), 2); QVERIFY(!backend.navigate("recording")); backend.activate("arbitrary-command"); QCOMPARE(backend.page(), QString("root")); @@ -33,6 +33,9 @@ private slots: Backend backend; backend.search("STORAGE"); QCOMPARE(backend.rows().size(), 1); + backend.search("brightness"); + QCOMPARE(backend.rows().size(), 1); + QCOMPARE(backend.rows().first().toMap()["id"].toString(), QString("display")); QVERIFY(backend.searching()); backend.back(); QVERIFY(!backend.searching()); diff --git a/packages/omamobile-settings/tests/session_app.pro b/packages/omamobile-settings/tests/session_app.pro index 64b50dec5..f1e538b50 100644 --- a/packages/omamobile-settings/tests/session_app.pro +++ b/packages/omamobile-settings/tests/session_app.pro @@ -5,7 +5,7 @@ TEMPLATE = app TARGET = settings-session-test-app INCLUDEPATH += ../app DEFINES += OMAMOBILE_SETTINGS_TEST_DEVICE_INFO -HEADERS += ../app/backend.h ../app/deviceinfocontroller.h -SOURCES += ../app/main.cpp ../app/backend.cpp ../app/deviceinfocontroller.cpp +HEADERS += ../app/backend.h ../app/deviceinfocontroller.h ../app/actionrunner.h +SOURCES += ../app/main.cpp ../app/backend.cpp ../app/deviceinfocontroller.cpp ../app/actionrunner.cpp RESOURCES += ../app/resources.qrc include(../version.pri) diff --git a/packages/omamobile-settings/version b/packages/omamobile-settings/version index 6e8bf73aa..17e51c385 100644 --- a/packages/omamobile-settings/version +++ b/packages/omamobile-settings/version @@ -1 +1 @@ -0.1.0 +0.1.1 From 568d96c5618fc6662f87f059df887d6b9acb6e0d Mon Sep 17 00:00:00 2001 From: Lef Date: Wed, 11 Nov 2026 07:27:39 +0200 Subject: [PATCH 2/2] omamobile-settings: say that a rotation undoes the refresh rate, test Back on the Display page Auto-rotate applies the monitor's preferred mode each time the phone is turned, so a chosen rate lasts only until then: the README, the script header and the page's status line say so. A core test goes to the display page and back to the root. --- packages/omamobile-settings/README.md | 4 +++- packages/omamobile-settings/app/DisplayPage.qml | 3 ++- packages/omamobile-settings/backends/display.sh | 5 +++-- packages/omamobile-settings/tests/core_tests.cpp | 7 +++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index a53a0c9dc..4b4b88960 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -8,7 +8,9 @@ Unknown values remain unavailable. It opens from the desktop launcher. 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). The page runs +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. Omarchy's existing tools continue to provide the other settings changes. Network, wallpaper, app management and recording controls are separate future contributions with their own runtime diff --git a/packages/omamobile-settings/app/DisplayPage.qml b/packages/omamobile-settings/app/DisplayPage.qml index b35beddd7..20609134d 100644 --- a/packages/omamobile-settings/app/DisplayPage.qml +++ b/packages/omamobile-settings/app/DisplayPage.qml @@ -17,7 +17,8 @@ ColumnLayout { if (r.error) { status = r.error; return } if (r.brightness === undefined || r.refresh === undefined) { status = qsTr("The display backend gave no values."); return } brightness = r.brightness; refresh = r.refresh; rates = r.rates || [] - status = qsTr("Tap a value; it applies at once.") + 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"]) diff --git a/packages/omamobile-settings/backends/display.sh b/packages/omamobile-settings/backends/display.sh index ce49290da..68090ed0a 100755 --- a/packages/omamobile-settings/backends/display.sh +++ b/packages/omamobile-settings/backends/display.sh @@ -7,8 +7,9 @@ # display.sh get {"brightness":50,"refresh":120,"rates":[60,120]} # display.sh set brightness N N is 10, 25, 50, 75 or 100 (never below 10, so the screen cannot go black) # display.sh set refresh N N must be one of the rates the monitor lists at its current size -# The rates are the monitor's own availableModes at its current width and height. The change is live only: a -# restart of the session or a reload of Hyprland's config sets the configured mode again. The monitor is the +# The rates are the monitor's own availableModes at its current width and height. The change is live only: turning the phone +# (omamobile-sensors' auto-rotate applies the monitor's preferred mode again each time), a restart of the +# session or a reload of Hyprland's config sets the configured mode again. The monitor is the # built-in panel (DSI-* or eDP-*), else the only one, else the focused one. Without a monitor the brightness # still works and "refresh" reads -1 with no rates. # The test runs a copy of this script with `fake` set to a file holding the brightness (a number) and the monitor diff --git a/packages/omamobile-settings/tests/core_tests.cpp b/packages/omamobile-settings/tests/core_tests.cpp index 602345261..e8e0a2e77 100644 --- a/packages/omamobile-settings/tests/core_tests.cpp +++ b/packages/omamobile-settings/tests/core_tests.cpp @@ -29,6 +29,13 @@ private slots: backend.back(); QCOMPARE(backend.page(), QString("root")); } + void displayPageGoesBackToRoot() { + Backend backend; + QVERIFY(backend.navigate("display")); + QCOMPARE(backend.page(), QString("display")); + backend.back(); + QCOMPARE(backend.page(), QString("root")); + } void searchHasOnlyImplementedRoutesAndBackClearsIt() { Backend backend; backend.search("STORAGE");