From d906fa030be824aca04a71683fa88a956b35a1ae Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikegami Date: Thu, 12 Nov 2026 22:56:14 +0900 Subject: [PATCH 1/2] omamobile-shell 0.2.132: Japanese input with fcitx5 and Mozc (omamobile-ime) `omamobile-ime on` hands Hyprland's one input method to fcitx5 with Mozc, and `off` gives it back to squeekboard. squeekboard's keys reach fcitx5 through the keyboard grab, so romaji converts with Space and commits with Enter. Mozc converts only while the keyboard's language (the globe key) is "Japanese (romaji)", a copy of the US layout that `on` adds to the list; with any other language fcitx5 passes keys through as typed. At login omamobile-ime.service restarts squeekboard once fcitx5 holds the input method, then follows the language. Off by default, and inert while off. With it on, squeekboard no longer sees text fields (double-tap the home strip), candidates take no taps, and the Kana layout can't be used (it needs more keycodes than a keymap has). Needs hyprland 0.57.0-3.4 (#762). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KgnCmDwY8r4r1jCa2SVYLN --- packages/omamobile-shell/PKGBUILD | 1 + packages/omamobile-shell/README.md | 6 + packages/omamobile-shell/bin/omamobile-ime | 143 +++++++++ packages/omamobile-shell/install | 3 + packages/omamobile-shell/squeekboard/generate | 5 +- .../squeekboard/keyboards/jp+romaji.yaml | 119 +++++++ .../squeekboard/keyboards/jp+romaji_wide.yaml | 119 +++++++ .../keyboards/terminal/jp+romaji.yaml | 301 +++++++++++++++++ .../keyboards/terminal/jp+romaji_wide.yaml | 302 ++++++++++++++++++ .../systemd/user/omamobile-ime.service | 18 ++ packages/omamobile-shell/test/all | 4 + packages/omamobile-shell/test/ime.sh | 71 ++++ .../omamobile-shell/test/keyboard-layouts.py | 4 +- packages/omamobile-shell/version | 2 +- 14 files changed, 1095 insertions(+), 3 deletions(-) create mode 100755 packages/omamobile-shell/bin/omamobile-ime create mode 100644 packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml create mode 100644 packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml create mode 100644 packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml create mode 100644 packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml create mode 100644 packages/omamobile-shell/systemd/user/omamobile-ime.service create mode 100755 packages/omamobile-shell/test/ime.sh 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..4b1d18d34 --- /dev/null +++ b/packages/omamobile-shell/bin/omamobile-ime @@ -0,0 +1,143 @@ +#!/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 omamobile-ime.service: restart squeekboard once +# fcitx5 is up, then follow the keyboard's language +# +# 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. Mozc converts only while the keyboard's +# language (the globe key) is Japanese (romaji), jp+romaji: a copy of the US +# layout, since jp.yaml's kana views need more keycodes than a keymap can +# carry. With any other language fcitx5 passes keys through as typed (a +# password in English is safe). "on" adds that language to the keyboard's +# list. 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} +GSETTINGS=${OMAMOBILE_GSETTINGS:-gsettings} +REMOTE=${OMAMOBILE_FCITX5_REMOTE:-fcitx5-remote} +SCHEMA=org.gnome.desktop.input-sources + +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 +} + +# fcitx5's profile: two groups, English (the US keyboard) and Japanese (Mozc +# alone, so it converts as soon as the group is chosen). A group is global, +# unlike activating Mozc, which reaches only the focused field (none while +# the language sheet is open). 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=English +Default Layout=us +DefaultIM=keyboard-us + +[Groups/0/Items/0] +Name=keyboard-us +Layout= + +[Groups/1] +Name=Japanese +Default Layout=us +DefaultIM=mozc + +[Groups/1/Items/0] +Name=mozc +Layout= + +[GroupOrder] +0=English +1=Japanese +EOF + fi + if [[ ! -e $FCITX/config ]]; then + printf '[Behavior]\nActiveByDefault=False\nShareInputState=All\n' > "$FCITX/config" + fi +} + +# squeekboard shows the first of the input sources; Mozc for Japanese only. +language() { "$GSETTINGS" get $SCHEMA sources | grep -o "'xkb', '[^']*'" | head -1 | sed "s/.*, '//; s/'$//"; } +apply() { + case $(language) in + jp+romaji) "$REMOTE" -g Japanese ;; + *) "$REMOTE" -g English ;; + esac +} + +# Add Japanese (romaji) to the keyboard's languages, last, if it isn't there. +add_language() { + local now + now=$("$GSETTINGS" get $SCHEMA sources) + grep -q "'jp+romaji'" <<<"$now" && return 0 + if [[ $now == *"('"* ]]; then + "$GSETTINGS" set $SCHEMA sources "${now%]}, ('xkb', 'jp+romaji')]" + else + "$GSETTINGS" set $SCHEMA sources "[('xkb', 'us'), ('xkb', 'jp+romaji')]" + 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 + add_language + mkdir -p "${FLAG%/*}"; : > "$FLAG" + "$SYSTEMCTL" --user restart omarchy-fcitx5.service + "$SYSTEMCTL" --user restart omamobile-ime.service + echo "Japanese input on: pick Japanese (romaji) with the globe key; double-tap the home strip for the keyboard" + ;; + off) + rm -f "$FLAG" + "$SYSTEMCTL" --user stop omamobile-ime.service 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 + apply + "$GSETTINGS" monitor $SCHEMA sources | while read -r _; do apply; done + ;; + *) 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/squeekboard/generate b/packages/omamobile-shell/squeekboard/generate index 9a15caa1d..4489c4155 100755 --- a/packages/omamobile-shell/squeekboard/generate +++ b/packages/omamobile-shell/squeekboard/generate @@ -56,7 +56,10 @@ HEADER_END = "# omamobile-setup-user links it into ~/.local/share/squeekboard/ke # The globe key: squeekboard's popover out, our language sheet in GLOBE_UPSTREAM = 'action: "show_prefs"' GLOBE = 'keysym: "XF86MediaLanguageMenu"' -HAND_MADE = {"terminal/us.yaml", "terminal/us_wide.yaml"} +HAND_MADE = {"terminal/us.yaml", "terminal/us_wide.yaml", + # Japanese (romaji) for omamobile-ime: copies of the US layouts + "jp+romaji.yaml", "jp+romaji_wide.yaml", + "terminal/jp+romaji.yaml", "terminal/jp+romaji_wide.yaml"} # Greek (gr, gr_wide): a row of its own under the action row with the accented # vowels, one key each, so ά is one tap and not two (open the accents view, # then tap; it closes itself after one key). The accents view stays for the rest of what is only there. diff --git a/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml new file mode 100644 index 000000000..ebf898840 --- /dev/null +++ b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml @@ -0,0 +1,119 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# Japanese (romaji), for Japanese input (omamobile-ime): a copy of +# us.yaml, whose header follows, so its keymap stays within +# the 255 keycodes an input method's keymap can carry (jp.yaml's kana +# views need 709). omamobile-ime turns Mozc on only while this layout is +# the keyboard's language. Listed in squeekboard/generate's HAND_MADE. +# squeekboard 1.43.1's us.yaml (https://gitlab.gnome.org/World/Phosh/squeekboard, +# tag v1.43.1, GPL-3.0-or-later), with two changes for Omarchy Mobile: the +# action row (Mic, Paste, Emoji, Hide; XF86 keysyms that hypr/phone.lua +# binds for squeekboard only) on top of every view, and the globe key +# sending XF86MediaLanguageMenu (the shell's language sheet) instead of +# opening squeekboard's popover. Made by +# squeekboard/generate (change the generator, not this file). The row +# sums to the widest row's 356.57: 2 x 106.971 + 2 x 71.314. +# omamobile-setup-user links it into ~/.local/share/squeekboard/keyboards/. +# Language: English (US) +--- +outlines: + default: { width: 35.657, height: 52 } + change-view: { width: 53.485, height: 52 } + change-view-2: { width: 62.399, height: 52 } + large: { width: 44.571, height: 52 } + spaceline: { width: 142.63, height: 52 } + special: { width: 44.571, height: 52 } + special-2: { width: 53.485, height: 52 } + special-3: { width: 62.399, height: 52 } + mic: { width: 106.971, height: 40 } + paste: { width: 106.971, height: 40 } + emoji: { width: 71.314, height: 40 } + hide: { width: 71.314, height: 40 } + +views: + base: + - "Mic Paste Emoji Hide" + - "q w e r t y u i o p" + - "a s d f g h j k l" + - "show_upper z x c v b n m BackSpace" + - "show_numbers preferences space . Return" + upper: + - "Mic Paste Emoji Hide" + - "Q W E R T Y U I O P" + - "A S D F G H J K L" + - "show_upper Z X C V B N M BackSpace" + - "show_numbers preferences space . Return" + numbers: + - "Mic Paste Emoji Hide" + - "1 2 3 4 5 6 7 8 9 0" + - "@ # $ % & - _ + ( )" + - "show_symbols , \" ' : ; ! ? BackSpace" + - "show_letters preferences space . Return" + symbols: + - "Mic Paste Emoji Hide" + - "~ ` | · √ π τ ÷ × ¶" + - "© ® £ € ¥ ^ ° * { }" + - "show_numbers_from_symbols \\ / < > = [ ] BackSpace" + - "show_letters preferences space . Return" + +buttons: + show_upper: + action: + locking: + lock_view: "upper" + unlock_view: "base" + outline: "change-view" + icon: "key-shift" + BackSpace: + outline: "special-2" + icon: "edit-clear-symbolic" + action: "erase" + preferences: + keysym: "XF86MediaLanguageMenu" + outline: "special" + icon: "keyboard-mode-symbolic" + show_numbers: + action: + set_view: "numbers" + outline: "change-view-2" + label: "123" + show_numbers_from_symbols: + action: + set_view: "numbers" + outline: "change-view" + label: "123" + show_letters: + action: + set_view: "base" + outline: "change-view-2" + label: "ABC" + show_symbols: + action: + set_view: "symbols" + outline: "change-view" + label: "*/=" + .: + outline: "large" + space: + outline: "spaceline" + text: " " + Return: + outline: "special-3" + icon: "key-enter" + keysym: "Return" + # The action row (hypr/phone.lua binds the keysyms) + Mic: + outline: "mic" + keysym: "XF86Dictate" + label: "󰍬 Mic" + Paste: + outline: "paste" + keysym: "XF86Paste" + label: "󰆒 Paste" + Emoji: + outline: "emoji" + keysym: "XF86EmojiPicker" + label: "󰞅 Emoji" + Hide: + outline: "hide" + keysym: "XF86Keyboard" + label: "󰌏 Hide" diff --git a/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml new file mode 100644 index 000000000..10ddca007 --- /dev/null +++ b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml @@ -0,0 +1,119 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# Japanese (romaji), for Japanese input (omamobile-ime): a copy of +# us_wide.yaml, whose header follows, so its keymap stays within +# the 255 keycodes an input method's keymap can carry (jp.yaml's kana +# views need 709). omamobile-ime turns Mozc on only while this layout is +# the keyboard's language. Listed in squeekboard/generate's HAND_MADE. +# squeekboard 1.43.1's us_wide.yaml (https://gitlab.gnome.org/World/Phosh/squeekboard, +# tag v1.43.1, GPL-3.0-or-later), with two changes for Omarchy Mobile: the +# action row (Mic, Paste, Emoji, Hide; XF86 keysyms that hypr/phone.lua +# binds for squeekboard only) on top of every view, and the globe key +# sending XF86MediaLanguageMenu (the shell's language sheet) instead of +# opening squeekboard's popover. Made by +# squeekboard/generate (change the generator, not this file). The row +# sums to the widest row's 537.6: 2 x 161.28 + 2 x 107.52. +# omamobile-setup-user links it into ~/.local/share/squeekboard/keyboards/. +# Language: English (US) +--- +outlines: + default: { width: 53.76, height: 42 } + change-view: { width: 80.64, height: 42 } + change-view-2: { width: 94.08, height: 42 } + large: { width: 53.76, height: 42 } + spaceline: { width: 241.92, height: 42 } + special: { width: 53.76, height: 42 } + special-2: { width: 80.64, height: 42 } + special-3: { width: 94.08, height: 42 } + mic: { width: 161.28, height: 32 } + paste: { width: 161.28, height: 32 } + emoji: { width: 107.52, height: 32 } + hide: { width: 107.52, height: 32 } + +views: + base: + - "Mic Paste Emoji Hide" + - "q w e r t y u i o p" + - "a s d f g h j k l" + - "show_upper z x c v b n m BackSpace" + - "show_numbers preferences space . Return" + upper: + - "Mic Paste Emoji Hide" + - "Q W E R T Y U I O P" + - "A S D F G H J K L" + - "show_upper Z X C V B N M BackSpace" + - "show_numbers preferences space . Return" + numbers: + - "Mic Paste Emoji Hide" + - "1 2 3 4 5 6 7 8 9 0" + - "@ # $ % & - _ + ( )" + - "show_symbols , \" ' : ; ! ? BackSpace" + - "show_letters preferences space . Return" + symbols: + - "Mic Paste Emoji Hide" + - "~ ` | · √ π τ ÷ × ¶" + - "© ® £ € ¥ ^ ° * { }" + - "show_numbers_from_symbols \\ / < > = [ ] BackSpace" + - "show_letters preferences space . Return" + +buttons: + show_upper: + action: + locking: + lock_view: "upper" + unlock_view: "base" + outline: "change-view" + icon: "key-shift" + BackSpace: + outline: "special-2" + icon: "edit-clear-symbolic" + action: "erase" + preferences: + keysym: "XF86MediaLanguageMenu" + outline: "special" + icon: "keyboard-mode-symbolic" + show_numbers: + action: + set_view: "numbers" + outline: "change-view-2" + label: "123" + show_numbers_from_symbols: + action: + set_view: "numbers" + outline: "change-view" + label: "123" + show_letters: + action: + set_view: "base" + outline: "change-view-2" + label: "ABC" + show_symbols: + action: + set_view: "symbols" + outline: "change-view" + label: "*/=" + .: + outline: "large" + space: + outline: "spaceline" + text: " " + Return: + outline: "special-3" + icon: "key-enter" + keysym: "Return" + # The action row (hypr/phone.lua binds the keysyms) + Mic: + outline: "mic" + keysym: "XF86Dictate" + label: "󰍬 Mic" + Paste: + outline: "paste" + keysym: "XF86Paste" + label: "󰆒 Paste" + Emoji: + outline: "emoji" + keysym: "XF86EmojiPicker" + label: "󰞅 Emoji" + Hide: + outline: "hide" + keysym: "XF86Keyboard" + label: "󰌏 Hide" diff --git a/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml new file mode 100644 index 000000000..a085ca077 --- /dev/null +++ b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml @@ -0,0 +1,301 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# Japanese (romaji), for Japanese input (omamobile-ime): a copy of +# terminal/us.yaml, whose header follows, so its keymap stays within +# the 255 keycodes an input method's keymap can carry (jp.yaml's kana +# views need 709). omamobile-ime turns Mozc on only while this layout is +# the keyboard's language. Listed in squeekboard/generate's HAND_MADE. +# squeekboard 1.43.1's terminal/us.yaml (https://gitlab.gnome.org/World/Phosh/squeekboard, +# tag v1.43.1, GPL-3.0-or-later), changed for Omarchy Mobile: +# - an action row on top (Mic, Paste, Emoji, Hide). Each sends an XF86 +# keysym that hypr/phone.lua binds, for squeekboard's virtual keyboard only +# (the voice bar through omamobile.voice, Omarchy's clipboard and +# emoji pickers, and omamobile.keyboard's hide). squeekboard has no action +# that runs a command, and a keysym key presses on touch-down and releases +# on lift-off, so Mic is push-to-talk (a tap keeps listening). +# - a terminal row of Esc, Tab, Ctrl, Alt, | ~ / and the arrows (upstream's +# Shift modifier stays on the Shift view's row, with Page Up/Down, Home, End). +# - the globe key sends XF86MediaLanguageMenu, which hypr/phone.lua binds to +# the shell's language sheet (omamobile.keyboard), instead of opening +# squeekboard's own popover. +# Widths: every row sums to 404.1, the letter rows' 10 x 40.41. The action row +# is 2 x 121.23 + 2 x 80.82; the terminal row 4 x 42.09 + 7 x 33.675; the Shift +# and actions views' top row 4 x 42.09 + 5 x 47.145. The outline names are CSS classes +# that omamobile-keyboard-theme styles from the Omarchy theme. +# omamobile-setup-user links it as +# ~/.local/share/squeekboard/keyboards/terminal/us.yaml, the only place +# squeekboard reads layouts from besides its built-in ones. +# Language: Englisch (US) +--- +outlines: + default: { width: 40.41, height: 52 } + action: { width: 67.35, height: 52 } + change-view: { width: 60.615, height: 52 } + change-view-2: { width: 67.35, height: 52 } + halfwidth: { width: 20.205, height: 52 } + large: { width: 60.615, height: 52 } + narrow: { width: 30.307, height: 52 } + small-row: { width: 47.145, height: 32 } + term-key: { width: 42.09, height: 32 } + term-narrow: { width: 33.675, height: 32 } + mic: { width: 121.23, height: 36 } + paste: { width: 121.23, height: 36 } + emoji: { width: 80.82, height: 36 } + hide: { width: 80.82, height: 36 } + spaceline: { width: 148.17, height: 52 } + special: { width: 60.615, height: 52 } + special-2: { width: 60.615, height: 52 } + special-3: { width: 67.35, height: 52 } + +views: + base: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt |-small ~-small /-small ← ↑ ↓ →" + - "q w e r t y u i o p" + - ".-thin a s d f g h j k l --thin" + - "show_upper z x c v b n m BackSpace" + - "show_numbers preferences space show_actions Return" + upper: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt Shift PageUp PageDown Home End" + - "Q W E R T Y U I O P" + - "/-thin A S D F G H J K L |-thin" + - "show_upper Z X C V B N M BackSpace" + - "show_numbers preferences space show_actions Return" + numbers: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt |-small ~-small /-small ← ↑ ↓ →" + - "1 2 3 4 5 6 7 8 9 0" + - "\\ * # $ / & - + ( ) _" + - "show_symbols , \" ' : ; ! ? BackSpace" + - "show_letters preferences space . Return" + symbols: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt |-small ~-small /-small ← ↑ ↓ →" + - "~ ` · √ π τ ÷ × ¶ @" + - "\\ © ® £ € ¥ ^ ° { } _" + - "show_numbers_from_symbols % | < > = [ ] BackSpace" + - "show_letters preferences space . Return" + actions: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt Shift PageUp PageDown Home End" + - "F1 F2 F3 F4 F5 F6" + - "F7 F8 F9 F10 F11 F12" + - "Esc Tab Pause Insert Up Del" + - "show_letters_actions Menu Break Left Down Right" + +buttons: + show_upper: + action: + locking: + lock_view: "upper" + unlock_view: "base" + outline: "change-view" + icon: "key-shift" + BackSpace: + outline: "special-2" + icon: "edit-clear-symbolic" + action: "erase" + preferences: + keysym: "XF86MediaLanguageMenu" + outline: "special" + icon: "keyboard-mode-symbolic" + show_numbers: + action: + set_view: "numbers" + outline: "change-view-2" + label: "123" + show_numbers_from_symbols: + action: + set_view: "numbers" + outline: "change-view" + label: "123" + show_letters: + action: + set_view: "base" + outline: "change-view-2" + label: "ABC" + show_letters_actions: + action: + set_view: "base" + outline: "change-view-2" + label: "ABC" + show_symbols: + action: + set_view: "symbols" + outline: "change-view" + label: "τ=\\" + show_actions: + action: + set_view: "actions" + outline: "change-view" + label: ">_" + .: + outline: "large" + space: + outline: "spaceline" + text: " " + Return: + outline: "special-3" + icon: "key-enter" + keysym: "Return" + F1: + outline: "action" + keysym: "F1" + F2: + outline: "action" + keysym: "F2" + F3: + outline: "action" + keysym: "F3" + F4: + outline: "action" + keysym: "F4" + F5: + outline: "action" + keysym: "F5" + F6: + outline: "action" + keysym: "F6" + F7: + outline: "action" + keysym: "F7" + F8: + outline: "action" + keysym: "F8" + F9: + outline: "action" + keysym: "F9" + F10: + outline: "action" + keysym: "F10" + F11: + outline: "action" + keysym: "F11" + F12: + outline: "action" + keysym: "F12" + Esc: + outline: "action" + keysym: "Escape" + Esc-small: + outline: "term-key" + keysym: "Escape" + label: "Esc" + Tab: + outline: "action" + keysym: "Tab" + Tab-small: + outline: "term-key" + keysym: "Tab" + label: "Tab" + Del: + outline: "action" + keysym: "Delete" + Insert: + outline: "action" + keysym: "Insert" + Menu: + outline: "action" + keysym: "Menu" + Pause: + outline: "action" + keysym: "Pause" + Break: + outline: "action" + keysym: "Break" + Home: + outline: "small-row" + keysym: "Home" + End: + outline: "small-row" + keysym: "End" + PageUp: + outline: "small-row" + keysym: "Page_Up" + label: "Page ↑" + PageDown: + outline: "small-row" + keysym: "Page_Down" + label: "Page ↓" + "↑": + outline: "term-narrow" + keysym: "Up" + "↓": + outline: "term-narrow" + keysym: "Down" + "←": + outline: "term-narrow" + keysym: "Left" + "→": + outline: "term-narrow" + keysym: "Right" + Up: + label: "↑" + outline: "action" + keysym: "Up" + Left: + label: "←" + outline: "action" + keysym: "Left" + Down: + label: "↓" + outline: "action" + keysym: "Down" + Right: + label: "→" + outline: "action" + keysym: "Right" + Ctrl: + modifier: "Control" + outline: "term-key" + label: "Ctrl" + Alt: + modifier: "Alt" + outline: "term-key" + label: "Alt" + Shift: + modifier: "Shift" + outline: "small-row" + label: "Shift" + --thin: + outline: "halfwidth" + text: "-" + /-thin: + outline: "halfwidth" + text: "/" + "|-thin": + outline: "halfwidth" + text: "|" + .-thin: + outline: "halfwidth" + text: "." + "\\": + outline: "halfwidth" + _: + outline: "halfwidth" + "|-small": + outline: "term-narrow" + text: "|" + "~-small": + outline: "term-narrow" + text: "~" + "/-small": + outline: "term-narrow" + text: "/" + # The action row (hypr/phone.lua binds the keysyms) + Mic: + outline: "mic" + keysym: "XF86Dictate" + label: "󰍬 Mic" + Paste: + outline: "paste" + keysym: "XF86Paste" + label: "󰆒 Paste" + Emoji: + outline: "emoji" + keysym: "XF86EmojiPicker" + label: "󰞅 Emoji" + Hide: + outline: "hide" + keysym: "XF86Keyboard" + label: "󰌏 Hide" diff --git a/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml new file mode 100644 index 000000000..438044c59 --- /dev/null +++ b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml @@ -0,0 +1,302 @@ +# SPDX-License-Identifier: GPL-3.0-or-later +# Japanese (romaji), for Japanese input (omamobile-ime): a copy of +# terminal/us_wide.yaml, whose header follows, so its keymap stays within +# the 255 keycodes an input method's keymap can carry (jp.yaml's kana +# views need 709). omamobile-ime turns Mozc on only while this layout is +# the keyboard's language. Listed in squeekboard/generate's HAND_MADE. +# squeekboard 1.43.1's terminal/us_wide.yaml, its landscape terminal layout +# (https://gitlab.gnome.org/World/Phosh/squeekboard, tag v1.43.1, GPL-3.0-or-later), changed for Omarchy Mobile: +# - an action row on top (Mic, Paste, Emoji, Hide). Each sends an XF86 +# keysym that hypr/phone.lua binds, for squeekboard's virtual keyboard only +# (the voice bar through omamobile.voice, Omarchy's clipboard and +# emoji pickers, and omamobile.keyboard's hide). squeekboard has no action +# that runs a command, and a keysym key presses on touch-down and releases +# on lift-off, so Mic is push-to-talk (a tap keeps listening). +# - a terminal row of Esc, Tab, Ctrl, Alt, | ~ / and the arrows (upstream's +# Shift modifier stays on the Shift view's row, with Page Up/Down, Home, End). +# - the globe key sends XF86MediaLanguageMenu, which hypr/phone.lua binds to +# the shell's language sheet (omamobile.keyboard), instead of opening +# squeekboard's own popover. +# Widths: the portrait layout's (terminal/us.yaml) times 618.24 / 404.1, so +# every row sums to 618.24, the letter rows' 10 x 61.824, as in upstream's +# landscape layout; heights 42 (letters), 30 (actions) and 26 (terminal row). +# The outline names are CSS classes +# that omamobile-keyboard-theme styles from the Omarchy theme. +# omamobile-setup-user links it as +# ~/.local/share/squeekboard/keyboards/terminal/us_wide.yaml, the only place +# squeekboard reads layouts from besides its built-in ones. +# Language: Englisch (US) +--- +outlines: + default: { width: 61.824, height: 42 } + action: { width: 103.04, height: 42 } + change-view: { width: 92.736, height: 42 } + change-view-2: { width: 103.04, height: 42 } + halfwidth: { width: 30.912, height: 42 } + large: { width: 92.736, height: 42 } + narrow: { width: 46.367, height: 42 } + small-row: { width: 72.128, height: 26 } + term-key: { width: 64.394, height: 26 } + term-narrow: { width: 51.52, height: 26 } + mic: { width: 185.472, height: 30 } + paste: { width: 185.472, height: 30 } + emoji: { width: 123.648, height: 30 } + hide: { width: 123.648, height: 30 } + spaceline: { width: 226.688, height: 42 } + special: { width: 92.736, height: 42 } + special-2: { width: 92.736, height: 42 } + special-3: { width: 103.04, height: 42 } + +views: + base: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt |-small ~-small /-small ← ↑ ↓ →" + - "q w e r t y u i o p" + - ".-thin a s d f g h j k l --thin" + - "show_upper z x c v b n m BackSpace" + - "show_numbers preferences space show_actions Return" + upper: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt Shift PageUp PageDown Home End" + - "Q W E R T Y U I O P" + - "/-thin A S D F G H J K L |-thin" + - "show_upper Z X C V B N M BackSpace" + - "show_numbers preferences space show_actions Return" + numbers: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt |-small ~-small /-small ← ↑ ↓ →" + - "1 2 3 4 5 6 7 8 9 0" + - "\\ * # $ / & - + ( ) _" + - "show_symbols , \" ' : ; ! ? BackSpace" + - "show_letters preferences space . Return" + symbols: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt |-small ~-small /-small ← ↑ ↓ →" + - "~ ` · √ π τ ÷ × ¶ @" + - "\\ © ® £ € ¥ ^ ° { } _" + - "show_numbers_from_symbols % | < > = [ ] BackSpace" + - "show_letters preferences space . Return" + actions: + - "Mic Paste Emoji Hide" + - "Esc-small Tab-small Ctrl Alt Shift PageUp PageDown Home End" + - "F1 F2 F3 F4 F5 F6" + - "F7 F8 F9 F10 F11 F12" + - "Esc Tab Pause Insert Up Del" + - "show_letters_actions Menu Break Left Down Right" + +buttons: + show_upper: + action: + locking: + lock_view: "upper" + unlock_view: "base" + outline: "change-view" + icon: "key-shift" + BackSpace: + outline: "special-2" + icon: "edit-clear-symbolic" + action: "erase" + preferences: + keysym: "XF86MediaLanguageMenu" + outline: "special" + icon: "keyboard-mode-symbolic" + show_numbers: + action: + set_view: "numbers" + outline: "change-view-2" + label: "123" + show_numbers_from_symbols: + action: + set_view: "numbers" + outline: "change-view" + label: "123" + show_letters: + action: + set_view: "base" + outline: "change-view-2" + label: "ABC" + show_letters_actions: + action: + set_view: "base" + outline: "change-view-2" + label: "ABC" + show_symbols: + action: + set_view: "symbols" + outline: "change-view" + label: "τ=\\" + show_actions: + action: + set_view: "actions" + outline: "change-view" + label: ">_" + .: + outline: "large" + space: + outline: "spaceline" + text: " " + Return: + outline: "special-3" + icon: "key-enter" + keysym: "Return" + F1: + outline: "action" + keysym: "F1" + F2: + outline: "action" + keysym: "F2" + F3: + outline: "action" + keysym: "F3" + F4: + outline: "action" + keysym: "F4" + F5: + outline: "action" + keysym: "F5" + F6: + outline: "action" + keysym: "F6" + F7: + outline: "action" + keysym: "F7" + F8: + outline: "action" + keysym: "F8" + F9: + outline: "action" + keysym: "F9" + F10: + outline: "action" + keysym: "F10" + F11: + outline: "action" + keysym: "F11" + F12: + outline: "action" + keysym: "F12" + Esc: + outline: "action" + keysym: "Escape" + Esc-small: + outline: "term-key" + keysym: "Escape" + label: "Esc" + Tab: + outline: "action" + keysym: "Tab" + Tab-small: + outline: "term-key" + keysym: "Tab" + label: "Tab" + Del: + outline: "action" + keysym: "Delete" + Insert: + outline: "action" + keysym: "Insert" + Menu: + outline: "action" + keysym: "Menu" + Pause: + outline: "action" + keysym: "Pause" + Break: + outline: "action" + keysym: "Break" + Home: + outline: "small-row" + keysym: "Home" + End: + outline: "small-row" + keysym: "End" + PageUp: + outline: "small-row" + keysym: "Page_Up" + label: "Page ↑" + PageDown: + outline: "small-row" + keysym: "Page_Down" + label: "Page ↓" + "↑": + outline: "term-narrow" + keysym: "Up" + "↓": + outline: "term-narrow" + keysym: "Down" + "←": + outline: "term-narrow" + keysym: "Left" + "→": + outline: "term-narrow" + keysym: "Right" + Up: + label: "↑" + outline: "action" + keysym: "Up" + Left: + label: "←" + outline: "action" + keysym: "Left" + Down: + label: "↓" + outline: "action" + keysym: "Down" + Right: + label: "→" + outline: "action" + keysym: "Right" + Ctrl: + modifier: "Control" + outline: "term-key" + label: "Ctrl" + Alt: + modifier: "Alt" + outline: "term-key" + label: "Alt" + Shift: + modifier: "Shift" + outline: "small-row" + label: "Shift" + --thin: + outline: "halfwidth" + text: "-" + /-thin: + outline: "halfwidth" + text: "/" + "|-thin": + outline: "halfwidth" + text: "|" + .-thin: + outline: "halfwidth" + text: "." + "\\": + outline: "halfwidth" + _: + outline: "halfwidth" + "|-small": + outline: "term-narrow" + text: "|" + "~-small": + outline: "term-narrow" + text: "~" + "/-small": + outline: "term-narrow" + text: "/" + # The action row (hypr/phone.lua binds the keysyms) + Mic: + outline: "mic" + keysym: "XF86Dictate" + label: "󰍬 Mic" + Paste: + outline: "paste" + keysym: "XF86Paste" + label: "󰆒 Paste" + Emoji: + outline: "emoji" + keysym: "XF86EmojiPicker" + label: "󰞅 Emoji" + Hide: + outline: "hide" + keysym: "XF86Keyboard" + label: "󰌏 Hide" 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..b2c2560c2 --- /dev/null +++ b/packages/omamobile-shell/systemd/user/omamobile-ime.service @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: MIT +# Japanese input (omamobile-ime on): once fcitx5 holds the input method, +# restart squeekboard so it doesn't keep it, then turn Mozc on or off with +# the keyboard's language. Inert while off. +[Unit] +Description=Omarchy Mobile: Japanese input follows the keyboard's language +ConditionPathExists=%h/.config/omamobile/fcitx5 +After=graphical-session.target omarchy-fcitx5.service +Wants=omarchy-fcitx5.service +PartOf=graphical-session.target + +[Service] +ExecStart=/usr/bin/omamobile-ime session +Restart=on-failure +RestartSec=2 + +[Install] +WantedBy=graphical-session.target diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 85affa2b1..6468571ed 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..9909cf1b2 --- /dev/null +++ b/packages/omamobile-shell/test/ime.sh @@ -0,0 +1,71 @@ +#!/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" +cat > "$t/bin/gsettings" <<'SH' +#!/bin/bash +[[ $1 == get ]] && cat "$IME_SOURCES" +[[ $1 == set ]] && printf '%s\n' "$4" > "$IME_SOURCES" +exit 0 +SH +printf '#!/bin/bash\necho "remote $*" >> "$IME_LOG"\n' > "$t/bin/fcitx5-remote" +chmod +x "$t/bin/gsettings" "$t/bin/fcitx5-remote" +: > "$t/mozc.conf" +printf "[('xkb', 'us'), ('xkb', 'jp')]\n" > "$t/sources" +run() { + HOME=$t/home XDG_CONFIG_HOME=$t/home/.config IME_LOG=$t/log IME_SOURCES=$t/sources OMAMOBILE_SYSTEMCTL=$t/bin/systemctl \ + OMAMOBILE_GSETTINGS=$t/bin/gsettings OMAMOBILE_FCITX5_REMOTE=$t/bin/fcitx5-remote \ + 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" && grep -qx '1=Japanese' "$c/fcitx5/profile" || fail "on writes English and Japanese (Mozc) groups" +grep -qx 'ActiveByDefault=False' "$c/fcitx5/config" || fail "Mozc starts off (the language turns it on)" +grep -qx -- '--user restart omarchy-fcitx5.service' "$t/log" || fail "on restarts fcitx5" +grep -qx -- '--user restart omamobile-ime.service' "$t/log" || fail "on starts the language follower" +[[ $(cat "$t/sources") == "[('xkb', 'us'), ('xkb', 'jp'), ('xkb', 'jp+romaji')]" ]] || fail "on adds Japanese (romaji) last" +[[ $(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 +[[ $(grep -o "jp+romaji" "$t/sources" | wc -l) == 1 ]] || fail "on adds the language once" +[[ $(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 omamobile-ime.service omarchy-fcitx5.service' "$t/log" || fail "off stops the follower and fcitx5" +run bogus 2>/dev/null && fail "unknown commands refused" + +# Mozc only while the keyboard's language (the first source) is Japanese +# (romaji); jp and jp+kana can't reach fcitx5 (too many keycodes). +for case in "us:-g English" "jp+romaji:-g Japanese" "jp:-g English" "jp+kana:-g English" "de:-g English"; do + printf "[('xkb', '%s'), ('xkb', 'jp')]\n" "${case%%:*}" > "$t/sources"; : > "$t/log" + run session + [[ $(cat "$t/log") == "remote ${case#*:}" ]] || fail "the ${case%%:*} keyboard sends fcitx5-remote ${case#*:}" +done + +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, Mozc only with Japanese (romaji), the user's fcitx5 files kept, off stops it" diff --git a/packages/omamobile-shell/test/keyboard-layouts.py b/packages/omamobile-shell/test/keyboard-layouts.py index dfefd737a..ea99eed36 100644 --- a/packages/omamobile-shell/test/keyboard-layouts.py +++ b/packages/omamobile-shell/test/keyboard-layouts.py @@ -50,7 +50,9 @@ def keysym_ok(sym): return xkb is None or xkb.xkb_keysym_from_name(sym.encode(), 0) != 0 -HAND_MADE = {"squeekboard/keyboards/terminal/us.yaml", "squeekboard/keyboards/terminal/us_wide.yaml"} +HAND_MADE = {"squeekboard/keyboards/terminal/us.yaml", "squeekboard/keyboards/terminal/us_wide.yaml", + # Japanese (romaji) for omamobile-ime: copies of the two above + "squeekboard/keyboards/terminal/jp+romaji.yaml", "squeekboard/keyboards/terminal/jp+romaji_wide.yaml"} GENERATED = "# squeekboard/generate (change the generator, not this file)." paths = sorted(glob.glob("squeekboard/keyboards/**/*.yaml", recursive=True)) names = {p[len("squeekboard/keyboards/"):] for p in paths} diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 3c7e99b54..316e280ff 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.131 +0.2.132 From 058aff6d630b03759180dce12c604ea24c60180d Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikegami Date: Sun, 15 Nov 2026 15:02:21 +0900 Subject: [PATCH 2/2] omamobile-shell: omamobile-ime keeps following when fcitx5 doesn't answer From the review of #763. A failed fcitx5-remote (fcitx5 not up yet at a slow login, or restarting) ended `session` under set -e, and each restart of the unit restarted squeekboard, so the keyboard went and came back until systemd gave up. Now a failed apply is logged and retried for up to 10 s at start, later changes are still applied, and squeekboard is restarted once per login session (a marker in $XDG_RUNTIME_DIR, cleared by on and off). Also from the review: the waits can be shortened for tests (the test runs in seconds), Japanese (romaji) is offered in the language sheet only while Japanese input is on, the jp+romaji headers name their language, and a test keeps their bodies the same as the US files'. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KgnCmDwY8r4r1jCa2SVYLN --- packages/omamobile-shell/bin/omamobile-ime | 39 +++++++++++++------ .../bin/omamobile-keyboard-languages | 13 ++++++- .../squeekboard/keyboards/jp+romaji.yaml | 2 +- .../squeekboard/keyboards/jp+romaji_wide.yaml | 2 +- .../keyboards/terminal/jp+romaji.yaml | 2 +- .../keyboards/terminal/jp+romaji_wide.yaml | 2 +- packages/omamobile-shell/test/ime.sh | 32 +++++++++++++-- .../test/keyboard-languages.sh | 12 +++++- 8 files changed, 82 insertions(+), 22 deletions(-) diff --git a/packages/omamobile-shell/bin/omamobile-ime b/packages/omamobile-shell/bin/omamobile-ime index 4b1d18d34..2a66ca483 100755 --- a/packages/omamobile-shell/bin/omamobile-ime +++ b/packages/omamobile-shell/bin/omamobile-ime @@ -31,14 +31,20 @@ SYSTEMCTL=${OMAMOBILE_SYSTEMCTL:-systemctl} MOZC=${OMAMOBILE_MOZC_ADDON:-/usr/share/fcitx5/addon/mozc.conf} GSETTINGS=${OMAMOBILE_GSETTINGS:-gsettings} REMOTE=${OMAMOBILE_FCITX5_REMOTE:-fcitx5-remote} +# How long session waits for squeekboard, and for fcitx5 to answer, in seconds +OSK_WAIT=${OMAMOBILE_IME_OSK_WAIT:-20} +REMOTE_WAIT=${OMAMOBILE_IME_REMOTE_WAIT:-10} +# squeekboard is restarted once per login session (and again after "on") +RESTARTED=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/omamobile-ime-osk-restarted SCHEMA=org.gnome.desktop.input-sources 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). +# OMAMOBILE_IME_OSK_RESTART runs instead, for tests. restart_squeekboard() { - [[ -n ${OMAMOBILE_IME_NO_OSK:-} ]] && return 0 + if [[ -n ${OMAMOBILE_IME_OSK_RESTART:-} ]]; then "$OMAMOBILE_IME_OSK_RESTART"; return; fi 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:-} @@ -85,12 +91,15 @@ EOF } # squeekboard shows the first of the input sources; Mozc for Japanese only. +# A failure (fcitx5 not up yet, or restarting) is logged, not fatal: the +# follower keeps running and applies the next change. language() { "$GSETTINGS" get $SCHEMA sources | grep -o "'xkb', '[^']*'" | head -1 | sed "s/.*, '//; s/'$//"; } apply() { - case $(language) in - jp+romaji) "$REMOTE" -g Japanese ;; - *) "$REMOTE" -g English ;; - esac + local group=English + [[ $(language) == jp+romaji ]] && group=Japanese + "$REMOTE" -g "$group" && return 0 + echo "omamobile-ime: fcitx5 didn't take the $group group" >&2 + return 1 } # Add Japanese (romaji) to the keyboard's languages, last, if it isn't there. @@ -121,23 +130,31 @@ case ${1:-} in write_config add_language mkdir -p "${FLAG%/*}"; : > "$FLAG" + rm -f "$RESTARTED" "$SYSTEMCTL" --user restart omarchy-fcitx5.service "$SYSTEMCTL" --user restart omamobile-ime.service echo "Japanese input on: pick Japanese (romaji) with the globe key; double-tap the home strip for the keyboard" ;; off) - rm -f "$FLAG" + rm -f "$FLAG" "$RESTARTED" "$SYSTEMCTL" --user stop omamobile-ime.service 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 - apply - "$GSETTINGS" monitor $SCHEMA sources | while read -r _; do apply; done + # then squeekboard keeps the input method: wait for it, then restart it, + # once per login session, so a restart of this unit doesn't take the + # keyboard away again. + if [[ ! -e $RESTARTED ]]; then + for _ in $(seq $((OSK_WAIT * 5))); do pgrep -x squeekboard >/dev/null && break; sleep 0.2; done + restart_squeekboard + : > "$RESTARTED" + fi + applied= + for _ in $(seq "$REMOTE_WAIT"); do apply 2>/dev/null && { applied=1; break; }; sleep 1; done + [[ -n $applied ]] || apply || true + "$GSETTINGS" monitor $SCHEMA sources | while read -r _; do apply || true; done ;; *) die "usage: omamobile-ime status|on|off" ;; esac diff --git a/packages/omamobile-shell/bin/omamobile-keyboard-languages b/packages/omamobile-shell/bin/omamobile-keyboard-languages index a8095b9fa..00271f24b 100644 --- a/packages/omamobile-shell/bin/omamobile-keyboard-languages +++ b/packages/omamobile-shell/bin/omamobile-keyboard-languages @@ -23,11 +23,14 @@ the same evdev.xml), "layout+variant" for a variant. Layouts that can be added are the ones the keyboard has: the layouts in /usr/share/omamobile/squeekboard/keyboards/ (squeekboard's own, with our -action row), not yet in the list. squeekboard's Emoji and Terminal overlays +action row), not yet in the list. Japanese (romaji) is offered only while +Japanese input is on (omamobile-ime's switch, ~/.config/omamobile/fcitx5): +without it, it is the US keyboard under a Japanese name. squeekboard's Emoji and Terminal overlays are not sources and can't be chosen from outside squeekboard (docs/VOICE-PLAN.md, "The language sheet"). -OMAMOBILE_XKB_RULES and OMAMOBILE_KEYBOARDS_DIR point elsewhere for tests.""" +OMAMOBILE_XKB_RULES, OMAMOBILE_KEYBOARDS_DIR and XDG_CONFIG_HOME point +elsewhere for tests.""" import ast import glob @@ -43,6 +46,10 @@ RULES = os.environ.get("OMAMOBILE_XKB_RULES", "/usr/share/X11/xkb/rules/evdev.xm KEYBOARDS = os.environ.get("OMAMOBILE_KEYBOARDS_DIR", "/usr/share/omamobile/squeekboard/keyboards") # What squeekboard shows with no sources at all (src/state.rs, Application::new) FALLBACK = "us" +# Layouts only for Japanese input (omamobile-ime), and its switch +IME_ONLY = {"jp+romaji"} +IME_SWITCH = os.path.join(os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config"), + "omamobile", "fcitx5") def gsettings(*args): @@ -106,6 +113,8 @@ def carried(): name = os.path.basename(path)[:-len(".yaml")] if not name.endswith("_wide"): out.add(name) + if not os.path.exists(IME_SWITCH): + out -= IME_ONLY return out diff --git a/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml index ebf898840..bc1701cab 100644 --- a/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml +++ b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji.yaml @@ -13,7 +13,7 @@ # squeekboard/generate (change the generator, not this file). The row # sums to the widest row's 356.57: 2 x 106.971 + 2 x 71.314. # omamobile-setup-user links it into ~/.local/share/squeekboard/keyboards/. -# Language: English (US) +# Language: Japanese (romaji) --- outlines: default: { width: 35.657, height: 52 } diff --git a/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml index 10ddca007..cf3fb7842 100644 --- a/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml +++ b/packages/omamobile-shell/squeekboard/keyboards/jp+romaji_wide.yaml @@ -13,7 +13,7 @@ # squeekboard/generate (change the generator, not this file). The row # sums to the widest row's 537.6: 2 x 161.28 + 2 x 107.52. # omamobile-setup-user links it into ~/.local/share/squeekboard/keyboards/. -# Language: English (US) +# Language: Japanese (romaji) --- outlines: default: { width: 53.76, height: 42 } diff --git a/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml index a085ca077..40be74977 100644 --- a/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml +++ b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji.yaml @@ -24,7 +24,7 @@ # omamobile-setup-user links it as # ~/.local/share/squeekboard/keyboards/terminal/us.yaml, the only place # squeekboard reads layouts from besides its built-in ones. -# Language: Englisch (US) +# Language: Japanese (romaji) --- outlines: default: { width: 40.41, height: 52 } diff --git a/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml index 438044c59..ae7f6db31 100644 --- a/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml +++ b/packages/omamobile-shell/squeekboard/keyboards/terminal/jp+romaji_wide.yaml @@ -25,7 +25,7 @@ # omamobile-setup-user links it as # ~/.local/share/squeekboard/keyboards/terminal/us_wide.yaml, the only place # squeekboard reads layouts from besides its built-in ones. -# Language: Englisch (US) +# Language: Japanese (romaji) --- outlines: default: { width: 61.824, height: 42 } diff --git a/packages/omamobile-shell/test/ime.sh b/packages/omamobile-shell/test/ime.sh index 9909cf1b2..e04d6608c 100755 --- a/packages/omamobile-shell/test/ime.sh +++ b/packages/omamobile-shell/test/ime.sh @@ -17,16 +17,20 @@ cat > "$t/bin/gsettings" <<'SH' #!/bin/bash [[ $1 == get ]] && cat "$IME_SOURCES" [[ $1 == set ]] && printf '%s\n' "$4" > "$IME_SOURCES" +[[ $1 == monitor && -n ${IME_MONITOR:-} ]] && echo "sources: changed" exit 0 SH -printf '#!/bin/bash\necho "remote $*" >> "$IME_LOG"\n' > "$t/bin/fcitx5-remote" -chmod +x "$t/bin/gsettings" "$t/bin/fcitx5-remote" +printf '#!/bin/bash\necho "remote $*" >> "$IME_LOG"\n[[ -z ${IME_REMOTE_FAIL:-} ]]\n' > "$t/bin/fcitx5-remote" +printf '#!/bin/bash\necho restart >> "$IME_OSK"\n' > "$t/bin/osk-restart" +chmod +x "$t/bin/gsettings" "$t/bin/fcitx5-remote" "$t/bin/osk-restart" +mkdir -p "$t/run" : > "$t/mozc.conf" printf "[('xkb', 'us'), ('xkb', 'jp')]\n" > "$t/sources" run() { HOME=$t/home XDG_CONFIG_HOME=$t/home/.config IME_LOG=$t/log IME_SOURCES=$t/sources OMAMOBILE_SYSTEMCTL=$t/bin/systemctl \ OMAMOBILE_GSETTINGS=$t/bin/gsettings OMAMOBILE_FCITX5_REMOTE=$t/bin/fcitx5-remote \ - OMAMOBILE_MOZC_ADDON=${MOZC:-$t/mozc.conf} OMAMOBILE_IME_NO_OSK=1 bin/omamobile-ime "$@" + OMAMOBILE_MOZC_ADDON=${MOZC:-$t/mozc.conf} OMAMOBILE_IME_OSK_RESTART=$t/bin/osk-restart IME_OSK=$t/osk \ + XDG_RUNTIME_DIR=$t/run OMAMOBILE_IME_OSK_WAIT=0 OMAMOBILE_IME_REMOTE_WAIT=${REMOTE_WAIT:-0} bin/omamobile-ime "$@" } c=$t/home/.config @@ -63,6 +67,28 @@ for case in "us:-g English" "jp+romaji:-g Japanese" "jp:-g English" "jp+kana:-g [[ $(cat "$t/log") == "remote ${case#*:}" ]] || fail "the ${case%%:*} keyboard sends fcitx5-remote ${case#*:}" done +# squeekboard is restarted once per login session, and again after "on". +: > "$t/osk"; rm -f "$t/run/omamobile-ime-osk-restarted" +run session; run session +[[ $(wc -l < "$t/osk") == 1 ]] || fail "session restarts squeekboard once per login session" +run on >/dev/null; run session +[[ $(wc -l < "$t/osk") == 2 ]] || fail "on lets the next session restart squeekboard" + +# fcitx5 not answering (a slow login, a restart) doesn't stop the follower: +# it retries, logs, and still applies the next change of language. +: > "$t/log" +REMOTE_WAIT=2 IME_REMOTE_FAIL=1 IME_MONITOR=1 run session 2>/dev/null || fail "a failing fcitx5-remote stops the follower" +[[ $(grep -c '^remote ' "$t/log") == 4 ]] || fail "the follower retries, then applies the next change ($(grep -c '^remote ' "$t/log") calls)" +REMOTE_WAIT=2 IME_REMOTE_FAIL=1 run session 2>&1 >/dev/null | grep -c "didn't take" >/dev/null || fail "a failed apply is logged" + +# The Japanese (romaji) layouts are the US ones under another name: their +# bodies must stay the same as the US files'. +for f in jp+romaji jp+romaji_wide terminal/jp+romaji terminal/jp+romaji_wide; do + cmp -s <(sed '1,/^---/d' "squeekboard/keyboards/$f.yaml") <(sed '1,/^---/d' "squeekboard/keyboards/${f/jp+romaji/us}.yaml") || + fail "squeekboard/keyboards/$f.yaml differs from ${f/jp+romaji/us}.yaml: copy it again" + grep -qx '# Language: Japanese (romaji)' "squeekboard/keyboards/$f.yaml" || fail "$f.yaml names its language" +done + 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" diff --git a/packages/omamobile-shell/test/keyboard-languages.sh b/packages/omamobile-shell/test/keyboard-languages.sh index 20dbaa441..cdb303ddd 100644 --- a/packages/omamobile-shell/test/keyboard-languages.sh +++ b/packages/omamobile-shell/test/keyboard-languages.sh @@ -33,9 +33,9 @@ cat >"$t/evdev.xml" <<'XML' XML -for f in us us_wide de de_wide fr fr_wide us+colemak us+colemak_wide; do : >"$t/keyboards/$f.yaml"; done +for f in us us_wide de de_wide fr fr_wide us+colemak us+colemak_wide jp+romaji jp+romaji_wide; do : >"$t/keyboards/$f.yaml"; done langs() { env T="$t" PATH="$t/fakes:$PATH" OMAMOBILE_XKB_RULES="$t/evdev.xml" OMAMOBILE_KEYBOARDS_DIR="$t/keyboards" \ - python3 -B bin/omamobile-keyboard-languages "$@"; } + XDG_CONFIG_HOME="$t/config" python3 -B bin/omamobile-keyboard-languages "$@"; } sources() { cat "$t/sources"; } echo "[('xkb', 'us'), ('xkb', 'de')]" >"$t/sources" @@ -49,6 +49,14 @@ assert [(r["name"], r["label"]) for r in d["available"]] == [("us+colemak", "Eng ' || fail "list: squeekboard's names, sorted, the current one, the layouts to add" pass "the list names each language as squeekboard does" +mkdir -p "$t/config/omamobile"; : >"$t/config/omamobile/fcitx5" +langs list | python3 -c ' +import json, sys +assert "jp+romaji" in [r["name"] for r in json.load(sys.stdin)["available"]] +' || fail "Japanese (romaji) is offered while Japanese input is on" +rm "$t/config/omamobile/fcitx5" +pass "Japanese (romaji) is offered only while Japanese input is on" + langs set de [[ $(sources) == "[('xkb', 'de'), ('xkb', 'us')]" ]] || fail "set moves the layout to the front: $(sources)" langs set fr