Reworking sixel implementation based on veltza's implementation (#117)

* sixel: remove black bars from sixel images

When the images don't fully cover the text cells, black bars are added
to them. This fix removes those bars, but if you need the old behavior,
you can restore it by setting 'sixelremovebars' to zero in config.h

* sixel: fix a potential memory leak

* sixel: improve behavior with text reflow

* sixel: prevent animated gifs from choking the terminal

Animated gifs constantly spawn new images that eventually choke the
terminal because the old animation frames are kept in the image buffer.
This fix removes overlapping images from the image buffer and prevents
them from piling up.

* sixel: add zooming and clipping

* sixel: copying bulk of changes

* sixel: move sixel_parser_parse() and add missing sequences and blocks (#113)

- Move sixel_parser_parse() from tputc() to twrite()
- Add missing 8452, DECSDM, XTSMGRAPHICS and XTWINOPS sequences
- Add more conditional blocks for the scrollback and sync patches
- Remove unused reflow_y from ImageList. It is only used for the
  scrollback-reflow patch in st-sx.

* sixel: update vtiden to VT200 family

* sixel: fix scrolling issues inside tmux (#114)

tmux is using the scrolling region and sequence to clear the screen
below the shell prompt. This peculiar behavior caused the tscrollup()
function to be called, which always scrolled the images regardless of
whether they were inside the region or not. So the images moved out of
place whenever the bottom of the screen was cleared. This fix checks
that the images are inside the region before scrolling them.

* sixel: prevent images from being deleted when resizing (#115)

This fixes resizing issues outside of tmux not inside.

* Rewriting tresize logic based on veltza's proposed implementation in PR #115

* tresize: correction for tscrollup call when scrollback patch is used

---------

Co-authored-by: veltza <106755522+veltza@users.noreply.github.com>
This commit is contained in:
Stein Gunnar Bakkeby 2024-03-07 09:22:44 +01:00 committed by GitHub
parent 2e0e84d56a
commit 677c2da0be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 790 additions and 321 deletions

View file

@ -1,57 +0,0 @@
sixel_state_t sixel_st;
void
dcshandle(void)
{
int bgcolor;
unsigned char r, g, b, a = 255;
switch (csiescseq.mode[0]) {
default:
fprintf(stderr, "erresc: unknown csi ");
csidump();
/* die(""); */
break;
case 'q': /* DECSIXEL */
if (IS_TRUECOL(term.c.attr.bg)) {
r = term.c.attr.bg >> 16 & 255;
g = term.c.attr.bg >> 8 & 255;
b = term.c.attr.bg >> 0 & 255;
} else {
xgetcolor(term.c.attr.bg, &r, &g, &b);
#if ALPHA_PATCH
if (term.c.attr.bg == defaultbg)
a = dc.col[defaultbg].pixel >> 24 & 255;
#endif // ALPHA_PATCH
}
bgcolor = a << 24 | b << 16 | g << 8 | r;
if (sixel_parser_init(&sixel_st, 255 << 24, bgcolor, 1, win.cw, win.ch) != 0)
perror("sixel_parser_init() failed");
term.mode |= MODE_SIXEL;
break;
}
}
void
scroll_images(int n) {
ImageList *im;
int tmp;
/* maximum sixel distance in lines from current view before
* deallocation
* TODO: should be in config.h */
int max_sixel_distance = 10000;
for (im = term.images; im; im = im->next) {
im->y += n;
/* check if the current sixel has exceeded the maximum
* draw distance, and should therefore be deleted */
tmp = im->y;
if (tmp < 0) { tmp = tmp * -1; }
if (tmp > max_sixel_distance) {
fprintf(stderr, "im@0x%08x exceeded maximum distance\n");
im->should_delete = 1;
}
}
}

View file

@ -1,2 +0,0 @@
static void dcshandle(void);
static void scroll_images(int n);

View file

@ -1,14 +0,0 @@
void
delete_image(ImageList *im)
{
if (im->prev)
im->prev->next = im->next;
else
term.images = im->next;
if (im->next)
im->next->prev = im->prev;
if (im->pixmap)
XFreePixmap(xw.dpy, (Drawable)im->pixmap);
free(im->pixels);
free(im);
}

View file

@ -20,9 +20,6 @@
#if SCROLLBACK_PATCH || SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH
#include "scrollback.c"
#endif
#if SIXEL_PATCH
#include "sixel_st.c"
#endif
#if SYNC_PATCH
#include "sync.c"
#endif

View file

@ -23,9 +23,6 @@
#if SCROLLBACK_PATCH || SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH
#include "scrollback.h"
#endif
#if SIXEL_PATCH
#include "sixel_st.h"
#endif
#if SYNC_PATCH
#include "sync.h"
#endif

View file

@ -32,9 +32,6 @@
#if RIGHTCLICKTOPLUMB_PATCH
#include "rightclicktoplumb_x.c"
#endif
#if SIXEL_PATCH
#include "sixel_x.c"
#endif
#if ST_EMBEDDER_PATCH
#include "st_embedder_x.c"
#endif