Skip to content
Draft
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
1 change: 1 addition & 0 deletions packages/omamobile-settings/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ license=(MIT)
depends=(omarchy bash coreutils systemd brightnessctl polkit python qt6-base qt6-declarative qt6-svg)
makedepends=(gcc make)
checkdepends=(dbus python)
optdepends=('feedbackd: the Keyboard haptics page edits its theme')

build() { "$startdir/bin/build"; }
check() { "$startdir/test/all"; }
Expand Down
12 changes: 10 additions & 2 deletions packages/omamobile-settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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 package contains the read-only foundation and one settings page, Display
(brightness and, where the monitor lists more than one, the refresh rate; the
This package contains the read-only foundation and three settings pages. Display
is 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
Expand Down Expand Up @@ -36,6 +36,14 @@ row stays hidden today: omamobile-device-husky blacklists `max77759_charger`
(`omamobile-max77759.conf`), so there is no `max77759-charger` power supply
until that blacklist is lifted on a kernel with
derekross/linux-omarchy-mobile#266.
A third page, Keyboard haptics, sets the pattern
feedbackd plays for key presses (low: one light tick; medium: a tick, then a 40 ms gap; high: a stronger tick, then the gap; tried by feel on a Pixel 8 Pro); it
edits the user's feedbackd theme (`~/.config/feedbackd/themes/custom.json`, the
two key entries of the `full` profile, never above 0.125 or 60 ms in total; the first version of the file is kept once as `custom.json.bak-haptics`, a theme that
does not have exactly those two entries is refused before anything changes). It never touches feedbackd's profile, so calls, messages and
alarms ring as before; changing the level restarts feedbackd, so a ring in progress stops. A phone without such a theme (or with one that does not have exactly the two key entries) gets a plain
message on the page and no buttons. That page runs
`backends/haptics.sh` through the same runner.
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 Down
61 changes: 61 additions & 0 deletions packages/omamobile-settings/app/HapticsPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
import QtQuick
import QtQuick.Layouts
import "."
ColumnLayout {
id: page
spacing: 14
property string level: ""
property string status: qsTr("Reading the haptics...")
property bool busy: true
// True once the theme has been read: a phone without the keyboard haptics theme gets no buttons.
property bool available: false
property int reqId: -1
readonly property var levels: [
{ id: "low", label: qsTr("Low"), hint: qsTr("one light tick") },
{ id: "medium", label: qsTr("Medium"), hint: qsTr("tick, then a short gap") },
{ id: "high", label: qsTr("High"), hint: qsTr("stronger tick, then a short gap") }
]
function apply(r) {
busy = false
if (r.error) { status = r.error; return }
if (!r.level) { status = qsTr("The haptics backend gave no level."); return }
available = true
level = r.level
status = qsTr("Keyboard tick: %1. Tap a level; it applies at once. Changing it restarts the feedback service, so a ring in progress stops.").arg(level)
}
Connections { target: actions; function onFinished(tool, r, id) { if (tool === "haptics" && id === page.reqId) page.apply(r) } }
Component.onCompleted: reqId = actions.run("haptics", ["get"])
// Leaving the page drops what was typed; nothing here is ever saved.
Component.onDestruction: { tryField.clear(); if (tryField.activeFocus) Qt.inputMethod.hide() }
Repeater {
model: page.levels
delegate: SettingsButton {
required property var modelData
Layout.fillWidth: true; Layout.preferredHeight: 64
visible: page.available
// No focus on tap, so the try field keeps the keyboard up while levels are compared.
focusPolicy: Qt.NoFocus
highlighted: page.level === modelData.id; enabled: page.available && !page.busy
onClicked: { page.busy = true; page.reqId = actions.run("haptics", ["set", "level", modelData.id]) }
contentItem: Column {
spacing: 2
SettingsLabel { text: modelData.label; color: backend.foreground; width: parent.width }
SettingsLabel { text: modelData.hint; color: backend.muted; font.pixelSize: SettingsStyle.fontPx(12); width: parent.width; wrapMode: Text.Wrap }
}
}
}
SettingsTextField {
id: tryField
objectName: "hapticsTryField"
Layout.fillWidth: true; Layout.preferredHeight: 52
visible: page.available
placeholderText: qsTr("Try it here: type to feel the ticks")
color: backend.foreground; placeholderTextColor: backend.muted
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhSensitiveData
background: Rectangle { radius: Math.min(backend.radius, width / 2, height / 2); color: SettingsStyle.fill("normal") }
onVisibleChanged: if (!visible) clear()
}
SettingsLabel { text: page.status; color: backend.muted; font.pixelSize: SettingsStyle.fontPx(13); wrapMode: Text.Wrap; Layout.fillWidth: true }
Item { Layout.fillHeight: true }
}
2 changes: 1 addition & 1 deletion packages/omamobile-settings/app/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ApplicationWindow {
if (backend.searching) search.clear()
backend.back()
}
readonly property var customPages: ({ display: "DisplayPage.qml", battery: "BatteryPage.qml" })
readonly property var customPages: ({ display: "DisplayPage.qml", battery: "BatteryPage.qml", haptics: "HapticsPage.qml" })
readonly property string customSource: backend.searching ? "" : (customPages[backend.page] || "")
readonly property bool showingAbout: backend.page === "about" && !backend.searching
Connections {
Expand Down
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", "haptics"};
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, haptics) 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
11 changes: 11 additions & 0 deletions packages/omamobile-settings/app/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
"page": "battery",
"requires": "charge"
},
{
"id": "haptics",
"title": "Keyboard haptics",
"detail": "Strength of the keyboard tick",
"icon": "haptics",
"page": "haptics"
},
{
"id": "about",
"title": "About this device",
Expand All @@ -37,5 +44,9 @@
"battery": {
"title": "Battery",
"rows": []
},
"haptics": {
"title": "Keyboard haptics",
"rows": []
}
}
1 change: 1 addition & 0 deletions packages/omamobile-settings/app/icons/haptics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/omamobile-settings/app/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<file>DisplayPage.qml</file>
<file>BatteryPage.qml</file>
<file>icons/battery.svg</file>
<file>HapticsPage.qml</file>
<file>icons/haptics.svg</file>
<file>icons/display.svg</file>
<file>catalog.json</file>
<file>icons/system.svg</file>
Expand Down
148 changes: 148 additions & 0 deletions packages/omamobile-settings/backends/haptics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# Keyboard haptics level: probe/get/set. The level is the pattern feedbackd plays for key and
# button presses. It lives in the user's feedbackd theme ($XDG_CONFIG_HOME/feedbackd/themes/custom.json, entries
# button-pressed and key-pressed of the "full" profile); where that theme comes from is the keyboard haptics notes in
# https://github.com/derekross/omarchy-mobile/issues/538. Levels (motor level of 255 in brackets):
# low: one 0.015 tick (3, the lowest) for 15 ms;
# medium: 0.07 (17) for 15 ms, then 0 for 40 ms;
# high: 0.1 (25) for 15 ms, then the same 40 ms gap.
# The gap levels were tried by feel on a Pixel 8 Pro (2026-11-19).
# Nothing above 0.125 and no pattern longer than 60 ms in total is ever written.
# Only the two key entries of the theme are written. feedbackd's profile, and so whether calls, messages and alarms
# ring, is never touched here: a keyboard page does not change that. Changing the level restarts feedbackd (a ring
# in progress stops).
# The theme directory comes from XDG_CONFIG_HOME, else HOME; nothing else in the environment is read (python3 is
# called by its absolute path, the helper tools by PATH). The test runs a copy
# of this script with `dry=1`, which skips feedbackd and the preview tick. The theme file is checked (exactly the
# two key entries in the full profile) before anything is changed.
set -euo pipefail
dry=0
dir=${XDG_CONFIG_HOME:-$HOME/.config}/feedbackd/themes
file=$dir/custom.json
cap=0.125
verb=${1:-}
key=${2:-}
value=${3:-}

fail() { printf '%s\n' "$1"; exit 2; }

level_pair() {
case $1 in
low) echo "0.015 15" ;;
medium) echo "0.07,0 15,40" ;;
high) echo "0.1,0 15,40" ;;
*) return 1 ;;
esac
}

# Prints the level; exit 3: the theme does not have exactly the two key entries (the same rule set applies);
# exit 4: it cannot be read as a theme.
current_level() {
/usr/bin/python3 -I - "$file" <<'PY'
import json, sys
try:
d = json.load(open(sys.argv[1]))
pairs = []
for p in d["profiles"]:
if p["name"] != "full":
continue
for f in p["feedbacks"]:
if f.get("type") == "VibraPattern" and f["event-name"] in ("button-pressed", "key-pressed"):
pairs.append((tuple(f["magnitudes"]), tuple(f["durations"])))
except Exception:
sys.exit(4)
if len(pairs) != 2:
sys.exit(3)
names = {((0.015,), (15,)): "low", ((0.07, 0), (15, 40)): "medium", ((0.1, 0), (15, 40)): "high"}
if pairs[0] == pairs[1] and pairs[0] in names:
print(names[pairs[0]])
else:
print("custom")
PY
}

case $verb in
probe)
if [[ -r $file ]] && current_level >/dev/null 2>&1; then
printf '{"id":"haptics","state":"working","reason":"","risk":"none"}\n'
else
printf '{"id":"haptics","state":"unavailable","reason":"no keyboard haptics theme on this phone","risk":"none"}\n'
exit 2
fi
;;
get)
[[ -r $file ]] || fail '{"error":"no keyboard haptics theme on this phone"}'
rc=0; lvl=$(current_level) || rc=$?
case $rc in
0) ;;
3) fail '{"error":"the haptics theme does not have the two key entries"}' ;;
*) fail '{"error":"the haptics theme could not be read"}' ;;
esac
printf '{"level":"%s"}\n' "$lvl"
;;
set)
[[ $key == level ]] || fail '{"error":"unknown key"}'
pair=$(level_pair "$value") || fail '{"error":"bad value"}'
mag=${pair% *}; ms=${pair#* }
# defence in depth: the table above can never exceed the cap or 60 ms in total
/usr/bin/python3 -I -c "import sys; m=[float(x) for x in '$mag'.split(',')]; d=[int(x) for x in '$ms'.split(',')]; sys.exit(0 if len(m) == len(d) and all(0 <= x <= $cap for x in m) and all(x > 0 for x in d) and sum(d) <= 60 else 1)" || fail '{"error":"above the safety cap"}'
[[ -e $file ]] || fail '{"error":"no keyboard haptics theme on this phone"}'
[[ -w $file ]] || fail '{"error":"theme file not writable"}'
edit() { /usr/bin/python3 -I - "$file" "$mag" "$ms" "$1" <<'PY'
import json, os, sys, tempfile
path, mode = sys.argv[1], sys.argv[4]
mag = [float(x) for x in sys.argv[2].split(",")]
ms = [int(x) for x in sys.argv[3].split(",")]
try:
d = json.load(open(path))
n = 0
for p in d["profiles"]:
if p["name"] != "full":
continue
for f in p["feedbacks"]:
if f.get("type") == "VibraPattern" and f["event-name"] in ("button-pressed", "key-pressed"):
f["magnitudes"] = mag
f["durations"] = ms
n += 1
except Exception:
n = -1
if n != 2:
print('{"error":"the haptics theme does not have the two key entries"}')
sys.exit(2)
if mode == "write":
real = os.path.realpath(path)
fd, tmp = tempfile.mkstemp(dir=os.path.dirname(real))
try:
with os.fdopen(fd, "w") as out:
json.dump(d, out, indent=2)
out.flush()
os.fsync(out.fileno())
os.chmod(tmp, os.stat(real).st_mode & 0o7777)
os.replace(tmp, real)
except BaseException:
try:
os.unlink(tmp)
except OSError:
pass
print('{"error":"could not write the haptics theme"}')
sys.exit(2)
PY
}
# nothing is changed until the theme is known to be what this edit expects
edit check || exit 2
[[ -e $file.bak-haptics ]] || cp -p "$file" "$file.bak-haptics" || fail '{"error":"could not keep a copy of the haptics theme"}'
edit write || exit 2
if [[ $dry != 1 ]]; then
# feedbackd reads the theme when it starts; D-Bus starts it again on the next event. Exact name only.
for p in $(pgrep -u "$(id -u)" -x feedbackd || true); do kill "$p" 2>/dev/null || true; done
sleep 1
# fbcli ends the feedback when its input closes, and the shell gives it none: keep it open for one pulse.
sleep 0.02 | fbcli -E button-pressed -w 1 >/dev/null 2>&1 || true
fi
printf '{"level":"%s"}\n' "$value"
;;
*)
fail '{"error":"usage: probe|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 @@ -15,3 +15,4 @@ install -Dm755 "$source_dir/backends/charge.sh" "$dest/usr/lib/omamobile-setting
install -Dm755 "$source_dir/libexec/charge-limit" "$dest/usr/lib/omamobile-settings/charge-limit"
install -Dm644 "$source_dir/vendor/systemd/system/omamobile-charge-limit@.service" "$dest/usr/lib/systemd/system/omamobile-charge-limit@.service"
install -Dm644 "$source_dir/vendor/polkit/50-omamobile-charge-limit.rules" "$dest/usr/share/polkit-1/rules.d/50-omamobile-charge-limit.rules"
install -Dm755 "$source_dir/backends/haptics.sh" "$dest/usr/lib/omamobile-settings/backends/haptics.sh"
1 change: 1 addition & 0 deletions packages/omamobile-settings/test/all
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build_dir=${OMAMOBILE_SETTINGS_TEST_BUILD_DIR:-"$source_dir/build/tests"}
"$source_dir/bin/build"
"$source_dir/test/display-backend.sh"
"$source_dir/test/charge-backend.sh"
"$source_dir/test/haptics-backend.sh"
mkdir -p "$build_dir"
fixture=$(mktemp -d)
trap 'rm -rf -- "$fixture"' EXIT HUP INT TERM
Expand Down
76 changes: 76 additions & 0 deletions packages/omamobile-settings/test/haptics-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
# backends/haptics.sh against a temporary feedbackd theme (XDG_CONFIG_HOME), in a copy of the script with dry=1,
# so feedbackd and fbcli are never called.
set -euo pipefail
src=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
tmp=$(mktemp -d); trap 'rm -rf -- "$tmp"' EXIT
mkdir -p "$tmp/config/feedbackd/themes"
dir=$tmp/config/feedbackd/themes
export XDG_CONFIG_HOME=$tmp/config
sed 's/^dry=0/dry=1/' "$src/backends/haptics.sh" > "$tmp/haptics.sh"
grep -q '^dry=1' "$tmp/haptics.sh"
cat > "$dir/custom.json" <<'EOT'
{"name":"custom","profiles":[{"name":"full","feedbacks":[
{"event-name":"button-pressed","type":"VibraPattern","magnitudes":[0.015],"durations":[15]},
{"event-name":"key-pressed","type":"VibraPattern","magnitudes":[0.015],"durations":[15]},
{"event-name":"message-new-instant","type":"Sound","effect":"message-new-instant"}]}]}
EOT
run() { bash "$tmp/haptics.sh" "$@" || true; }
eq() { [[ $1 == "$2" ]] || { echo "FAIL: got $1, want $2" >&2; exit 1; }; }

# the full magnitudes and durations of both key entries, for every level
pat() { /usr/bin/python3 -I -c 'import json,sys; print(sorted({(tuple(f["magnitudes"]),tuple(f["durations"])) for p in json.load(open(sys.argv[1]))["profiles"] for f in p["feedbacks"] if f.get("type")=="VibraPattern"}))' "$dir/custom.json"; }
eq "$(pat)" '[((0.015,), (15,))]'
eq "$(run get)" '{"level":"low"}'
eq "$(run set level medium)" '{"level":"medium"}'
eq "$(run get)" '{"level":"medium"}'
eq "$(pat)" '[((0.07, 0.0), (15, 40))]'
eq "$(run set level high)" '{"level":"high"}'
eq "$(pat)" '[((0.1, 0.0), (15, 40))]'
# "off" is not a level here: it would be the phone-wide silent profile, which this page never touches
eq "$(run set level off)" '{"error":"bad value"}'
eq "$(run get)" '{"level":"high"}'
eq "$(run set level low)" '{"level":"low"}'
eq "$(pat)" '[((0.015,), (15,))]'
eq "$(run get)" '{"level":"low"}'
eq "$(run set level loud)" '{"error":"bad value"}'
eq "$(run set level 0.5)" '{"error":"bad value"}'
eq "$(run set strength low)" '{"error":"unknown key"}'
eq "$(run nonsense)" '{"error":"usage: probe|get|set"}'
# nothing above the cap is ever in the theme, and the sound entry is left alone
python3 - "$dir/custom.json" <<'PY'
import json, sys
d = json.load(open(sys.argv[1]))
fb = d["profiles"][0]["feedbacks"]
assert all(all(0 <= m <= 0.125 for m in f["magnitudes"]) and sum(f["durations"]) <= 60 for f in fb if f["type"] == "VibraPattern")
assert any(f["type"] == "Sound" for f in fb)
PY
# the mode of the file is kept, and the first theme is saved once
[[ $(stat -c %a "$dir/custom.json") == 644 ]] || { chmod 644 "$dir/custom.json"; run set level high >/dev/null; [[ $(stat -c %a "$dir/custom.json") == 644 ]]; }
[[ -e $dir/custom.json.bak-haptics ]]
# a theme with one key entry is refused before anything is touched, by set and by get
cp "$dir/custom.json" "$tmp/good.json"
python3 - "$dir/custom.json" <<'PY'
import json, sys
d = json.load(open(sys.argv[1]))
d["profiles"][0]["feedbacks"] = [f for f in d["profiles"][0]["feedbacks"] if f["event-name"] != "key-pressed"]
json.dump(d, open(sys.argv[1], "w"))
PY
before=$(sha256sum "$dir/custom.json")
eq "$(run set level medium)" '{"error":"the haptics theme does not have the two key entries"}'
[[ $(sha256sum "$dir/custom.json") == "$before" ]]
eq "$(run get)" '{"error":"the haptics theme does not have the two key entries"}'
[[ $(run probe) == *'"state":"unavailable"'* ]] || { echo "FAIL: probe says working on a one-entry theme" >&2; exit 1; }
# a theme that is not JSON at all
echo "{ not json" > "$dir/custom.json"
eq "$(run get)" '{"error":"the haptics theme could not be read"}'
[[ $(run probe) == *'"state":"unavailable"'* ]] || { echo "FAIL: probe says working on a broken theme" >&2; exit 1; }
cp "$tmp/good.json" "$dir/custom.json"
eq "$(run probe)" '{"id":"haptics","state":"working","reason":"","risk":"none"}'
# a theme that is not there: a plain message, no crash, nothing is created, no level can be set
rm "$dir/custom.json" "$dir/custom.json.bak-haptics"
eq "$(run get)" '{"error":"no keyboard haptics theme on this phone"}'
eq "$(run set level medium)" '{"error":"no keyboard haptics theme on this phone"}'
[[ ! -e $dir/custom.json && ! -e $dir/custom.json.bak-haptics ]]
echo "haptics backend: ok"
Loading