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: 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 qt6-base qt6-declarative qt6-svg)
depends=(omarchy bash brightnessctl python qt6-base qt6-declarative qt6-svg)
makedepends=(gcc make)
checkdepends=(dbus python)

Expand Down
11 changes: 8 additions & 3 deletions packages/omamobile-settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ 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: 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
contracts and tests; this catalog does not offer those routes.

Expand All @@ -28,7 +33,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
Expand Down
55 changes: 55 additions & 0 deletions packages/omamobile-settings/app/DisplayPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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 = 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"])
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 }
}
7 changes: 5 additions & 2 deletions packages/omamobile-settings/app/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,16 +54,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 {
Expand Down
49 changes: 49 additions & 0 deletions packages/omamobile-settings/app/actionrunner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
#include "actionrunner.h"
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMetaObject>
#include <QProcess>
#include <QProcessEnvironment>
#include <QRegularExpression>
#include <QTimer>

// 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;
}
20 changes: 20 additions & 0 deletions packages/omamobile-settings/app/actionrunner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
#pragma once
#include <QObject>
#include <QVariantMap>
#include <QStringList>

// 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;
};
11 changes: 11 additions & 0 deletions packages/omamobile-settings/app/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -14,5 +21,9 @@
"about": {
"title": "About this device",
"rows": []
},
"display": {
"title": "Display",
"rows": []
}
}
1 change: 1 addition & 0 deletions packages/omamobile-settings/app/icons/display.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/omamobile-settings/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) 2026 Marsel Nenaj
#include "backend.h"
#include "deviceinfocontroller.h"
#include "actionrunner.h"
#include <QGuiApplication>
#include <QDBusConnection>
#include <QDBusInterface>
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions packages/omamobile-settings/app/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<qresource prefix="/">
<file>Main.qml</file>
<file>AboutPage.qml</file>
<file>DisplayPage.qml</file>
<file>icons/display.svg</file>
<file>catalog.json</file>
<file>icons/system.svg</file>
<file>SettingsStyle.qml</file>
Expand Down
107 changes: 107 additions & 0 deletions packages/omamobile-settings/backends/display.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/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: 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
# 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
1 change: 1 addition & 0 deletions packages/omamobile-settings/install
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions packages/omamobile-settings/omamobile-settings.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions packages/omamobile-settings/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading