commit 48c85cdcf5ec739c22e9fb9a5b1f9e13702eb047
parent 546dd288c02cdab44e92fbfbbe86de57c680e1e1
Author: veltza <106755522+veltza@users.noreply.github.com>
Date: Fri, 5 Jul 2024 12:30:55 +0300
sixel: refactor the sixel display mode (#142)
This does not change the current behavior of SDM.
Diffstat:
| M | st.c | | | 62 | +++++++++++++++++++++++++++++++++++++++----------------------- |
1 file changed, 39 insertions(+), 23 deletions(-)
diff --git a/st.c b/st.c
@@ -220,6 +220,9 @@ static void tsetattr(const int *, int);
static void tsetchar(Rune, const Glyph *, int, int);
static void tsetdirt(int, int);
static void tsetscroll(int, int);
+#if SIXEL_PATCH
+static inline void tsetsixelattr(Line line, int x1, int x2);
+#endif // SIXEL_PATCH
static void tswapscreen(void);
static void tsetmode(int, int, const int *, int);
static int twrite(const char *, int, int);
@@ -1149,6 +1152,15 @@ tsetdirtattr(int attr)
}
}
+#if SIXEL_PATCH
+void
+tsetsixelattr(Line line, int x1, int x2)
+{
+ for (; x1 <= x2; x1++)
+ line[x1].mode |= ATTR_SIXEL;
+}
+#endif // SIXEL_PATCH
+
void
tfulldirt(void)
{
@@ -2592,7 +2604,7 @@ strhandle(void)
};
#if SIXEL_PATCH
ImageList *im, *newimages, *next, *tail;
- int i, x, y, x1, y1, x2, y2, numimages;
+ int i, x1, y1, x2, y2, numimages;
int cx, cy;
Line line;
#if SCROLLBACK_PATCH || REFLOW_PATCH
@@ -2736,36 +2748,40 @@ strhandle(void)
} else {
term.images = newimages;
}
- x2 = MIN(x2, term.col);
- for (i = 0, im = newimages; im; im = next, i++) {
- next = im->next;
- #if SCROLLBACK_PATCH || REFLOW_PATCH
- scr = IS_SET(MODE_ALTSCREEN) ? 0 : term.scr;
- #endif // SCROLLBACK_PATCH
- if (IS_SET(MODE_SIXEL_SDM)) {
+ x2 = MIN(x2, term.col) - 1;
+ if (IS_SET(MODE_SIXEL_SDM)) {
+ /* Sixel display mode: put the sixel in the upper left corner of
+ * the screen, disable scrolling (the sixel will be truncated if
+ * it is too long) and do not change the cursor position. */
+ for (i = 0, im = newimages; im; im = next, i++) {
+ next = im->next;
if (i >= term.row) {
delete_image(im);
continue;
}
im->y = i + scr;
- line = term.line[i];
- } else {
- im->y = term.c.y + scr;
- line = term.line[term.c.y];
- }
- for (x = im->x; x < x2; x++) {
- line[x].mode |= ATTR_SIXEL;
+ tsetsixelattr(term.line[i], x1, x2);
+ term.dirty[MIN(im->y, term.row-1)] = 1;
}
- term.dirty[MIN(im->y, term.row-1)] = 1;
- if (!IS_SET(MODE_SIXEL_SDM) && i < numimages-1) {
- im->next = NULL;
- tnewline(0);
- im->next = next;
+ } else {
+ for (i = 0, im = newimages; im; im = next, i++) {
+ next = im->next;
+ #if SCROLLBACK_PATCH || REFLOW_PATCH
+ scr = IS_SET(MODE_ALTSCREEN) ? 0 : term.scr;
+ #endif // SCROLLBACK_PATCH
+ im->y = term.c.y + scr;
+ tsetsixelattr(term.line[term.c.y], x1, x2);
+ term.dirty[MIN(im->y, term.row-1)] = 1;
+ if (i < numimages-1) {
+ im->next = NULL;
+ tnewline(0);
+ im->next = next;
+ }
}
+ /* if mode 8452 is set, sixel scrolling leaves cursor to right of graphic */
+ if (IS_SET(MODE_SIXEL_CUR_RT))
+ term.c.x = MIN(term.c.x + newimages->cols, term.col-1);
}
- /* if mode 8452 is set, sixel scrolling leaves cursor to right of graphic */
- if (!IS_SET(MODE_SIXEL_SDM) && IS_SET(MODE_SIXEL_CUR_RT))
- term.c.x = MIN(term.c.x + newimages->cols, term.col-1);
}
#endif // SIXEL_PATCH
#if SYNC_PATCH