simple mode: expose window size and terminal size

This commit is contained in:
Dylan Araps 2019-01-07 19:40:37 +02:00
parent ea44816a3c
commit 7e96b42860
1 changed files with 11 additions and 12 deletions

View File

@ -3581,19 +3581,19 @@ get_window_size() {
# -put as a variable. # -put as a variable.
# The 1 second timeout is required for older bash # The 1 second timeout is required for older bash
case "${BASH_VERSINFO[0]}" in case "${BASH_VERSINFO[0]}" in
4|5) IFS=';t' read -d t -t 0.05 -sra win_size ;; 4|5) IFS=';t' read -d t -t 0.05 -sra term_size ;;
*) IFS=';t' read -d t -t 1 -sra win_size ;; *) IFS=';t' read -d t -t 1 -sra term_size ;;
esac esac
unset IFS unset IFS
# Split the string into height/width. # Split the string into height/width.
if [[ "$image_backend" == "tycat" ]]; then if [[ "$image_backend" == "tycat" ]]; then
term_width="$((win_size[2] * win_size[0]))" term_width="$((term_size[2] * term_size[0]))"
term_height="$((win_size[3] * win_size[1]))" term_height="$((term_size[3] * term_size[1]))"
else else
term_height="${win_size[1]}" term_height="${term_size[1]}"
term_width="${win_size[2]}" term_width="${term_size[2]}"
fi fi
[[ "$image_backend" == "kitty" ]] && \ [[ "$image_backend" == "kitty" ]] && \
@ -3623,16 +3623,16 @@ get_window_size() {
# If the ID was found get the window size. # If the ID was found get the window size.
if [[ "$current_window" ]]; then if [[ "$current_window" ]]; then
win_size="$(xwininfo -id "$current_window")" term_size="$(xwininfo -id "$current_window")"
term_width="${win_size#*Width: }" term_width="${term_size#*Width: }"
term_width="${term_width/$'\n'*}" term_width="${term_width/$'\n'*}"
term_height="${win_size/*Height: }" term_height="${term_size/*Height: }"
term_height="${term_height/$'\n'*}" term_height="${term_height/$'\n'*}"
fi fi
fi fi
fi fi
window_size="${term_width:=0}x${term_height:=0}" term_width="${term_width:-0}"
} }
@ -3643,7 +3643,6 @@ get_term_size() {
# Calculate font size. # Calculate font size.
font_width="$((term_width / columns))" font_width="$((term_width / columns))"
font_height="$((term_height / lines))" font_height="$((term_height / lines))"
term_size="${lines}x${columns}"
} }
get_image_size() { get_image_size() {
@ -4697,7 +4696,7 @@ get_args() {
# Known implicit unused variables. # Known implicit unused variables.
mpc_args=() mpc_args=()
: "$term_size $window_size $kernel $icons $font $battery $locale ${mpc_args[*]}" printf '%s\n' "$kernel $icons $font $battery $locale ${mpc_args[*]}"
;; ;;
esac esac