sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

index.md (3891B)


      1 Synchronized rendering
      2 ======================
      3 
      4 Summary
      5 -------
      6 Better draw timing to reduce flicker/tearing and improve animation smoothness.
      7 
      8 Background
      9 ----------
     10 
     11 Terminals have to guess when to draw and refresh the screen. This is because
     12 the terminal doesn't know whether the application has completed a "batch" of
     13 output, or whether it's about to have more output right after the refresh.
     14 
     15 This means that sometimes the terminal draws before the application has
     16 completed an output "batch", and usually this results in flicker or tearing.
     17 
     18 In st, the parameters which control the timing are `xfps` and `actionfps`.
     19 `xfps` determines how long st waits before drawing after interactive X events
     20 (KB/mouse), and `actionfps` determines the draw frequency for output which
     21 doesn't follow X events - i.e. unattended output - e.g. during animation.
     22 
     23 
     24 Part 1: auto-sync
     25 -----------------
     26 
     27 *NOTE*: this patch (part 1) is not required if you use st-master. It was
     28 merged upsream on 2020-05-10 and will be included in the next release.
     29 
     30 This patch replaces the timing algorithm and uses a range instead of fixed
     31 timing values. The range gives it the flexibility to choose when to draw, and
     32 it tries to draw once an output "batch" is complete, i.e. when there's some
     33 idle period where no new output arrived. Typically this eliminates flicker and
     34 tearing almost completely.
     35 
     36 The range is defined with the new configuration values `minlatency` and
     37 `maxlatency` (which replace xfps/actionfps), and you should ensure they're at
     38 your `config.h` file.
     39 
     40 This range has equal effect for both X events and unattended output; it doesn't
     41 care what the trigger was, and only cares when idle arrives. Interactively idle
     42 usually arrives very quickly so latency is near `minlatency`, while for
     43 animation it might take longer until the application completes its output.
     44 `maxlatency` is almost never reached, except e.g. during `cat huge.txt` where
     45 idle never happens until the whole file was printed.
     46 
     47 Note that the interactive timing (mouse/KB) was fine before this patch, so the
     48 main improvement is for animation e.g. `mpv --vo=tct`, `cava`, terminal games,
     49 etc, but interactive timing also benefits from this flexibility.
     50 
     51 Part 2: application-sync
     52 ------------------------
     53 
     54 The problem of draw timing is not unique to st. All terminals have to deal
     55 with it, and a new suggested standard tries to solve it. It's called
     56 "Synchronized Updates" and it allows the application to tell the terminal when
     57 the output "batch" is complete so that the terminal knows not to draw partial
     58 output - hence "application sync".
     59 
     60 The suggestion - by iTerm2 author - is available here:
     61 https://gitlab.com/gnachman/iterm2/-/wikis/synchronized-updates-spec
     62 
     63 This patch adds synchronized-updates/application-sync support in st. It
     64 requires the auto-sync patch above installed first. This patch has no effect
     65 except when an application uses the synchronized-update escape sequences.
     66 
     67 Note that currently there are very few terminals or applications which support
     68 it, but one application which does support it is `tmux` since 2020-04-18. With
     69 this patch nearly all cursor flicker is eliminated in tmux, and tmux detects
     70 it automatically via terminfo and enables it when st is installed correctly.
     71 
     72 
     73 Download
     74 --------
     75 Part 1 is independent, but part 2 needs part 1 first. Both files are git
     76 patches and can be applied with either `git am` or with `patch`. Both files
     77 add values at `config.def.h`, and part 2 also updates `st.info`.
     78 
     79 * Part 1 (merged upstream): [st-autosync-0.8.3.diff](st-autosync-0.8.3.diff)
     80 * Part 2 (st 0.8.3): [st-appsync-0.8.3.diff](st-appsync-0.8.3.diff)
     81 * Part 2 (st master 2020-06-17 or later):
     82   [st-appsync-20200618-b27a383.diff](st-appsync-20200618-b27a383.diff)
     83 
     84 
     85 Author
     86 ------
     87 * Avi Halachmi (:avih) - [https://github.com/avih](https://github.com/avih)
     88   Contact email is available inside the patch files.