bakkeby / st-flexipatch

An st build with preprocessor directives to decide which patches to include during build time
MIT License
347 stars 107 forks source link

sixel images flickering in lf file manager preview #128

Closed Zerogaku closed 5 months ago

Zerogaku commented 5 months ago

Hi i'm using chafa to display sixels in the terminal and am using the lf preview script with lf file manager, sixels display correctly but when previewing images in lf, the images will sometimes flicker repeatedly, from what i've noticed it happens more when the terminal/lf is maximized or close to maximized, but it's inconsistent.

https://github.com/bakkeby/st-flexipatch/assets/144664603/e9ff8233-5971-4e34-9286-bcd62c10c9ac

bakkeby commented 5 months ago

From the video it looks like the preview is refreshed every second. I doubt it would be the terminal itself doing that.

veltza commented 5 months ago

I use lf file manager and have never seen that happen before. What version of lf are you using? I can see the window title says lfub. What is that?

Zerogaku commented 5 months ago

I'm using version 31.r56.gd2136df and Thanks for telling me about lfub, I swapped from using ueberzug to sixels for image previews and forgot to remove lfub which is a wrapper script to use ueberzug, but The issue appears to be here still, maybe it happens less but it could be placebo 😅

veltza commented 5 months ago

31.r56.gd2136df

I have no idea what version that is. You could try downloading version r31 from the lf repo or compiling it yourself to see if that makes a difference.

If that doesn't work, here are more questions:

  1. What kind of patches are you using? Try disabling all patches except sixels to see if that helps.
  2. Have you tried using other DE/WMs than DWM?
  3. Does this also happen on other terminals? You could try WezTerm. It supports sixels and provides an AppImage version as well, so you don't even need to install it.
Zerogaku commented 5 months ago

31.r56.gd2136df

I have no idea what version that is. You could try downloading version r31 from the lf repo or compiling it yourself to see if that makes a difference.

If that doesn't work, here are more questions:

1. What kind of patches are you using? Try disabling all patches except sixels to see if that helps.

2. Have you tried using other DE/WMs than DWM?

3. Does this also happen on other terminals? You could try [WezTerm](https://github.com/wez/wezterm). It supports sixels and provides an AppImage version as well, so you don't even need to install it.

I do believe that's the version i'm using (r31) mine's from the arch repos.

And for patches I tried disabling all patches except sixel, and this issue will still persists (when the window is maximized/larger that half the screen).

I did try playing around with a new install of st flexipatch, with one difference, the font used. I normally use:

static char *font = "JetBrainsMono Nerd Font:size=12:antialias=true:autohint=true";

in my setup and it displays much larger that the default:

static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";

Since it was a fresh installation with the default font, the text was smaller and indirectly or directly made the image preview smaller so no flickering.

But when I try to increase the preview size by using options like "chafa --fit-width" in the chafa preview script, the flickering comes back.

I'll try wezterm

and in terms of other DE/WMS I do have a wayland install with dwl and use foot terminal there, and there hasn't been any flickering.

Zerogaku commented 5 months ago

I tried wezterm and the issue appears to be worse, the flickering is more consistent

https://github.com/bakkeby/st-flexipatch/assets/144664603/5e0f2cf3-904d-48c8-bdc0-f067a08c1a5a

I think the only time it doesn't flicker is when the image is super minimal and has few colors like delta

veltza commented 5 months ago

Something strange is going on in your system. Try to disable the compositor. Picom or whatever you are using.

Zerogaku commented 5 months ago

I've tried disabling picom but doesn't solve the problem, i'll experiment more and try with a fresh installation of arch (with only the bare minimum).

Isn't the sixel patch localized? as in doesn't it only keep it's functionality within the terminal? how could an external app be causing the type of flickering?

My other possible culprits are lf or chafa but from what you told me they should be working normally, so I'm stumped 😓. Currently in my setup I can't think of any other thing possibly causing this issue, or at least I don't know enough about the sixel patch or st's functionality to infer what would possibly affect it.

veltza commented 5 months ago

You said you use the simple lf preview script, but then you also talked about the 'chafa --fit-width' option. So could you please paste your lfrc and preview scripts so I can see if there is anything odd there.

Since the problem occurs on both terminals, it suggests that the problem is outside of them. Have you tried chafa's -f symbols feature? Does that fix the problem?

Zerogaku commented 5 months ago

Here's the preview script:

#!/bin/sh

case "$(file -Lb --mime-type -- "$1")" in
    image/*)
        chafa -f sixels -s "$2x$3" --animate off --polite on "$1"
        ;;
    *)
        cat "$1"
        ;;
esac

I only used chafa -f sixels -s "$2x$3" --animate off --fit-width --polite on "$1" temporarily to make the preview bigger when using a smaller font size to test.

and here is the lfrc:

# Luke's lf settings

# Note on Image Previews
# For those wanting image previews, like this system, there are four steps to
# set it up. These are done automatically for LARBS users, but I will state
# them here for others doing it manually.
#
# 1. ueberzug must be installed.
# 2. The scope file (~/.config/lf/scope for me), must have a command similar to
#    mine to generate ueberzug images.
# 3. A `set cleaner` line as below is a cleaner script.
# 4. lf should be started through a wrapper script (~/.local/bin/lfub for me)
#    that creates the environment for ueberzug. This command can be be aliased
#    in your shellrc (`alias lf="lfub") or if set to a binding, should be
#    called directly instead of normal lf.

# Basic vars
set shellopts '-eu'
set ifs "\n"
set scrolloff 10
set icons
set period 1
set hiddenfiles ".*:*.aux:*.log:*.bbl:*.bcf:*.blg:*.run.xml"

# set cleaner '~/.config/lf/cleaner'
# set previewer '~/.config/lf/scope'

set sixel
set previewer '~/.config/lf/scripts/preview'

set autoquit true
set drawbox
set cursorpreviewfmt ""

# cmds/functions
cmd open ${{
    case $(file --mime-type "$(readlink -f $f)" -b) in
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) localc $fx ;;
    image/vnd.djvu|application/pdf|application/octet-stream|application/postscript) setsid -f zathura $fx >/dev/null 2>&1 ;;
        text/*|application/json|inode/x-empty|application/x-subrip) $EDITOR $fx;;
    image/x-xcf) setsid -f gimp $f >/dev/null 2>&1 ;;
    image/svg+xml) display -- $f ;;
    image/*) rotdir $f | grep -i "\.\(png\|jpg\|jpeg\|gif\|webp\|avif\|tif\|ico\)\(_large\)*$" |
        setsid -f nsxiv -aio 2>/dev/null | while read -r file; do
            [ -z "$file" ] && continue
            lf -remote "send select \"$file\""
            lf -remote "send toggle"
        done &
        ;;
    audio/*|video/x-ms-asf) mpv --audio-display=no $f ;;
    video/*) setsid -f mpv $f -quiet >/dev/null 2>&1 ;;
    application/pdf|application/vnd.djvu|application/epub*) setsid -f zathura $fx >/dev/null 2>&1 ;;
    application/pgp-encrypted) $EDITOR $fx ;;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document|application/vnd.oasis.opendocument.text|application/vnd.openxmlformats-officedocument.spreadsheetml.sheet|application/octet-stream|application/vnd.oasis.opendocument.spreadsheet|application/vnd.oasis.opendocument.spreadsheet-template|application/vnd.openxmlformats-officedocument.presentationml.presentation|application/vnd.oasis.opendocument.presentation-template|application/vnd.oasis.opendocument.presentation|application/vnd.ms-powerpoint|application/vnd.oasis.opendocument.graphics|application/vnd.oasis.opendocument.graphics-template|application/vnd.oasis.opendocument.formula|application/vnd.oasis.opendocument.database) setsid -f libreoffice $fx >/dev/null 2>&1 ;;
        *) for f in $fx; do setsid -f $OPENER $f >/dev/null 2>&1; done;;
    esac
}}

cmd mkdir $mkdir -p "$(echo $* | tr ' ' '\ ')"

cmd extract ${{
    clear; tput cup $(($(tput lines)/3)); tput bold
    set -f
    printf "%s\n\t" "$fx"
    printf "extract?[y/N]"
    read ans
    [ $ans = "y" ] && aunpack $fx
}}

cmd delete ${{
    clear; tput cup $(($(tput lines)/3)); tput bold
    set -f
    printf "%s\n\t" "$fx"
    printf "delete?[y/N]"
    read ans
    [ $ans = "y" ] && rm -rf -- $fx
}}

cmd moveto ${{
    clear; tput cup $(($(tput lines)/3)); tput bold
    set -f
    clear; echo "Move to where?"
    dest="$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf | sed 's|~|$HOME|')" &&
    for x in $fx; do
        eval mv -iv \"$x\" \"$dest\"
    done &&
    notify-send "🚚 File(s) moved." "File(s) moved to $dest."
}}

cmd copyto ${{
    clear; tput cup $(($(tput lines)/3)); tput bold
    set -f
    clear; echo "Copy to where?"
    dest="$(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf | sed 's|~|$HOME|')" &&
    for x in $fx; do
        eval cp -ivr \"$x\" \"$dest\"
    done &&
    notify-send "📋 File(s) copied." "File(s) copies to $dest."
}}

# cmd setbg "$1"
# cmd firefox "$1"

cmd bulkrename ${{
    tmpfile_old="$(mktemp)"
    tmpfile_new="$(mktemp)"

    [ -n "$fs" ] && fs=$(basename -a $fs) || fs=$(ls)

    echo "$fs" > "$tmpfile_old"
    echo "$fs" > "$tmpfile_new"
    $EDITOR "$tmpfile_new"

    [ "$(wc -l < "$tmpfile_old")" -eq "$(wc -l < "$tmpfile_new")" ] || { rm -f "$tmpfile_old" "$tmpfile_new"; exit 1; }

    paste "$tmpfile_old" "$tmpfile_new" | while IFS="$(printf '\t')" read -r src dst
    do
        [ "$src" = "$dst" ] || [ -e "$dst" ] || mv -- "$src" "$dst"
    done

    rm -f "$tmpfile_old" "$tmpfile_new"
    lf -remote "send $id unselect"
}}

# Bindings
map <c-f> $lf -remote "send $id select \"$(fzf)\""
map J $lf -remote "send $id cd $(sed -e 's/\s*#.*//' -e '/^$/d' -e 's/^\S*\s*//' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | fzf)"
map gh
map g top
map D delete
map E extract
map C copyto
map M moveto
map <c-n> push :mkdir<space>
map <c-r> reload
map <c-s> set hidden!
map <enter> shell
map x $$f
map X !$f
map o &mimeopen "$f"
map O $mimeopen --ask "$f"

map A :rename; cmd-end # at the very end
map c push A<c-u> # new rename
map I :rename; cmd-home # at the very beginning
map i :rename # before extension
map a :rename; cmd-right # after extension
map B bulkrename
# use &setbg over $setbg so setgif doesn't quit when lf quits,
# though can be fixed using super+q on lf terminal instead.
map b &setbg $f
map S $$BROWSER $fx

map <c-e> down
map <c-y> up
map V push :!nvim<space>

map W $setsid -f $TERMINAL >/dev/null 2>&1

map Y $printf "%s" "$fx" | xclip -selection clipboard

# Source Bookmarks
source "~/.config/lf/shortcutrc"

and using chafa -f symbols -s "$2x$3" --animate off --polite on "$1" in the preview gets rid of the flickering (inluding in wezterm), but that's because it's no longer using sixels but unicode symbols instead i'm assuming. Also could the problem be related to a missing dependency?

veltza commented 5 months ago

Remove this line and it will stop flickering: set period 1

You should report to lf developers that period causes sixels to flicker.

Zerogaku commented 5 months ago

Hey @veltza thanks a lot for the help, removing the line solved the problem!

One last thing, a really small detail which I think is intentional, is it normal for it to flicker a little when swapping between tags?

It does only when swapping tags and it does it only once after the tag has been swapped to, I don't really mind it though.

https://github.com/bakkeby/st-flexipatch/assets/144664603/c8ea4b83-e7d1-4067-a6a4-69a236d36e6e

veltza commented 5 months ago

Yes, that's one of lf's quirks too. It's probably related to that other issue, so you might want to report that to the lf devs as well.

Zerogaku commented 5 months ago

Thank you I'll make sure to do that 👍🏼