From cd710f583f5ab8650fa2e41c08dc9a6332a5680f Mon Sep 17 00:00:00 2001 From: miseran Date: Tue, 12 Oct 2021 01:46:35 +0200 Subject: Fix behaviour when TrueColor / 24 bit depth is not available (#114) * Fix regression introduced in c7ca547 which made nsxiv not start in non-TrueColor X server. * Introduce a new fix for embedding into tabbed-alpha. * Fixes a visual glitch from original sxiv when drawing transparent images in 8 bit depth. In 8 bit PseudoColor, `.pixel` is just an index into the 256 defined colors and thus trying to extract rgb bits from it would result in visual glitch. The values `.color.red` on the other hand and so on are always integers between 0 and 0xFFFF representing the color as expected. * Use XColor for win_bg/fg and mrk_fg Co-authored-by: NRK --- window.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'window.c') diff --git a/window.c b/window.c index 9f22fba..5e1392f 100644 --- a/window.c +++ b/window.c @@ -80,12 +80,11 @@ void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col) } #endif /* HAVE_LIBFONTS */ -void win_alloc_color(const win_env_t *e, const char *name, unsigned long *pixel) +void win_alloc_color(const win_env_t *e, const char *name, XColor *col) { - XColor screen, exact; - if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, &exact)) + XColor screen; + if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, col)) error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); - *pixel = exact.pixel; } const char* win_res(XrmDatabase db, const char *name, const char *def) @@ -112,9 +111,6 @@ void win_init(win_t *win) #endif char *res_man; XrmDatabase db; - XVisualInfo vis; - XWindowAttributes attr; - Window parent; memset(win, 0, sizeof(win_t)); @@ -125,19 +121,9 @@ void win_init(win_t *win) e->scr = DefaultScreen(e->dpy); e->scrw = DisplayWidth(e->dpy, e->scr); e->scrh = DisplayHeight(e->dpy, e->scr); - - parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr); - - if (options->embed == 0) { - e->depth = DefaultDepth(e->dpy, e->scr); - } else { - XGetWindowAttributes(e->dpy, parent, &attr); - e->depth = attr.depth; - } - - XMatchVisualInfo(e->dpy, e->scr, e->depth, TrueColor, &vis); - e->vis = vis.visual; - e->cmap = XCreateColormap(e->dpy, parent, e->vis, None); + e->depth = DefaultDepth(e->dpy, e->scr); + e->vis = DefaultVisual(e->dpy, e->scr); + e->cmap = DefaultColormap(e->dpy, e->scr); if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0) error(0, 0, "No locale support"); @@ -197,6 +183,7 @@ void win_open(win_t *win) XWMHints hints; pid_t pid; char hostname[256]; + XSetWindowAttributes attrs; e = &win->env; parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr); @@ -238,8 +225,12 @@ void win_open(win_t *win) win->y = 0; } + attrs.colormap = e->cmap; + attrs.border_pixel = 0; + win->xwin = XCreateWindow(e->dpy, parent, win->x, win->y, win->w, win->h, 0, - e->depth, InputOutput, e->vis, 0, NULL); + e->depth, InputOutput, e->vis, + CWColormap | CWBorderPixel, &attrs); if (win->xwin == None) error(EXIT_FAILURE, 0, "Error creating X window"); @@ -317,7 +308,7 @@ void win_open(win_t *win) win->buf.h = e->scrh; win->buf.pm = XCreatePixmap(e->dpy, win->xwin, win->buf.w, win->buf.h, e->depth); - XSetForeground(e->dpy, gc, win->win_bg); + XSetForeground(e->dpy, gc, win->win_bg.pixel); XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm); XMapWindow(e->dpy, win->xwin); @@ -398,7 +389,7 @@ void win_clear(win_t *win) win->buf.pm = XCreatePixmap(e->dpy, win->xwin, win->buf.w, win->buf.h, e->depth); } - XSetForeground(e->dpy, gc, win->win_bg); + XSetForeground(e->dpy, gc, win->win_bg.pixel); XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); } @@ -455,7 +446,7 @@ void win_draw_bar(win_t *win) XSetForeground(e->dpy, gc, win->bar_bg.pixel); XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h); - XSetForeground(e->dpy, gc, win->win_bg); + XSetForeground(e->dpy, gc, win->win_bg.pixel); XSetBackground(e->dpy, gc, win->bar_bg.pixel); if ((len = strlen(r->buf)) > 0) { -- cgit v1.2.3