From a4a86549a939dee9da41f28efe7435ba4884f1a6 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 19 Apr 2023 11:56:52 +0200 Subject: fix coloring --- swt.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/swt.c b/swt.c index 9711940..446267a 100644 --- a/swt.c +++ b/swt.c @@ -72,6 +72,7 @@ static int execshortcut(); static char *kmap(); static void buffer_release(void *data, struct wl_buffer *buffer); static void draw_frame(); +static uint32_t get_color(int i); static void draw_glyph(Glyph g, int x, int y); static void commit_surface(); static void surface_configure(void *data, struct xdg_surface *surface, uint32_t serial); @@ -214,9 +215,20 @@ paste() } +uint32_t +get_color(int i) +{ + if (!BETWEEN(i, 0, sizeof(colors) / sizeof(uint32_t))) + return colors[defaultbg]; + + return colors[i]; +} + + void draw_glyph(Glyph g, int x, int y) { + uint32_t bg; uint32_t fg; @@ -224,8 +236,8 @@ draw_glyph(Glyph g, int x, int y) g.mode ^= ATTR_REVERSE; } - bg = (g.mode & ATTR_REVERSE) ? colors[g.fg] : colors[g.bg]; - fg = (g.mode & ATTR_REVERSE) ? colors[g.bg] : colors[g.fg]; + bg = (g.mode & ATTR_REVERSE) ? get_color(g.fg) : get_color(g.bg); + fg = (g.mode & ATTR_REVERSE) ? get_color(g.bg) : get_color(g.fg); win.fontcache->fonttype = FONTMODE(g.mode); draw_rect( @@ -248,6 +260,7 @@ draw_glyph(Glyph g, int x, int y) ); } + draw_char( win.canvas, win.fontcache, @@ -267,7 +280,7 @@ wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) { borderpx + oy * win.fontcache->box.height, win.fontcache->box.width, win.fontcache->box.height, - colors[og.bg] + get_color(og.bg) ); draw_glyph(og, ox, oy); @@ -290,7 +303,7 @@ wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) { borderpx + cy * win.fontcache->box.height + win.fontcache->box.height - cursorthickness, win.fontcache->box.width, cursorthickness, - colors[defaultcursorcolor] + get_color(defaultcursorcolor) ); break; case 5: /* Bar */ @@ -302,7 +315,7 @@ wdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og) { borderpx + cy * win.fontcache->box.height, cursorthickness, win.fontcache->box.height, - colors[defaultcursorcolor] + get_color(defaultcursorcolor) ); break; } @@ -340,7 +353,7 @@ void wloadcols() { sixd_to_8bit(((i - 16) / 6) % 6) << 8 | sixd_to_8bit(((i - 16) / 1) % 6); } else { - c = 0x08 + 0x0a * (i - (6 * 6 * 6 * 6 + 16)); + c = 0x08 + 0x0a * (i - (6 * 6 * 6 + 16)); c &= 0xff; colors[i] = (c << 16) | (c << 8) | c; } @@ -361,9 +374,9 @@ int wgetcolor(int x, unsigned char *r, unsigned char *g, unsigned char *b) { if (!BETWEEN(x, 0, sizeof(colors) / sizeof(uint32_t))) return 1; - *r = (colors[x] & 0xff0000) >> 16; - *g = (colors[x] & 0x00ff00) >> 8; - *b = (colors[x] & 0x0000ff); + *r = (get_color(x) & 0xff0000) >> 16; + *g = (get_color(x) & 0x00ff00) >> 8; + *b = (get_color(x) & 0x0000ff); return 0; } @@ -424,7 +437,7 @@ buffer_release(void *data, struct wl_buffer *buffer) void draw_frame() { - draw_rect(win.canvas, 0, 0, win.width, win.height, colors[defaultbg]); + draw_rect(win.canvas, 0, 0, win.width, win.height, get_color(defaultbg)); } -- cgit v1.2.3-70-g09d2