diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 4c783e778..2b10b8a66 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -47,7 +47,8 @@ jobs: run: | pacman -Syu --noconfirm --needed git base-devel e2fsprogs zstd lz4 openssl \ python python-dbus python-gobject dbus nodejs dtc cpio file jq busybox \ - xz gzip qt6-declarative qt6-svg shellcheck rsync android-tools + xz gzip qt6-declarative qt6-svg shellcheck rsync android-tools \ + lua # omamobile-shell: hypr/phone.lua's rules and the display scale under a stub of Hyprland's Lua # Arch's nodejs can lag a simdjson soname bump: on 2026-10-29 # simdjson 5.0.8 dropped the libsimdjson.so.34 that nodejs still # linked, and node no longer started. Only while node can't start, diff --git a/AGENTS.md b/AGENTS.md index a024081fc..59576561e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -207,8 +207,9 @@ Each entry gives the gotcha, then the reason or the fix. Details are in the link - **`grep -q` under `set -o pipefail`:** `grep -q` exits early, SIGPIPEs the writer, and the pipeline fails on large input. Use `grep -c … >/dev/null`. - **Omarchy's Chromium launcher splits each line of `chromium-flags.conf` on spaces:** quote a flag whose value has spaces (`"--user-agent=…"`). -- **Chromium needs `--force-device-scale-factor` on the phone,** even with the mobile user agent: its window layout won't go below about 500 px and the panel is 480 px wide in logical pixels, so without it the window runs off the right edge. Sites get phone layouts from the user agent. -- **Grok Bot needs it too** (`~/.config/grok-bot-flags.conf`, read by its launcher): it won't lay out narrower than 512 px. `omamobile-setup-user` picks the factor from the panel's mode so the layout is about 578 px wide (0.83 on the 7 Pro, 0.70 on the 9a). +- **Chromium needs `--force-device-scale-factor` on the phone,** even with the mobile user agent: its window layout won't go below about 500 px and the panel is 480 px wide in logical pixels on the 7 Pro (450 to 504 on the others), so without it the window runs off the right edge. Sites get phone layouts from the user agent. +- **Grok Bot needs it too** (`~/.config/grok-bot-flags.conf`, read by its launcher): it won't lay out narrower than 512 px. `omamobile-setup-user` picks the factor once, before the compositor runs, from the panel's mode at scale 3, so the layout is about 578 px wide on the 7 Pro (0.83) and wider elsewhere (0.62 on a 9a set up from omamobile-shell 0.2.116, whose panel is 450 px at its own 2.4; 0.70 on one set up before, at 8/3). +- **Each screen's scale comes from its pixels per inch, in the config.** `hypr/display-scale.lua` (omamobile-shell 0.2.116+; `omamobile-setup-user` loads it at the top of `monitors.lua`) gives a DSI panel the 7 Pro's 170.7 logical px per inch from the mode and the millimetres DRM reports, snapped to a scale Hyprland takes (3 on the 7 Pro, 2.4 on the 9a, 8/3 on the 8 Pro), through `omarchy_monitor_scale`; other outputs get rules of their own (110 px/in, or 1 without a size). Change scales in `monitors.lua` (a number for `omarchy_monitor_scale`, or a rule for the output further down; a rule for another mode only, such as 60 Hz, keeps `scale = omarchy_monitor_scale`), not with `hyprctl eval` or `keyword monitor`: the next config reload, which Omarchy causes often, drops a runtime rule. `omamobile-display-scale` shows the numbers, read-only. A panel that reports 0x0 mm keeps 3. - **The screensaver runs in a terminal, so focusing it pops up the on-screen keyboard:** `patches/omarchy/0006-*` turns `org.gnome.desktop.a11y.applications screen-keyboard-enabled` off for the screensaver and back on afterwards (from an EXIT trap in the launcher, since omamobile-omarchy 0.1.9), and `omamobile-osk-guard` (omamobile-shell 0.2.19) turns it back on whenever it is off with no screensaver running. If the keyboard stops appearing, check that key first. - **Vendor chroots:** bootstrap binaries such as `servicemanager` use `/system/bin/bootstrap/linker64` as their interpreter. `extract-vendor-chroot` links it to the runtime APEX linker. Run the chroot by path, without `env chroot`. - **If a shell change doesn't show on a phone, check that `omamobile-setup-user.service` runs at login and that its marker exists.** The user unit re-links every `omamobile.*` plugin into `~/.config/omarchy/plugins/` at each login, so a package update reaches the user; it runs only if `~/.local/state/omarchy/done/omamobile-shell-profile` exists, which firstboot creates. On the 9a, whose user was set up during bring-up, the marker was missing, so the unit was skipped at every login, and two plugin links still pointed at hand copies (`omamobile.quicksettings` at a 2026-10-17 copy with no notification shade, `omamobile.switcher` at a 2026-10-22 copy) while four plugins weren't linked at all. Check with `systemctl --user status omamobile-setup-user` and `ls ~/.local/state/omarchy/done/`. Relink with the script's loop (`for p in /usr/share/omamobile/shell/plugins/omamobile.*; do ln -sfn "$p" ~/.config/omarchy/plugins/"${p##*/}"; done`), not the script: without its markers it would copy the package's `shell.json` over the user's and repeat every other once-only step, such as appending the cursor and keyboard lines to the Hyprland files again. [tegu NOTES](device/tegu/NOTES.md#2026-10-31-and-11-01-leftovers-on-the-palmtop-from-bring-up) diff --git a/packages/omamobile-shell/PKGBUILD b/packages/omamobile-shell/PKGBUILD index 4517ea59a..13f035216 100644 --- a/packages/omamobile-shell/PKGBUILD +++ b/packages/omamobile-shell/PKGBUILD @@ -11,7 +11,8 @@ depends=(omarchy omamobile-apps 'omamobile-omarchy>=0.1.11' 'omamobile-owl-widge which # voice input: voxtype finds wtype and wl-copy with which pipewire-audio pipewire-pulse pipewire-alsa wireplumber inotify-tools qt6-declarative - iproute2 jq # omamobile-sleepd: ss for SSH sessions; jq also for omamobile-keys + iproute2 jq # omamobile-sleepd: ss for SSH sessions; jq also for omamobile-keys and omamobile-display-scale + lua # omamobile-display-scale runs hypr/display-scale.lua (Hyprland pulls it in too) # Both are in Omarchy's base package list, which root images install. dnsmasq # the Hotspot tile: NetworkManager's shared mode hands out addresses with it foot xdg-terminal-exec # guard for hand-built/partial installations diff --git a/packages/omamobile-shell/README.md b/packages/omamobile-shell/README.md index 3efb5644d..327105977 100644 --- a/packages/omamobile-shell/README.md +++ b/packages/omamobile-shell/README.md @@ -20,7 +20,8 @@ Omarchy Mobile's phone profile for Omarchy's own shell. It isn't a fork: these a | `plugins/omamobile.access` | The permission sheet: "Allow Camera to use the camera?" with the app's icon and two large buttons, in place of xdg-desktop-portal-gtk's desktop dialog | | `plugins/omamobile.fingerprint` | The under-display fingerprint sensor: target during verification, enrollment screen | | `profile/shell.json` | The phone layout the setup seeds once | -| `bin/omamobile-setup-user` | Omarchy Mobile's per-user setup (Omarchy lifecycle `setup-user`); at every login it also enables and starts the Phone and Messages agent's user unit (`omatel-agent.service`, when installed), so calls and texts notify with no app open; `--adopt`, for a user set up by hand rather than by firstboot, marks the once-only steps that would overwrite or repeat what that user has (the shell profile, the monitor scale, the cursor and keyboard lines, the screensaver, Files' click policy) done without running them; the other steps run as for a new user (missing phone plugins and an idle block go into `shell.json`, Chromium's flags are written), and the setup service then runs at each login | +| `bin/omamobile-setup-user` | Omarchy Mobile's per-user setup (Omarchy lifecycle `setup-user`); at every login it also enables and starts the Phone and Messages agent's user unit (`omatel-agent.service`, when installed), so calls and texts notify with no app open; `--adopt`, for a user set up by hand rather than by firstboot, marks the once-only steps that would overwrite or repeat what that user has (the shell profile, the monitor scale and the per-screen scale, the cursor and keyboard lines, the screensaver, Files' click policy) done without running them; the other steps run as for a new user (missing phone plugins and an idle block go into `shell.json`, Chromium's flags are written), and the setup service then runs at each login | +| `bin/omamobile-display-scale` | Shows the scale each screen gets so the UI is the same physical size on every phone (read-only): for each output Hyprland has, its mode, its size in mm, pixels per inch, the scale `hypr/display-scale.lua` gives it, the logical size and how large the UI comes out against the Pixel 7 Pro's; with `W H MMW MMH [OUTPUT]`, the same for a panel without a compositor. Hyprland applies the scales itself, from `monitors.lua` | | `bin/omamobile-launch` | One app per screen: every launch from the shell (drawer, home screen, widgets, links, the agent) gets a new empty workspace through a per-launch Hyprland exec rule, or focuses the app's open window; and the switcher's "Show with…" and "Move to its own screen" | | `bin/omamobile-osk-watch` | Reports squeekboard's visibility (sm.puri.OSK0) to the fingerprint, keyboard and launcher plugins | | `bin/omamobile-screenshot-open` | What a screenshot toast's tap ("Tap to view", patch 0020) opens on a phone (`OMARCHY_SCREENSHOT_EDITOR`, set in `environment.d/30-omamobile-screenshot.conf`; Omarchy passes the saved file's path): the screenshot in Loupe (omamobile-apps), fitted, with touch zoom, pan and swipe, and Loupe's copy, share and delete. Tensaku, Omarchy's default, can't be panned or zoomed by touch; without Loupe it is the fallback, through `omamobile-screenshot-edit` | @@ -97,7 +98,23 @@ Open, save and choose-a-folder requests through the portal (Qt, GTK, Electron an ## Windows on a phone screen -`hypr/phone.lua` maximizes every app between the bar and the dock, with no gaps, no border and full opacity (Omarchy's 0.96-0.985 let the home widgets show through). When the maximized window closes, the next one takes the screen (`misc:exit_window_retains_fullscreen`). Modal dialogs float centred at their own size, never bigger than the screen; picture-in-picture is 300x169 in the top-right corner. `omamobile-setup-user` sets the monitor scale to 3 with `GDK_SCALE` to match, gives foot 6 px padding, a scrollback multiplier of 3 and a 300 ms long press, and adds Chromium's Wayland input-method flags, each once and only over Omarchy's own values. +`hypr/phone.lua` maximizes every app between the bar and the dock, with no gaps, no border and full opacity (Omarchy's 0.96-0.985 let the home widgets show through). When the maximized window closes, the next one takes the screen (`misc:exit_window_retains_fullscreen`). Modal dialogs float centred at their own size, never bigger than the screen; picture-in-picture is 16:9 in the top-right corner, 62.5% of the screen's shorter side wide (300x169 on the 7 Pro). `omamobile-setup-user` loads `hypr/display-scale.lua` at the top of the user's `monitors.lua` (once, while the monitor scale is still a default): every screen's scale comes from its pixels and the millimetres DRM reports, so a phone's panel gets the Pixel 7 Pro's 170.7 logical px per inch (3 on the 7 Pro, 2.4 on the 9a, 8/3 on the 8 Pro) and an external screen 110 px per inch, each snapped to a scale Hyprland takes; the panel's goes through Omarchy's `omarchy_monitor_scale` (3 until Hyprland has read the panel) and `GDK_SCALE` follows it rounded up, and a number there or a rule for one output further down still wins. It also gives foot 6 px padding, a scrollback multiplier of 3 and a 300 ms long press, and adds Chromium's Wayland input-method flags, each once and only over Omarchy's own values. + +## The same size on every phone + +The shell was laid out on the Pixel 7 Pro: 1440x3120 at 512 px/in, scale 3, 480x1040 logical px. `hypr/display-scale.lua` gives every phone's panel that density, 170.7 logical px per inch, from the mode and the millimetres DRM reports (`hyprctl monitors -j` shows them as `physicalWidth` and `physicalHeight`), snapped to the nearest scale that divides the mode into whole logical pixels in 120ths, which is all Hyprland takes: + +| Phone | Panel | px/in | Scale | Logical | UI size against the 7 Pro | +| --- | --- | --- | --- | --- | --- | +| Pixel 7 Pro (`cheetah`) | 1440x3120, 71x155 mm | 512 | 3 | 480x1040 | 100% | +| Pixel 9a (`tegu`) | 1080x2424 | 422 | 2.4 | 450x1010 | 97% | +| Pixel 8 Pro (`husky`) | 1344x2992, 70x155 mm | 489 | 8/3 | 504x1122 | 93% | + +At one scale of 3 for every phone the 9a's UI was 21% larger than the 7 Pro's, and the 8 Pro's 2992 px don't divide by 3 (Hyprland moved it to 3.2, with a warning). A phone that isn't listed gets its scale the same way, from what its panel reports; a panel that reports no size keeps 3. An external screen gets 110 px/in (a 27-inch 4K is 1.5, 1440p 1), and one of unknown size (a headless output) 1. `omamobile-display-scale` shows the numbers for every output, or for a panel given as `W H MMW MMH`. + +It all comes from the config, so a reload keeps it: `monitors.lua` loads the module, Omarchy's rule for every output takes the panel's scale through `omarchy_monitor_scale`, and every other output gets a rule of its own. A rule a user copies from Omarchy's line (a 60 Hz mode, say) keeps the panel's scale as long as it keeps `scale = omarchy_monitor_scale`; a number in `omarchy_monitor_scale`, or a rule with a number for one output further down (Omarchy's display scaling writes one), wins. Nothing changes an output's mode: the module makes no rule for the panel, its rule for any other output keeps the mode that output already has, a user's rule replaces it whole, and the setup changes only the two `local` lines of `monitors.lua`. Hyprland reads the config before it has any outputs, so on a cold start the panel comes up at 3 and, where its own scale differs (the 9a, the 8 Pro), Hyprland reloads its config once, before the shell has drawn. An output plugged in later does the same. + +The cost of a fractional scale (2.4, 8/3; the 7 Pro's 3 is whole). Clients that speak `wp-fractional-scale-v1` draw at the exact size: Qt 6 (the shell itself), GTK 4, foot, Chromium and Electron, Firefox. The others get a buffer scale of 3, the scale rounded up, and Hyprland scales their buffer down to the panel: their text is a little softer, and they draw more pixels than the panel has (1350x3030 for the 9a's 1080x2424, 1.56 times; 1512x3366 for the 8 Pro's 1344x2992, 1.27 times), which costs some GPU time and battery while they redraw. GTK 3 apps are among them, and so is squeekboard, the on-screen keyboard. X11 apps under XWayland are drawn unscaled with `GDK_SCALE` 3 (the panel's scale rounded up), so on the 9a they come out 25% larger than the rest, and on the 8 Pro 12.5%, rather than smaller. The package contract follows omarchy-mac's: `./install DESTDIR` stages files and enables nothing, `test/all` runs the package's own tests, and `version` holds the version. diff --git a/packages/omamobile-shell/bin/omamobile-display-scale b/packages/omamobile-shell/bin/omamobile-display-scale new file mode 100755 index 000000000..24f5993fd --- /dev/null +++ b/packages/omamobile-shell/bin/omamobile-display-scale @@ -0,0 +1,64 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# The scale each screen gets, so the phone's UI is the same physical size on +# every model: from the mode and the size in mm that DRM reports, the scale +# that gives the Pixel 7 Pro's 170.7 logical px per inch on a panel in the +# hand (512 px/in at 3) and 110 on an external screen, snapped to the nearest +# scale Hyprland takes (whole logical pixels, in 120ths). Hyprland applies it +# itself: hypr/display-scale.lua, which omamobile-setup-user loads from the +# user's monitors.lua, does the same sums. This command only shows them; it +# changes nothing. +# +# omamobile-display-scale every output: its mode, size, pixels +# per inch, the scale it should have, +# and the scale Hyprland has now +# omamobile-display-scale W H MMW MMH [OUTPUT] +# the scale for a W x H panel of +# MMW x MMH mm (OUTPUT names its +# connector, DSI-1 by default) +# omamobile-display-scale --help +# +# SIZE is how large the UI comes out against its target: 100% is the 7 Pro's +# size on a panel, under 100% smaller. A "-" for SCALE is a panel that +# reports no size: it keeps the scale in monitors.lua. +set -euo pipefail + +module=${OMAMOBILE_SHELL_SHARE:-/usr/share/omamobile/shell}/hypr/display-scale.lua + +usage() { awk 'NR > 2 && !/^#/ { exit } NR > 2 { sub(/^# ?/, ""); print }' "${BASH_SOURCE[0]}"; } + +# Rows on stdin: name, width, height, mm width, mm height, current scale +# (tab-separated); a table on stdout. +table() { + OMAMOBILE_DISPLAY_MODULE=$module lua -e ' +local M = dofile(os.getenv("OMAMOBILE_DISPLAY_MODULE")) +local function num(s) return string.format("%.4g", s) end +print(string.format("%-12s %-10s %-8s %-6s %-6s %-10s %-5s %s", "OUTPUT", "MODE", "MM", "PX/IN", "SCALE", "LOGICAL", "SIZE", "NOW")) +for line in io.stdin:lines() do + local name, w, h, mw, mh, now = line:match("^([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)\t([^\t]*)$") + if name then + w, h, mw, mh = tonumber(w) or 0, tonumber(h) or 0, tonumber(mw) or 0, tonumber(mh) or 0 + local ppi = M.ppi(w, h, mw, mh) + local s = M.scale_for(name, w, h, mw, mh) + local target = M.handheld(name) and M.PHONE_PPI or M.DESKTOP_PPI + print(string.format("%-12s %-10s %-8s %-6s %-6s %-10s %-5s %s", name, w .. "x" .. h, mw .. "x" .. mh, + ppi and string.format("%.0f", ppi) or "-", s and num(s) or "-", + s and string.format("%dx%d", math.floor(w / s + 0.5), math.floor(h / s + 0.5)) or "-", + (s and ppi) and string.format("%.0f%%", 100 * s * target / ppi) or "-", + tonumber(now) and num(tonumber(now)) or now)) + end +end' +} + +case ${1:-} in + -h | --help) usage ;; + "") + command -v hyprctl >/dev/null || { echo "omamobile-display-scale: no hyprctl; give W H MMW MMH instead" >&2; exit 1; } + hyprctl monitors all -j | jq -r '.[] | select(.disabled != true) | [.name, .width, .height, .physicalWidth, .physicalHeight, .scale] | @tsv' | table + ;; + *) + (($# == 4 || $# == 5)) || { usage >&2; exit 2; } + for n in "$1" "$2" "$3" "$4"; do [[ $n =~ ^[0-9]+$ ]] || { usage >&2; exit 2; }; done + printf '%s\t%s\t%s\t%s\t%s\t-\n' "${5:-DSI-1}" "$1" "$2" "$3" "$4" | table + ;; +esac diff --git a/packages/omamobile-shell/bin/omamobile-setup-user b/packages/omamobile-shell/bin/omamobile-setup-user index 9d3b09421..c56740a8e 100755 --- a/packages/omamobile-shell/bin/omamobile-setup-user +++ b/packages/omamobile-shell/bin/omamobile-setup-user @@ -9,18 +9,18 @@ set -euo pipefail # --adopt: for a user set up by hand (a bring-up), not by firstboot. The # once-only steps that would overwrite or repeat what such a user already # has are marked done without running: the shell profile (shell.json), the -# monitor scale, the cursor and on-screen keyboard lines appended to the -# Hyprland files, the screensaver's branding files and Files' click -# policy (a hand-set-up user may have chosen double-click). Every other step -# runs as on a new user: most check the user's files first (the menu -# entries, foot's touch lines, phone.lua, the idle block), and a few -# change what is there (they add the missing phone plugins to shell.json, -# replace Chromium's user agent and scale factor, and set the suspend and -# lock toggles). A marked -# step the user does want can be had by removing its marker from -# ~/.local/state/omarchy/done/ before the next login. +# monitor scale and the per-screen scale, the cursor and on-screen keyboard +# lines appended to the Hyprland files, the screensaver's branding files and +# Files' click policy (a hand-set-up user may have chosen double-click). +# Every other step runs as on a new user: most check the user's files first +# (the menu entries, foot's touch lines, phone.lua, the idle block), and a +# few change what is there (they add the missing phone plugins to +# shell.json, replace Chromium's user agent and scale factor, and set the +# suspend and lock toggles). A marked step the user does want can be had by +# removing its marker from ~/.local/state/omarchy/done/ before the next +# login. if [[ ${1:-} == --adopt ]]; then - adopt=" omamobile-shell-profile omamobile-monitor-scale omamobile-hide-cursor omamobile-osk omamobile-screensaver omamobile-files-single-tap " + adopt=" omamobile-shell-profile omamobile-monitor-scale omamobile-display-scale omamobile-hide-cursor omamobile-osk omamobile-screensaver omamobile-files-single-tap " omarchy-done() { if [[ $1 == ensure && $adopt == *" $2 "* ]]; then command omarchy-done check "$2" 2>/dev/null || { command omarchy-done mark "$2"; echo "omamobile-setup-user: adopted $2 (marked done, not run)"; } @@ -150,13 +150,14 @@ if omarchy-done ensure omamobile-credential-type; then fi fi -# Phone scale, seeded once: the Pixel 7 Pro's 1440x3120 at 3 is 480x1040 -# logical; the Pixel 9a's 1080x2424 at 8/3 is 405x909, its owner's choice -# (device/tegu NOTES, 2026-10-25). monitors.lua is Lua, so 8 / 3 is a value. -scale=3 -tr -d '\0' < "${OMAMOBILE_DT:-/proc/device-tree}/compatible" 2>/dev/null | grep -c 'google,zumapro-tegu' >/dev/null && scale='8 \/ 3' +# Phone scale, seeded once: 3, the Pixel 7 Pro's (1440x3120 at 3 is 480x1040 +# logical). With the step after the GDK one it is only the scale a phone +# starts at until Hyprland has read its panel's size, and the one a panel +# that reports no size keeps. (0.2.35-0.2.115 seeded 8 / 3 on the Pixel 9a, +# its owner's choice in device/tegu NOTES, 2026-10-25; a 9a set up then +# keeps it.) if omarchy-done ensure omamobile-monitor-scale; then - sed -i "s/^local omarchy_monitor_scale = .*/local omarchy_monitor_scale = $scale/" ~/.config/hypr/monitors.lua + sed -i "s/^local omarchy_monitor_scale = .*/local omarchy_monitor_scale = 3/" ~/.config/hypr/monitors.lua fi # ...and GDK_SCALE to match (TOUCH-PLAN 2.8): at Omarchy's 2, X11 GTK apps # (xwayland force_zero_scaling) drew at two thirds of the size of the rest. @@ -167,6 +168,55 @@ if omarchy-done ensure omamobile-gdk-scale; then sed -i 's/^local omarchy_gdk_scale = 2$/local omarchy_gdk_scale = 3/' ~/.config/hypr/monitors.lua fi fi +# Each screen at its own scale, from its pixels and the millimetres DRM +# reports, so the phone's UI is the same physical size on every model: +# hypr/display-scale.lua, loaded at the top of monitors.lua. The panel's +# scale goes through omarchy_monitor_scale (so a rule that copies Omarchy's +# line keeps it), GDK_SCALE follows it rounded up, and other screens get +# rules of their own; a rule further down for one output (Omarchy's display +# scaling writes one) still wins. Once, and only while the monitor scale is +# still a default (Omarchy's "auto", or the 3 above): a scale of the user's +# own stays, as does a 9a's 8 / 3. The file is built beside monitors.lua +# and renamed into place, through any symlink, since a running Hyprland +# reloads on every write (as Omarchy's omarchy-hyprland-monitor-scaling +# does it). +if omarchy-done ensure omamobile-display-scale; then + monitors=$(readlink -f ~/.config/hypr/monitors.lua 2>/dev/null || true) + if [[ -f $monitors ]] && grep -cE '^local omarchy_monitor_scale = ("auto"|3)$' "$monitors" >/dev/null && + ! grep -c 'hypr/display-scale\.lua' "$monitors" >/dev/null && tmp=$(mktemp "$monitors.XXXXXX"); then + # Above the first statement and the comment that leads into it + if awk -v module="$share/hypr/display-scale.lua" ' + /^local omarchy_gdk_scale = [23]$/ { + $0 = "local omarchy_gdk_scale = omamobile_display.gdk_scale(" substr($0, length($0)) ")" + } + /^local omarchy_monitor_scale = ("auto"|3)$/ { + sub(/= /, "= omamobile_display.monitor_scale(") + $0 = $0 ")" + } + { line[NR] = $0 } + !first && /^(local |hl\.)/ { first = NR } + END { + if (!first) exit 1 + for (at = first; at > 1 && line[at - 1] ~ /^[[:space:]]*--/; at--) {} + for (i = 1; i < at; i++) print line[i] + print "-- Omarchy Mobile: every screen at the scale that makes the phone'"'"'s UI the" + print "-- same physical size on every model, from its pixels and its size in mm" + print "-- (omamobile-display-scale shows the numbers). omarchy_monitor_scale is the" + print "-- panel'"'"'s (3 until Hyprland has read its size); a number there, or a rule" + print "-- further down for one output (Omarchy'"'"'s display scaling writes one), wins." + print "-- For another mode only (60 Hz, say), keep scale = omarchy_monitor_scale." + print "local omamobile_display = dofile(\"" module "\").setup()" + print "" + for (i = at; i <= NR; i++) print line[i] + } + ' "$monitors" >"$tmp"; then + chmod --reference="$monitors" "$tmp" + mv -f "$tmp" "$monitors" + else + rm -f "$tmp" + fi + fi +fi # Touch phone: no pointer on screen (it still hides on touch if a USB mouse is # attached and the user turns it back on). Added once to the user's override @@ -308,7 +358,8 @@ if omarchy-done ensure omamobile-lock-keypad; then fi # Chromium won't lay out narrower than about 500 px, wider than the phone's -# 480 px (at scale 3), so its window ran off the right edge. On Wayland its +# 480 px (the 7 Pro at scale 3; 450 to 504 on the other phones at their own +# scale), so its window ran off the right edge. On Wayland its # --force-device-scale-factor multiplies the output scale, so 0.83 gives about # 550 px of layout width (2.5, the first try, made everything 2.5x bigger). if omarchy-done ensure omamobile-chromium-scale-2; then @@ -341,10 +392,13 @@ fi # px (SAND_MIN_WINDOW_SIZE in its main process), wider than a phone's logical # width, so its window ran off the right edge as Chromium's did. Its launcher # reads ~/.config/grok-bot-flags.conf. The scale factor there gives the 578 px -# of layout width Chromium gets on the 7 Pro (480 / 0.83): 0.83 there, 0.70 -# on the 9a (405 px), 0.62 at 360 px (a 1080 px panel at scale 3), and 0.83 -# when no panel mode can be read. Once; a factor the user's file already has -# stays theirs. +# of layout width Chromium gets on the 7 Pro (480 / 0.83): 0.83 there, 0.62 +# at 360 px (a 1080 px panel at scale 3), and 0.83 when no panel mode can be +# read. The width is the panel's at 3: this runs before the compositor, so +# the panel's size in mm, and with it its own scale (2.4 on the 9a, 450 px), +# isn't known yet; at 3 a narrower panel's width comes out smaller than it +# will be, so the factor errs small and the window still fits. Once; a +# factor the user's file already has stays theirs. if omarchy-done ensure omamobile-grok-bot-fit; then flags=~/.config/grok-bot-flags.conf factor=0.83 mode= width=0 @@ -352,8 +406,7 @@ if omarchy-done ensure omamobile-grok-bot-fit; then if [[ -r $m ]]; then mode=$(sed -n 1p "$m"); break; fi done if [[ $mode =~ ^([0-9]+)x ]]; then - width=$((BASH_REMATCH[1] / 3)) # $scale, from the monitor step above - [[ $scale == '8 \/ 3' ]] && width=$((BASH_REMATCH[1] * 3 / 8)) + width=$((BASH_REMATCH[1] / 3)) fi if ((width > 0)); then factor=$(awk -v w="$width" 'BEGIN { f = int(100 * w / 578) / 100; printf "%.2f", (f < 0.83 ? f : 0.83) }') diff --git a/packages/omamobile-shell/hypr/display-scale.lua b/packages/omamobile-shell/hypr/display-scale.lua new file mode 100644 index 000000000..f6205810b --- /dev/null +++ b/packages/omamobile-shell/hypr/display-scale.lua @@ -0,0 +1,208 @@ +-- SPDX-License-Identifier: MIT +-- Each screen's scale, from its pixels and the millimetres DRM reports for +-- it, so the phone's UI is the same physical size on every model. The shell +-- was laid out on the Pixel 7 Pro: 1440x3120 at 512 px/in, scale 3, 480x1040 +-- logical px. One scale for every phone made the Pixel 9a's UI 21% larger +-- (1080x2424 at 422 px/in: 360 px wide at 3) and the Pixel 8 Pro's 2992 px +-- not divisible by 3 at all (Hyprland moved it to 3.2, with a warning). A +-- handheld panel gets the 7 Pro's 170.7 logical px per inch instead, snapped +-- to the nearest clean scale: 3 on the 7 Pro, 2.4 on the 9a (450x1010, the +-- UI at 97% of the 7 Pro's size), 8/3 on the 8 Pro (504x1122, at 93%). +-- +-- omamobile-setup-user loads this from the user's monitors.lua, once, at +-- the top, and makes omarchy_monitor_scale (the scale of Omarchy's rule for +-- every output) monitor_scale(3): the panel's scale, so a rule of the +-- user's that copies Omarchy's line (a 60 Hz mode, say) keeps it too. Every +-- other screen (an external one, a foldable's second panel) gets a rule of +-- its own here. A number in omarchy_monitor_scale, or a rule for one output +-- further down (Omarchy's display scaling writes one), still wins: in +-- Hyprland a rule that names an output beats the one for every output +-- wherever it is, and a later rule for the same name replaces an earlier +-- one. It is all in the config itself, so a reload (Omarchy writes its +-- config files often) keeps it; a rule set at runtime with `hyprctl eval` +-- would be lost at the next reload, and the scale would jump back and forth. +-- +-- A fractional scale costs a little: a client without wp-fractional-scale-v1 +-- (GTK 3, squeekboard) draws at 3 and Hyprland scales it down, 1.56 times +-- the panel's pixels on the 9a. The package README has the details. +-- +-- The functions above setup() are plain Lua: test/display-scale.lua and the +-- omamobile-display-scale command run them outside Hyprland. + +local M = {} + +-- The 7 Pro's density at scale 3, for a panel held in the hand. +M.PHONE_PPI = 512 / 3 +-- An external screen, further away: 27" 1440p is scale 1, 27" 4K 1.5. +M.DESKTOP_PPI = 110 +-- Hyprland and wp-fractional-scale-v1 count scales in 120ths. +M.STEPS = 120 +M.MIN_SCALE, M.MAX_SCALE = 1, 4 + +-- A panel in the hand: DSI (or DPI) on the board, or the boot framebuffer +-- that simpledrm drives before the panel's driver loads ("Unknown-1"). +-- Anything else (DP, HDMI, a headless output) is a screen further away. +function M.handheld(name) + name = tostring(name or "") + return name:match("^DSI%-") ~= nil or name:match("^DPI%-") ~= nil or name:match("^Unknown%-") ~= nil +end + +-- Pixels per inch along the diagonal, or nil when the size is missing or +-- can't be a screen's: 0x0 from a panel driver that sets none, or an EDID +-- that gives its aspect ratio ("16x9 mm"), which comes out at thousands of +-- pixels per inch. +function M.ppi(w, h, mm_w, mm_h) + w, h, mm_w, mm_h = tonumber(w) or 0, tonumber(h) or 0, tonumber(mm_w) or 0, tonumber(mm_h) or 0 + if w <= 0 or h <= 0 or mm_w <= 0 or mm_h <= 0 then return nil end + local ppi = math.sqrt(w * w + h * h) / (math.sqrt(mm_w * mm_w + mm_h * mm_h) / 25.4) + if ppi < 50 or ppi > 1000 then return nil end + return ppi +end + +local function gcd(a, b) + while b ~= 0 do a, b = b, a % b end + return a +end + +-- The clean scale nearest to `ideal`: a whole number of 120ths that divides +-- both sides of the mode into whole logical pixels (Hyprland refuses any +-- other), nearest by ratio, between MIN_SCALE and MAX_SCALE. 120/120 +-- always divides, so there is always one. +function M.snap(ideal, w, h) + w, h = tonumber(w) or 0, tonumber(h) or 0 + if not ideal or w <= 0 or h <= 0 then return nil end + ideal = math.min(M.MAX_SCALE, math.max(M.MIN_SCALE, ideal)) + local g = gcd(w * M.STEPS, h * M.STEPS) + local best, best_d + for k = M.MIN_SCALE * M.STEPS, M.MAX_SCALE * M.STEPS do + if g % k == 0 then + local d = math.abs(math.log(k / M.STEPS / ideal)) + if not best or d < best_d then best, best_d = k, d end + end + end + return best / M.STEPS +end + +-- The scale for one output, or nil to leave it to the rule for every +-- output. A handheld panel gets the phone density and an external screen +-- the desktop one. A screen of unknown size gets 1 (a headless output, a +-- projector), except a handheld panel: guessing there could make the phone +-- unusable, so the phone's own default stays. +function M.scale_for(name, w, h, mm_w, mm_h) + w, h = tonumber(w) or 0, tonumber(h) or 0 + if w <= 0 or h <= 0 then return nil end + local ppi = M.ppi(w, h, mm_w, mm_h) + if not ppi then + if M.handheld(name) then return nil end + return 1 + end + return M.snap(ppi / (M.handheld(name) and M.PHONE_PPI or M.DESKTOP_PPI), w, h) +end + +-- The mode an output already has ("1440x3120@60"), for a rule that is only +-- there for its scale: a 60 Hz mode chosen for the battery, or any other, +-- stays. "preferred" (what Omarchy's rule for every output asks for) only +-- when Hyprland reports none. +function M.mode_of(m) + local w, h, hz = tonumber(m.width) or 0, tonumber(m.height) or 0, tonumber(m.refresh_rate) or 0 + if w <= 0 or h <= 0 or hz <= 0 then return "preferred" end + return string.format("%dx%d@%s", w, h, (string.format("%.3f", hz):gsub("%.?0+$", ""))) +end + +-- GDK_SCALE, the factor X11 GTK apps draw at under XWayland (Omarchy leaves +-- them unscaled by Hyprland, so they stay sharp). GTK takes whole numbers +-- only: the panel's scale rounded up, so 2.4 and 8/3 give 3 as on the 7 Pro, +-- and an X11 app is a little larger than the rest on a touch screen rather +-- than smaller. It has no effect on Wayland apps. +function M.gdk_for(scale) + return math.max(1, math.ceil(scale - 1e-6)) +end + +-- ---------------------------------------------------------------- Hyprland + +-- Called from monitors.lua at every evaluation of the config, before +-- Omarchy's lines. The first handheld panel Hyprland has is the phone's +-- (monitor_scale() hands its scale to Omarchy's rule for every output, and +-- to any rule of the user's that says scale = omarchy_monitor_scale): this +-- makes no rule for it, so its mode is whatever those rules say. Every +-- other output gets a rule of its own, with the mode it already has; a rule +-- of the user's for it further down replaces that one, mode and all. Nothing +-- here sets a rule at runtime or writes a file. An output that appears later +-- (Hyprland reads the config before it has any outputs, so on a cold start +-- that is the panel too) is checked once its rule has been applied, and if +-- the config would give it another scale, or GDK_SCALE another value, +-- Hyprland reloads its config, once, so that it comes from the config, in +-- the config's order. On the 7 Pro the fallback 3 is its own scale and +-- nothing reloads. +function M.setup() + M.seen, M.rules, M.panel, M.panel_name = {}, {}, nil, nil + M.follows, M.gdk_follows, M.gdk = false, false, nil + -- A Hyprland whose API has moved on (an option or an event renamed) must + -- not take monitors.lua down with it: the fallbacks there still apply. + local function guarded(what, fn, ...) + local ok, err = pcall(fn, ...) + if not ok then print("omamobile display-scale: " .. what .. ": " .. tostring(err)) end + return ok + end + guarded("outputs", function() + for _, m in ipairs(hl.get_monitors({ all = true }) or {}) do + if m.name then + M.seen[m.name] = true + local s = M.scale_for(m.name, m.width, m.height, m.physical_width, m.physical_height) + if s and not M.panel and M.handheld(m.name) then + M.panel, M.panel_name = s, m.name + elseif s then + hl.monitor({ output = m.name, mode = M.mode_of(m), position = "auto", scale = s }) + M.rules[m.name] = s + end + end + end + end) + + local reloading = false + local function check(name) + if reloading or not name or M.seen[name] then return end + local m = hl.get_monitor(name) + if not m then return end + local s = M.scale_for(name, m.width, m.height, m.physical_width, m.physical_height) + if not s then return end + -- After a reload this output would be the panel: its scale comes from + -- omarchy_monitor_scale, if that still asks this module for it + local panel = M.handheld(name) and not M.panel + local off = (M.follows or not panel) and math.abs((tonumber(m.scale) or 0) - s) > 0.001 + local gdk = panel and M.gdk_follows and M.gdk ~= M.gdk_for(s) + if off or gdk then + reloading = true + -- Not while Omarchy's package transaction holds reloads back + hl.exec_cmd("omarchy-hyprland-reload-guard paused >/dev/null 2>&1 || hyprctl reload >/dev/null") + end + end + -- Once the new output's rule has been applied (its scale is then the one + -- this compares against), as Omarchy defers its own monitor handlers. + local function later(name) + hl.timer(function() guarded("check " .. tostring(name), check, name) end, { type = "oneshot", timeout = 1 }) + end + guarded("monitor.added", hl.on, "monitor.added", function(m) later(m and m.name) end) + -- In case Hyprland's first outputs come before the handler above runs + guarded("hyprland.start", hl.on, "hyprland.start", function() + for _, m in ipairs(hl.get_monitors({ all = true }) or {}) do later(m.name) end + end) + return M +end + +-- omarchy_monitor_scale: the panel's scale when Hyprland has the panel, +-- otherwise `fallback` (the value the line had before) until a reload. +function M.monitor_scale(fallback) + M.follows = true + return M.panel or fallback +end + +-- GDK_SCALE for monitors.lua's hl.env line: from the panel's scale when +-- Hyprland has the panel, otherwise `fallback` (the line's value before). +function M.gdk_scale(fallback) + M.gdk_follows = true + M.gdk = M.panel and M.gdk_for(M.panel) or fallback + return M.gdk +end + +return M diff --git a/packages/omamobile-shell/hypr/phone.lua b/packages/omamobile-shell/hypr/phone.lua index e055deb25..52a5e5e14 100644 --- a/packages/omamobile-shell/hypr/phone.lua +++ b/packages/omamobile-shell/hypr/phone.lua @@ -4,7 +4,8 @@ -- Apps fill the screen between the bar and the dock, like Android. Omarchy's -- floating windows (its terminal, btop, dialogs) are sized for a desktop and --- would land mostly off a 480 px wide screen. +-- would land mostly off a phone's screen (480 px wide on the 7 Pro; 450 to +-- 504 on the others, at their own scale: hypr/display-scale.lua). -- Omarchy floats them through its floating-window tag, so drop the tag. hl.window_rule({ match = { class = ".*" }, tag = "-floating-window" }) hl.window_rule({ match = { class = ".*" }, maximize = true }) @@ -13,7 +14,7 @@ hl.window_rule({ match = { class = "^org.omarchy.screensaver$" }, maximize = fal hl.window_rule({ match = { class = "^org.omarchy.screensaver$" }, fullscreen = true }) -- Edge to edge (TOUCH-PLAN 2.2): Omarchy's gaps (5 and 10) and 2 px border --- cost about 24 px of a 480 px wide screen, so none on the phone. +-- cost about 24 px of the 7 Pro's 480 px wide screen, so none on the phone. hl.config({ general = { gaps_in = 0, gaps_out = 0, border_size = 0 } }) -- ...and every window fully opaque: at Omarchy's 0.985/0.96 the home -- screen's widgets (a layer below) showed through apps. Dropping the tag @@ -61,17 +62,21 @@ hl.window_rule({ -- Tensaku, the screenshot editor (Open With, or the toast without Loupe): Omarchy floats -- it by class (default/hypr/apps/system.lua), not through the floating-window -- tag the first rule drops, so it opened as a desktop-sized float (814x936 on --- a 480 px wide screen) with the screenshot cut off. Tiled and maximized, the +-- the 7 Pro's 480 px wide screen) with the screenshot cut off. Tiled and maximized, the -- canvas gets the screen and fits the image to it. hl.window_rule({ match = { class = "^dev.tensaku.Tensaku$" }, float = false, maximize = true }) -- Picture-in-picture (TOUCH-PLAN 3.5): Omarchy floats it, pinned, at 600x338, -- wider than the screen, and the maximize rule above made it fill the --- screen. A small window in the top-right corner, below the bar, instead. +-- screen. A small 16:9 window in the top-right corner, below the bar, +-- instead: 62.5% of the screen's shorter side wide (300x169 on the 7 Pro's +-- 480 px), so it takes the same share of any phone's screen at any scale, +-- and stays that size with the phone on its side. Hyprland works these out +-- with muParser, which has min(); no spaces inside an expression. hl.window_rule({ match = { tag = "pip" }, maximize = false, - size = { 300, 169 }, + size = { "(min(monitor_w,monitor_h)*0.625)", "(min(monitor_w,monitor_h)*0.3515625)" }, move = { "(monitor_w-window_w-8)", "(monitor_h*0.08)" }, }) diff --git a/packages/omamobile-shell/plugins/README.md b/packages/omamobile-shell/plugins/README.md index c3105fb4e..b377180fe 100644 --- a/packages/omamobile-shell/plugins/README.md +++ b/packages/omamobile-shell/plugins/README.md @@ -758,8 +758,8 @@ enrollment produced one (TIMEOUT: "Time's up"), else fprintd's result. The pure logic is in `SensorModel.js` (`test/sensor-model.js`), the helper's in `test/fp-enroll.py`. -Placement. Panel pixels scale by the screen's logical size (480/1440 at -scale 3) and follow Hyprland's transform for the panel (0-3, as +Placement. Panel pixels scale by the screen's logical size (480/1440 on +the 7 Pro at scale 3, whatever the phone's scale) and follow Hyprland's transform for the panel (0-3, as `omamobile-autorotate` sets them); a flipped transform or a screen of another shape hides the target. Before the bridge has written its file once, the enrollment screen uses stock cheetah's sensor (717, 2360, radius 121). @@ -862,7 +862,7 @@ gesture) and `state ''`. ## omamobile.update Omarchy's update in a sheet, since its terminal update (gum prompts and the -ASCII logo) doesn't fit 480 px with the keyboard up. Everything goes through +ASCII logo) doesn't fit a phone's 450-500 px with the keyboard up. Everything goes through `omamobile-update` from `omamobile-omarchy` (its header and [RELEASES.md](../../../docs/RELEASES.md) §5.4 list what it keeps and skips of Omarchy's update). diff --git a/packages/omamobile-shell/plugins/omamobile.access/AccessSheet.qml b/packages/omamobile-shell/plugins/omamobile.access/AccessSheet.qml index 2b5a6076a..d7523be56 100644 --- a/packages/omamobile-shell/plugins/omamobile.access/AccessSheet.qml +++ b/packages/omamobile-shell/plugins/omamobile.access/AccessSheet.qml @@ -10,9 +10,10 @@ import "AccessModel.js" as AccessModel // app's icon, the question and two large buttons. Access.qml puts it in its // layer-shell window; test/access-render.qml draws it offscreen. // -// On its side (TOUCH-PLAN 2.4: 1040x480) the card keeps to 600 px, centred, -// and the two buttons sit side by side, Allow on the right, so the question -// and both answers fit 480 px of height. +// On its side (TOUCH-PLAN 2.4: 1040x480 on the 7 Pro) the card keeps to +// 600 px, centred, and the two buttons sit side by side, Allow on the right, +// so the question and both answers fit a phone's height on its side (480 px +// on the 7 Pro, 450 on the 9a). Item { id: sheet diff --git a/packages/omamobile-shell/plugins/omamobile.home/Home.qml b/packages/omamobile-shell/plugins/omamobile.home/Home.qml index 1eda58941..c8cc377a4 100644 --- a/packages/omamobile-shell/plugins/omamobile.home/Home.qml +++ b/packages/omamobile-shell/plugins/omamobile.home/Home.qml @@ -448,11 +448,17 @@ Item { } readonly property string homeDir: Quickshell.env("HOME") - // Geometry: the pager (one page) and the surface, in logical px. - property real owlPageWidth: 480 - property real owlPagerHeight: 908 - property real owlScreenWidth: 480 - property real owlScreenHeight: 924 + // Geometry: the pager (one page) and the surface, in logical px, as the + // layout sets them below. Until it does, the screen's, less the bar and + // the dock (44 + 72) and the pager's top margin and dots: each phone's + // own (its width at its own scale, hypr/display-scale.lua), the 7 Pro's + // 480x1040 while there is no screen yet. + readonly property size owlScreenSize: screenInfo && screenInfo.width > 0 && screenInfo.height > 0 + ? Qt.size(screenInfo.width, screenInfo.height) : Qt.size(480, 1040) + property real owlPageWidth: owlScreenSize.width + property real owlPagerHeight: owlScreenSize.height - 132 + property real owlScreenWidth: owlScreenSize.width + property real owlScreenHeight: owlScreenSize.height - 116 // The screen the surface is on (the offscreen renders put a stand-in // here), and its shorter side: the portrait page width, whichever way the // phone is held (the surface itself loses the bar and the dock). diff --git a/packages/omamobile-shell/plugins/omamobile.home/Readable.js b/packages/omamobile-shell/plugins/omamobile.home/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.home/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.home/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/plugins/omamobile.launcher/Readable.js b/packages/omamobile-shell/plugins/omamobile.launcher/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.launcher/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.launcher/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/plugins/omamobile.mobilenetwork/Readable.js b/packages/omamobile-shell/plugins/omamobile.mobilenetwork/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.mobilenetwork/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.mobilenetwork/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/plugins/omamobile.quicksettings/Readable.js b/packages/omamobile-shell/plugins/omamobile.quicksettings/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.quicksettings/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.quicksettings/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/plugins/omamobile.switcher/Readable.js b/packages/omamobile-shell/plugins/omamobile.switcher/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.switcher/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.switcher/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/plugins/omamobile.update/Readable.js b/packages/omamobile-shell/plugins/omamobile.update/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.update/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.update/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/plugins/omamobile.update/Update.qml b/packages/omamobile-shell/plugins/omamobile.update/Update.qml index ee213d129..e9bf910de 100644 --- a/packages/omamobile-shell/plugins/omamobile.update/Update.qml +++ b/packages/omamobile-shell/plugins/omamobile.update/Update.qml @@ -10,7 +10,7 @@ import "UpdateModel.js" as UpdateModel import "Readable.js" as Readable // The phone's update sheet, in place of Omarchy's terminal update (gum and -// the ASCII logo don't fit 480 px with the keyboard up). Opened from the +// the ASCII logo don't fit a phone's 450-500 px with the keyboard up). Opened from the // "Update available" toast, the menu's Update > Omarchy, or // `omarchy-shell shell summon omamobile.update '{}'`. // diff --git a/packages/omamobile-shell/plugins/omamobile.voice/Readable.js b/packages/omamobile-shell/plugins/omamobile.voice/Readable.js index 2a7811cd2..f8478c0b3 100644 --- a/packages/omamobile-shell/plugins/omamobile.voice/Readable.js +++ b/packages/omamobile-shell/plugins/omamobile.voice/Readable.js @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT // The smallest size for text that has to be read. Omarchy's type scale is a -// desktop's (caption 10 px, body 12 px); on the phone's 480 px wide screen, -// held at arm's length, nothing read goes under 12 px (docs/TOUCH-PLAN.md -// 2.1). A floor here rather than theme font overrides, which a theme change -// would drop. Plugins are separate directories with no shared import, so -// each one that needs it carries this same file (test/all checks they match). +// desktop's (caption 10 px, body 12 px); on a phone's screen (480 px wide on +// the 7 Pro, and the same physical size on the others at their own scale, +// hypr/display-scale.lua), held at arm's length, nothing read goes under +// 12 px (docs/TOUCH-PLAN.md 2.1). A floor here rather than theme font +// overrides, which a theme change would drop. Plugins are separate +// directories with no shared import, so each one that needs it carries this +// same file (test/all checks they match). var MIN_PX = 12 diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 2502ae12a..a86db4695 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -91,12 +91,6 @@ b=plugins/omamobile.back/Back.qml python3 -c 'import json; assert {"id": "omamobile.back"} in json.load(open("profile/shell.json"))["plugins"]' \ || fail "the phone profile enables the back gesture" grep -c 'add_plugin omamobile.back' bin/omamobile-setup-user >/dev/null || fail "existing users get the back gesture" -grep -c "google,zumapro-tegu' >/dev/null && scale='8 \\\\/ 3'" bin/omamobile-setup-user >/dev/null || fail "the 9a's scale is 8/3" -# the seeded line stays valid Lua for both scales -for sc in 3 '8 \/ 3'; do - t=$(printf 'local omarchy_monitor_scale = 2\n' | sed "s/^local omarchy_monitor_scale = .*/local omarchy_monitor_scale = $sc/") - [[ $t == 'local omarchy_monitor_scale = 3' || $t == 'local omarchy_monitor_scale = 8 / 3' ]] || fail "the seeded scale line ($t)" -done grep -c 'Quickshell.execDetached(BackModel.ESCAPE_ARGV)' "$b" >/dev/null || fail "back sends Escape through BackModel" grep -c 'WlrLayershell.namespace: "omamobile-back"' "$b" >/dev/null || fail "back strips' namespace" grep -c 'mask: Region { item: strip }' "$b" >/dev/null || fail "only the edge strip takes touches" @@ -982,6 +976,39 @@ else pass "phone.lua window rules # SKIP no lua" fi +# Each screen's scale (hypr/display-scale.lua): the sums for the three phones +# and for other screens, and its rules under Hyprland's (test/display-scale.lua; +# test/setup-user.sh runs it on the monitors.lua it sets up too). Then the +# command that shows them, on the three panels and on a fake Hyprland. +bash -n bin/omamobile-display-scale || fail "omamobile-display-scale parses" +if [[ -n $lua ]]; then + out=$("$lua" test/display-scale.lua) || { grep -v '^ok' <<<"$out"; fail "display-scale.lua"; } + ds() { OMAMOBILE_SHELL_SHARE=$PWD PATH="$ds_path" bash bin/omamobile-display-scale "$@"; } + ds_dir=$(mktemp -d); ds_path="$ds_dir:$PATH" + for row in '1440 3120 71 155|DSI-1 1440x3120 71x155 512 3 480x1040 100% -' \ + '1080 2424 65 146|DSI-1 1080x2424 65x146 422 2.4 450x1010 97% -' \ + '1344 2992 70 155|DSI-1 1344x2992 70x155 490 2.667 504x1122 93% -' \ + '1080 2424 0 0|DSI-1 1080x2424 0x0 - - - - -' \ + '3840 2160 597 336 DP-1|DP-1 3840x2160 597x336 163 1.5 2560x1440 101% -'; do + # shellcheck disable=SC2086 + got=$(ds ${row%%|*} | tail -1 | tr -s ' ') + [[ $got == "${row#*|}" ]] || fail "omamobile-display-scale ${row%%|*}: $got" + done + printf '#!/bin/sh\n[ "$*" = "monitors all -j" ] && printf %%s %s\n' \ + "'[{\"name\":\"DSI-1\",\"width\":1080,\"height\":2424,\"physicalWidth\":65,\"physicalHeight\":146,\"scale\":3,\"disabled\":false},{\"name\":\"HEADLESS-1\",\"width\":1920,\"height\":1080,\"physicalWidth\":0,\"physicalHeight\":0,\"scale\":2,\"disabled\":true}]'" \ + >"$ds_dir/hyprctl" + chmod +x "$ds_dir/hyprctl" + got=$(ds | tr -s ' ') + [[ $(wc -l <<<"$got") == 2 && $(tail -1 <<<"$got") == 'DSI-1 1080x2424 65x146 422 2.4 450x1010 97% 3' ]] \ + || fail "omamobile-display-scale lists Hyprland's enabled outputs: $got" + ds 1080 2424 65 >/dev/null 2>&1 && fail "omamobile-display-scale refuses three numbers" + ds 1080 '' 65 146 >/dev/null 2>&1 && fail "omamobile-display-scale refuses an empty number" + rm -rf "$ds_dir" + pass "display scale: 3, 2.4 and 8/3 on the three phones, 1.5 on a 4K screen, and the command that shows them" +else + pass "display scale # SKIP no lua" +fi + # The session environment: no empty values (environment.d skips such a line # silently), and GTK's file choosers go through the portal (TOUCH-PLAN 3.2). env_d=environment.d/20-omamobile-osk.conf diff --git a/packages/omamobile-shell/test/display-scale.lua b/packages/omamobile-shell/test/display-scale.lua new file mode 100644 index 000000000..9c1799220 --- /dev/null +++ b/packages/omamobile-shell/test/display-scale.lua @@ -0,0 +1,310 @@ +-- SPDX-License-Identifier: MIT +-- hypr/display-scale.lua: the scale sums for the three phones and for other +-- screens, then its rules under a stub of Hyprland's Lua API (hl.*) that +-- resolves them as Hyprland 0.57 does (a rule naming an output beats the +-- one for every output, a later rule for a name replaces an earlier one). +-- Run from the package directory: lua test/display-scale.lua [monitors.lua] +-- With a monitors.lua (test/setup-user.sh passes the one it set up), that +-- file is evaluated too, on each phone. +local M = dofile("hypr/display-scale.lua") + +local failed = false +local function check(ok, what) + print((ok and "ok - " or "not ok - ") .. what) + if not ok then failed = true end +end +local function near(a, b) return a ~= nil and b ~= nil and math.abs(a - b) < 1e-9 end + +-- Hyprland's own test of a scale (CMonitor::applyMonitorRule, 0.57): taken +-- silently when it divides the mode into whole pixels after rounding to +-- 120ths; otherwise it looks for the nearest clean one (warning about it) +-- and returns that. +local function hyprland_takes(s, w, h) + local k = math.floor(s * 120 + 0.5) + local function clean(k) return (w * 120) % k == 0 and (h * 120) % k == 0 end + if clean(k) then return true, k / 120 end + for i = 1, 89 do + if clean(k + i) then return false, (k + i) / 120 end + if clean(k - i) then return false, (k - i) / 120 end + end + return false, nil +end + +-- ------------------------------------------------------------ the phones + +-- Their panels (owl/phone.js BOARDS: pixels and px/in), and the size in mm +-- DRM reports where it has been read on the phone: 71x155 on the 7 Pro +-- (hyprctl monitors -j), 70x155 on the 8 Pro (kernel #154). For the 9a, the +-- size its density gives, and a range around it. +local phones = { + { "cheetah", "Pixel 7 Pro", 1440, 3120, 512, { 71, 155 }, 3, "480x1040", 100 }, + { "tegu", "Pixel 9a", 1080, 2424, 422, false, 2.4, "450x1010", 97 }, + { "husky", "Pixel 8 Pro", 1344, 2992, 489, { 70, 155 }, 8 / 3, "504x1122", 93 }, +} +local unpack = table.unpack or unpack +for _, p in ipairs(phones) do + local code, model, w, h, dpi, mm, want, logical, size = unpack(p) + local from_dpi = { w / dpi * 25.4, h / dpi * 25.4 } + for _, size_mm in ipairs(mm and { from_dpi, mm } or { from_dpi }) do + local s = M.scale_for("DSI-1", w, h, size_mm[1], size_mm[2]) + check(near(s, want), string.format("%s (%s) at %.0fx%.0f mm: scale %.4g", model, code, size_mm[1], size_mm[2], s or 0)) + end + local s = M.scale_for("DSI-1", w, h, from_dpi[1], from_dpi[2]) + check(string.format("%dx%d", w / s, h / s) == logical and w % 1 == 0 and (w / s) % 1 == 0 and (h / s) % 1 == 0, + model .. ": " .. logical .. " whole logical pixels") + check(math.floor(100 * s * M.PHONE_PPI / dpi + 0.5) == size, model .. ": the UI at " .. size .. "% of the 7 Pro's size") + check((hyprland_takes(s, w, h)), model .. ": Hyprland takes " .. string.format("%.4g", s) .. " without a warning") + check(M.gdk_for(s) == 3, model .. ": GDK_SCALE 3") +end +-- A panel driver reports whole millimetres: a millimetre either way of the +-- 9a's 65x146 still gives 2.4, of the 8 Pro's 70x155 still 8/3, and of the +-- 7 Pro's 71x155 still 3. +local steady = true +for dw = -1, 1 do for dh = -1, 1 do + steady = steady and near(M.scale_for("DSI-1", 1080, 2424, 65 + dw, 146 + dh), 2.4) + and near(M.scale_for("DSI-1", 1344, 2992, 70 + dw, 155 + dh), 8 / 3) + and near(M.scale_for("DSI-1", 1440, 3120, 71 + dw, 155 + dh), 3) +end end +check(steady, "a millimetre either way changes no phone's scale") +-- What one scale for every phone did: 3 isn't clean on the 8 Pro (Hyprland +-- warned and moved it to 3.2), and made the 9a 360 px wide. +local ok, moved = hyprland_takes(3, 1344, 2992) +check(not ok and near(moved, 3.2), "the old scale 3 on the 8 Pro: Hyprland moves it to 3.2, with a warning") +check(1080 / 3 == 360, "the old scale 3 on the 9a: 360 px wide") +-- 8/3 is passed as the closest double; Hyprland rounds to 120ths first, so +-- a shortened 2.66667 (autorotate.py's {scale:g}) lands on it too. +check((hyprland_takes(2.66667, 1344, 2992)) and (hyprland_takes(2.66667, 1080, 2424)), "a scale printed short still rounds to the clean 8/3") + +-- ------------------------------------------------------------ other screens + +check(near(M.scale_for("DP-1", 3840, 2160, 597, 336), 1.5), "27-inch 4K on DP: 1.5") +check(near(M.scale_for("DP-1", 2560, 1440, 597, 336), 1), "27-inch 1440p: 1") +check(near(M.scale_for("HDMI-A-1", 1920, 1080, 531, 299), 1), "24-inch 1080p: 1, never below") +check(near(M.scale_for("HEADLESS-1", 1920, 1080, 0, 0), 1), "a headless output (no size): 1") +check(M.scale_for("DSI-1", 1080, 2424, 0, 0) == nil, "a panel that reports no size keeps monitors.lua's scale") +check(M.scale_for("DSI-1", 1080, 2424, 16, 9) == nil and near(M.scale_for("DP-1", 1920, 1080, 16, 9), 1), + "an EDID's aspect ratio in place of a size counts as no size") +check(near(M.scale_for("Unknown-1", 1440, 3120, 71, 155), 3), "the boot framebuffer (simpledrm, Unknown-1) is the panel") +check(M.scale_for("DSI-1", 0, 0, 71, 155) == nil, "an output without a mode gets no rule") +check(near(M.scale_for("DSI-1", 3120, 1440, 155, 71), 3) and near(M.scale_for("DSI-1", 2424, 1080, 146, 65), 2.4), + "turned on its side, the same scale") +check(near(M.scale_for("DSI-1", 1644, 3840, 65, 152), M.snap(643 / M.PHONE_PPI, 1644, 3840)) and M.scale_for("DSI-1", 1644, 3840, 65, 152) > 3, + "a denser panel than the 7 Pro's goes above 3") +check(near(M.snap(9, 1440, 3120), 4) and near(M.snap(0.2, 1440, 3120), 1), "scales stay between 1 and 4") +local all_clean = true +for w = 720, 1600, 8 do + local s = M.snap(2.7, w, 2 * w + 120) + all_clean = all_clean and (hyprland_takes(s, w, 2 * w + 120)) +end +check(all_clean, "every snapped scale is one Hyprland takes as it is") +check(M.handheld("DSI-1") and M.handheld("Unknown-1") and not M.handheld("DP-1") and not M.handheld("HEADLESS-2") + and not M.handheld("eDP-1"), "a panel in the hand is DSI (or simpledrm's Unknown)") +check(M.gdk_for(2) == 2 and M.gdk_for(1.5) == 2 and M.gdk_for(1) == 1 and M.gdk_for(3.2) == 4, "GDK_SCALE rounds up") + +-- ------------------------------------------------------------ in Hyprland + +local panels = { + cheetah = { name = "DSI-1", width = 1440, height = 3120, physical_width = 71, physical_height = 155 }, + tegu = { name = "DSI-1", width = 1080, height = 2424, physical_width = 65, physical_height = 146 }, + husky = { name = "DSI-1", width = 1344, height = 2992, physical_width = 70, physical_height = 155 }, + blind = { name = "DSI-1", width = 1080, height = 2424, physical_width = 0, physical_height = 0 }, + dp = { name = "DP-1", width = 3840, height = 2160, physical_width = 597, physical_height = 336, refresh_rate = 59.94 }, +} +local function copy(t) local c = {} for k, v in pairs(t) do c[k] = v end return c end + +-- A Hyprland with these outputs, before the config runs (`connected`, as on +-- a reload) or after (`later`, as on a cold start or a hotplug). +local current +function H_rules() return current.rules end +local function hyprland(connected) + local H = { rules = {}, handlers = {}, timers = {}, commands = {}, env = {}, outputs = {} } + current = H + for _, m in ipairs(connected or {}) do H.outputs[#H.outputs + 1] = copy(m) end + hl = { + get_monitors = function() return H.outputs end, + get_monitor = function(name) for _, m in ipairs(H.outputs) do if m.name == name then return m end end end, + monitor = function(spec) + local kept = {} + for _, r in ipairs(H.rules) do if r.output ~= spec.output then kept[#kept + 1] = r end end + kept[#kept + 1] = spec + H.rules = kept + end, + on = function(event, fn) H.handlers[event] = H.handlers[event] or {}; table.insert(H.handlers[event], fn) end, + timer = function(fn) H.timers[#H.timers + 1] = fn end, + exec_cmd = function(cmd) H.commands[#H.commands + 1] = cmd end, + env = function(k, v) H.env[k] = v end, + } + -- the rule Hyprland picks for an output, and the scale it applies + function H.rule(name) + for i = #H.rules, 1, -1 do if H.rules[i].output == name then return H.rules[i] end end + for _, r in ipairs(H.rules) do if r.output == "" then return r end end + end + function H.connect(m) + m = copy(m) + local r = H.rule(m.name) + m.scale = r and tonumber(r.scale) or 1 + H.outputs[#H.outputs + 1] = m + for _, fn in ipairs(H.handlers["monitor.added"] or {}) do fn(m) end + end + function H.start() for _, fn in ipairs(H.handlers["hyprland.start"] or {}) do fn() end end + function H.run_timers() local t = H.timers; H.timers = {}; for _, fn in ipairs(t) do fn() end end + function H.reloads() + local n = 0 + for _, c in ipairs(H.commands) do if c:find("hyprctl reload", 1, true) then n = n + 1 end end + return n + end + return H +end + +-- monitors.lua as setup-user leaves it: the module first, Omarchy's rule for +-- every output with the panel's scale, then GDK_SCALE (Omarchy's order). +-- `o` adds what a user may have: a rule for the panel copied from Omarchy's +-- line with another mode (copied), one with a number (rule), a number in +-- omarchy_monitor_scale (pinned). +local function config(o) + o = o or {} + local D = dofile("hypr/display-scale.lua").setup() + -- the module never makes a rule for the panel itself + for _, r in ipairs(H_rules()) do + if r.output == "DSI-1" then error("the module made a rule for the panel") end + end + local omarchy_monitor_scale = o.pinned or D.monitor_scale(3) + hl.monitor({ output = "", mode = "preferred", position = "auto", scale = omarchy_monitor_scale }) + if o.copied then hl.monitor({ output = "DSI-1", mode = "1440x3120@60", position = "auto", scale = omarchy_monitor_scale }) end + if o.rule then hl.monitor({ output = "DSI-1", mode = "preferred", position = "auto", scale = o.rule }) end + -- the battery's 60 Hz line with a number for the scale + if o.literal60 then hl.monitor({ output = "DSI-1", mode = "1440x3120@60", position = "auto", scale = o.literal60 }) end + local omarchy_gdk_scale = D.gdk_scale(3) + hl.env("GDK_SCALE", tostring(omarchy_gdk_scale)) + return D +end + +for code, want in pairs({ cheetah = 3, tegu = 2.4, husky = 8 / 3 }) do + local H = hyprland({ panels[code] }) + config() + local r = H.rule("DSI-1") + check(near(r.scale, want) and r.output == "" and #H.rules == 1, + code .. ", a reload: the panel takes " .. string.format("%.4g", want) .. " through Omarchy's rule for every output") + check(H.env.GDK_SCALE == "3", code .. ": GDK_SCALE 3") + H.start(); H.run_timers() + check(H.reloads() == 0, code .. ": a panel the config already saw needs no reload") +end + +-- What a user adds still works, and wins where it says so +do + for code, want in pairs({ cheetah = 0, tegu = 1 }) do + -- the 60 Hz line with scale = 3: its mode stays at a reload and after a + -- cold start, and so does its 3 (on the 9a too: a number wins) + local R = hyprland({ panels[code] }) + config({ literal60 = 3 }) + local r = R.rule("DSI-1") + check(r.mode == "1440x3120@60" and r.scale == 3, code .. ": the 60 Hz line with scale = 3 keeps its mode and its scale") + local C = hyprland({}) + config({ literal60 = 3 }) + C.connect(panels[code]); C.start(); C.run_timers() + check(C.reloads() == want and C.rule("DSI-1").mode == "1440x3120@60", + code .. ", cold start with that line: 60 Hz from the first frame" .. (want == 0 and ", no reload" or ", one reload that changes nothing")) + end + + local H = hyprland({ panels.tegu }) + config({ copied = true }) + local r = H.rule("DSI-1") + check(r.mode == "1440x3120@60" and near(r.scale, 2.4), "a rule copied from Omarchy's line (60 Hz) keeps the panel's own scale") + H = hyprland({ panels.tegu }) + config({ rule = 8 / 3 }) + check(near(H.rule("DSI-1").scale, 8 / 3), "a rule with a number of the user's for the panel wins") + H = hyprland({ panels.tegu }) + config({ pinned = 2 }) + check(near(H.rule("DSI-1").scale, 2), "a number in omarchy_monitor_scale wins") +end + +-- Cold start: the config runs with no outputs, the panel comes up at the +-- fallback 3; where that's wrong, one reload, after which the panel has its +-- own scale. +for code, want in pairs({ cheetah = 0, tegu = 1, husky = 1 }) do + local H = hyprland({}) + config() + check(H.env.GDK_SCALE == "3" and #H.rules == 1 and H.rules[1].scale == 3, code .. ", cold start: 3 at first") + H.connect(panels[code]); H.start(); H.run_timers() + check(H.reloads() == want, code .. ", cold start: " .. (want == 0 and "no reload (3 is its scale)" or "one reload, though both the event and the start ran")) + check(not H.commands[1] or H.commands[1]:find("omarchy-hyprland-reload-guard paused", 1, true) ~= nil, + code .. ": no reload while Omarchy holds reloads back") +end +do + local H = hyprland({}) + config({ pinned = 2 }) + H.connect(panels.tegu); H.start(); H.run_timers() + check(H.reloads() == 0, "cold start with the user's own number: nothing to reload for") + H = hyprland({}) + config({ copied = true }) + H.connect(panels.tegu); H.start(); H.run_timers() + local R = hyprland({ panels.tegu }) + config({ copied = true }) + check(H.reloads() == 1 and near(R.rule("DSI-1").scale, 2.4) and R.rule("DSI-1").mode == "1440x3120@60", + "cold start with a copied 60 Hz rule: one reload, then 60 Hz at the panel's own scale") +end +-- A panel with no size: nothing to reload for, it keeps 3 +do + local H = hyprland({}) + config() + H.connect(panels.blind); H.start(); H.run_timers() + local R = hyprland({ panels.blind }) + config() + check(H.reloads() == 0 and R.rule("DSI-1").scale == 3 and R.env.GDK_SCALE == "3", + "a panel that reports no size: no reload, it keeps 3") +end +-- An external screen plugged in, and a foldable's second panel +do + local H = hyprland({ panels.cheetah }) + config() + H.connect(panels.dp); H.run_timers() + check(H.reloads() == 1, "an external screen plugged in: a reload") + local R = hyprland({ panels.cheetah, panels.dp }) + config() + check(near(R.rule("DP-1").scale, 1.5) and R.rule("DP-1").output == "DP-1" and near(R.rule("DSI-1").scale, 3) + and R.env.GDK_SCALE == "3", "...after which it has its own 1.5, the panel keeps 3, and GDK_SCALE follows the panel") + check(R.rule("DP-1").mode == "3840x2160@59.94", "...in the mode it already had, not \"preferred\"") + local nohz = copy(panels.dp); nohz.refresh_rate = nil + local P = hyprland({ panels.cheetah, nohz }) + config() + check(P.rule("DP-1").mode == "preferred", "an output that reports no mode gets \"preferred\"") + local inner = { name = "DSI-2", width = 2208, height = 1840, physical_width = 148, physical_height = 123 } + local F = hyprland({ panels.tegu, inner }) + config() + local s2 = M.scale_for("DSI-2", 2208, 1840, 148, 123) + check(near(F.rule("DSI-1").scale, 2.4) and F.rule("DSI-2").output == "DSI-2" and near(F.rule("DSI-2").scale, s2) and not near(s2, 2.4), + "a second panel (a foldable's) gets a rule of its own, at its own scale") +end + +-- A Hyprland whose API has moved on: monitors.lua still runs, with its +-- fallbacks +do + local H = hyprland({ panels.tegu }) + hl.get_monitors = function() error("no such option: all") end + hl.on = function(event) error("unknown event " .. event) end + local printed = print + print = function() end + local ran = pcall(config) + print = printed + check(ran and H.rule("DSI-1").scale == 3 and H.env.GDK_SCALE == "3", "a Hyprland whose API has changed: monitors.lua runs, at 3") +end + +-- ------------------------------------------------------------ setup-user's file + +local path = arg and arg[1] +if path then + for code, want in pairs({ cheetah = 3, tegu = 2.4, husky = 8 / 3 }) do + local H = hyprland({ panels[code] }) + local chunk, err = loadfile(path) + check(chunk ~= nil, path .. " is valid Lua" .. (err and (": " .. err) or "")) + if chunk then + local ran, run_err = pcall(chunk) + check(ran, path .. " runs on the " .. code .. (run_err and (": " .. tostring(run_err)) or "")) + local r = H.rule("DSI-1") + check(r and near(r.scale, want), path .. " on the " .. code .. ": scale " .. string.format("%.4g", want)) + check(H.env.GDK_SCALE == "3", path .. " on the " .. code .. ": GDK_SCALE 3") + end + end +end + +os.exit(failed and 1 or 0) diff --git a/packages/omamobile-shell/test/phone-rules.lua b/packages/omamobile-shell/test/phone-rules.lua index 80340ba78..65dedfded 100644 --- a/packages/omamobile-shell/test/phone-rules.lua +++ b/packages/omamobile-shell/test/phone-rules.lua @@ -110,8 +110,24 @@ check(effect(tensaku, "maximize") == true and effect(tensaku, "float") == false, local pip = { tag = "pip" } local size, move = effect(pip, "size"), effect(pip, "move") -check(effect(pip, "maximize") == false and type(size) == "table" and size[1] == 300 and size[2] == 169, - "picture-in-picture is 300x169, not maximized") +-- Hyprland's expression for a screen of w x h logical px: muParser's min() +-- and arithmetic, nothing else in these +local function px(expr, w, h) + if type(expr) ~= "string" or expr:find("%s") then return nil end + local lua_expr = expr:gsub("monitor_w", tostring(w)):gsub("monitor_h", tostring(h)):gsub("min%(", "math.min(") + local f = (loadstring or load)("return " .. lua_expr) + return f and f() +end +local function pip_at(w, h) + if type(size) ~= "table" then return nil end + local x, y = px(size[1], w, h), px(size[2], w, h) + return x and y and string.format("%.0fx%.0f", x, y) +end +check(effect(pip, "maximize") == false and pip_at(480, 1040) == "300x169", + "picture-in-picture is 300x169 on the 7 Pro, not maximized") +check(pip_at(450, 1010) == "281x158" and pip_at(504, 1122) == "315x177" and pip_at(360, 808) == "225x127", + "picture-in-picture takes the same share of any phone's screen (9a, 8 Pro, a 360 px screen)") +check(pip_at(1040, 480) == "300x169", "picture-in-picture keeps its size with the phone on its side") check(type(move) == "table" and move[1] == "(monitor_w-window_w-8)", "picture-in-picture sits in the right corner") local saver = { class = "^org.omarchy.screensaver$" } diff --git a/packages/omamobile-shell/test/setup-user.sh b/packages/omamobile-shell/test/setup-user.sh index 86e93ed51..24846bd16 100644 --- a/packages/omamobile-shell/test/setup-user.sh +++ b/packages/omamobile-shell/test/setup-user.sh @@ -182,9 +182,15 @@ grep -c 'dofile(".*hypr/phone.lua")' "$t/gate/.config/hypr/hyprland.lua" >/dev/n grep -c 'hypr/phone.lua' "$t/gate/.config/hypr/looknfeel.lua" >/dev/null && fail "the phone rules aren't put where Hyprland never reads them" pass "the phone rules go to the file Hyprland loads, once" -# GDK_SCALE follows the phone's monitor scale (TOUCH-PLAN 2.8) -grep -cx 'local omarchy_monitor_scale = 3' "$H/.config/hypr/monitors.lua" >/dev/null || fail "the monitor scale is 3" -grep -cx 'local omarchy_gdk_scale = 3' "$H/.config/hypr/monitors.lua" >/dev/null || fail "GDK_SCALE is 3 with it" +# Each screen's own scale (hypr/display-scale.lua), loaded once at the top of +# monitors.lua: the panel's through omarchy_monitor_scale (3 until Hyprland +# has read the panel), and GDK_SCALE following it (TOUCH-PLAN 2.8) +m=$H/.config/hypr/monitors.lua +grep -cx 'local omarchy_monitor_scale = omamobile_display.monitor_scale(3)' "$m" >/dev/null || fail "the monitor scale is the panel's, 3 until Hyprland has read it" +[[ $(grep -c 'hypr/display-scale\.lua' "$m") == 1 ]] || fail "monitors.lua loads display-scale.lua once, after several logins" +grep -cx "local omamobile_display = dofile(\"$pkg/hypr/display-scale.lua\").setup()" "$m" >/dev/null || fail "the module comes from the package" +[[ $(grep -n '^local ' "$m" | head -1) == *omamobile_display* ]] || fail "the module is set up before any other line of monitors.lua" +grep -cx 'local omarchy_gdk_scale = omamobile_display.gdk_scale(3)' "$m" >/dev/null || fail "GDK_SCALE follows the panel's scale, 3 until Hyprland has one" # Foot for touch (TOUCH-PLAN 2.9), after two logins foot=$H/.config/foot/foot.ini grep -cx 'pad=6x6' "$foot" >/dev/null && ! grep -c '^pad=14x14' "$foot" >/dev/null || fail "foot's padding is 6x6" @@ -218,6 +224,7 @@ printf '[main]\npad=10x10\n\n[scrollback]\nmultiplier=5.0\n\n[touch]\nlong-press cp "$h/.config/foot/foot.ini" "$t/custom-foot.ini" RUN_HOME=$h run grep -cx 'local omarchy_gdk_scale = 2' "$h/.config/hypr/monitors.lua" >/dev/null || fail "GDK_SCALE stays with a user's own monitor scale" +grep -c 'display-scale' "$h/.config/hypr/monitors.lua" >/dev/null && fail "a user's own monitor scale gets no per-screen scale" cmp -s "$h/.config/foot/foot.ini" "$t/custom-foot.ini" || fail "a user's own foot values stay theirs" [[ -e $h/.local/state/omarchy/done/omamobile-foot-touch ]] || fail "the foot step runs once foot.ini is there" [[ $(grep -cx -- --enable-wayland-ime "$h/.config/chromium-flags.conf") == 1 ]] || fail "a flag the user has isn't added twice" @@ -228,16 +235,108 @@ g=$h/.config/grok-bot-flags.conf [[ $(wc -l <"$g") == 2 ]] && grep -cx -- --disable-gpu "$g" >/dev/null || fail "Grok Bot's file keeps the user's other flags, unchanged" pass "GDK scale, foot, Chromium's and Grok Bot's flags, once each, and a user's own values are kept" -# The Pixel 9a: a new user gets 8 / 3 (405x909 logical), and GDK_SCALE stays -# Omarchy's 2 (its step only follows a monitor scale of exactly 3) +# The Pixel 9a: a new user gets the per-screen scale like every phone (2.4 +# once Hyprland has read the panel: 450x1010), and Grok Bot's factor from +# the panel's width at 3 (360 px), which errs small. A 9a set up by +# 0.2.35-0.2.115 keeps the 8 / 3 it seeded, its owner's choice, and gets no +# per-screen scale. h9=$t/tegu; mkdir -p "$h9/.config/hypr" "$h9/.config/omarchy/extensions" cp "$H"/.config/hypr/{looknfeel,autostart}.lua "$h9/.config/hypr/" printf 'local omarchy_gdk_scale = 2\nlocal omarchy_monitor_scale = "auto"\n' >"$h9/.config/hypr/monitors.lua" RUN_HOME=$h9 RUN_DT=$t/dt-zumapro-tegu RUN_DRM=$t/drm-1080x2424 run -grep -cx 'local omarchy_monitor_scale = 8 / 3' "$h9/.config/hypr/monitors.lua" >/dev/null || fail "the 9a's monitor scale is 8 / 3" -grep -cx 'local omarchy_gdk_scale = 2' "$h9/.config/hypr/monitors.lua" >/dev/null || fail "the 9a's GDK_SCALE step is skipped" -grep -cx -- --force-device-scale-factor=0.70 "$h9/.config/grok-bot-flags.conf" >/dev/null || fail "Grok Bot's factor on the 9a (405 px) is 0.70" -pass "the Pixel 9a's scale: 8 / 3, GDK_SCALE left at 2, Grok Bot at 0.70" +grep -cx 'local omarchy_monitor_scale = omamobile_display.monitor_scale(3)' "$h9/.config/hypr/monitors.lua" >/dev/null && + grep -c 'hypr/display-scale\.lua' "$h9/.config/hypr/monitors.lua" >/dev/null || fail "the 9a gets the per-screen scale" +grep -cx 'local omarchy_gdk_scale = omamobile_display.gdk_scale(3)' "$h9/.config/hypr/monitors.lua" >/dev/null || fail "the 9a's GDK_SCALE follows its panel" +grep -cx -- --force-device-scale-factor=0.62 "$h9/.config/grok-bot-flags.conf" >/dev/null || fail "Grok Bot's factor on a new 9a (360 px at 3) is 0.62" +h9o=$t/tegu-0.2.35; mkdir -p "$h9o/.config/hypr" "$h9o/.config/omarchy/extensions" "$h9o/.local/state/omarchy/done" +cp "$H"/.config/hypr/{looknfeel,autostart}.lua "$h9o/.config/hypr/" +printf 'local omarchy_gdk_scale = 2\nlocal omarchy_monitor_scale = 8 / 3\n' >"$h9o/.config/hypr/monitors.lua" +cp "$h9o/.config/hypr/monitors.lua" "$t/tegu-0.2.35-monitors.lua" +touch "$h9o/.local/state/omarchy/done/"{omamobile-monitor-scale,omamobile-gdk-scale} +RUN_HOME=$h9o RUN_DT=$t/dt-zumapro-tegu RUN_DRM=$t/drm-1080x2424 run +cmp -s "$h9o/.config/hypr/monitors.lua" "$t/tegu-0.2.35-monitors.lua" || fail "a 9a's 8 / 3 from 0.2.35 stays, untouched" +pass "the Pixel 9a: a new user gets the per-screen scale, a 9a's 8 / 3 stays, Grok Bot at 0.62" + +# monitors.lua as Omarchy ships it (the rule for every output, then GDK_SCALE) +# and as this package left it before (GDK_SCALE first, scale 3, both steps +# done, and a 60 Hz rule for the panel copied from Omarchy's line, as on the +# reference 7 Pro): each comes out as Lua that gives each phone its own +# scale, with Omarchy's rule kept as it was (Omarchy's display scaling finds +# it by that shape). +lua=$(command -v lua || command -v lua5.4 || command -v luajit || true) +for shape in omarchy before; do + hm=$t/monitors-$shape; mkdir -p "$hm/.config/hypr" "$hm/.config/omarchy/extensions" "$hm/.local/state/omarchy/done" + cp "$H"/.config/hypr/{looknfeel,autostart}.lua "$hm/.config/hypr/" + if [[ $shape == omarchy ]]; then + cat >"$hm/.config/hypr/monitors.lua" <<'LUA' +-- See https://wiki.hypr.land/Configuring/Basics/Monitors/ +-- List current monitors and supported resolutions with: hyprctl monitors all + +-- Monitor scale is Hyprland's scale for the output. +local omarchy_monitor_scale = "auto" +hl.monitor({ output = "", mode = "preferred", position = "auto", scale = omarchy_monitor_scale }) + +-- Configure a specific monitor. +-- hl.monitor({ output = "DP-2", mode = "2560x1440@144", position = "0x0", scale = 1 }) + +-- GDK scale is GDK_SCALE, the factor GTK draws its own UI at. +local omarchy_gdk_scale = 2 +hl.env("GDK_SCALE", tostring(omarchy_gdk_scale)) +LUA + else + cat >"$hm/.config/hypr/monitors.lua" <<'LUA' +-- See https://wiki.hypr.land/Configuring/Basics/Monitors/ +-- List current monitors and supported resolutions with: hyprctl monitors all + +local omarchy_gdk_scale = 3 +local omarchy_monitor_scale = 3 + +hl.env("GDK_SCALE", tostring(omarchy_gdk_scale)) +hl.monitor({ output = "", mode = "preferred", position = "auto", scale = omarchy_monitor_scale }) + +-- Battery: the built-in panel at 60 Hz instead of 120. +hl.monitor({ output = "DSI-1", mode = "1440x3120@60", position = "auto", scale = omarchy_monitor_scale }) +LUA + touch "$hm/.local/state/omarchy/done/"{omamobile-monitor-scale,omamobile-gdk-scale} + # kept in a dotfiles folder, linked into place + mkdir -p "$hm/dotfiles"; mv "$hm/.config/hypr/monitors.lua" "$hm/dotfiles/" + ln -s "$hm/dotfiles/monitors.lua" "$hm/.config/hypr/monitors.lua" + fi + RUN_HOME=$hm run + f=$hm/.config/hypr/monitors.lua + if [[ $shape == before ]]; then + [[ -L $f ]] && grep -c 'display-scale' "$hm/dotfiles/monitors.lua" >/dev/null || fail "a linked monitors.lua is changed through its link" + ls "$hm/dotfiles/" | grep -c 'monitors\.lua\.' >/dev/null && fail "no temporary file is left beside the linked file" + fi + grep -cx 'hl.monitor({ output = "", mode = "preferred", position = "auto", scale = omarchy_monitor_scale })' "$f" >/dev/null \ + || fail "$shape: Omarchy's rule for every output is kept as it was" + ls "$hm/.config/hypr/" | grep -c 'monitors\.lua\.' >/dev/null && fail "$shape: no temporary file is left beside monitors.lua" + if [[ -n $lua ]]; then + out=$("$lua" test/display-scale.lua "$f") || { grep -v '^ok' <<<"$out"; fail "$shape: monitors.lua under Hyprland's rules"; } + fi +done +pass "Omarchy's monitors.lua and this package's earlier one both give each phone its own scale" + +# A rule of the user's for the panel (the 60 Hz line, with a number for its +# scale or with Omarchy's variable) is left exactly as it is: only the two +# `local` lines change, and the module's block goes above them. +hz=$t/monitors-60hz; mkdir -p "$hz/.config/hypr" "$hz/.config/omarchy/extensions" "$hz/.local/state/omarchy/done" +cp "$H"/.config/hypr/{looknfeel,autostart}.lua "$hz/.config/hypr/" +cat >"$hz/.config/hypr/monitors.lua" <<'LUA' +local omarchy_gdk_scale = 3 +local omarchy_monitor_scale = 3 +hl.env("GDK_SCALE", tostring(omarchy_gdk_scale)) +hl.monitor({ output = "", mode = "preferred", position = "auto", scale = omarchy_monitor_scale }) +hl.monitor({ output = "DSI-1", mode = "1440x3120@60", position = "auto", scale = 3 }) +hl.monitor({ output = "DSI-2", mode = "1080x2092@60", position = "auto", scale = omarchy_monitor_scale }) +LUA +touch "$hz/.local/state/omarchy/done/"{omamobile-monitor-scale,omamobile-gdk-scale} +grep -v '^local ' "$hz/.config/hypr/monitors.lua" >"$t/60hz-rest" +RUN_HOME=$hz run +f=$hz/.config/hypr/monitors.lua +grep -c 'hypr/display-scale\.lua' "$f" >/dev/null || fail "a monitors.lua with a 60 Hz rule still gets the per-screen scale" +diff <(grep -v -e '^local ' -e '^--' -e '^$' "$f") "$t/60hz-rest" >/dev/null || fail "the user's rules (60 Hz) are left exactly as they were" +pass "a user's own rule for an output (a 60 Hz mode) is left exactly as it was" # Grok Bot's factor follows the panel: 0.62 for a 1080 px panel at scale 3 # (360 px), and 0.83 when no panel mode can be read @@ -419,7 +518,7 @@ before=$(snap) RUN_HOME=$ha run --adopt; out=$(cat "$t/out") [[ $(snap) == "$before" ]] || fail "--adopt changed a file an overwriting step owns" python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); assert {"id":"mine"} in d["plugins"]' "$ha/.config/omarchy/shell.json" || fail "--adopt reseeded shell.json" -for s in omamobile-shell-profile omamobile-monitor-scale omamobile-hide-cursor omamobile-osk omamobile-screensaver omamobile-files-single-tap; do +for s in omamobile-shell-profile omamobile-monitor-scale omamobile-display-scale omamobile-hide-cursor omamobile-osk omamobile-screensaver omamobile-files-single-tap; do [[ -e $ha/.local/state/omarchy/done/$s ]] || fail "--adopt did not mark $s" grep -c "adopted $s" <<<"$out" >/dev/null || fail "--adopt did not say it adopted $s" done diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 24b086d02..f491cd41b 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.115 +0.2.116 diff --git a/packages/omamobile-shell/widgets/WIDGETS.md b/packages/omamobile-shell/widgets/WIDGETS.md index f14ee7c01..5b3ad7a79 100644 --- a/packages/omamobile-shell/widgets/WIDGETS.md +++ b/packages/omamobile-shell/widgets/WIDGETS.md @@ -212,8 +212,9 @@ at once, as long as nothing is hard-coded: `Commons.Color...`: Qt 6.12's own `Color` type shadows a bare `Color`. * Text from settings, commands or the network is shown with `textFormat: Text.PlainText`. -* Touch targets are at least 44 logical pixels; the phone is 480 x 1040 - logical, so a cell is about 120 x 150. +* Touch targets are at least 44 logical pixels; the Pixel 7 Pro is 480 x 1040 + logical, so a cell is about 120 x 150 (the other phones are 450 to 504 + wide, at about the same physical size, so their cells are too). * Widgets that show a time use `host.timeFormat`, so they follow the system's 12/24-hour choice like the built-in clock (which uses `HomeModel.systemTimeFormat` on the same setting).