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 @@ -66,7 +66,7 @@ sleep 0.15
if [[ $use_universal == "true" ]]; then
hyprctl dispatch 'o.universal_paste' >/dev/null 2>&1 || true
elif [[ $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
48 changes: 48 additions & 0 deletions bin/omarchy-voxtype-output
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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.

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

# The marker holds the id systemd gave this run of the daemon. One left behind
# by a Voxtype that stopped between the two hooks must not arm a paste for the
# next run, whose first recording may be cancelled.
daemon_run() {
systemctl --user show voxtype.service --property=InvocationID --value 2>/dev/null
}

case "${1:-}" in
begin)
if [[ $(voxtype config get output.mode) == "clipboard" ]]; then
daemon_run >"$marker"
else
rm -f "$marker"
fi
;;
end)
if [[ -e $marker ]]; then
armed_run=$(<"$marker")
rm -f "$marker"

if [[ $armed_run == "$(daemon_run)" ]]; 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 @@ -189,9 +189,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 @@ -210,7 +210,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 @@ -378,36 +378,38 @@ capture_output=$(WL_PASTE_TYPES="text/plain\nx-kde-passwordManagerHint\n" XDG_RU
[[ -z $capture_output ]] || fail "clipboard capture ignores password manager hint"
pass "clipboard capture ignores password manager hint"

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
27 changes: 27 additions & 0 deletions test/shell.d/dictation-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,30 @@ printf '%s\n' voxtype > "$config"
omarchy-remove-dictation-hex
[[ $(cat "$config") == "voxtype" ]] || fail "removing Hex preserves another selected backend"
pass "Hex installer selects Hex only after setup succeeds, and removal clears only its own selection"

cat > "$test_tmp/bin/voxtype" <<'SH'
#!/bin/bash
[[ $* == "config get output.mode" ]] && echo "$VOXTYPE_MODE"
SH
cat > "$test_tmp/bin/systemctl" <<'SH'
#!/bin/bash
[[ $* == "--user show voxtype.service --property=InvocationID --value" ]] && echo "$VOXTYPE_RUN"
SH
chmod +x "$test_tmp/bin/voxtype" "$test_tmp/bin/systemctl"
export XDG_RUNTIME_DIR="$test_tmp/run" VOXTYPE_RUN=first
mkdir -p "$XDG_RUNTIME_DIR"
: > "$DICTATION_LOG"
VOXTYPE_MODE=clipboard omarchy-voxtype-output end
[[ ! -s $DICTATION_LOG ]] || fail "a cancelled recording must not paste the clipboard"
VOXTYPE_MODE=type omarchy-voxtype-output begin
omarchy-voxtype-output end
[[ ! -s $DICTATION_LOG ]] || fail "type mode must not paste over the typed transcript"
VOXTYPE_MODE=clipboard omarchy-voxtype-output begin
VOXTYPE_RUN=second omarchy-voxtype-output end
[[ ! -s $DICTATION_LOG ]] || fail "a recording cancelled after Voxtype restarts must not paste the clipboard"
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"
10 changes: 5 additions & 5 deletions test/shell.d/emojis-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ cat >"$WL_COPY_OUT.tmp"
mv "$WL_COPY_OUT.tmp" "$WL_COPY_OUT"
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'
Expand All @@ -75,9 +75,9 @@ for (( i = 0; i < 500; i++ )); do
done
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/emoji" WTYPE_OUT="$TMPDIR/wtype" PATH="$TMPDIR/bin:$PATH" \
WL_COPY_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 @@ -93,5 +93,5 @@ pass "emoji insert helper keeps the emoji out of clipboard history"
[[ $copy_args == *" --foreground "* ]] || fail "emoji insert helper serves the clipboard from a process it can stop"
pass "emoji insert helper serves the clipboard from a process it can stop"

[[ $(<"$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"