diff --git a/sh/clear.sh b/sh/clear.sh index ba8172a..180dbd8 100644 --- a/sh/clear.sh +++ b/sh/clear.sh @@ -3,4 +3,4 @@ setup_image 1 [ "$image_method" = "$image_method_ueberzug" ] && printf '{"action": "remove", "identifier": "preview"}\n' > "$fifo" -is_kitty && kitty +kitten icat --clear --transfer-mode file +is_kitty && kitty_clear diff --git a/sh/end.sh b/sh/end.sh index 30e9baa..b1c378c 100644 --- a/sh/end.sh +++ b/sh/end.sh @@ -1,4 +1,15 @@ setup_image 1 # tell ctpv server to exit -[ "$image_method" = "$image_method_ueberzug" ] && printf '\0' > "$fifo" +printf '\0' > "$fifo" + +# Kill running icat +icat_pid="$(kitty_icat_pid)" +[ -e "$icat_pid" ] && pid="$(cat "$icat_pid")" && [ -e "/proc/$pid" ] && kill "$pid" + +# A dirty hack to fix lf issue where ctpv runs before quit +if is_kitty; then + kitty_clear & + { sleep 1; kitty_clear; } & + wait +fi diff --git a/sh/helpers.sh b/sh/helpers.sh index 9f610e5..3c59fe6 100644 --- a/sh/helpers.sh +++ b/sh/helpers.sh @@ -22,6 +22,10 @@ is_kitty() { [ -n "$KITTY_PID" ] } +kitty_clear() { + kitty +kitten icat --clear --transfer-mode file +} + fifo_open() { # https://unix.stackexchange.com/a/522940/183147 dd oflag=nonblock conv=notrunc,nocreat count=0 of="$1" \ @@ -75,6 +79,10 @@ setup_image() { [ "$image_method" = "$image_method_ueberzug" ] && setup_fifo "$@" } +kitty_icat_pid() { + printf '/tmp/ctpvicat.%d' "$id" +} + send_image() { noimages && return 127 @@ -86,7 +94,9 @@ send_image() { ;; "$image_method_kitty") kitty +kitten icat --transfer-mode file --align left \ - --place "${w}x${h}@${x}x${y}" "$1" + --place "${w}x${h}@${x}x${y}" "$1" & + printf '%d\n' "$!" > "$(kitty_icat_pid)" + wait return 1 ;; "$image_method_chafa")