Fix crash when cursor color is truecolor
[st.git] / x.c
diff --git a/x.c b/x.c
index ffd005f..4155a70 100644 (file)
--- a/x.c
+++ b/x.c
@@ -1404,6 +1404,7 @@ void
 xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
 {
        Color drawcol;
+       uint32_t cc;
 
        /* remove the old cursor */
        if (selected(ox, oy))
@@ -1419,13 +1420,23 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
        g.mode &= ATTR_BOLD|ATTR_ITALIC|ATTR_UNDERLINE|ATTR_STRUCK|ATTR_WIDE;
 
        if (selected(cx, cy)) {
-               g.bg = defaultrcs;
-               g.fg = defaultfg;
+               cc = g.bg;
        } else {
-               g.bg = defaultcs;
-               g.fg = defaultbg;
+               g.mode |= ATTR_REVERSE;
+               if (g.mode & ATTR_BOLD && BETWEEN(g.fg, 0, 7))
+                       cc = g.fg + 8;
+               else
+                       cc = g.fg;
+       }
+
+       if (IS_TRUECOL(cc)) {
+               drawcol.color.alpha = 0xffff;
+               drawcol.color.red = TRUERED(cc);
+               drawcol.color.green = TRUEGREEN(cc);
+               drawcol.color.blue = TRUEBLUE(cc);
+       } else {
+               drawcol = dc.col[cc];
        }
-       drawcol = dc.col[g.bg];
 
        if (IS_SET(MODE_REVERSE)) {
                drawcol.color.red = ~drawcol.color.red;