diff --git a/packages/omamobile-shell/PKGBUILD b/packages/omamobile-shell/PKGBUILD index b662b4da6..719ad71ac 100644 --- a/packages/omamobile-shell/PKGBUILD +++ b/packages/omamobile-shell/PKGBUILD @@ -20,6 +20,7 @@ depends=(omarchy omamobile-apps 'omamobile-omarchy>=0.1.11' 'omamobile-owl-widge xdg-desktop-portal-gnome) # the file chooser (portal/hyprland-portals.conf) checkdepends=(nodejs) # test/weather.py runs HomeModel.js under node optdepends=('fprintd: fingerprint setup and unlock (with omamobile-fingerprint)' + 'fcitx5-mozc: Japanese input (omamobile-ime on)' 'omamobile-voice: the speech model for voice input, so Voxtype works with no download (the root image has it)' 'voxtype-bin: voice input (the root image has it; or Install > AI > Dictation)') backup=(etc/xdg/xdg-desktop-portal/hyprland-portals.conf) diff --git a/packages/omamobile-shell/README.md b/packages/omamobile-shell/README.md index 71f4ac874..c6b265799 100644 --- a/packages/omamobile-shell/README.md +++ b/packages/omamobile-shell/README.md @@ -92,6 +92,12 @@ machine: the model comes from a pinned commit of whisper.cpp's model repository with a pinned sha256, and makepkg keeps it in its source cache afterwards. +## Japanese input + +`omamobile-ime on` (with `fcitx5-mozc` installed) hands the input method to fcitx5 with Mozc, and `omamobile-ime off` gives it back to squeekboard. Hyprland gives it to one client, so with it on squeekboard no longer sees text fields: double-tap the home strip to show it. Type romaji, Space converts, Enter commits. It needs hyprland 0.57.0-3.4, which resends squeekboard's keymap to fcitx5. At login `omamobile-ime.service` restarts squeekboard once fcitx5 holds the input method. + +Not yet: picking a candidate by tap (fcitx5's window takes no taps; a candidate bar above the keyboard, through fcitx5's kimpanel, would), showing the keyboard when a field takes focus, and the Kana layout (it needs more keycodes than a keymap has). + ## File dialogs Open, save and choose-a-folder requests through the portal (Qt, GTK, Electron and Flatpak apps alike) get Nautilus's libadwaita file chooser from xdg-desktop-portal-gnome, not xdg-desktop-portal-gtk's GTK 3 desktop chooser, whose Places sidebar took half of the 480 px width. Nautilus's chooser folds its sidebar away at phone width and has touch-sized rows; `hypr/phone.lua` tiles it, even when it has a parent window, so it fills the screen between the bar and the on-screen keyboard. Only FileChooser goes to the gnome backend: its other interfaces need gnome-shell. It runs without gnome-shell (its Mutter service channel is missing, so it falls back to a plain Wayland connection). xdg-desktop-portal-gtk stays as the fallback and for its other interfaces. GTK apps that would draw their own chooser in-process are sent to the portal too (`GTK_USE_PORTAL=1` for GTK 3, `GDK_DEBUG=portals` for GTK 4, in `environment.d/20-omamobile-osk.conf`); Qt Widgets apps keep Omarchy's `QT_QPA_PLATFORMTHEME=gtk3` for now. diff --git a/packages/omamobile-shell/bin/omamobile-ime b/packages/omamobile-shell/bin/omamobile-ime new file mode 100755 index 000000000..67a48f7e1 --- /dev/null +++ b/packages/omamobile-shell/bin/omamobile-ime @@ -0,0 +1,103 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-ime: Japanese input (fcitx5 with Mozc) on or off, for the user. +# +# omamobile-ime status on or off, and whether fcitx5 and Mozc are there +# omamobile-ime on fcitx5 (Mozc) takes the input method, from now on +# omamobile-ime off squeekboard takes it back, as before +# omamobile-ime session at login (omamobile-ime.service): restart +# squeekboard once fcitx5 is up +# +# Hyprland gives the input method to one client. squeekboard holds it by +# default and shows itself when a text field takes focus. With this on, +# fcitx5 holds it and converts what squeekboard types (its keys reach fcitx5 +# through the keyboard grab; hyprland 0.57.0-3.4 resends squeekboard's +# keymap there), but squeekboard no longer sees text fields: double-tap the +# home strip to show or hide it. Romaji only: the Kana layout needs more +# keycodes than a keymap has. Space converts, Enter commits; candidates +# appear in fcitx5's own window, which takes no taps. The switch is +# ~/.config/omamobile/fcitx5 (the drop-in on omarchy-fcitx5.service reads +# it too). +set -euo pipefail + +CONF=${XDG_CONFIG_HOME:-$HOME/.config} +FLAG=$CONF/omamobile/fcitx5 +FCITX=$CONF/fcitx5 +SYSTEMCTL=${OMAMOBILE_SYSTEMCTL:-systemctl} +MOZC=${OMAMOBILE_MOZC_ADDON:-/usr/share/fcitx5/addon/mozc.conf} + +die() { echo "omamobile-ime: $*" >&2; exit 1; } + +# squeekboard as Omarchy's autostart starts it, through Hyprland's exec: +# started straight from a script it didn't come back (omamobile-keyboard-theme). +restart_squeekboard() { + [[ -n ${OMAMOBILE_IME_NO_OSK:-} ]] && return 0 + pkill -x squeekboard 2>/dev/null || true + for _ in $(seq 30); do pgrep -x squeekboard >/dev/null || break; sleep 0.1; done + local sig=${HYPRLAND_INSTANCE_SIGNATURE:-} + [[ -n $sig ]] || sig=$(ls "${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/hypr" 2>/dev/null | head -1) + [[ -n $sig ]] || die "no Hyprland session to start squeekboard in" + HYPRLAND_INSTANCE_SIGNATURE=$sig hyprctl dispatch 'hl.dsp.exec_cmd("uwsm-app -- squeekboard")' >/dev/null +} + +# Mozc in fcitx5's profile, active in every field from the start. Only +# written when the user has no profile or config of their own. +write_config() { + mkdir -p "$FCITX" + if [[ ! -e $FCITX/profile ]]; then + cat > "$FCITX/profile" <<'EOF' +[Groups/0] +Name=Default +Default Layout=us +DefaultIM=mozc + +[Groups/0/Items/0] +Name=keyboard-us +Layout= + +[Groups/0/Items/1] +Name=mozc +Layout= + +[GroupOrder] +0=Default +EOF + fi + if [[ ! -e $FCITX/config ]]; then + printf '[Behavior]\nActiveByDefault=True\nShareInputState=All\n' > "$FCITX/config" + fi +} + +status() { + local state=off mozc=no + [[ -e $FLAG ]] && state=on + [[ -e $MOZC ]] && mozc=yes + echo "japanese input: $state" + echo "mozc installed: $mozc" + echo "fcitx5: $("$SYSTEMCTL" --user is-active omarchy-fcitx5.service 2>/dev/null || true)" +} + +case ${1:-} in + status) status ;; + on) + [[ -e $MOZC ]] || die "fcitx5-mozc isn't installed (sudo pacman -S fcitx5-mozc)" + write_config + mkdir -p "${FLAG%/*}"; : > "$FLAG" + "$SYSTEMCTL" --user restart omarchy-fcitx5.service + restart_squeekboard + echo "Japanese input on: double-tap the home strip for the keyboard" + ;; + off) + rm -f "$FLAG" + "$SYSTEMCTL" --user stop omarchy-fcitx5.service 2>/dev/null || true + restart_squeekboard + echo "Japanese input off" + ;; + session) + # Hyprland's autostart may start squeekboard before fcitx5 is up, and + # then squeekboard keeps the input method: wait for it, then restart it. + for _ in $(seq 100); do pgrep -x squeekboard >/dev/null && break; sleep 0.2; done + restart_squeekboard + ;; + *) die "usage: omamobile-ime status|on|off" ;; +esac diff --git a/packages/omamobile-shell/install b/packages/omamobile-shell/install index f886a7c8d..ac41cb05a 100755 --- a/packages/omamobile-shell/install +++ b/packages/omamobile-shell/install @@ -49,6 +49,9 @@ ln -sfn ../omamobile-setup-user.service "$destination/usr/lib/systemd/user/graph install -Dm644 systemd/user/omamobile-osk-guard.service "$destination/usr/lib/systemd/user/omamobile-osk-guard.service" install -d "$destination/usr/lib/systemd/user/graphical-session.target.wants" ln -sfn ../omamobile-osk-guard.service "$destination/usr/lib/systemd/user/graphical-session.target.wants/omamobile-osk-guard.service" +# Japanese input (omamobile-ime on): squeekboard after fcitx5 at login; inert while off. +install -Dm644 systemd/user/omamobile-ime.service "$destination/usr/lib/systemd/user/omamobile-ime.service" +ln -sfn ../omamobile-ime.service "$destination/usr/lib/systemd/user/graphical-session.target.wants/omamobile-ime.service" # Sleep on screen-off, for every user's graphical session; it does nothing # until the user turns the omamobile-sleep toggle on. install -Dm644 systemd/user/omamobile-sleepd.service "$destination/usr/lib/systemd/user/omamobile-sleepd.service" diff --git a/packages/omamobile-shell/systemd/user/omamobile-ime.service b/packages/omamobile-shell/systemd/user/omamobile-ime.service new file mode 100644 index 000000000..8ca6fa021 --- /dev/null +++ b/packages/omamobile-shell/systemd/user/omamobile-ime.service @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Japanese input (omamobile-ime on): at login, once fcitx5 holds the input +# method, restart squeekboard so it doesn't keep it. Inert while off. +[Unit] +Description=Omarchy Mobile: squeekboard after fcitx5 for Japanese input +ConditionPathExists=%h/.config/omamobile/fcitx5 +After=graphical-session.target omarchy-fcitx5.service +Wants=omarchy-fcitx5.service +PartOf=graphical-session.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/omamobile-ime session + +[Install] +WantedBy=graphical-session.target diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 1a41a1b11..8b6fd1d69 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -1099,6 +1099,8 @@ else pass "widget crash guard: same-boot death held back, one retry after a system going down, clean run and quit clear" fi bash test/osk-guard.sh || fail "omamobile-osk-guard" +bash -n bin/omamobile-ime || fail "omamobile-ime parses" +bash test/ime.sh || fail "omamobile-ime" bash -n bin/omamobile-onboarding || fail "omamobile-onboarding parses" bash test/onboarding-fingerprint.sh || fail "omamobile-onboarding's fingerprint offer" bash test/onboarding-mobile.sh || fail "omamobile-onboarding's SIM line" @@ -1188,6 +1190,8 @@ grep -cx 'ExecStart=/usr/bin/omamobile-setup-user' systemd/user/omamobile-setup- [[ -x $tmp/root/usr/bin/omamobile-sleepd && -f $u/omamobile-sleepd.service && $(readlink "$u/graphical-session.target.wants/omamobile-sleepd.service") == ../omamobile-sleepd.service ]] \ || fail "the sleep watcher is staged and runs for every user's session" +[[ -x $tmp/root/usr/bin/omamobile-ime && $(readlink "$u/graphical-session.target.wants/omamobile-ime.service") == ../omamobile-ime.service ]] || + fail "Japanese input's login unit is staged for every session" grep -cx 'ExecStart=/usr/bin/omamobile-sleepd' systemd/user/omamobile-sleepd.service >/dev/null || fail "the unit runs the watcher" # Double tap to wake: phone.lua turns Hyprland's wake on touch off, so the # watcher must run for every session, or a single touch and a double tap diff --git a/packages/omamobile-shell/test/ime.sh b/packages/omamobile-shell/test/ime.sh new file mode 100755 index 000000000..7070603e8 --- /dev/null +++ b/packages/omamobile-shell/test/ime.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# omamobile-ime against a scratch home and a fake systemctl. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +fail() { echo "not ok - ime: $*" >&2; exit 1; } +mkdir -p "$t/bin" "$t/home" +cat > "$t/bin/systemctl" <<'SH' +#!/bin/bash +echo "$*" >> "$IME_LOG" +[[ $* == "--user is-active omarchy-fcitx5.service" ]] && echo active +exit 0 +SH +chmod +x "$t/bin/systemctl" +: > "$t/mozc.conf" +run() { + HOME=$t/home XDG_CONFIG_HOME=$t/home/.config IME_LOG=$t/log OMAMOBILE_SYSTEMCTL=$t/bin/systemctl \ + OMAMOBILE_MOZC_ADDON=${MOZC:-$t/mozc.conf} OMAMOBILE_IME_NO_OSK=1 bin/omamobile-ime "$@" +} +c=$t/home/.config + +[[ $(run status | head -1) == "japanese input: off" ]] || fail "off by default" +MOZC=$t/none run on 2>/dev/null && fail "on refuses without fcitx5-mozc" +[[ ! -e $c/omamobile/fcitx5 ]] || fail "a refused on leaves the switch off" + +run on >/dev/null +[[ -e $c/omamobile/fcitx5 ]] || fail "on sets the switch" +grep -qx 'DefaultIM=mozc' "$c/fcitx5/profile" || fail "on writes a Mozc profile" +grep -qx 'ActiveByDefault=True' "$c/fcitx5/config" || fail "Mozc is active from the start" +grep -qx -- '--user restart omarchy-fcitx5.service' "$t/log" || fail "on restarts fcitx5" +[[ $(run status | head -1) == "japanese input: on" ]] || fail "status reads the switch" + +# A profile or config of the user's own is never overwritten. +printf 'mine\n' > "$c/fcitx5/profile"; printf 'mine\n' > "$c/fcitx5/config" +run on >/dev/null +[[ $(cat "$c/fcitx5/profile") == mine && $(cat "$c/fcitx5/config") == mine ]] || fail "the user's fcitx5 files are kept" + +: > "$t/log" +run off >/dev/null +[[ ! -e $c/omamobile/fcitx5 ]] || fail "off clears the switch" +grep -qx -- '--user stop omarchy-fcitx5.service' "$t/log" || fail "off stops fcitx5" +run bogus 2>/dev/null && fail "unknown commands refused" + +u=systemd/user/omamobile-ime.service +grep -qx 'ConditionPathExists=%h/.config/omamobile/fcitx5' $u || fail "the login unit is inert while off" +grep -q '^After=.*omarchy-fcitx5.service' $u || fail "the login unit runs after fcitx5" +grep -qx 'ConditionPathExists=%h/.config/omamobile/fcitx5' systemd/user/omarchy-fcitx5-omamobile.conf || + fail "fcitx5 reads the same switch" +echo "ok - omamobile-ime: off by default, on writes Mozc's profile once and starts fcitx5, off stops it" diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 6cf0bd9e1..97d931a2b 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.126 +0.2.128