From 54ca366a1ffa9eacf8ae8356d9b1a4298f57199e Mon Sep 17 00:00:00 2001 From: Lef Date: Tue, 10 Nov 2026 19:29:08 +0200 Subject: [PATCH 1/7] omamobile-settings 0.1.2: a Keyboard haptics page The strength of the tick feedbackd plays for key and button presses, in three levels (0.015, 0.035 and 0.07 for 15 ms, nothing above 0.125 or 60 ms is ever written), or Off, which switches feedbackd's profile to silent for the whole phone. It edits the two key entries of the user's custom feedbackd theme (a .bak-haptics copy is kept once), restarts feedbackd by exact name and plays one tick. A phone without that theme gets a plain message on the page. Stacked on the Display page (the ActionRunner and the catalog are from there). The theme and the udev rule that tags the motor are not in a package yet; the page needs them. Signed-off-by: Lef --- packages/omamobile-settings/PKGBUILD | 1 + packages/omamobile-settings/README.md | 11 +- .../omamobile-settings/app/HapticsPage.qml | 44 +++++ packages/omamobile-settings/app/Main.qml | 2 +- .../omamobile-settings/app/actionrunner.cpp | 2 +- .../omamobile-settings/app/actionrunner.h | 2 +- packages/omamobile-settings/app/catalog.json | 11 ++ .../omamobile-settings/app/icons/haptics.svg | 1 + packages/omamobile-settings/app/resources.qrc | 2 + .../omamobile-settings/backends/haptics.sh | 150 ++++++++++++++++++ packages/omamobile-settings/install | 1 + packages/omamobile-settings/test/all | 1 + .../test/haptics-backend.sh | 62 ++++++++ .../omamobile-settings/tests/core_tests.cpp | 12 +- 14 files changed, 291 insertions(+), 11 deletions(-) create mode 100644 packages/omamobile-settings/app/HapticsPage.qml create mode 100644 packages/omamobile-settings/app/icons/haptics.svg create mode 100755 packages/omamobile-settings/backends/haptics.sh create mode 100755 packages/omamobile-settings/test/haptics-backend.sh diff --git a/packages/omamobile-settings/PKGBUILD b/packages/omamobile-settings/PKGBUILD index cb9f9b41c..629436313 100644 --- a/packages/omamobile-settings/PKGBUILD +++ b/packages/omamobile-settings/PKGBUILD @@ -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 and profile') build() { "$startdir/bin/build"; } check() { "$startdir/test/all"; } diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index 3cdd006cd..2077efd98 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -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 @@ -36,6 +36,13 @@ 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 strength +of the tick feedbackd plays for key presses, or silent for the whole phone; 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; 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, and a level after Off puts the profile +back to `full` whatever it was before) and says so on the page when the phone has no such theme. 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. diff --git a/packages/omamobile-settings/app/HapticsPage.qml b/packages/omamobile-settings/app/HapticsPage.qml new file mode 100644 index 000000000..c45478c13 --- /dev/null +++ b/packages/omamobile-settings/app/HapticsPage.qml @@ -0,0 +1,44 @@ +// 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 + property int reqId: -1 + readonly property var levels: [ + { id: "off", label: qsTr("Silent, whole phone"), hint: qsTr("no vibration from any app, lock screen too") }, + { id: "low", label: qsTr("Low"), hint: qsTr("keyboard tick, gentlest") }, + { id: "medium", label: qsTr("Medium"), hint: qsTr("keyboard tick") }, + { id: "high", label: qsTr("High"), hint: qsTr("keyboard tick, strongest") } + ] + function apply(r) { + busy = false + if (r.error) { status = r.error; return } + if (!r.level) { status = qsTr("The haptics backend gave no level."); return } + level = r.level + status = level === "off" ? qsTr("Haptics are silent for the whole phone. Pick a level to turn them back on.") + : qsTr("Keyboard tick: %1. Tap a level; it applies at once.").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"]) + Repeater { + model: page.levels + delegate: SettingsButton { + required property var modelData + Layout.fillWidth: true; Layout.preferredHeight: 64 + highlighted: page.level === modelData.id; enabled: !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 } + } + } + } + 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 3d4ccd66b..c954aaf54 100644 --- a/packages/omamobile-settings/app/Main.qml +++ b/packages/omamobile-settings/app/Main.qml @@ -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 { diff --git a/packages/omamobile-settings/app/actionrunner.cpp b/packages/omamobile-settings/app/actionrunner.cpp index 83822926e..022970d76 100644 --- a/packages/omamobile-settings/app/actionrunner.cpp +++ b/packages/omamobile-settings/app/actionrunner.cpp @@ -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"); diff --git a/packages/omamobile-settings/app/actionrunner.h b/packages/omamobile-settings/app/actionrunner.h index 3ebe43868..cdd519621 100644 --- a/packages/omamobile-settings/app/actionrunner.h +++ b/packages/omamobile-settings/app/actionrunner.h @@ -4,7 +4,7 @@ #include #include -// 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 { diff --git a/packages/omamobile-settings/app/catalog.json b/packages/omamobile-settings/app/catalog.json index 35b266a24..26ccded4b 100644 --- a/packages/omamobile-settings/app/catalog.json +++ b/packages/omamobile-settings/app/catalog.json @@ -17,6 +17,13 @@ "page": "battery", "requires": "charge" }, + { + "id": "haptics", + "title": "Keyboard haptics", + "detail": "Tick strength, or silent for the whole phone", + "icon": "haptics", + "page": "haptics" + }, { "id": "about", "title": "About this device", @@ -37,5 +44,9 @@ "battery": { "title": "Battery", "rows": [] + }, + "haptics": { + "title": "Keyboard haptics", + "rows": [] } } diff --git a/packages/omamobile-settings/app/icons/haptics.svg b/packages/omamobile-settings/app/icons/haptics.svg new file mode 100644 index 000000000..972c941a8 --- /dev/null +++ b/packages/omamobile-settings/app/icons/haptics.svg @@ -0,0 +1 @@ + diff --git a/packages/omamobile-settings/app/resources.qrc b/packages/omamobile-settings/app/resources.qrc index 27e14cec7..a5f13ec18 100644 --- a/packages/omamobile-settings/app/resources.qrc +++ b/packages/omamobile-settings/app/resources.qrc @@ -6,6 +6,8 @@ DisplayPage.qml BatteryPage.qml icons/battery.svg + HapticsPage.qml + icons/haptics.svg icons/display.svg catalog.json icons/system.svg diff --git a/packages/omamobile-settings/backends/haptics.sh b/packages/omamobile-settings/backends/haptics.sh new file mode 100755 index 000000000..26830244f --- /dev/null +++ b/packages/omamobile-settings/backends/haptics.sh @@ -0,0 +1,150 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# Keyboard haptics level: probe/get/set. The level is the strength of one 15 ms tick that 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). Levels (Lef 2026-11-08, motor level of 255 in brackets): +# low 0.015 (motor level 3, the lowest and the default he chose), medium 0.035 (8), high 0.07 (17), all 15 ms. +# The length is the same for every level (Lef: only the strength differs; a longer pulse was tried and rejected). +# Nothing above 0.125 and nothing longer than 60 ms is ever written. +# "off" switches feedbackd's profile to "silent": no haptic from any app, the lock-screen PIN pad included (Lef 2026-11-08). +# Any other level puts the profile back to "full" and writes the strength. +# Nothing in the environment changes what runs here except XDG_CONFIG_HOME (the theme directory); the test runs a copy +# of this script with `dry=1`, which skips feedbackd, gsettings and the preview tick. The theme file is checked +# (exactly the two key entries in the full profile) before anything is changed, and the previous profile is not +# restored: any level after Off puts the profile back to full. +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.035 15" ;; + high) echo "0.07 15" ;; + *) return 1 ;; + esac +} + +get_profile() { + if [[ $dry == 1 ]]; then cat "$dir/.profile-dry" 2>/dev/null || echo full + else gsettings get org.sigxcpu.feedbackd profile | tr -d "'"; fi +} +set_profile() { + if [[ $dry == 1 ]]; then echo "$1" >"$dir/.profile-dry" + else gsettings set org.sigxcpu.feedbackd profile "$1"; fi +} + +current_level() { + [[ $(get_profile) == silent ]] && { echo off; return; } + /usr/bin/python3 -I - "$file" <<'PY' +import json, sys +d = json.load(open(sys.argv[1])) +pairs = set() +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.add((f["magnitudes"][0], f["durations"][0])) +names = {(0.015, 15): "low", (0.035, 15): "medium", (0.07, 15): "high"} +if len(pairs) == 1 and next(iter(pairs)) in names: + print(names[next(iter(pairs))]) +elif pairs: + print("custom") +else: + sys.exit(1) +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"}' + lvl=$(current_level) || fail '{"error":"the haptics theme has no key entries"}' + printf '{"level":"%s"}\n' "$lvl" + ;; +set) + [[ $key == level ]] || fail '{"error":"unknown key"}' + if [[ $value == off ]]; then + set_profile silent || fail '{"error":"could not set the feedbackd profile"}' + printf '{"level":"off"}\n' + exit 0 + fi + 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 + /usr/bin/python3 -I -c "import sys; sys.exit(0 if float('$mag') <= $cap and int('$ms') <= 60 else 1)" || fail '{"error":"above the safety cap"}' + [[ -w $file ]] || fail '{"error":"theme file not writable"}' + edit() { /usr/bin/python3 -I - "$file" "$mag" "$ms" "$1" <<'PY' +import json, os, sys, tempfile +path, mag, ms, mode = sys.argv[1], float(sys.argv[2]), int(sys.argv[3]), sys.argv[4] +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 (OSError, ValueError, KeyError, TypeError): + 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 + raise +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" + # best effort: the strength edit below must work even where gsettings cannot be reached + [[ $(get_profile) == silent ]] && { set_profile full || fail '{"error":"could not turn haptics back on"}'; } + edit write || fail '{"error":"could not write the haptics theme"}' + 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" + ;; +watch) + "$0" get + ;; +*) + fail '{"error":"usage: probe|get|set|watch"}' + ;; +esac diff --git a/packages/omamobile-settings/install b/packages/omamobile-settings/install index 6847708ce..8d1716384 100755 --- a/packages/omamobile-settings/install +++ b/packages/omamobile-settings/install @@ -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" diff --git a/packages/omamobile-settings/test/all b/packages/omamobile-settings/test/all index a8623d42a..653229fae 100755 --- a/packages/omamobile-settings/test/all +++ b/packages/omamobile-settings/test/all @@ -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 diff --git a/packages/omamobile-settings/test/haptics-backend.sh b/packages/omamobile-settings/test/haptics-backend.sh new file mode 100755 index 000000000..3245f3e95 --- /dev/null +++ b/packages/omamobile-settings/test/haptics-backend.sh @@ -0,0 +1,62 @@ +#!/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, gsettings 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; }; } + +eq "$(run get)" '{"level":"low"}' +eq "$(run set level medium)" '{"level":"medium"}' +eq "$(run get)" '{"level":"medium"}' +eq "$(run set level high)" '{"level":"high"}' +eq "$(run set level off)" '{"level":"off"}' +eq "$(run get)" '{"level":"off"}' +eq "$(run set level low)" '{"level":"low"}' +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|watch"}' +# 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(f["magnitudes"][0] <= 0.125 and f["durations"][0] <= 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, and the profile stays as it was +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 +echo silent > "$dir/.profile-dry" +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 "$(cat "$dir/.profile-dry")" silent +cp "$tmp/good.json" "$dir/custom.json"; echo full > "$dir/.profile-dry" +# a theme that is not there: a plain message, no crash +rm "$dir/custom.json" +eq "$(run get)" '{"error":"no keyboard haptics theme on this phone"}' +echo "haptics backend: ok" diff --git a/packages/omamobile-settings/tests/core_tests.cpp b/packages/omamobile-settings/tests/core_tests.cpp index b87a721ce..ffec3529c 100644 --- a/packages/omamobile-settings/tests/core_tests.cpp +++ b/packages/omamobile-settings/tests/core_tests.cpp @@ -31,22 +31,22 @@ private slots: void probeShowsTheBatteryRowOnlyWhenTheBackendSaysAvailable() { Backend on; on.setBackendDir(stubs("on")); - QCOMPARE(on.rows().size(), 2); - QTRY_COMPARE(on.rows().size(), 3); + QCOMPARE(on.rows().size(), 3); + QTRY_COMPARE(on.rows().size(), 4); Backend off; off.setBackendDir(stubs("off")); off.setToolAvailable("charge", true); - QTRY_COMPARE(off.rows().size(), 2); // the probe's answer clears it + QTRY_COMPARE(off.rows().size(), 3); // the probe's answer clears it } void navigationRejectsUnknownAndHiddenActions() { Backend backend; backend.setBackendDir(stubs("off")); QVERIFY(backend.catalogProblems().isEmpty()); - QCOMPARE(backend.rows().size(), 2); // the Battery row waits for the charge backend, absent here + QCOMPARE(backend.rows().size(), 3); // the Battery row waits for the charge backend, absent here backend.setToolAvailable("charge", true); - QCOMPARE(backend.rows().size(), 3); + QCOMPARE(backend.rows().size(), 4); backend.setToolAvailable("charge", false); - QCOMPARE(backend.rows().size(), 2); + QCOMPARE(backend.rows().size(), 3); QVERIFY(!backend.navigate("recording")); backend.activate("arbitrary-command"); QCOMPARE(backend.page(), QString("root")); From 399bd6f0c9d347ca9e3cb66eb1fa15c6e7d733f0 Mon Sep 17 00:00:00 2001 From: Lef Date: Fri, 13 Nov 2026 19:51:03 +0200 Subject: [PATCH 2/7] omamobile-settings: keyboard haptics leaves the profile alone, no buttons without the theme Off is gone: feedbackd's silent profile drops sound as well as vibration, so a keyboard page must not set it, and nothing in the backend touches feedbackd's profile now (the profile helpers and the watch verb are removed). Where the theme is missing the page reads the error and leaves the three level buttons off, and set refuses before anything changes (test). The header points to the keyboard haptics notes in #538 instead of dated notes, the README says that a level change restarts feedbackd, and a core test goes to the page and back. --- packages/omamobile-settings/README.md | 7 ++-- .../omamobile-settings/app/HapticsPage.qml | 9 +++-- .../omamobile-settings/backends/haptics.sh | 38 +++++-------------- .../test/haptics-backend.sh | 15 ++++---- .../omamobile-settings/tests/core_tests.cpp | 8 ++++ 5 files changed, 34 insertions(+), 43 deletions(-) diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index 2077efd98..3961fa268 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -37,11 +37,12 @@ row stays hidden today: omamobile-device-husky blacklists `max77759_charger` until that blacklist is lifted on a kernel with derekross/linux-omarchy-mobile#266. A third page, Keyboard haptics, sets the strength -of the tick feedbackd plays for key presses, or silent for the whole phone; it +of the tick feedbackd plays for key presses (low, medium or high); 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; 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, and a level after Off puts the profile -back to `full` whatever it was before) and says so on the page when the phone has no such theme. That page runs +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 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 diff --git a/packages/omamobile-settings/app/HapticsPage.qml b/packages/omamobile-settings/app/HapticsPage.qml index c45478c13..2e81466f2 100644 --- a/packages/omamobile-settings/app/HapticsPage.qml +++ b/packages/omamobile-settings/app/HapticsPage.qml @@ -8,9 +8,10 @@ ColumnLayout { 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: "off", label: qsTr("Silent, whole phone"), hint: qsTr("no vibration from any app, lock screen too") }, { id: "low", label: qsTr("Low"), hint: qsTr("keyboard tick, gentlest") }, { id: "medium", label: qsTr("Medium"), hint: qsTr("keyboard tick") }, { id: "high", label: qsTr("High"), hint: qsTr("keyboard tick, strongest") } @@ -19,9 +20,9 @@ ColumnLayout { 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 = level === "off" ? qsTr("Haptics are silent for the whole phone. Pick a level to turn them back on.") - : qsTr("Keyboard tick: %1. Tap a level; it applies at once.").arg(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"]) @@ -30,7 +31,7 @@ ColumnLayout { delegate: SettingsButton { required property var modelData Layout.fillWidth: true; Layout.preferredHeight: 64 - highlighted: page.level === modelData.id; enabled: !page.busy + 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 diff --git a/packages/omamobile-settings/backends/haptics.sh b/packages/omamobile-settings/backends/haptics.sh index 26830244f..bc197d747 100755 --- a/packages/omamobile-settings/backends/haptics.sh +++ b/packages/omamobile-settings/backends/haptics.sh @@ -2,16 +2,16 @@ # SPDX-License-Identifier: MIT # Keyboard haptics level: probe/get/set. The level is the strength of one 15 ms tick that 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). Levels (Lef 2026-11-08, motor level of 255 in brackets): -# low 0.015 (motor level 3, the lowest and the default he chose), medium 0.035 (8), high 0.07 (17), all 15 ms. -# The length is the same for every level (Lef: only the strength differs; a longer pulse was tried and rejected). +# 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 0.015 (3, the lowest), medium 0.035 (8), high 0.07 (17), all 15 ms: only the strength differs. # Nothing above 0.125 and nothing longer than 60 ms is ever written. -# "off" switches feedbackd's profile to "silent": no haptic from any app, the lock-screen PIN pad included (Lef 2026-11-08). -# Any other level puts the profile back to "full" and writes the strength. +# 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). # Nothing in the environment changes what runs here except XDG_CONFIG_HOME (the theme directory); the test runs a copy -# of this script with `dry=1`, which skips feedbackd, gsettings and the preview tick. The theme file is checked -# (exactly the two key entries in the full profile) before anything is changed, and the previous profile is not -# restored: any level after Off puts the profile back to full. +# 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 @@ -32,17 +32,7 @@ level_pair() { esac } -get_profile() { - if [[ $dry == 1 ]]; then cat "$dir/.profile-dry" 2>/dev/null || echo full - else gsettings get org.sigxcpu.feedbackd profile | tr -d "'"; fi -} -set_profile() { - if [[ $dry == 1 ]]; then echo "$1" >"$dir/.profile-dry" - else gsettings set org.sigxcpu.feedbackd profile "$1"; fi -} - current_level() { - [[ $(get_profile) == silent ]] && { echo off; return; } /usr/bin/python3 -I - "$file" <<'PY' import json, sys d = json.load(open(sys.argv[1])) @@ -79,11 +69,6 @@ get) ;; set) [[ $key == level ]] || fail '{"error":"unknown key"}' - if [[ $value == off ]]; then - set_profile silent || fail '{"error":"could not set the feedbackd profile"}' - printf '{"level":"off"}\n' - exit 0 - fi 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 @@ -129,8 +114,6 @@ 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" - # best effort: the strength edit below must work even where gsettings cannot be reached - [[ $(get_profile) == silent ]] && { set_profile full || fail '{"error":"could not turn haptics back on"}'; } edit write || fail '{"error":"could not write the haptics theme"}' if [[ $dry != 1 ]]; then # feedbackd reads the theme when it starts; D-Bus starts it again on the next event. Exact name only. @@ -141,10 +124,7 @@ PY fi printf '{"level":"%s"}\n' "$value" ;; -watch) - "$0" get - ;; *) - fail '{"error":"usage: probe|get|set|watch"}' + fail '{"error":"usage: probe|get|set"}' ;; esac diff --git a/packages/omamobile-settings/test/haptics-backend.sh b/packages/omamobile-settings/test/haptics-backend.sh index 3245f3e95..a96ca9550 100755 --- a/packages/omamobile-settings/test/haptics-backend.sh +++ b/packages/omamobile-settings/test/haptics-backend.sh @@ -23,14 +23,15 @@ eq "$(run get)" '{"level":"low"}' eq "$(run set level medium)" '{"level":"medium"}' eq "$(run get)" '{"level":"medium"}' eq "$(run set level high)" '{"level":"high"}' -eq "$(run set level off)" '{"level":"off"}' -eq "$(run get)" '{"level":"off"}' +# "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 "$(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|watch"}' +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 @@ -50,13 +51,13 @@ 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 -echo silent > "$dir/.profile-dry" 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 "$(cat "$dir/.profile-dry")" silent -cp "$tmp/good.json" "$dir/custom.json"; echo full > "$dir/.profile-dry" -# a theme that is not there: a plain message, no crash +cp "$tmp/good.json" "$dir/custom.json" +# a theme that is not there: a plain message, no crash, and no level can be set (the profile is never touched) rm "$dir/custom.json" eq "$(run get)" '{"error":"no keyboard haptics theme on this phone"}' +eq "$(run set level medium)" '{"error":"theme file not writable"}' +[[ ! -e $dir/.profile-dry ]] echo "haptics backend: ok" diff --git a/packages/omamobile-settings/tests/core_tests.cpp b/packages/omamobile-settings/tests/core_tests.cpp index ffec3529c..917fd0378 100644 --- a/packages/omamobile-settings/tests/core_tests.cpp +++ b/packages/omamobile-settings/tests/core_tests.cpp @@ -134,6 +134,14 @@ private slots: QMetaObject::invokeMethod(page.get(), "apply", QVariant(QVariantMap{{"available", false}})); QCOMPARE(page->property("status").toString(), QString("Settings cannot set a charge limit on this phone.")); } + void hapticsPageGoesBackToRoot() { + Backend backend; + backend.setBackendDir(stubs("off")); + QVERIFY(backend.navigate("haptics")); + QCOMPARE(backend.page(), QString("haptics")); + backend.back(); + QCOMPARE(backend.page(), QString("root")); + } void searchHasOnlyImplementedRoutesAndBackClearsIt() { Backend backend; backend.setBackendDir(stubs("off")); From 54ac99c3828344cfb5cb99212b88020f53a84f6c Mon Sep 17 00:00:00 2001 From: Lef Date: Fri, 13 Nov 2026 19:54:03 +0200 Subject: [PATCH 3/7] omamobile-settings: haptics page hides its buttons without a theme, one rule for get and set The three buttons are not drawn until the theme has been read, a theme that does not have exactly the two key entries is refused by get and probe as well as by set, a missing theme is named as missing, and every failure path of set prints one JSON line. The catalog row and the PKGBUILD no longer mention the silent profile, the header says which environment is read, and the test also covers get and probe on a one-entry, a broken and a missing theme and that nothing is created without a theme. --- packages/omamobile-settings/PKGBUILD | 2 +- packages/omamobile-settings/README.md | 2 +- .../omamobile-settings/app/HapticsPage.qml | 1 + packages/omamobile-settings/app/catalog.json | 2 +- .../omamobile-settings/backends/haptics.sh | 51 ++++++++++++------- .../test/haptics-backend.sh | 19 ++++--- 6 files changed, 49 insertions(+), 28 deletions(-) diff --git a/packages/omamobile-settings/PKGBUILD b/packages/omamobile-settings/PKGBUILD index 629436313..9395e74bd 100644 --- a/packages/omamobile-settings/PKGBUILD +++ b/packages/omamobile-settings/PKGBUILD @@ -9,7 +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 and profile') +optdepends=('feedbackd: the Keyboard haptics page edits its theme') build() { "$startdir/bin/build"; } check() { "$startdir/test/all"; } diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index 3961fa268..278c82087 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -41,7 +41,7 @@ of the tick feedbackd plays for key presses (low, medium or high); 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; 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 gets a plain +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 diff --git a/packages/omamobile-settings/app/HapticsPage.qml b/packages/omamobile-settings/app/HapticsPage.qml index 2e81466f2..785901cab 100644 --- a/packages/omamobile-settings/app/HapticsPage.qml +++ b/packages/omamobile-settings/app/HapticsPage.qml @@ -31,6 +31,7 @@ ColumnLayout { delegate: SettingsButton { required property var modelData Layout.fillWidth: true; Layout.preferredHeight: 64 + visible: page.available 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 { diff --git a/packages/omamobile-settings/app/catalog.json b/packages/omamobile-settings/app/catalog.json index 26ccded4b..7201f8063 100644 --- a/packages/omamobile-settings/app/catalog.json +++ b/packages/omamobile-settings/app/catalog.json @@ -20,7 +20,7 @@ { "id": "haptics", "title": "Keyboard haptics", - "detail": "Tick strength, or silent for the whole phone", + "detail": "Strength of the keyboard tick", "icon": "haptics", "page": "haptics" }, diff --git a/packages/omamobile-settings/backends/haptics.sh b/packages/omamobile-settings/backends/haptics.sh index bc197d747..b62cd7cc1 100755 --- a/packages/omamobile-settings/backends/haptics.sh +++ b/packages/omamobile-settings/backends/haptics.sh @@ -9,7 +9,8 @@ # 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). -# Nothing in the environment changes what runs here except XDG_CONFIG_HOME (the theme directory); the test runs a copy +# 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 @@ -32,24 +33,29 @@ level_pair() { 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 -d = json.load(open(sys.argv[1])) -pairs = set() -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.add((f["magnitudes"][0], f["durations"][0])) +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((f["magnitudes"][0], f["durations"][0])) +except Exception: + sys.exit(4) +if len(pairs) != 2: + sys.exit(3) names = {(0.015, 15): "low", (0.035, 15): "medium", (0.07, 15): "high"} -if len(pairs) == 1 and next(iter(pairs)) in names: - print(names[next(iter(pairs))]) -elif pairs: - print("custom") +if pairs[0] == pairs[1] and pairs[0] in names: + print(names[pairs[0]]) else: - sys.exit(1) + print("custom") PY } @@ -64,7 +70,12 @@ probe) ;; get) [[ -r $file ]] || fail '{"error":"no keyboard haptics theme on this phone"}' - lvl=$(current_level) || fail '{"error":"the haptics theme has no key entries"}' + 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) @@ -73,6 +84,7 @@ set) mag=${pair% *}; ms=${pair#* } # defence in depth: the table above can never exceed the cap or 60 ms /usr/bin/python3 -I -c "import sys; sys.exit(0 if float('$mag') <= $cap and int('$ms') <= 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 @@ -88,7 +100,7 @@ try: f["magnitudes"] = [mag] f["durations"] = [ms] n += 1 -except (OSError, ValueError, KeyError, TypeError): +except Exception: n = -1 if n != 2: print('{"error":"the haptics theme does not have the two key entries"}') @@ -108,13 +120,14 @@ if mode == "write": os.unlink(tmp) except OSError: pass - raise + 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" - edit write || fail '{"error":"could not write the haptics theme"}' + [[ -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 diff --git a/packages/omamobile-settings/test/haptics-backend.sh b/packages/omamobile-settings/test/haptics-backend.sh index a96ca9550..5c5d29056 100755 --- a/packages/omamobile-settings/test/haptics-backend.sh +++ b/packages/omamobile-settings/test/haptics-backend.sh @@ -1,7 +1,7 @@ #!/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, gsettings and fbcli are never called. +# so feedbackd and fbcli are never called. set -euo pipefail src=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) tmp=$(mktemp -d); trap 'rm -rf -- "$tmp"' EXIT @@ -43,7 +43,7 @@ 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, and the profile stays as it was +# 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 @@ -54,10 +54,17 @@ 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" -# a theme that is not there: a plain message, no crash, and no level can be set (the profile is never touched) -rm "$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":"theme file not writable"}' -[[ ! -e $dir/.profile-dry ]] +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" From 97399d17e3bab8baaea64efb157a0b24a6c68e8e Mon Sep 17 00:00:00 2001 From: Lef Date: Thu, 19 Nov 2026 08:55:34 +0200 Subject: [PATCH 4/7] omamobile-settings 0.1.4 Signed-off-by: Lef --- packages/omamobile-settings/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/omamobile-settings/version b/packages/omamobile-settings/version index b1e80bb24..845639eef 100644 --- a/packages/omamobile-settings/version +++ b/packages/omamobile-settings/version @@ -1 +1 @@ -0.1.3 +0.1.4 From 4063b28c075f6519416906a02a6072ef210821bf Mon Sep 17 00:00:00 2001 From: Lef Date: Thu, 19 Nov 2026 20:16:58 +0200 Subject: [PATCH 5/7] omamobile-settings: keyboard haptics levels use a tick-and-gap pattern Low is one light tick (0.015, 15 ms). Medium is 0.07 for 15 ms then 0 for 40 ms, High 0.1 then the same gap. A first mapping, to be confirmed by feel on the phone. Still capped at 0.125, and 60 ms in total. --- packages/omamobile-settings/README.md | 6 ++-- .../omamobile-settings/app/HapticsPage.qml | 6 ++-- .../omamobile-settings/backends/haptics.sh | 29 +++++++++++-------- .../test/haptics-backend.sh | 8 ++++- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index 278c82087..60d8435d9 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -36,10 +36,10 @@ 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 strength -of the tick feedbackd plays for key presses (low, medium or high); it +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; a first mapping, still to be confirmed by feel on the phone); 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; the first version of the file is kept once as `custom.json.bak-haptics`, a theme that +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 diff --git a/packages/omamobile-settings/app/HapticsPage.qml b/packages/omamobile-settings/app/HapticsPage.qml index 785901cab..3311f8452 100644 --- a/packages/omamobile-settings/app/HapticsPage.qml +++ b/packages/omamobile-settings/app/HapticsPage.qml @@ -12,9 +12,9 @@ ColumnLayout { property bool available: false property int reqId: -1 readonly property var levels: [ - { id: "low", label: qsTr("Low"), hint: qsTr("keyboard tick, gentlest") }, - { id: "medium", label: qsTr("Medium"), hint: qsTr("keyboard tick") }, - { id: "high", label: qsTr("High"), hint: qsTr("keyboard tick, strongest") } + { 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 diff --git a/packages/omamobile-settings/backends/haptics.sh b/packages/omamobile-settings/backends/haptics.sh index b62cd7cc1..5e9e79195 100755 --- a/packages/omamobile-settings/backends/haptics.sh +++ b/packages/omamobile-settings/backends/haptics.sh @@ -1,11 +1,14 @@ #!/bin/bash # SPDX-License-Identifier: MIT -# Keyboard haptics level: probe/get/set. The level is the strength of one 15 ms tick that feedbackd plays for key and +# 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 0.015 (3, the lowest), medium 0.035 (8), high 0.07 (17), all 15 ms: only the strength differs. -# Nothing above 0.125 and nothing longer than 60 ms is ever written. +# 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 are a first mapping, still to be confirmed by feel on the phone. +# 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). @@ -27,8 +30,8 @@ fail() { printf '%s\n' "$1"; exit 2; } level_pair() { case $1 in low) echo "0.015 15" ;; - medium) echo "0.035 15" ;; - high) echo "0.07 15" ;; + medium) echo "0.07,0 15,40" ;; + high) echo "0.1,0 15,40" ;; *) return 1 ;; esac } @@ -46,12 +49,12 @@ try: continue for f in p["feedbacks"]: if f.get("type") == "VibraPattern" and f["event-name"] in ("button-pressed", "key-pressed"): - pairs.append((f["magnitudes"][0], f["durations"][0])) + 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.035, 15): "medium", (0.07, 15): "high"} +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: @@ -82,13 +85,15 @@ 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 - /usr/bin/python3 -I -c "import sys; sys.exit(0 if float('$mag') <= $cap and int('$ms') <= 60 else 1)" || fail '{"error":"above the safety cap"}' + # 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, mag, ms, mode = sys.argv[1], float(sys.argv[2]), int(sys.argv[3]), sys.argv[4] +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 @@ -97,8 +102,8 @@ try: 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] + f["magnitudes"] = mag + f["durations"] = ms n += 1 except Exception: n = -1 diff --git a/packages/omamobile-settings/test/haptics-backend.sh b/packages/omamobile-settings/test/haptics-backend.sh index 5c5d29056..ffd793e58 100755 --- a/packages/omamobile-settings/test/haptics-backend.sh +++ b/packages/omamobile-settings/test/haptics-backend.sh @@ -19,14 +19,20 @@ 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"}' @@ -37,7 +43,7 @@ python3 - "$dir/custom.json" <<'PY' import json, sys d = json.load(open(sys.argv[1])) fb = d["profiles"][0]["feedbacks"] -assert all(f["magnitudes"][0] <= 0.125 and f["durations"][0] <= 60 for f in fb if f["type"] == "VibraPattern") +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 From 843f71e3e0f1ce15b1253530272cbaf373fec654 Mon Sep 17 00:00:00 2001 From: Lef Date: Thu, 19 Nov 2026 22:17:59 +0200 Subject: [PATCH 6/7] omamobile-settings: haptics page gets a try-it field to feel the levels Typing in it brings up the keyboard so the ticks can be felt. The level buttons don't take focus, so the keyboard stays up while switching. Nothing typed is kept; the field clears when the page is left. --- .../omamobile-settings/app/HapticsPage.qml | 15 +++++++++++ .../omamobile-settings/tests/core_tests.cpp | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/omamobile-settings/app/HapticsPage.qml b/packages/omamobile-settings/app/HapticsPage.qml index 3311f8452..0dac869f8 100644 --- a/packages/omamobile-settings/app/HapticsPage.qml +++ b/packages/omamobile-settings/app/HapticsPage.qml @@ -26,12 +26,16 @@ ColumnLayout { } 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 { @@ -41,6 +45,17 @@ ColumnLayout { } } } + 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 } } diff --git a/packages/omamobile-settings/tests/core_tests.cpp b/packages/omamobile-settings/tests/core_tests.cpp index 917fd0378..39eb36d1b 100644 --- a/packages/omamobile-settings/tests/core_tests.cpp +++ b/packages/omamobile-settings/tests/core_tests.cpp @@ -4,6 +4,7 @@ #include "deviceinfocontroller.h" #include "actionrunner.h" #include +#include #include #include #include @@ -142,6 +143,32 @@ private slots: backend.back(); QCOMPARE(backend.page(), QString("root")); } + void hapticsTryFieldExistsAndIsClearedOnLeaving() { + Backend backend; + backend.setBackendDir(stubs("off")); + backend.setHomeCommand({}); + ActionRunner runner; + runner.setBackendDir(stubs("off")); + DeviceInfoController info(true); + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("actions", &runner); + engine.rootContext()->setContextProperty("deviceInfo", &info); + engine.load(QUrl("qrc:/Main.qml")); + QCOMPARE(engine.rootObjects().size(), 1); + auto *window = engine.rootObjects().first(); + QVERIFY(backend.navigate("haptics")); + QTRY_VERIFY(window->findChild("hapticsTryField")); + QPointer field = window->findChild("hapticsTryField"); + field->setProperty("text", "typed"); + QCOMPARE(field->property("text").toString(), QString("typed")); + QVERIFY(QMetaObject::invokeMethod(window, "goBack")); + QCOMPARE(backend.page(), QString("root")); + QTRY_VERIFY(!field || field->property("text").toString().isEmpty()); + QVERIFY(backend.navigate("haptics")); + QTRY_VERIFY(window->findChild("hapticsTryField")); + QCOMPARE(window->findChild("hapticsTryField")->property("text").toString(), QString()); + } void searchHasOnlyImplementedRoutesAndBackClearsIt() { Backend backend; backend.setBackendDir(stubs("off")); From f144d19436888859c725078b07683b80ad3c47ec Mon Sep 17 00:00:00 2001 From: Lef Date: Thu, 19 Nov 2026 22:51:02 +0200 Subject: [PATCH 7/7] omamobile-settings: the haptics levels were tried on the phone --- packages/omamobile-settings/README.md | 2 +- packages/omamobile-settings/backends/haptics.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/omamobile-settings/README.md b/packages/omamobile-settings/README.md index 60d8435d9..1aad5d1f8 100644 --- a/packages/omamobile-settings/README.md +++ b/packages/omamobile-settings/README.md @@ -37,7 +37,7 @@ row stays hidden today: omamobile-device-husky blacklists `max77759_charger` 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; a first mapping, still to be confirmed by feel on the phone); it +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 diff --git a/packages/omamobile-settings/backends/haptics.sh b/packages/omamobile-settings/backends/haptics.sh index 5e9e79195..b2cbb65ba 100755 --- a/packages/omamobile-settings/backends/haptics.sh +++ b/packages/omamobile-settings/backends/haptics.sh @@ -7,7 +7,7 @@ # 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 are a first mapping, still to be confirmed by feel on the phone. +# 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