workaround for Audacity stealing focus on AddLabel

This commit is contained in:
Sebastian Kiesel 2023-08-13 17:07:32 +02:00
parent 4f2763c5e4
commit d59643353c

View File

@ -112,10 +112,18 @@ trap 'kill "${RECEIVE_FROM_AUDACITY_PID}"' EXIT
##### #####
# LABEL is assumed to be a global variable holding an integer value # LABEL is assumed to be a global variable holding an integer value
set_label_text_audacity () { add_label_with_text_to_audacity () {
local L="${LABEL:-"0"}" local L="${LABEL:-"0"}"
local T="$(printf "%04d" ${LABEL:-"0"})" local T="$(printf "%04d" ${LABEL:-"0"})"
# first observed with audacity 3.2.4 on Debian bookworm
# audacity steals the input focus when labels are added / changed
FOCUSEDWINID=$(xdotool getwindowfocus)
send_to_audacity 'AddLabel'
send_to_audacity "SetLabel: Label=${L} Selected=0 Text=\"${T}\"" send_to_audacity "SetLabel: Label=${L} Selected=0 Text=\"${T}\""
sleep 0.3
echo "Trying to get the focus back to ${FOCUSEDWINID}"
xdotool windowfocus "${FOCUSEDWINID}"
} }
############################################################################ ############################################################################
@ -181,8 +189,7 @@ while true ; do
CLIPS[0]=0 CLIPS[0]=0
send_to_audacity 'NewMonoTrack' send_to_audacity 'NewMonoTrack'
send_to_audacity 'NewLabelTrack' send_to_audacity 'NewLabelTrack'
send_to_audacity 'AddLabel' add_label_with_text_to_audacity
set_label_text_audacity
send_to_audacity 'SelAllTracks' send_to_audacity 'SelAllTracks'
;; ;;
@ -233,10 +240,9 @@ while true ; do
else else
echo "Adding label at end while paused" echo "Adding label at end while paused"
send_to_audacity 'CursTrackEnd' send_to_audacity 'CursTrackEnd'
send_to_audacity 'AddLabel'
LABEL=$(( ${LABEL} + 1 )) LABEL=$(( ${LABEL} + 1 ))
CLIPS[$LABEL]=0 CLIPS[$LABEL]=0
set_label_text_audacity add_label_with_text_to_audacity
send_to_geeqie 'next' send_to_geeqie 'next'
fi fi
;; ;;
@ -277,8 +283,7 @@ while true ; do
send_to_audacity 'SelPrevClipBoundaryToCursor' send_to_audacity 'SelPrevClipBoundaryToCursor'
send_to_audacity 'Delete' send_to_audacity 'Delete'
echo "Re-install deleted label" echo "Re-install deleted label"
send_to_audacity 'AddLabel' add_label_with_text_to_audacity
set_label_text_audacity
CLIPS[$LABEL]=0 CLIPS[$LABEL]=0
;; ;;
*) *)