qb: Fix window focusing

This commit is contained in:
gardouille 2024-09-18 11:37:37 +02:00
parent c479300999
commit cc67a57ee5
Signed by: gardouille
GPG Key ID: E759BAA22501AF32

11
qb
View File

@ -129,8 +129,8 @@ No existing instance of Qutebrowser. Starting…" >> /tmp/qb.log
focus_to_qutebrowser() { # {{{
## Get desktop and window ID of the first "qutebrowser" window
qutebrowser_desktop_id=$(command wmctrl -l | grep --max-count=1 -E -- "${QUTEBROWSER_WINDOW_TITLE}" | cut -d" " -f3)
qutebrowser_window_id=$(command wmctrl -l | grep --max-count=1 -E -- "${QUTEBROWSER_WINDOW_TITLE}" | cut -d" " -f1)
qutebrowser_desktop_id=$(command wmctrl -l | grep --max-count=1 --extended-regexp -- "${QUTEBROWSER_WINDOW_TITLE}*" | cut --delimiter=" " --fields=3)
qutebrowser_window_id=$(command wmctrl -l | grep --max-count=1 --extended-regexp -- "${QUTEBROWSER_WINDOW_TITLE}*" | cut --delimiter=" " --fields=1)
debug_message "focus_to_qutebrowser \
Qutebrowser window ID (window title: ${QUTEBROWSER_WINDOW_TITLE}): ${RED}${qutebrowser_window_id}${COLOR_DEBUG} on desktop ID: ${RED}${qutebrowser_desktop_id}${COLOR_DEBUG}."
@ -298,8 +298,11 @@ Try to switch to buffer id: ${buffer_id}."
echo "{\"args\":[\":tab-select ${buffer_id}\"], \"target_arg\":\"\", \"protocol_version\":1}" |\
socat - UNIX-CONNECT:"${QUTEBROWSER_SOCKET_FILE}"
## Ensure to focus on expected buffer
QUTEBROWSER_WINDOW_TITLE="${buffer_title}"
## Use wanted buffer title as window title (for focusing)
## Remove :
## the first argument : Qutebrowser Window ID/Qutebrowser buffer ID
## the last argument : PyQt6…('URL')
QUTEBROWSER_WINDOW_TITLE="$(echo ${buffer_title} | awk '{for(i=2; i<NF; i++){ printf("%s",( (i>2) ? OFS : "" ) $i) } ;}')"
}
# }}}