Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/omarchy-clipboard-paste-file
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ if [[ $copy_only == "true" ]]; then
fi

sleep 0.15
wtype -M shift -k Insert -m shift 2>/dev/null || true
omarchy-hyprland-send-shortcut SHIFT Insert 2>/dev/null || true
2 changes: 1 addition & 1 deletion bin/omarchy-clipboard-paste-text
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fi
sleep 0.15

if [[ $use_shift_insert == "true" ]]; then
wtype -M shift -k Insert -m shift 2>/dev/null || true
omarchy-hyprland-send-shortcut SHIFT Insert 2>/dev/null || true
else
wtype "$text" 2>/dev/null || true
fi
29 changes: 29 additions & 0 deletions bin/omarchy-hyprland-send-shortcut
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# omarchy:summary=Send a keyboard shortcut to the focused surface through Hyprland
# omarchy:args=<mods> <key>
# omarchy:examples=omarchy-hyprland-send-shortcut SHIFT Insert
# omarchy:hidden=true

# Hyprland presses the keys on the seat's own keymap, so XWayland apps receive
# them as sent. wtype types through a keymap it uploads for each run, which
# XWayland clients never load: they read its keys as Escape, digits and
# letters, so wtype's Shift+Insert arrives as Shift+Escape. Omitting the window
# target also reaches focused layer-shell surfaces, and the down/up split works
# around Hyprland leaving synthetic keys stuck, as default/hypr/bindings/clipboard.lua does.

mods=${1:-}
key=${2:-}

if [[ ! $mods =~ ^[A-Z_\ ]*$ || ! $key =~ ^[A-Za-z0-9_]+$ ]]; then
echo "Usage: omarchy-hyprland-send-shortcut <mods> <key>" >&2
exit 1
fi

send_key_state() {
hyprctl dispatch "hl.dsp.send_key_state({ mods = \"$mods\", key = \"$key\", state = \"$1\" })" >/dev/null
}

send_key_state down
sleep 0.05
send_key_state up
2 changes: 1 addition & 1 deletion bin/omarchy-menu-emoji-insert
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ printf '%s' "$emoji" | wl-copy --type text/plain --sensitive --foreground &
copy_pid=$!

sleep 0.15
wtype -M shift -k Insert -m shift 2>/dev/null || true
omarchy-hyprland-send-shortcut SHIFT Insert 2>/dev/null || true
sleep 0.2

kill "$copy_pid" 2>/dev/null || true
57 changes: 57 additions & 0 deletions bin/omarchy-voxtype-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# omarchy:summary=Paste Voxtype dictation through Hyprland
# omarchy:args=<begin|end>
# omarchy:hidden=true

# Voxtype runs `begin` as its pre_output_command and `end` as its
# post_output_command. In clipboard mode it only copies the transcript, and
# `end` pastes it with Shift+Insert from Hyprland, which XWayland apps receive
# intact where wtype's typing arrives as Escape and digits. Voxtype also runs
# post_output_command after cancelled and empty recordings, so `end` pastes
# only after a `begin`. Type and paste modes deliver the text themselves, so
# `begin` arms nothing there.

runtime_dir="${XDG_RUNTIME_DIR:-/tmp}"
marker="$runtime_dir/omarchy-voxtype-output"

daemon_identity() {
local pid process_stat
local stat_fields=()

# Voxtype writes this before running hooks, including for manual launches.
# Hook shell PIDs change on each call; the daemon's PID and start time do not.
[[ -r $runtime_dir/voxtype/pid ]] || return 1
pid=$(<"$runtime_dir/voxtype/pid") || return 1
[[ $pid =~ ^[1-9][0-9]*$ && -r /proc/$pid/stat ]] || return 1
process_stat=$(</proc/"$pid"/stat) || return 1
read -r -a stat_fields <<<"${process_stat##*) }"
[[ ${stat_fields[0]} != "Z" && ${stat_fields[19]:-} =~ ^[0-9]+$ ]] || return 1
printf '%s:%s\n' "$pid" "${stat_fields[19]}"
}

case "${1:-}" in
begin)
if [[ $(voxtype config get output.mode) == "clipboard" ]] && identity=$(daemon_identity); then
printf '%s\n' "$identity" > "$marker"
else
rm -f "$marker"
fi
;;
end)
if [[ -f $marker ]]; then
pending=$(<"$marker")
rm -f "$marker"
# A marker left by a dead daemon must not paste on the next cancellation.
if identity=$(daemon_identity) && [[ $pending == "$identity" ]]; then
# Voxtype's own paste mode gives the clipboard as long to settle.
sleep 0.1
omarchy-hyprland-send-shortcut SHIFT Insert
fi
fi
;;
*)
echo "Usage: omarchy-voxtype-output <begin|end>" >&2
exit 1
;;
esac
17 changes: 13 additions & 4 deletions default/voxtype/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ translate = false
# threads = 4

[output]
# Primary output mode: "type" or "clipboard"
# - type: Simulates keyboard input at cursor position (requires ydotool)
# - clipboard: Copies text to clipboard (requires wl-copy)
mode = "type"
# Primary output mode: "clipboard", "type" or "paste"
# - clipboard: Copies text to the clipboard (requires wl-copy). The hooks below
# then paste it with Shift+Insert sent by Hyprland.
# - type: Simulates keyboard input at the cursor through wtype. XWayland apps,
# such as the ChatGPT and Hermes desktop apps, receive wtype's keys as Escape
# and digits instead of the transcript.
# - paste: Copies text and sends paste_keys through wtype, which XWayland apps
# receive as Escape.
mode = "clipboard"

# Paste the transcript after clipboard mode copies it; see omarchy-voxtype-output
pre_output_command = "omarchy-voxtype-output begin"
post_output_command = "omarchy-voxtype-output end"

# Fall back to clipboard if typing fails
fallback_to_clipboard = true
Expand Down
24 changes: 13 additions & 11 deletions test/shell.d/clipboard-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ elif [[ $1 == "--type" && $2 == "text" ]]; then
fi
SH

cat >"$TMPDIR/bin/wtype" <<'SH'
cat >"$TMPDIR/bin/hyprctl" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >"$WTYPE_OUT"
printf '%s\n' "$*" >>"$HYPRCTL_OUT"
SH

cat >"$TMPDIR/bin/omarchy-launch-browser" <<'SH'
Expand All @@ -301,7 +301,7 @@ cat >"$TMPDIR/bin/omasnap" <<'SH'
printf '%s\n' "$*" >"$OMASNAP_OUT"
SH

chmod +x "$TMPDIR/bin/wl-copy" "$TMPDIR/bin/wl-paste" "$TMPDIR/bin/wtype" "$TMPDIR/bin/omarchy-launch-browser" "$TMPDIR/bin/omarchy-launch-editor" "$TMPDIR/bin/omasnap"
chmod +x "$TMPDIR/bin/wl-copy" "$TMPDIR/bin/wl-paste" "$TMPDIR/bin/hyprctl" "$TMPDIR/bin/omarchy-launch-browser" "$TMPDIR/bin/omarchy-launch-editor" "$TMPDIR/bin/omasnap"

capture_output=$(XDG_RUNTIME_DIR="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh")
[[ $capture_output == '{"type":"text","text":"terminal copy"}' ]] || fail "clipboard capture records normal text events"
Expand Down Expand Up @@ -530,36 +530,38 @@ kill "$owner_pid" 2>/dev/null || true
process_gone "$watch_pid" || fail "clipboard watcher dies with its owner via pdeathsig"
pass "clipboard watcher dies with its owner via pdeathsig"

shift_insert_through_hyprland=$'dispatch hl.dsp.send_key_state({ mods = "SHIFT", key = "Insert", state = "down" })\ndispatch hl.dsp.send_key_state({ mods = "SHIFT", key = "Insert", state = "up" })'

jq -n --arg text "$(printf 'large block line 1\nlarge block line 2\n')" '[{type:"text", text:"ignored"}, {type:"text", text:$text}]' >"$TMPDIR/home/.local/state/omarchy/clipboard-history.json"

WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HOME="$TMPDIR/home" PATH="$TMPDIR/bin:$PATH" \
WL_COPY_OUT="$TMPDIR/copied" HYPRCTL_OUT="$TMPDIR/hyprctl" HOME="$TMPDIR/home" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-text" --shift-insert --history-index 1

[[ $(<"$TMPDIR/copied") == "$(printf 'large block line 1\nlarge block line 2')" ]] || fail "clipboard paste helper copies history entry text"
pass "clipboard paste helper copies history entry text"

[[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "clipboard paste helper pastes history entries with shift insert"
[[ $(<"$TMPDIR/hyprctl") == "$shift_insert_through_hyprland" ]] || fail "clipboard paste helper pastes history entries with shift insert"
pass "clipboard paste helper pastes history entries with shift insert"

rm -f "$TMPDIR/wtype"
WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" HOME="$TMPDIR/home" PATH="$TMPDIR/bin:$PATH" \
rm -f "$TMPDIR/hyprctl"
WL_COPY_OUT="$TMPDIR/copied" HYPRCTL_OUT="$TMPDIR/hyprctl" HOME="$TMPDIR/home" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-text" --copy-only --history-index 1

[[ $(<"$TMPDIR/copied") == "$(printf 'large block line 1\nlarge block line 2')" ]] || fail "clipboard paste helper copy-only copies history entry text"
pass "clipboard paste helper copy-only copies history entry text"

[[ ! -e "$TMPDIR/wtype" ]] || fail "clipboard paste helper copy-only skips typing"
[[ ! -e "$TMPDIR/hyprctl" ]] || fail "clipboard paste helper copy-only skips typing"
pass "clipboard paste helper copy-only skips typing"

printf 'image-data' >"$TMPDIR/image.png"
rm -f "$TMPDIR/wtype"
WL_COPY_OUT="$TMPDIR/copied" WTYPE_OUT="$TMPDIR/wtype" PATH="$TMPDIR/bin:$PATH" \
rm -f "$TMPDIR/hyprctl"
WL_COPY_OUT="$TMPDIR/copied" HYPRCTL_OUT="$TMPDIR/hyprctl" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
"$ROOT/bin/omarchy-clipboard-paste-file" --copy-only image/png "$TMPDIR/image.png"

[[ $(<"$TMPDIR/copied") == "image-data" ]] || fail "clipboard file paste helper copy-only copies file content"
pass "clipboard file paste helper copy-only copies file content"

[[ ! -e "$TMPDIR/wtype" ]] || fail "clipboard file paste helper copy-only skips paste keystroke"
[[ ! -e "$TMPDIR/hyprctl" ]] || fail "clipboard file paste helper copy-only skips paste keystroke"
pass "clipboard file paste helper copy-only skips paste keystroke"

jq -n --arg url 'https://example.com/docs' --arg text "$(printf 'plain text\nsecond line')" --arg image "$TMPDIR/image.png" \
Expand Down
54 changes: 54 additions & 0 deletions test/shell.d/dictation-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,57 @@ printf '%s\n' voxtype > "$config"
omarchy-remove-dictation-superwhisper
[[ $(cat "$config") == "voxtype" ]] || fail "removing Superwhisper preserves another selected backend"
pass "Superwhisper removal clears its selection and owned links while preserving user data and other backends"

cat > "$test_tmp/bin/voxtype" <<'SH'
#!/bin/bash
[[ $* == "config get output.mode" ]] && echo "$VOXTYPE_MODE"
SH
chmod +x "$test_tmp/bin/voxtype"
export XDG_RUNTIME_DIR="$test_tmp/run"
mkdir -p "$XDG_RUNTIME_DIR/voxtype"
printf '%s\n' "$$" > "$XDG_RUNTIME_DIR/voxtype/pid"
: > "$DICTATION_LOG"
VOXTYPE_MODE=clipboard omarchy-voxtype-output end
[[ ! -s $DICTATION_LOG ]] || fail "a cancelled recording must not paste the clipboard"
for mode in type paste; do
VOXTYPE_MODE=$mode omarchy-voxtype-output begin
omarchy-voxtype-output end
[[ ! -s $DICTATION_LOG ]] || fail "$mode mode must not paste over its own output"
done
VOXTYPE_MODE=clipboard omarchy-voxtype-output begin
omarchy-voxtype-output end
omarchy-voxtype-output end
expected=$'hyprctl dispatch hl.dsp.send_key_state({ mods = "SHIFT", key = "Insert", state = "down" })\nhyprctl dispatch hl.dsp.send_key_state({ mods = "SHIFT", key = "Insert", state = "up" })'
[[ $(cat "$DICTATION_LOG") == "$expected" ]] || fail "clipboard mode pastes each transcript once through Hyprland"
pass "Voxtype output hooks paste clipboard transcripts once and nothing else"

# Voxtype writes its PID before launching hooks through sh -c. Separate
# subshells model a daemon dying after begin and its replacement cancelling.
daemon_hook() {
printf '%s\n' "$BASHPID" > "$XDG_RUNTIME_DIR/voxtype/pid"
VOXTYPE_MODE=clipboard /bin/sh -c 'omarchy-voxtype-output "$1"' sh "$1"
}

: > "$DICTATION_LOG"
(daemon_hook begin)
(daemon_hook end)
[[ ! -s $DICTATION_LOG ]] || fail "cancellation after a daemon restart must not paste stale text"
[[ ! -e $XDG_RUNTIME_DIR/omarchy-voxtype-output ]] || fail "a stale output marker must be removed"
pass "Voxtype cancellation after a daemon restart discards pending output"

(daemon_hook begin; daemon_hook end)
[[ $(cat "$DICTATION_LOG") == "$expected" ]] || fail "a restarted daemon must still paste its own transcript"
pass "a restarted Voxtype daemon can paste a new transcript"

: > "$DICTATION_LOG"
: > "$XDG_RUNTIME_DIR/omarchy-voxtype-output"
daemon_hook end
[[ ! -s $DICTATION_LOG ]] || fail "an old unqualified marker must not authorize a paste"
pass "Voxtype ignores output markers from before the lifetime guard"

VOXTYPE_MODE=clipboard omarchy-voxtype-output begin
rm -f "$XDG_RUNTIME_DIR/voxtype/pid"
omarchy-voxtype-output end
[[ ! -s $DICTATION_LOG ]] || fail "missing daemon identity must not authorize a paste"
[[ ! -e $XDG_RUNTIME_DIR/omarchy-voxtype-output ]] || fail "unverifiable output must be discarded"
pass "Voxtype discards pending output when the daemon identity is unavailable"
10 changes: 5 additions & 5 deletions test/shell.d/emojis-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ printf '%s\n' "$args" >"$target.args"
cat >"$target"
SH

cat >"$TMPDIR/bin/wtype" <<'SH'
cat >"$TMPDIR/bin/hyprctl" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >"$WTYPE_OUT"
printf '%s\n' "$*" >>"$HYPRCTL_OUT"
SH

cat >"$TMPDIR/bin/sleep" <<'SH'
#!/bin/bash
exit 0
SH

chmod +x "$TMPDIR/bin/wl-copy" "$TMPDIR/bin/wtype" "$TMPDIR/bin/sleep"
chmod +x "$TMPDIR/bin/wl-copy" "$TMPDIR/bin/hyprctl" "$TMPDIR/bin/sleep"

WL_COPY_OUT="$TMPDIR/copy" WL_COPY_EMOJI_OUT="$TMPDIR/emoji" WTYPE_OUT="$TMPDIR/wtype" PATH="$TMPDIR/bin:$PATH" \
WL_COPY_OUT="$TMPDIR/copy" WL_COPY_EMOJI_OUT="$TMPDIR/emoji" HYPRCTL_OUT="$TMPDIR/hyprctl" PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
"$ROOT/bin/omarchy-menu-emoji-insert" "😀"

[[ $(<"$TMPDIR/emoji") == "😀" ]] || fail "emoji insert helper copies emoji transiently"
Expand All @@ -84,5 +84,5 @@ pass "emoji insert helper copies emoji transiently"
[[ $(<"$TMPDIR/emoji.args") == "--type text/plain --sensitive --foreground" ]] || fail "emoji insert helper serves sensitive transient clipboard in foreground"
pass "emoji insert helper serves transient clipboard in foreground"

[[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "emoji insert helper pastes with shift insert"
[[ $(<"$TMPDIR/hyprctl") == $'dispatch hl.dsp.send_key_state({ mods = "SHIFT", key = "Insert", state = "down" })\ndispatch hl.dsp.send_key_state({ mods = "SHIFT", key = "Insert", state = "up" })' ]] || fail "emoji insert helper pastes with shift insert"
pass "emoji insert helper pastes with shift insert"