diff --git a/.config/sway/config b/.config/sway/config index 3769ae0..0459e17 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -195,8 +195,6 @@ input "1267:12734:ELAN06FA:00_04F3:31BE_Touchpad" { # If there are multiple scratchpad windows, this command cycles through them. bindsym $mod+minus scratchpad show - # Dedicated scratchpad terminal for voice queries to pi. - for_window [app_id="pi-voice"] border pixel 2, move scratchpad # # Resizing containers: # @@ -243,15 +241,6 @@ bindsym $mod+r mode "resize" bindcode 66 exec sh -c 'voxtype record start; pkill -USR1 -f "$HOME/.config/sway/status.sh"' bindcode --release 66 exec sh -c 'voxtype record stop; pkill -USR1 -f "$HOME/.config/sway/status.sh"' - # Voice query to pi in a dedicated tmux session/scratchpad terminal. - # Hold $mod+Shift+x, speak, release; transcription is submitted to pi. - bindsym $mod+Shift+x exec ~/bin/pi-voice-query start - bindsym --release $mod+Shift+x exec ~/bin/pi-voice-query stop - - - # Pick an entry from clipboard history and copy it back to the clipboard - bindsym $mod+c exec sh -c 'cliphist list | wmenu -l 10 | cliphist decode | wl-copy' - # # Status Bar: # diff --git a/bin/pi-voice-query b/bin/pi-voice-query deleted file mode 100755 index f8fd436..0000000 --- a/bin/pi-voice-query +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/sh -set -eu - -SESSION="pi-voice" -APP_ID="pi-voice" -TITLE="Pi Voice" -OUT="${XDG_RUNTIME_DIR:-/tmp}/pi-voice-query.txt" -STATUS_SCRIPT="$HOME/.config/sway/status.sh" - -refresh_bar() { - pkill -USR1 -f "$STATUS_SCRIPT" 2>/dev/null || true -} - -position_pi_window() { - # Size scratchpad window to 60% of the focused output using absolute pixels. - # Doing this here is more reliable than a for_window percentage resize. - set -- $(swaymsg -t get_outputs 2>/dev/null | python3 -c ' -import json, sys -outs = json.load(sys.stdin) -out = next((o for o in outs if o.get("focused")), None) or next((o for o in outs if o.get("active")), None) -rect = (out or {}).get("rect", {}) -w = int(rect.get("width", 1200) * 0.6) -h = int(rect.get("height", 800) * 0.6) -print(w, h) -') - w=${1:-1200} - h=${2:-800} - swaymsg '[app_id="'"$APP_ID"'"] border pixel 2, resize set width '"$w"' px height '"$h"' px, move position center' >/dev/null 2>&1 || true -} - -ensure_pi_terminal() { - if ! tmux has-session -t "$SESSION" 2>/dev/null; then - tmux new-session -d -s "$SESSION" 'pi' - fi - - if command -v swaymsg >/dev/null 2>&1; then - if ! swaymsg -t get_tree 2>/dev/null | grep -q '"app_id": "'"$APP_ID"'"'; then - foot --app-id="$APP_ID" --title="$TITLE" \ - --override=main.resize-by-cells=no \ - --override=colors.alpha=1.0 \ - --override=main.pad=0x0 \ - tmux attach-session -t "$SESSION" >/dev/null 2>&1 & - # Give the window a moment to appear before trying to show/focus it. - sleep 0.5 - fi - swaymsg '[app_id="'"$APP_ID"'"] scratchpad show, focus' >/dev/null 2>&1 || true - position_pi_window - fi -} - -send_to_pi() { - text=$1 - [ -n "$text" ] || exit 0 - - ensure_pi_terminal - - # Paste literally, then press Enter to submit to pi. - printf '%s' "$text" | tmux load-buffer - - tmux paste-buffer -t "$SESSION" - tmux send-keys -t "$SESSION" Enter -} - -case "${1:-}" in - start) - ensure_pi_terminal - : > "$OUT" - voxtype record start --file="$OUT" - refresh_bar - ;; - stop) - voxtype record stop - refresh_bar - - # Wait for transcription to land in OUT. Stop early once voxtype is idle - # and the file has text, otherwise allow slower large-model runs. - i=0 - while [ "$i" -lt 180 ]; do - if [ -s "$OUT" ]; then - break - fi - state=$(voxtype status 2>/dev/null || true) - [ "$state" = idle ] && [ "$i" -gt 2 ] && break - sleep 0.5 - i=$((i + 1)) - done - refresh_bar - - text=$(cat "$OUT" 2>/dev/null || true) - send_to_pi "$text" - ;; - *) - echo "usage: $0 start|stop" >&2 - exit 2 - ;; -esac