Screenshare: preselect the shared window's audio

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-18 20:06:49 +01:00
parent 4afc78ee8f
commit 7b239c3972
3 changed files with 155 additions and 11 deletions

View file

@ -126,7 +126,8 @@ in
# After answering, it grim-shots the selection to xdph-preview.jpg for
# Vesktop's dialog (~70ms vs Electron's ~1s PipeWire thumbnail). grim
# reads the screen, so a window that isn't visible is skipped and Vesktop
# falls back to the thumbnail.
# falls back to the thumbnail. A shared window's pid goes to
# xdph-selection-pid so Vesktop can preselect that process's audio.
xdg.configFile."hypr/xdph.conf".text = ''
screencopy {
allow_token_by_default = true
@ -138,8 +139,9 @@ in
run=''${XDG_RUNTIME_DIR:-/tmp}
flag=$run/xdph-pick-manually
preview=$run/xdph-preview.jpg
selpid=$run/xdph-selection-pid
list=''${XDPH_WINDOW_SHARING_LIST-}
rm -f "$preview"
rm -f "$preview" "$selpid"
printf -v now '%(%s)T' -1
{ forced=$(< "$flag"); } 2>/dev/null || forced=0 # no trailing newline, so not `read`
@ -175,16 +177,19 @@ in
local target=''${1#*/} where=()
case $target in
window:*)
local id=''${target#window:} addr geom
local id=''${target#window:} addr pid geom
if (( id < 0 )); then id=$(( id + 4294967296 )); fi # the Qt picker prints it signed
addr=$(entries "$id" '$1 == want { print $4 }')
[ -n "$addr" ] || return 0
geom=$(hyprctl -j clients | jq -r --arg a "$(printf '0x%x' "$addr")" \
# pid always; geometry only if the window is actually on screen
IFS=$'\t' read -r pid geom <<< "$(hyprctl -j clients | jq -r --arg a "$(printf '0x%x' "$addr")" \
--argjson mons "$(hyprctl -j monitors)" '
[$mons[] | .activeWorkspace.id, .specialWorkspace.id] as $shown
| .[] | select(.address == $a and (.hidden | not))
| select(.workspace.id as $w | any($shown[]; . == $w))
| "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')
| .[] | select(.address == $a)
| [.pid, if (.hidden | not) and (.workspace.id as $w | any($shown[]; . == $w))
then "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])" else "" end]
| @tsv')"
if [ -n "$pid" ]; then printf '%s' "$pid" > "$selpid"; fi
[ -n "$geom" ] || return 0
where=(-g "$geom")
;;