From b796928504107228fc8fde81b03eaeafcaf07f3b Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Sat, 25 Aug 2012 09:59:03 +0100 Subject: [PATCH] Draw window borders with correct colormap. Using window-supplied depth, visual and colormap information has the side effect of causing window borders to be draw using inconsistent colormap entries. Allocate entries from each window's colormap when drawing its border. Force setting the border when the window is first created so it's guaranteed to be drawn in a consistent state. --- src/actions.c | 10 ++++++++-- src/framewin.c | 26 ++++++++++++++++++++++++++ src/framewin.h | 2 ++ src/wconfig.h.in | 1 + 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/actions.c b/src/actions.c index 988e90a6..0d4cff11 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1863,7 +1863,10 @@ void wSelectWindow(WWindow *wwin, Bool flag) if (flag) { wwin->flags.selected = 1; - XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel); + if (wwin->frame->selected_border_pixel) + XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->selected_border_pixel); + else + XSetWindowBorder(dpy, wwin->frame->core->window, scr->white_pixel); if (!HAS_BORDER(wwin)) { XSetWindowBorderWidth(dpy, wwin->frame->core->window, FRAME_BORDER_WIDTH); @@ -1874,7 +1877,10 @@ void wSelectWindow(WWindow *wwin, Bool flag) WMAddToArray(scr->selected_windows, wwin); } else { wwin->flags.selected = 0; - XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel); + if (wwin->frame->border_pixel) + XSetWindowBorder(dpy, wwin->frame->core->window, *wwin->frame->border_pixel); + else + XSetWindowBorder(dpy, wwin->frame->core->window, scr->frame_border_pixel); if (!HAS_BORDER(wwin)) { XSetWindowBorderWidth(dpy, wwin->frame->core->window, 0); diff --git a/src/framewin.c b/src/framewin.c index 448d204f..2a269526 100644 --- a/src/framewin.c +++ b/src/framewin.c @@ -58,6 +58,27 @@ static void paintButton(WCoreWindow * button, WTexture * texture, static void updateTitlebar(WFrameWindow * fwin); +static void allocFrameBorderPixel(Colormap colormap, char *color_name, unsigned long **pixel); + +static void allocFrameBorderPixel(Colormap colormap, char *color_name, unsigned long **pixel) { + XColor xcol; + + *pixel = NULL; + + if (!XParseColor(dpy, colormap, color_name, &xcol)) { + wwarning(_("could not parse color \"%s\""), color_name); + return; + } + if (!XAllocColor(dpy, colormap, &xcol)) { + wwarning(_("could not allocate color \"%s\""), color_name); + return; + } + + *pixel = wmalloc(sizeof(unsigned long)); + if (*pixel) + **pixel = xcol.pixel; +} + WFrameWindow *wFrameWindowCreate(WScreen * scr, int wlevel, int x, int y, int width, int height, int *clearance, int *title_min, int *title_max, int flags, @@ -88,6 +109,8 @@ WFrameWindow *wFrameWindowCreate(WScreen * scr, int wlevel, int x, int y, fwin->depth = depth; fwin->visual = visual; fwin->colormap = colormap; + allocFrameBorderPixel(fwin->colormap, FRAME_BORDER_COLOR, &fwin->border_pixel); + allocFrameBorderPixel(fwin->colormap, FRAME_SELECTED_BORDER_COLOR, &fwin->selected_border_pixel); fwin->core = wCoreCreateTopLevel(scr, x, y, width, height, (flags & WFF_BORDER) ? FRAME_BORDER_WIDTH : 0, fwin->depth, fwin->visual, fwin->colormap); @@ -413,6 +436,9 @@ void wFrameWindowUpdateBorders(WFrameWindow * fwin, int flags) } checkTitleSize(fwin); + + if (fwin->border_pixel) + XSetWindowBorder(dpy, fwin->core->window, *fwin->border_pixel); } void wFrameWindowDestroy(WFrameWindow * fwin) diff --git a/src/framewin.h b/src/framewin.h index 27e6518a..d893cd14 100644 --- a/src/framewin.h +++ b/src/framewin.h @@ -150,6 +150,8 @@ typedef struct WFrameWindow { int depth; Visual *visual; Colormap colormap; + unsigned long *border_pixel; + unsigned long *selected_border_pixel; } WFrameWindow; diff --git a/src/wconfig.h.in b/src/wconfig.h.in index 0046863a..baef4469 100644 --- a/src/wconfig.h.in +++ b/src/wconfig.h.in @@ -344,6 +344,7 @@ #undef NO_MINIWINDOW_TITLES #define FRAME_BORDER_COLOR "black" +#define FRAME_SELECTED_BORDER_COLOR "white" /* for boxes with high mouse sampling rates (SGI) */ #define DELAY_BETWEEN_MOUSE_SAMPLING 10