From 3be59059f4f11ddab616ae70178e25f721b993ef Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 12:35:42 -0800 Subject: [PATCH] Shading seems to work, still need to add config --- Makefile.in | 1 + src/barwin.c | 13 +++++++------ src/color.c | 39 ++++++++++++++++++++++++--------------- src/color.h | 45 --------------------------------------------- src/frame.c | 16 ++++++++-------- src/util.c | 15 --------------- src/wmfs.h | 5 +++-- 7 files changed, 43 insertions(+), 91 deletions(-) delete mode 100644 src/color.h diff --git a/Makefile.in b/Makefile.in index f29a06e..e3ab8a8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,6 +27,7 @@ src/systray.c \ src/tag.c \ src/util.c \ src/viwmfs.c \ +src/color.c \ src/wmfs.c # flags diff --git a/src/barwin.c b/src/barwin.c index 13ce885..78c0caf 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -31,6 +31,7 @@ */ #include "wmfs.h" +#include "color.h" /** Create a BarWindow * \param parent Parent window of the BarWindow @@ -82,10 +83,10 @@ barwin_create(Window parent, { bw->bord = True; - CWIN(bw->border.left, bw->win, 0, 0, SHADH, h, 0, CWBackPixel, color_enlight(bg), &at); - CWIN(bw->border.top, bw->win, 0, 0, w, SHADH, 0, CWBackPixel, color_enlight(bg), &at); - CWIN(bw->border.bottom, bw->win, 0, h - SHADH, w, SHADH, 0, CWBackPixel, SHADC, &at); - CWIN(bw->border.right, bw->win, w - SHADH, 0, SHADH, h, 0, CWBackPixel, SHADC, &at); + CWIN(bw->border.left, bw->win, 0, 0, SHADH, h, 0, CWBackPixel, bg, &at); + CWIN(bw->border.top, bw->win, 0, 0, w, SHADH, 0, CWBackPixel, bg, &at); + CWIN(bw->border.bottom, bw->win, 0, h - SHADH, w, SHADH, 0, CWBackPixel, bg, &at); + CWIN(bw->border.right, bw->win, w - SHADH, 0, SHADH, h, 0, CWBackPixel, bg, &at); } /* Property */ @@ -95,8 +96,8 @@ barwin_create(Window parent, bw->geo.height = h; bw->bg = bg; bw->fg = fg; - bw->border.light = color_enlight(bg); - bw->border.dark = SHADC; + bw->border.light = color_shade(bg, 0.10); + bw->border.dark = color_shade(bg, -0.10); bw->stipple = stipple; bw->stipple_color = -1; diff --git a/src/color.c b/src/color.c index 7e3f6d3..fe72f6b 100644 --- a/src/color.c +++ b/src/color.c @@ -30,7 +30,13 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "color.h" +#include "wmfs.h" + +static void color_unpack_rgb(uint, uint*, uint*, uint*); +static void color_rgb_to_hsl(uint, uint, uint, double*, double*, double*); +static void color_hsl_to_rgb(double, double, double, uint*, uint*, uint*); +static double color_clamp(double, double, double); +static uint color_pack_rgb(uint, uint, uint); uint color_shade(uint rgb, double shadeVal) @@ -38,20 +44,20 @@ color_shade(uint rgb, double shadeVal) uint r, g, b; double h, s, l; - unpack_rgb(rgb, &r, &g, &b); - rgb_to_hsl(r, g, b, &h, &s, &l); + color_unpack_rgb(rgb, &r, &g, &b); + color_rgb_to_hsl(r, g, b, &h, &s, &l); l += shadeVal; - l = clamp(l, 0, 1); + l = color_clamp(l, 0, 1); - hsl_to_rgb(h, s, l, &r, &g, &b); - rgb = pack_rgb(r, g, b); + color_hsl_to_rgb(h, s, l, &r, &g, &b); + rgb = color_pack_rgb(r, g, b); return rgb; } -double +static double color_clamp(double x, double a, double b) { if(x < a) @@ -62,13 +68,13 @@ color_clamp(double x, double a, double b) return x; } -uint +static uint color_pack_rgb(uint r, uint g, uint b) { return (r << 16) | (g << 8) | b; } -void +static void color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b) { *r = (rgb >> 16) & 0xFF; @@ -76,7 +82,7 @@ color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b) *b = rgb & 0xFF; } -void +static void color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) { double r = xr/255.0; @@ -92,10 +98,13 @@ color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) *s = 0; *l = 0; - v = MAX(r, g); - v = MAX(v, b); - m = MIN(r, g); - m = MIN(m, b); + /* v is max(r, g, b) + * m is min(r, g, b) + */ + v = r > g ? r : g; + v = v > b ? v : b; + m = r < g ? r : g; + m = m < b ? m : b; *l = (m + v)/2.0; @@ -124,7 +133,7 @@ color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) *h /= 6.0; } -void +static void color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx) { double v; diff --git a/src/color.h b/src/color.h deleted file mode 100644 index af9cbd5..0000000 --- a/src/color.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* color.h -* Copyright © 2011 Brian Mock -* All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following disclaimer -* in the documentation and/or other materials provided with the -* distribution. -* * Neither the name of the nor the names of its -* contributors may be used to endorse or promote products derived from -* this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef COLOR_H -#define COLOR_H - -#include "structs.h" - -double color_clamp(double, double, double); -uint color_pack_rgb(uint, uint, uint); -uint color_shade(uint, double); -void color_unpack_rgb(uint, uint*, uint*, uint*); -void color_rgb_to_hsl(uint, uint, uint, double*, double*, double*); -void color_hsl_to_rgb(double, double, double, uint*, uint*, uint*); - -#endif diff --git a/src/frame.c b/src/frame.c index 9dd8f52..61e6eaa 100644 --- a/src/frame.c +++ b/src/frame.c @@ -118,10 +118,10 @@ frame_create(Client *c) /* Border (for shadow) */ if(conf.client.border_shadow) { - CWIN(c->left, c->frame, 0, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, color_enlight(c->colors.frame), &at); - CWIN(c->top, c->frame, 0, 0, c->frame_geo.width, SHADH, 0, CWBackPixel, color_enlight(c->colors.frame), &at); - CWIN(c->bottom, c->frame, 0, c->frame_geo.height - SHADH, c->frame_geo.width, SHADH, 0, CWBackPixel, SHADC, &at); - CWIN(c->right, c->frame, c->frame_geo.width - SHADH, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, SHADC, &at); + CWIN(c->left, c->frame, 0, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, c->colors.frame, &at); + CWIN(c->top, c->frame, 0, 0, c->frame_geo.width, SHADH, 0, CWBackPixel, c->colors.frame, &at); + CWIN(c->bottom, c->frame, 0, c->frame_geo.height - SHADH, c->frame_geo.width, SHADH, 0, CWBackPixel, c->colors.frame, &at); + CWIN(c->right, c->frame, c->frame_geo.width - SHADH, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, c->colors.frame, &at); } /* Reparent window with the frame */ @@ -258,10 +258,10 @@ frame_update(Client *c) if(conf.client.border_shadow) { - XSetWindowBackground(dpy, c->left, color_enlight(c->colors.frame)); - XSetWindowBackground(dpy, c->top, color_enlight(c->colors.frame)); - XSetWindowBackground(dpy, c->right, SHADC); - XSetWindowBackground(dpy, c->bottom, SHADC); + XSetWindowBackground(dpy, c->left, color_shade(c->colors.frame, 0.01)); + XSetWindowBackground(dpy, c->top, color_shade(c->colors.frame, 0.01)); + XSetWindowBackground(dpy, c->right, color_shade(c->colors.frame, -0.01)); + XSetWindowBackground(dpy, c->bottom, color_shade(c->colors.frame, -0.01)); XClearWindow(dpy, c->left); XClearWindow(dpy, c->top); diff --git a/src/util.c b/src/util.c index 59cbe61..cbc1382 100644 --- a/src/util.c +++ b/src/util.c @@ -142,21 +142,6 @@ getcolor(char *color) return xcolor.pixel; } -/** Enlight an hexadecimal color - * \param col Color - * \return The clarified color -*/ -ulong -color_enlight(ulong col) -{ - if((col + 0x330000) < 0xffffff - && (col + 0x003300) < 0xffffff - && (col + 0x000033) < 0xffffff) - return col + 0x333333; - else - return col; -} - /** Set the window WM State * \param win Window target * \param state WM State diff --git a/src/wmfs.h b/src/wmfs.h index e7955e5..46b6c47 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -86,7 +86,6 @@ #define INFOBARH ((conf.bars.height > 0) ? conf.bars.height : (font->height * 1.5)) #define FHINFOBAR ((font->height - font->descent) + (INFOBARH - font->height) / 2) #define SHADH (1) -#define SHADC (0x000000) /* 'Cause i don't know how darken a color yet */ #define BORDH conf.client.borderheight #define TBARH ((conf.titlebar.height < BORDH) ? BORDH : conf.titlebar.height) #define RESHW (6 * (BORDH)) @@ -233,6 +232,9 @@ void frame_update(Client *c); /* config.c */ void init_conf(void); +/* color.c */ +uint color_shade(uint, double); + /* event.c */ void buttonpress(XButtonEvent *ev); void configureevent(XConfigureRequestEvent *ev); @@ -289,7 +291,6 @@ void *xrealloc(void *, size_t, size_t); #define zrealloc(ptr, size) xrealloc((ptr), 1, (size)) char *xstrdup(const char *); int xasprintf(char **, const char *, ...); -ulong color_enlight(ulong col); long getcolor(char *color); void setwinstate(Window win, long state); /* Conf usage {{{ */