Shading seems to work, still need to add config

This commit is contained in:
Brian Mock
2011-02-22 12:35:42 -08:00
parent 5729fe95fb
commit 3be59059f4
7 changed files with 43 additions and 91 deletions

View File

@@ -27,6 +27,7 @@ src/systray.c \
src/tag.c \ src/tag.c \
src/util.c \ src/util.c \
src/viwmfs.c \ src/viwmfs.c \
src/color.c \
src/wmfs.c src/wmfs.c
# flags # flags

View File

@@ -31,6 +31,7 @@
*/ */
#include "wmfs.h" #include "wmfs.h"
#include "color.h"
/** Create a BarWindow /** Create a BarWindow
* \param parent Parent window of the BarWindow * \param parent Parent window of the BarWindow
@@ -82,10 +83,10 @@ barwin_create(Window parent,
{ {
bw->bord = True; bw->bord = True;
CWIN(bw->border.left, bw->win, 0, 0, SHADH, h, 0, CWBackPixel, color_enlight(bg), &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, color_enlight(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, SHADC, &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, SHADC, &at); CWIN(bw->border.right, bw->win, w - SHADH, 0, SHADH, h, 0, CWBackPixel, bg, &at);
} }
/* Property */ /* Property */
@@ -95,8 +96,8 @@ barwin_create(Window parent,
bw->geo.height = h; bw->geo.height = h;
bw->bg = bg; bw->bg = bg;
bw->fg = fg; bw->fg = fg;
bw->border.light = color_enlight(bg); bw->border.light = color_shade(bg, 0.10);
bw->border.dark = SHADC; bw->border.dark = color_shade(bg, -0.10);
bw->stipple = stipple; bw->stipple = stipple;
bw->stipple_color = -1; bw->stipple_color = -1;

View File

@@ -30,7 +30,13 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 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 uint
color_shade(uint rgb, double shadeVal) color_shade(uint rgb, double shadeVal)
@@ -38,20 +44,20 @@ color_shade(uint rgb, double shadeVal)
uint r, g, b; uint r, g, b;
double h, s, l; double h, s, l;
unpack_rgb(rgb, &r, &g, &b); color_unpack_rgb(rgb, &r, &g, &b);
rgb_to_hsl(r, g, b, &h, &s, &l); color_rgb_to_hsl(r, g, b, &h, &s, &l);
l += shadeVal; l += shadeVal;
l = clamp(l, 0, 1); l = color_clamp(l, 0, 1);
hsl_to_rgb(h, s, l, &r, &g, &b); color_hsl_to_rgb(h, s, l, &r, &g, &b);
rgb = pack_rgb(r, g, b); rgb = color_pack_rgb(r, g, b);
return rgb; return rgb;
} }
double static double
color_clamp(double x, double a, double b) color_clamp(double x, double a, double b)
{ {
if(x < a) if(x < a)
@@ -62,13 +68,13 @@ color_clamp(double x, double a, double b)
return x; return x;
} }
uint static uint
color_pack_rgb(uint r, uint g, uint b) color_pack_rgb(uint r, uint g, uint b)
{ {
return (r << 16) | (g << 8) | b; return (r << 16) | (g << 8) | b;
} }
void static void
color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b) color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b)
{ {
*r = (rgb >> 16) & 0xFF; *r = (rgb >> 16) & 0xFF;
@@ -76,7 +82,7 @@ color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b)
*b = rgb & 0xFF; *b = rgb & 0xFF;
} }
void static void
color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l)
{ {
double r = xr/255.0; 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; *s = 0;
*l = 0; *l = 0;
v = MAX(r, g); /* v is max(r, g, b)
v = MAX(v, b); * m is min(r, g, b)
m = MIN(r, g); */
m = MIN(m, 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; *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; *h /= 6.0;
} }
void static void
color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx) color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx)
{ {
double v; double v;

View File

@@ -1,45 +0,0 @@
/*
* color.h
* Copyright © 2011 Brian Mock <mock.brian@gmail.com>
* 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

View File

@@ -118,10 +118,10 @@ frame_create(Client *c)
/* Border (for shadow) */ /* Border (for shadow) */
if(conf.client.border_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->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, color_enlight(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, SHADC, &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, SHADC, &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 */ /* Reparent window with the frame */
@@ -258,10 +258,10 @@ frame_update(Client *c)
if(conf.client.border_shadow) if(conf.client.border_shadow)
{ {
XSetWindowBackground(dpy, c->left, color_enlight(c->colors.frame)); XSetWindowBackground(dpy, c->left, color_shade(c->colors.frame, 0.01));
XSetWindowBackground(dpy, c->top, color_enlight(c->colors.frame)); XSetWindowBackground(dpy, c->top, color_shade(c->colors.frame, 0.01));
XSetWindowBackground(dpy, c->right, SHADC); XSetWindowBackground(dpy, c->right, color_shade(c->colors.frame, -0.01));
XSetWindowBackground(dpy, c->bottom, SHADC); XSetWindowBackground(dpy, c->bottom, color_shade(c->colors.frame, -0.01));
XClearWindow(dpy, c->left); XClearWindow(dpy, c->left);
XClearWindow(dpy, c->top); XClearWindow(dpy, c->top);

View File

@@ -142,21 +142,6 @@ getcolor(char *color)
return xcolor.pixel; 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 /** Set the window WM State
* \param win Window target * \param win Window target
* \param state WM State * \param state WM State

View File

@@ -86,7 +86,6 @@
#define INFOBARH ((conf.bars.height > 0) ? conf.bars.height : (font->height * 1.5)) #define INFOBARH ((conf.bars.height > 0) ? conf.bars.height : (font->height * 1.5))
#define FHINFOBAR ((font->height - font->descent) + (INFOBARH - font->height) / 2) #define FHINFOBAR ((font->height - font->descent) + (INFOBARH - font->height) / 2)
#define SHADH (1) #define SHADH (1)
#define SHADC (0x000000) /* 'Cause i don't know how darken a color yet */
#define BORDH conf.client.borderheight #define BORDH conf.client.borderheight
#define TBARH ((conf.titlebar.height < BORDH) ? BORDH : conf.titlebar.height) #define TBARH ((conf.titlebar.height < BORDH) ? BORDH : conf.titlebar.height)
#define RESHW (6 * (BORDH)) #define RESHW (6 * (BORDH))
@@ -233,6 +232,9 @@ void frame_update(Client *c);
/* config.c */ /* config.c */
void init_conf(void); void init_conf(void);
/* color.c */
uint color_shade(uint, double);
/* event.c */ /* event.c */
void buttonpress(XButtonEvent *ev); void buttonpress(XButtonEvent *ev);
void configureevent(XConfigureRequestEvent *ev); void configureevent(XConfigureRequestEvent *ev);
@@ -289,7 +291,6 @@ void *xrealloc(void *, size_t, size_t);
#define zrealloc(ptr, size) xrealloc((ptr), 1, (size)) #define zrealloc(ptr, size) xrealloc((ptr), 1, (size))
char *xstrdup(const char *); char *xstrdup(const char *);
int xasprintf(char **, const char *, ...); int xasprintf(char **, const char *, ...);
ulong color_enlight(ulong col);
long getcolor(char *color); long getcolor(char *color);
void setwinstate(Window win, long state); void setwinstate(Window win, long state);
/* Conf usage {{{ */ /* Conf usage {{{ */