From 16120744a8afe0bd98b7134b93f3540c21c540a5 Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Mon, 21 Feb 2011 16:20:02 -0800 Subject: [PATCH 01/19] Added color functions --- src/color.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/color.h | 13 +++++ 2 files changed, 172 insertions(+) create mode 100644 src/color.c create mode 100644 src/color.h diff --git a/src/color.c b/src/color.c new file mode 100644 index 0000000..c81f057 --- /dev/null +++ b/src/color.c @@ -0,0 +1,159 @@ +// author: Brian Mock + +#include "color.h" + +uint +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); + + l += shadeVal; + + l = clamp(l, 0, 1); + + hsl_to_rgb(h, s, l, &r, &g, &b); + rgb = pack_rgb(r, g, b); + + return rgb; +} + +double +color_clamp(double x, double a, double b) +{ + if(x < a) + return a; + else if(x > b) + return b; + else + return x; +} + +uint +color_pack_rgb(uint r, uint g, uint b) +{ + return (r << 16) | (g << 8) | b; +} + +void +color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b) +{ + *r = (rgb >> 16) & 0xFF; + *g = (rgb >> 8) & 0xFF; + *b = rgb & 0xFF; +} + +void +color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) +{ + double r = xr/255.0; + double g = xg/255.0; + double b = xb/255.0; + + double v; + double m; + double vm; + double r2, g2, b2; + + *h = 0; + *s = 0; + *l = 0; + + v = MAX(r, g); + v = MAX(v, b); + m = MIN(r, g); + m = MIN(m, b); + + *l = (m + v)/2.0; + + if(*l <= 0.0) + return; + + vm = v - m; + *s = vm; + + if(*s > 0.0) + *s /= (*l <= 0.5) ? (v + m) : (2.0 - v - m); + else + return; + + r2 = (v - r)/vm; + g2 = (v - g)/vm; + b2 = (v - b)/vm; + + if(r == v) + *h = (g == m ? 5.0 + b2 : 1.0 - g2); + else if(g == v) + *h = (b == m ? 1.0 + r2 : 3.0 - b2); + else + *h = (r == m ? 3.0 + g2 : 5.0 - r2); + + *h /= 6.0; +} + +void +color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx) +{ + double v; + double r,g,b; + + r = l; + g = l; + b = l; + v = (l <= 0.5) ? (l * (1.0 + sl)) : (l + sl - l * sl); + if (v > 0) { + double m; + double sv; + int sextant; + double fract, vsf, mid1, mid2; + + m = l + l - v; + sv = (v - m ) / v; + h *= 6.0; + sextant = (int) h; + fract = h - sextant; + vsf = v * sv * fract; + mid1 = m + vsf; + mid2 = v - vsf; + switch(sextant) + { + case 0: + r = v; + g = mid1; + b = m; + break; + case 1: + r = mid2; + g = v; + b = m; + break; + case 2: + r = m; + g = v; + b = mid1; + break; + case 3: + r = m; + g = mid2; + b = v; + break; + case 4: + r = mid1; + g = m; + b = v; + break; + case 5: + r = v; + g = m; + b = mid2; + break; + } + } + + *rx = r * 255.0; + *gx = g * 255.0; + *bx = b * 255.0; +} diff --git a/src/color.h b/src/color.h new file mode 100644 index 0000000..64d88a1 --- /dev/null +++ b/src/color.h @@ -0,0 +1,13 @@ +#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 From d1f400e940e225cca63548af644e9dd41c9e158a Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Mon, 21 Feb 2011 16:23:56 -0800 Subject: [PATCH 02/19] Forgot license info --- src/color.c | 32 +++++++++++++++++++++++++++++++- src/color.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/color.c b/src/color.c index c81f057..fa195b8 100644 --- a/src/color.c +++ b/src/color.c @@ -1,4 +1,34 @@ -// author: Brian Mock +/* +* color.c +* Copyright © 2008, 2009 Martin Duquesnoy +* 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. +*/ #include "color.h" diff --git a/src/color.h b/src/color.h index 64d88a1..e0d8794 100644 --- a/src/color.h +++ b/src/color.h @@ -1,3 +1,35 @@ +/* +* color.h +* Copyright © 2008, 2009 Martin Duquesnoy +* 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 From 43686dc82c986a223d18ce5fb0ff351a1dd55d18 Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Mon, 21 Feb 2011 16:28:38 -0800 Subject: [PATCH 03/19] Fixed licensing info to use my name --- src/color.c | 2 +- src/color.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/color.c b/src/color.c index fa195b8..48aa713 100644 --- a/src/color.c +++ b/src/color.c @@ -1,6 +1,6 @@ /* * color.c -* Copyright © 2008, 2009 Martin Duquesnoy +* Copyright © 2011 Brian Mock * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/color.h b/src/color.h index e0d8794..af9cbd5 100644 --- a/src/color.h +++ b/src/color.h @@ -1,6 +1,6 @@ /* * color.h -* Copyright © 2008, 2009 Martin Duquesnoy +* Copyright © 2011 Brian Mock * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 5729fe95fb3dfb0a0e6177202f5b27f96cf9bf1b Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Mon, 21 Feb 2011 16:30:23 -0800 Subject: [PATCH 04/19] Fixed style on "if" --- src/color.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/color.c b/src/color.c index 48aa713..7e3f6d3 100644 --- a/src/color.c +++ b/src/color.c @@ -134,7 +134,8 @@ color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx) g = l; b = l; v = (l <= 0.5) ? (l * (1.0 + sl)) : (l + sl - l * sl); - if (v > 0) { + if(v > 0) + { double m; double sv; int sextant; From 3be59059f4f11ddab616ae70178e25f721b993ef Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 12:35:42 -0800 Subject: [PATCH 05/19] 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 {{{ */ From 83d2da9da698681ec6358cd3e8e37d9bb0d09e72 Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 13:02:40 -0800 Subject: [PATCH 06/19] Added comments to all my color.c functions --- src/color.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/color.c b/src/color.c index fe72f6b..cd77454 100644 --- a/src/color.c +++ b/src/color.c @@ -38,6 +38,12 @@ 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); +/** Shades a color by the amount. This works by converting a packed RGB + * color to HSL, adding the amount to the lightness, + * and then converting back to RGB. 1.0 is max lightness, 0.0 is min lightness. + * \param shadeVal the amount to shade the lightness by. + * \return the shaded color + */ uint color_shade(uint rgb, double shadeVal) { @@ -57,6 +63,12 @@ color_shade(uint rgb, double shadeVal) return rgb; } +/** Clamp a number x within the range [a, b]. + * \param x the number which to clamp + * \param a the lowest possible value + * \param b the highest possible value + * \return the clamped number + */ static double color_clamp(double x, double a, double b) { @@ -68,12 +80,24 @@ color_clamp(double x, double a, double b) return x; } +/** Pack a triplet of RGB values into a single uint + * \param r the red value + * \param g the green value + * \param b the blue value + * \return the packed RGB value + */ static uint color_pack_rgb(uint r, uint g, uint b) { return (r << 16) | (g << 8) | b; } +/** Unpack an RGB uint into three separate values + * \param rgb the packed color + * \param r a pointer to a uint where the red value will be stored + * \param g a pointer to a uint where the green value will be stored + * \param b a pointer to a uint where the blue value will be stored + */ static void color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b) { @@ -82,6 +106,9 @@ color_unpack_rgb(uint rgb, uint *r, uint *g, uint *b) *b = rgb & 0xFF; } +/** Convert unpacked RGB values into HSL, storing in the doubles referenced + * by the pointers h, s, l + */ static void color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) { @@ -133,6 +160,9 @@ color_rgb_to_hsl(uint xr, uint xg, uint xb, double *h, double *s, double *l) *h /= 6.0; } +/** Convert h, s, l values to RGB and store them in the three uint + * referenced by the last three parameters. + */ static void color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx) { From bd1575e1b25bf119fedc4dfe9c25a96fb7a3e1bb Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 14:05:46 -0800 Subject: [PATCH 07/19] Fixed some bad whitespace in config.c --- src/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index 264b87f..d820988 100644 --- a/src/config.c +++ b/src/config.c @@ -789,12 +789,12 @@ conf_keybind_section(void) void init_conf(void) { - if (get_conf(conf.confpath) == -1) + if(get_conf(conf.confpath) == -1) { warnx("parsing configuration file (%s) failed.", conf.confpath); sprintf(conf.confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR); warnx("Use the default configuration (%s).", conf.confpath); - if (get_conf(conf.confpath) == -1) + if(get_conf(conf.confpath) == -1) errx(1, "parsing configuration file (%s) failed.", conf.confpath); } From 971fb3240acccebfc292413a33728f19d7a9ca76 Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 15:37:50 -0800 Subject: [PATCH 08/19] Should work... but no compile --- src/barwin.c | 5 ++--- src/config.c | 6 ++++++ src/frame.c | 8 ++++---- src/structs.h | 4 ++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index 78c0caf..a9cb568 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -31,7 +31,6 @@ */ #include "wmfs.h" -#include "color.h" /** Create a BarWindow * \param parent Parent window of the BarWindow @@ -96,8 +95,8 @@ barwin_create(Window parent, bw->geo.height = h; bw->bg = bg; bw->fg = fg; - bw->border.light = color_shade(bg, 0.10); - bw->border.dark = color_shade(bg, -0.10); + bw->border.light = color_shade(bg, conf.colors.bar_light_shade); + bw->border.dark = color_shade(bg, conf.colors.bar_dark_shade); bw->stipple = stipple; bw->stipple_color = -1; diff --git a/src/config.c b/src/config.c index d820988..d45e5a0 100644 --- a/src/config.c +++ b/src/config.c @@ -203,6 +203,9 @@ conf_bar_section(void) conf.colors.bar = getcolor((barbg = fetch_opt_first(bar, "#000000", "bg").str)); conf.colors.text = fetch_opt_first(bar, "#ffffff", "fg").str; + conf.colors.bar_light_shade = fetch_opt_first(bar, "0.25", "light_shade").fnum; + conf.colors.bar_dark_shade = fetch_opt_first(bar, "-0.25", "dark_shade").fnum; + mouse = fetch_section(bar, "mouse"); if ((conf.bars.nmouse = fetch_section_count(mouse)) > 0) @@ -301,6 +304,9 @@ conf_client_section(void) conf.client.default_open_screen = fetch_opt_first(sec, "-1", "default_open_screen").num; conf.client.new_client_get_mouse = fetch_opt_first(sec, "false", "new_client_get_mouse").bool; + conf.colors.client_light_shade = fetch_opt_first(bar, "0.25", "light_shade").fnum; + conf.colors.client_dark_shade = fetch_opt_first(bar, "-0.25", "dark_shade").fnum; + mouse = fetch_section(sec, "mouse"); if((conf.client.nmouse = fetch_section_count(mouse)) > 0) diff --git a/src/frame.c b/src/frame.c index 61e6eaa..22d7ff8 100644 --- a/src/frame.c +++ b/src/frame.c @@ -258,10 +258,10 @@ frame_update(Client *c) if(conf.client.border_shadow) { - 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)); + XSetWindowBackground(dpy, c->left, color_shade(c->colors.frame, conf.colors.client_light_shade)); + XSetWindowBackground(dpy, c->top, color_shade(c->colors.frame, conf.colors.client_light_shade)); + XSetWindowBackground(dpy, c->right, color_shade(c->colors.frame, conf.colors.client_dark_shade)); + XSetWindowBackground(dpy, c->bottom, color_shade(c->colors.frame, conf.colors.client_dark_shade)); XClearWindow(dpy, c->left); XClearWindow(dpy, c->top); diff --git a/src/structs.h b/src/structs.h index 1ee0aa9..272795d 100644 --- a/src/structs.h +++ b/src/structs.h @@ -216,6 +216,10 @@ struct Client uint frame; char *fg; uint resizecorner; + float client_light_shade; + float client_dark_shade; + float bar_light_shade; + float bar_dark_shade; } colors; /* Client Information by flags */ uint flags; From 9235775dd24809074b68c3c2475b337c85abd104 Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 19:37:06 -0800 Subject: [PATCH 09/19] Final touches, including wmfsrc default options --- src/config.c | 4 ++-- src/structs.h | 8 ++++---- wmfsrc | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/config.c b/src/config.c index d45e5a0..2d7c74d 100644 --- a/src/config.c +++ b/src/config.c @@ -304,8 +304,8 @@ conf_client_section(void) conf.client.default_open_screen = fetch_opt_first(sec, "-1", "default_open_screen").num; conf.client.new_client_get_mouse = fetch_opt_first(sec, "false", "new_client_get_mouse").bool; - conf.colors.client_light_shade = fetch_opt_first(bar, "0.25", "light_shade").fnum; - conf.colors.client_dark_shade = fetch_opt_first(bar, "-0.25", "dark_shade").fnum; + conf.colors.client_light_shade = fetch_opt_first(sec, "0.25", "light_shade").fnum; + conf.colors.client_dark_shade = fetch_opt_first(sec, "-0.25", "dark_shade").fnum; mouse = fetch_section(sec, "mouse"); diff --git a/src/structs.h b/src/structs.h index 272795d..cf540f2 100644 --- a/src/structs.h +++ b/src/structs.h @@ -216,10 +216,6 @@ struct Client uint frame; char *fg; uint resizecorner; - float client_light_shade; - float client_dark_shade; - float bar_light_shade; - float bar_dark_shade; } colors; /* Client Information by flags */ uint flags; @@ -414,6 +410,10 @@ typedef struct uint tagbord; char *layout_fg; uint layout_bg; + float client_light_shade; + float client_dark_shade; + float bar_light_shade; + float bar_dark_shade; } colors; struct { diff --git a/wmfsrc b/wmfsrc index 0f7d3c2..9b76d00 100644 --- a/wmfsrc +++ b/wmfsrc @@ -26,6 +26,9 @@ border = true #height = "-1" + light_shade = 0.10 + dark_shade = -0.10 + [systray] # Enable/disable systray active = true @@ -189,6 +192,9 @@ # Modifier for mouse use modifier = "Alt" + light_shade = 0.10 + dark_shade = -0.10 + # *DEPRECATED* but works, see [rules] section # Set automatic free or max client # autofree = "xterm|MPlayer" From ddcdf6ce835e87c7d4f5b8b5a3ce880de0d5833f Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Tue, 22 Feb 2011 23:25:39 -0800 Subject: [PATCH 10/19] Tag background wasn't shaded properly --- src/barwin.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index a9cb568..3176fe6 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -299,10 +299,15 @@ barwin_refresh_color(BarWindow *bw) if(bw->bord) { - XSetWindowBackground(dpy, bw->border.left, bw->border.light); - XSetWindowBackground(dpy, bw->border.top, bw->border.light); - XSetWindowBackground(dpy, bw->border.bottom, bw->border.dark); - XSetWindowBackground(dpy, bw->border.right, bw->border.dark); + //XSetWindowBackground(dpy, bw->border.left, bw->border.light); + //XSetWindowBackground(dpy, bw->border.top, bw->border.light); + //XSetWindowBackground(dpy, bw->border.bottom, bw->border.dark); + //XSetWindowBackground(dpy, bw->border.right, bw->border.dark); + + XSetWindowBackground(dpy, bw->border.left, color_shade(bw->border.light, conf.colors.bar_light_shade)); + XSetWindowBackground(dpy, bw->border.top, color_shade(bw->border.light, conf.colors.bar_light_shade)); + XSetWindowBackground(dpy, bw->border.bottom, color_shade(bw->border.dark, conf.colors.bar_dark_shade)); + XSetWindowBackground(dpy, bw->border.right, color_shade(bw->border.dark, conf.colors.bar_dark_shade)); XClearWindow(dpy, bw->border.left); XClearWindow(dpy, bw->border.top); From ac00fefaa9f556e1d5101b6ad79e83b4214fc726 Mon Sep 17 00:00:00 2001 From: Brian Mock Date: Wed, 23 Feb 2011 00:51:50 -0800 Subject: [PATCH 11/19] Fixed tag bar border drawing --- src/barwin.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index 3176fe6..49f7eb8 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -299,15 +299,10 @@ barwin_refresh_color(BarWindow *bw) if(bw->bord) { - //XSetWindowBackground(dpy, bw->border.left, bw->border.light); - //XSetWindowBackground(dpy, bw->border.top, bw->border.light); - //XSetWindowBackground(dpy, bw->border.bottom, bw->border.dark); - //XSetWindowBackground(dpy, bw->border.right, bw->border.dark); - - XSetWindowBackground(dpy, bw->border.left, color_shade(bw->border.light, conf.colors.bar_light_shade)); - XSetWindowBackground(dpy, bw->border.top, color_shade(bw->border.light, conf.colors.bar_light_shade)); - XSetWindowBackground(dpy, bw->border.bottom, color_shade(bw->border.dark, conf.colors.bar_dark_shade)); - XSetWindowBackground(dpy, bw->border.right, color_shade(bw->border.dark, conf.colors.bar_dark_shade)); + XSetWindowBackground(dpy, bw->border.left, color_shade(bw->bg, conf.colors.bar_light_shade)); + XSetWindowBackground(dpy, bw->border.top, color_shade(bw->bg, conf.colors.bar_light_shade)); + XSetWindowBackground(dpy, bw->border.bottom, color_shade(bw->bg, conf.colors.bar_dark_shade)); + XSetWindowBackground(dpy, bw->border.right, color_shade(bw->bg, conf.colors.bar_dark_shade)); XClearWindow(dpy, bw->border.left); XClearWindow(dpy, bw->border.top); From d213d13784e44ee05b6f717ff9395b47736f43dd Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 23 Feb 2011 15:15:31 +0100 Subject: [PATCH 12/19] Barwin/Frame: Optimization of saikobee feature --- src/barwin.c | 29 ++++++++++++++++++++------ src/client.c | 16 ++------------- src/frame.c | 57 +++++++++++++++++++++++++++++++++++++++++++-------- src/infobar.c | 3 ++- src/layout.c | 2 ++ src/structs.h | 1 + src/wmfs.h | 2 ++ 7 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/barwin.c b/src/barwin.c index 49f7eb8..2898dc9 100644 --- a/src/barwin.c +++ b/src/barwin.c @@ -81,6 +81,8 @@ barwin_create(Window parent, if(border) { bw->bord = True; + bw->border.light = color_shade(bg, conf.colors.bar_light_shade); + bw->border.dark = color_shade(bg, conf.colors.bar_dark_shade); 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); @@ -95,8 +97,6 @@ barwin_create(Window parent, bw->geo.height = h; bw->bg = bg; bw->fg = fg; - bw->border.light = color_shade(bg, conf.colors.bar_light_shade); - bw->border.dark = color_shade(bg, conf.colors.bar_dark_shade); bw->stipple = stipple; bw->stipple_color = -1; @@ -143,6 +143,23 @@ barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_imag return; } +void +barwin_color_set(BarWindow *bw, uint bg, char *fg) +{ + CHECK(bw); + + bw->bg = bg; + bw->fg = fg; + + if(bw->bord) + { + bw->border.light = color_shade(bg, conf.colors.bar_light_shade); + bw->border.dark = color_shade(bg, conf.colors.bar_dark_shade); + } + + return; +} + /** Delete a BarWindow * \param bw BarWindow pointer */ @@ -299,10 +316,10 @@ barwin_refresh_color(BarWindow *bw) if(bw->bord) { - XSetWindowBackground(dpy, bw->border.left, color_shade(bw->bg, conf.colors.bar_light_shade)); - XSetWindowBackground(dpy, bw->border.top, color_shade(bw->bg, conf.colors.bar_light_shade)); - XSetWindowBackground(dpy, bw->border.bottom, color_shade(bw->bg, conf.colors.bar_dark_shade)); - XSetWindowBackground(dpy, bw->border.right, color_shade(bw->bg, conf.colors.bar_dark_shade)); + XSetWindowBackground(dpy, bw->border.left, bw->border.light); + XSetWindowBackground(dpy, bw->border.top, bw->border.light); + XSetWindowBackground(dpy, bw->border.bottom, bw->border.dark); + XSetWindowBackground(dpy, bw->border.right, bw->border.dark); XClearWindow(dpy, bw->border.left); XClearWindow(dpy, bw->border.top); diff --git a/src/client.c b/src/client.c index 96b588c..c576077 100644 --- a/src/client.c +++ b/src/client.c @@ -360,19 +360,13 @@ client_focus(Client *c) if(sel && sel != c) { - sel->colors.frame = conf.client.bordernormal; - sel->colors.fg = conf.titlebar.fg_normal; - sel->colors.resizecorner = conf.client.resizecorner_normal; - - if(TBARH - BORDH && sel->titlebar->stipple) - sel->titlebar->stipple_color = conf.titlebar.stipple.colors.normal; - if(sel->flags & AboveFlag) sel->flags &= ~AboveFlag; XChangeProperty(dpy, sel->frame, net_atom[net_wm_window_opacity], XA_CARDINAL, 32, PropModeReplace, (uchar *)&conf.opacity, 1); + frame_update_color(sel, True); frame_update(sel); mouse_grabbuttons(sel, !conf.focus_pclick); @@ -380,10 +374,6 @@ client_focus(Client *c) if((sel = c)) { - c->colors.frame = conf.client.borderfocus; - c->colors.fg = conf.titlebar.fg_focus; - c->colors.resizecorner = conf.client.resizecorner_focus; - /* Set focusontag option */ for(cc = clients; cc; cc = cc->next) if(cc->focusontag == (int)c->tag) @@ -391,11 +381,9 @@ client_focus(Client *c) c->focusontag = seltag[selscreen]; - if(TBARH - BORDH && c->titlebar->stipple) - c->titlebar->stipple_color = conf.titlebar.stipple.colors.focus; - XDeleteProperty(dpy, c->frame, net_atom[net_wm_window_opacity]); + frame_update_color(c, False); frame_update(c); mouse_grabbuttons(c, True); diff --git a/src/frame.c b/src/frame.c index 22d7ff8..6481eb8 100644 --- a/src/frame.c +++ b/src/frame.c @@ -118,10 +118,13 @@ 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, 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); + c->colors.borddark = color_shade(c->colors.frame, conf.colors.client_dark_shade); + c->colors.bordlight = color_shade(c->colors.frame, conf.colors.client_light_shade); + + CWIN(c->left, c->frame, 0, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, c->colors.bordlight, &at); + CWIN(c->top, c->frame, 0, 0, c->frame_geo.width, SHADH, 0, CWBackPixel, c->colors.bordlight, &at); + CWIN(c->bottom, c->frame, 0, c->frame_geo.height - SHADH, c->frame_geo.width, SHADH, 0, CWBackPixel, c->colors.borddark, &at); + CWIN(c->right, c->frame, c->frame_geo.width - SHADH, 0, SHADH, c->frame_geo.height, 0, CWBackPixel, c->colors.borddark, &at); } /* Reparent window with the frame */ @@ -191,6 +194,44 @@ frame_moveresize(Client *c, XRectangle geo) return; } +/** Update frame colors for focus event + *\param c Client pointer +*/ +void +frame_update_color(Client *c, Bool focused) +{ + CHECK(c); + + /* Not focused client */ + if(focused) + { + c->colors.frame = conf.client.bordernormal; + c->colors.fg = conf.titlebar.fg_normal; + c->colors.resizecorner = conf.client.resizecorner_normal; + + if(TBARH - BORDH && c->titlebar->stipple) + c->titlebar->stipple_color = conf.titlebar.stipple.colors.normal; + } + /* Focused */ + else + { + c->colors.frame = conf.client.borderfocus; + c->colors.fg = conf.titlebar.fg_focus; + c->colors.resizecorner = conf.client.resizecorner_focus; + + if(TBARH - BORDH && c->titlebar->stipple) + c->titlebar->stipple_color = conf.titlebar.stipple.colors.focus; + } + + if(conf.client.border_shadow) + { + c->colors.borddark = color_shade(c->colors.frame, conf.colors.client_dark_shade); + c->colors.bordlight = color_shade(c->colors.frame, conf.colors.client_light_shade); + } + + return; +} + /** Update the client frame; Set the new color * and the title --> refresh * \param c Client pointer @@ -258,10 +299,10 @@ frame_update(Client *c) if(conf.client.border_shadow) { - XSetWindowBackground(dpy, c->left, color_shade(c->colors.frame, conf.colors.client_light_shade)); - XSetWindowBackground(dpy, c->top, color_shade(c->colors.frame, conf.colors.client_light_shade)); - XSetWindowBackground(dpy, c->right, color_shade(c->colors.frame, conf.colors.client_dark_shade)); - XSetWindowBackground(dpy, c->bottom, color_shade(c->colors.frame, conf.colors.client_dark_shade)); + XSetWindowBackground(dpy, c->left, c->colors.bordlight); + XSetWindowBackground(dpy, c->top, c->colors.bordlight); + XSetWindowBackground(dpy, c->right, c->colors.borddark); + XSetWindowBackground(dpy, c->bottom, c->colors.borddark); XClearWindow(dpy, c->left); XClearWindow(dpy, c->top); diff --git a/src/infobar.c b/src/infobar.c index d3a1306..2650b3e 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -272,6 +272,7 @@ infobar_draw_taglist(int sc) ? conf.colors.tag_occupied_fg : conf.colors.text)); + barwin_color_set(infobar[sc].tags[i], infobar[sc].tags[i]->bg, infobar[sc].tags[i]->fg); barwin_refresh_color(infobar[sc].tags[i]); if(tags[sc][i].name) @@ -417,7 +418,7 @@ uicb_infobar_toggledisplay(uicb_t cmd) ? 0 : (tags[selscreen][seltag[selscreen]].prev_barpos ? tags[selscreen][seltag[selscreen]].prev_barpos : 2 )); - + tags[selscreen][seltag[selscreen]].prev_barpos = tags[selscreen][seltag[selscreen]].barpos; tags[selscreen][seltag[selscreen]].barpos = new_pos; diff --git a/src/layout.c b/src/layout.c index 9f9ed13..71336aa 100644 --- a/src/layout.c +++ b/src/layout.c @@ -748,7 +748,9 @@ uicb_togglemax(uicb_t cmd) sel->free_geo = sel->geo; sel->flags &= ~(TileFlag | FreeFlag); client_maximize(sel); + XRaiseWindow(dpy, sel->frame); sel->flags |= MaxFlag; + } else { diff --git a/src/structs.h b/src/structs.h index cf540f2..0100c1f 100644 --- a/src/structs.h +++ b/src/structs.h @@ -216,6 +216,7 @@ struct Client uint frame; char *fg; uint resizecorner; + uint bordlight, borddark; } colors; /* Client Information by flags */ uint flags; diff --git a/src/wmfs.h b/src/wmfs.h index 46b6c47..6c6944e 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -120,6 +120,7 @@ BarWindow *barwin_create(Window parent, Bool border); void barwin_draw_text(BarWindow *bw, int x, int y, char *text); void barwin_draw_image_ofset_text(BarWindow *bw, int x, int y, char *text, int x_image_ofset, int y_image_ofset); +void barwin_color_set(BarWindow *bw, uint bg, char *fg); void barwin_delete(BarWindow *bw); void barwin_delete_subwin(BarWindow *bw); void barwin_map(BarWindow *bw); @@ -227,6 +228,7 @@ void ewmh_manage_window_type(Client *c); void frame_create(Client *c); void frame_delete(Client *c); void frame_moveresize(Client *c, XRectangle geo); +void frame_update_color(Client *c, Bool focused); void frame_update(Client *c); /* config.c */ From f5134bd6b3ddef7239e4a14bdbc267e28f2a9fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 20:38:17 +0100 Subject: [PATCH 13/19] Option -W is deprecated; -Wextra is its replacement --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index e3ab8a8..a17a550 100644 --- a/Makefile.in +++ b/Makefile.in @@ -33,7 +33,7 @@ src/wmfs.c # flags CFLAGS+= -DXDG_CONFIG_DIR=\"${XDG_CONFIG_DIR}\" CFLAGS+= -DWMFS_VERSION=\"${VERSION}\" -CFLAGS+= -W -Wall -Wextra +CFLAGS+= -Wall -Wextra OBJS= ${SRCS:.c=.o} From d79404f5ee1a8ab3ede62848b447aada012009b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 20:56:09 +0100 Subject: [PATCH 14/19] Avoid last ret char not being zero after strncpy --- src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index cbc1382..32e9f6f 100644 --- a/src/util.c +++ b/src/util.c @@ -360,7 +360,7 @@ patht(char *path) return NULL; strncpy(ret, path, sizeof(ret)); - + ret[sizeof(ret) - 1] = 0; if(strstr(path, "~/")) sprintf(ret, "%s/%s", getenv("HOME"), path + 2); From 9766392332ae8caf2709bd67ba82cdfac91ffda1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 20:57:01 +0100 Subject: [PATCH 15/19] Avoid overflow on ret --- src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index 32e9f6f..6306f3b 100644 --- a/src/util.c +++ b/src/util.c @@ -362,7 +362,7 @@ patht(char *path) strncpy(ret, path, sizeof(ret)); ret[sizeof(ret) - 1] = 0; if(strstr(path, "~/")) - sprintf(ret, "%s/%s", getenv("HOME"), path + 2); + snprintf(ret, sizeof(ret), "%s/%s", getenv("HOME"), path + 2); return ret; } From 7d66c5067661630f4b9beaab015c9016a878726a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 21:12:57 +0100 Subject: [PATCH 16/19] Cosmetic --- src/client.c | 3 --- src/draw.c | 2 -- src/event.c | 2 -- src/infobar.c | 1 - src/layout.c | 1 - src/menu.c | 2 -- 6 files changed, 11 deletions(-) diff --git a/src/client.c b/src/client.c index c576077..0a9bb30 100644 --- a/src/client.c +++ b/src/client.c @@ -1259,7 +1259,6 @@ client_focus_next(Client *c) return; } - /** Unmanage a client * \param c Client pointer */ @@ -1420,7 +1419,6 @@ uicb_client_screen_prev(uicb_t cmd) return; } - /** Move a client *\param cmd uicb_t type */ @@ -1610,4 +1608,3 @@ uicb_client_ignore_tag(uicb_t cmd) return; } - diff --git a/src/draw.c b/src/draw.c index 8cf8a5d..d4a59c4 100644 --- a/src/draw.c +++ b/src/draw.c @@ -231,5 +231,3 @@ textw(char *text) return gl.width + font->descent; } - - diff --git a/src/event.c b/src/event.c index 26e5a34..4ca0dff 100644 --- a/src/event.c +++ b/src/event.c @@ -605,7 +605,6 @@ reparentnotify(XReparentEvent *ev) return; } - /** SelectionClearEvent handle event * \param ev XSelectionClearEvent pointer */ @@ -621,7 +620,6 @@ selectionclearevent(XSelectionClearEvent *ev) return; } - /** UnmapNotify handle event * \param ev XUnmapEvent pointer */ diff --git a/src/infobar.c b/src/infobar.c index 2650b3e..c97b262 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -321,7 +321,6 @@ infobar_update_taglist(int sc) return; } - /** Destroy the InfoBar */ void diff --git a/src/layout.c b/src/layout.c index 71336aa..9035733 100644 --- a/src/layout.c +++ b/src/layout.c @@ -729,7 +729,6 @@ uicb_togglefree(uicb_t cmd) return; } - /** Toggle the selected client to max * \param cmd uicb_t type unused */ diff --git a/src/menu.c b/src/menu.c index c8c8160..8ded5ee 100644 --- a/src/menu.c +++ b/src/menu.c @@ -49,7 +49,6 @@ menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, c return; } - void menu_new_item(MenuItem *mi, char *name, void *func, char *cmd) { @@ -358,4 +357,3 @@ menu_get_checkstring_needed(MenuItem *mi, int nitem) (void)nitem; return True; } - From 22c9eee9afd7b45bd9c128175a1abbe93e2b0471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 21:58:17 +0100 Subject: [PATCH 17/19] Remove unused functions --- src/layout.c | 7 ------- src/util.c | 22 ---------------------- src/wmfs.h | 1 - 3 files changed, 30 deletions(-) diff --git a/src/layout.c b/src/layout.c index 9035733..e29ecdd 100644 --- a/src/layout.c +++ b/src/layout.c @@ -689,13 +689,6 @@ grid_vertical(int screen) /** Put the selected client to the master postion * \param cmd uicb_t type unused */ -void -uicb_tile_switch(uicb_t cmd) -{ - (void)cmd; - layout_set_client_master (sel); - return; -} /** Toggle the selected client to free * \param cmd uicb_t type unused diff --git a/src/util.c b/src/util.c index 6306f3b..bad11c1 100644 --- a/src/util.c +++ b/src/util.c @@ -210,28 +210,6 @@ layout_name_to_struct(Layout lt[], char *name, int n, const func_name_list_t lli return lt[0]; } - -char* -alias_to_str(char *conf_choice) -{ - int i; - char *tmpchar = NULL; - - if(!conf_choice) - return 0; - - if(conf.alias) - for(i = 0; conf.alias[i].name; i++) - if(!strcmp(conf_choice, conf.alias[i].name)) - tmpchar = conf.alias[i].content; - - if(tmpchar) - return xstrdup(tmpchar); - else - return xstrdup(conf_choice); - - return NULL; -} /* }}} */ /** Execute a sh command diff --git a/src/wmfs.h b/src/wmfs.h index 6c6944e..e3ad539 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -300,7 +300,6 @@ void* name_to_func(char *name, const func_name_list_t *l); ulong char_to_modkey(char *name, key_name_list_t key_l[]); uint char_to_button(char *name, name_to_uint_t blist[]); Layout layout_name_to_struct(Layout lt[], char *name, int n, const func_name_list_t llist[]); -char* alias_to_str(char *conf_choice); /* }}} */ char *char_to_str(const char c); pid_t spawn(const char *str, ...); From 6a0eedb63cd6f6f364c42102e2d1fb4765242f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 21:00:46 +0100 Subject: [PATCH 18/19] Make a bunch of stuff static --- src/client.c | 18 +++++++++++------- src/config.c | 4 ++-- src/draw.c | 4 ++++ src/event.c | 30 ++++++++++++++--------------- src/infobar.c | 4 +++- src/launcher.c | 2 +- src/layout.c | 8 ++++---- src/menu.c | 20 ++++++++++++++------ src/mouse.c | 8 ++++---- src/status.c | 8 ++++---- src/tag.c | 11 +++++++---- src/viwmfs.c | 4 ++-- src/wmfs.c | 10 +++++----- src/wmfs.h | 51 -------------------------------------------------- 14 files changed, 76 insertions(+), 106 deletions(-) diff --git a/src/client.c b/src/client.c index 0a9bb30..b1e6f71 100644 --- a/src/client.c +++ b/src/client.c @@ -88,7 +88,7 @@ client_detach(Client *c) /** Get the next client *\return The next client or NULL */ -Client* +static Client* client_get_next(void) { Client *c = NULL; @@ -109,7 +109,7 @@ client_get_next(void) /** Get the previous client *\return The previous client or NULL */ -Client* +static Client* client_get_prev(void) { Client *c = NULL, *d; @@ -135,7 +135,7 @@ client_get_prev(void) *\param pos Position (Left/Right/Top/Bottom *\return Client found */ -Client* +static Client* client_get_next_with_direction(Position pos) { Client *c = NULL; @@ -322,7 +322,7 @@ uicb_client_focus_bottom(uicb_t cmd) /** Set the client c above *\param c Client pointer */ -void +static void client_above(Client *c) { XRectangle geo; @@ -664,6 +664,8 @@ client_map(Client *c) return; } +static void client_set_rules(Client *c); + /** Manage a client with a window and his attributes * \param w Cient's futur Window * \param wa XWindowAttributes pointer, Window w attributes @@ -1037,7 +1039,7 @@ client_swap(Client *c1, Client *c2) /** Set the wanted tag or autofree/max of a client *\param c Client pointer */ -void +static void client_set_rules(Client *c) { XClassHint xch; @@ -1352,7 +1354,7 @@ client_unmap(Client *c) *\param c Client pointer *\param s Screen id */ -void +static void client_set_screen(Client *c, int s) { int os; @@ -1489,6 +1491,8 @@ uicb_ignore_next_client_rules(uicb_t cmd) return; } +static void uicb_client_select(uicb_t cmd); + /** Show clientlist menu *\param cmd uicb_t type */ @@ -1551,7 +1555,7 @@ uicb_clientlist(uicb_t cmd) /** Select client *\param cmd uicb_t type clientlist index */ -void +static void uicb_client_select(uicb_t cmd) { int i; diff --git a/src/config.c b/src/config.c index 2d7c74d..68119c0 100644 --- a/src/config.c +++ b/src/config.c @@ -100,7 +100,7 @@ const func_name_list_t func_list[] = {NULL, NULL} }; -key_name_list_t key_list[] = +static key_name_list_t key_list[] = { {"Control", ControlMask }, {"Shift", ShiftMask }, @@ -115,7 +115,7 @@ key_name_list_t key_list[] = {NULL, NoSymbol } }; -name_to_uint_t mouse_button_list[] = +static name_to_uint_t mouse_button_list[] = { {"Button1", Button1 }, {"Button2", Button2 }, diff --git a/src/draw.c b/src/draw.c index d4a59c4..b2a80ad 100644 --- a/src/draw.c +++ b/src/draw.c @@ -32,6 +32,10 @@ #include "wmfs.h" +#ifdef HAVE_IMLIB +static void draw_image(Drawable dr, int x, int y, int w, int h, char *name); +#endif /* HAVE_IMLIB */ + void draw_text(Drawable d, int x, int y, char* fg, char *str) { diff --git a/src/event.c b/src/event.c index 4ca0dff..b38b428 100644 --- a/src/event.c +++ b/src/event.c @@ -35,7 +35,7 @@ /** ButtonPress handle event * \param ev XButtonEvent pointer */ -void +static void buttonpress(XButtonEvent *ev) { Client *c; @@ -162,7 +162,7 @@ buttonpress(XButtonEvent *ev) /* ClientMessage handle event *\param ev XClientMessageEvent pointer */ -void +static void clientmessageevent(XClientMessageEvent *ev) { Client *c; @@ -289,7 +289,7 @@ clientmessageevent(XClientMessageEvent *ev) /** ConfigureRequesthandle events * \param ev XConfigureRequestEvent pointer */ -void +static void configureevent(XConfigureRequestEvent *ev) { XWindowChanges wc; @@ -342,7 +342,7 @@ configureevent(XConfigureRequestEvent *ev) /** DestroyNotify handle event * \param ev XDestroyWindowEvent pointer */ -void +static void destroynotify(XDestroyWindowEvent *ev) { Client *c; @@ -366,7 +366,7 @@ destroynotify(XDestroyWindowEvent *ev) /** EnterNotify handle event * \param ev XCrossingEvent pointer */ -void +static void enternotify(XCrossingEvent *ev) { Client *c; @@ -399,7 +399,7 @@ enternotify(XCrossingEvent *ev) /** ExposeEvent handle event * \param ev XExposeEvent pointer */ -void +static void expose(XExposeEvent *ev) { Client *c; @@ -430,7 +430,7 @@ expose(XExposeEvent *ev) * \param ev XFocusChangeEvent pointer * \return */ -void +static void focusin(XFocusChangeEvent *ev) { if(sel && ev->window != sel->win) @@ -463,7 +463,7 @@ grabkeys(void) /** KeyPress handle event * \param ev XKeyPressedEvent pointer */ -void +static void keypress(XKeyPressedEvent *ev) { int i; @@ -483,7 +483,7 @@ keypress(XKeyPressedEvent *ev) /** MappingNotify handle event * \param ev XMappingEvent pointer */ -void +static void mappingnotify(XMappingEvent *ev) { XRefreshKeyboardMapping(ev); @@ -497,7 +497,7 @@ mappingnotify(XMappingEvent *ev) /** MapNotify handle event * \param ev XMapEvent pointer */ -void +static void mapnotify(XMapEvent *ev) { Client *c; @@ -520,7 +520,7 @@ mapnotify(XMapEvent *ev) /** MapRequest handle event * \param ev XMapRequestEvent pointer */ -void +static void maprequest(XMapRequestEvent *ev) { XWindowAttributes at; @@ -543,7 +543,7 @@ maprequest(XMapRequestEvent *ev) /** PropertyNotify handle event * \param ev XPropertyEvent pointer */ -void +static void propertynotify(XPropertyEvent *ev) { Client *c; @@ -597,7 +597,7 @@ propertynotify(XPropertyEvent *ev) /** XReparentEvent handle event * \param ev XReparentEvent pointer */ -void +static void reparentnotify(XReparentEvent *ev) { (void)ev; @@ -608,7 +608,7 @@ reparentnotify(XReparentEvent *ev) /** SelectionClearEvent handle event * \param ev XSelectionClearEvent pointer */ -void +static void selectionclearevent(XSelectionClearEvent *ev) { /* Getting selection if lost it */ @@ -623,7 +623,7 @@ selectionclearevent(XSelectionClearEvent *ev) /** UnmapNotify handle event * \param ev XUnmapEvent pointer */ -void +static void unmapnotify(XUnmapEvent *ev) { Client *c; diff --git a/src/infobar.c b/src/infobar.c index c97b262..4156355 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -135,6 +135,8 @@ infobar_init(void) return; } +static void infobar_draw_layout(int sc); + /** Draw the Infobar *\param sc Screen number */ @@ -153,7 +155,7 @@ infobar_draw(int sc) /** Draw the layout button in the InfoBar *\param sc Screen number */ -void +static void infobar_draw_layout(int sc) { if(!conf.layout_placement) diff --git a/src/launcher.c b/src/launcher.c index 3aa32f3..2df2160 100644 --- a/src/launcher.c +++ b/src/launcher.c @@ -35,7 +35,7 @@ static char *complete_on_command(char*, size_t); static char *complete_on_files(char*, size_t); -void +static void launcher_execute(Launcher *launcher) { BarWindow *bw; diff --git a/src/layout.c b/src/layout.c index e29ecdd..5cea3c2 100644 --- a/src/layout.c +++ b/src/layout.c @@ -168,7 +168,7 @@ maxlayout(int screen) * \param c Client pointer * \return a client pointer */ -Client* +static Client* tiled_client(int screen, Client *c) { for(;c && ((c->flags & MaxFlag) @@ -235,7 +235,7 @@ uicb_set_nmaster(uicb_t cmd) /** Grid layout function */ -void +static void grid(int screen, Bool horizontal) { Client *c; @@ -300,7 +300,7 @@ grid(int screen, Bool horizontal) /** Multi tile function * \param type Postion type { Top, Bottom, Left, Right } */ -void +static void multi_tile(int screen, Position type) { Client *c; @@ -430,7 +430,7 @@ multi_tile(int screen, Position type) * \param screen Screen to execute this function * \param horizont To specify the mirror mode (vertical/horizontal) */ -void +static void mirror(int screen, Bool horizontal) { Client *c; diff --git a/src/menu.c b/src/menu.c index 8ded5ee..1301353 100644 --- a/src/menu.c +++ b/src/menu.c @@ -32,6 +32,14 @@ #include "wmfs.h" +static Bool menu_activate_item(Menu *menu, int i); +static Bool menu_get_checkstring_needed(MenuItem *mi, int nitem); +static Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); +static Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); +static int menu_get_longer_string(MenuItem *mi, int nitem); +static void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen); +static void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]); + void menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n) { @@ -122,7 +130,7 @@ menu_draw(Menu menu, int x, int y) return; } -Bool +static Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]) { int i, c = 0; @@ -208,7 +216,7 @@ menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]) return quit; } -Bool +static Bool menu_activate_item(Menu *menu, int i) { int j, x, y; @@ -239,7 +247,7 @@ menu_activate_item(Menu *menu, int i) return False; } -void +static void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]) { int i; @@ -268,7 +276,7 @@ menu_focus_item(Menu *menu, int item, BarWindow *winitem[]) return; } -void +static void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen) { int x; @@ -299,7 +307,7 @@ menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen) return; } -int +static int menu_get_longer_string(MenuItem *mi, int nitem) { int i, w, l = 0; @@ -350,7 +358,7 @@ menu_clear(Menu *menu) return; } -Bool +static Bool menu_get_checkstring_needed(MenuItem *mi, int nitem) { (void)mi; diff --git a/src/mouse.c b/src/mouse.c index 3d75f1f..cb042c6 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -34,7 +34,7 @@ /** Draw the border when a client in dragging/resizing with mouse */ -void +static void mouse_dragborder(XRectangle geo, GC g) { XDrawRectangle(dpy, ROOT, g, @@ -49,7 +49,7 @@ mouse_dragborder(XRectangle geo, GC g) /** Move a client in tile grid with the mouse *\param c Client double pointer */ -void +static void mouse_move_tile_client(Client **c) { Client *sc; @@ -76,7 +76,7 @@ mouse_move_tile_client(Client **c) /** Move a client from one tag to another with dah mouse *\param c client pointer */ -void +static void mouse_move_tag_client(Client *c) { Window w; @@ -110,7 +110,7 @@ mouse_move_tag_client(Client *c) /** Move the client with the mouse * \param c Client pointer */ -void +static void mouse_move(Client *c) { int ocx, ocy, mx, my; diff --git a/src/status.c b/src/status.c index ea78f17..e052b43 100644 --- a/src/status.c +++ b/src/status.c @@ -38,7 +38,7 @@ *\param str String *\return n Length of r */ -int +static int statustext_rectangle(StatusRec *r, char *str) { char as; @@ -62,7 +62,7 @@ statustext_rectangle(StatusRec *r, char *str) *\param str String *\return n Length of g */ -int +static int statustext_graph(StatusGraph *g, char *str) { char as, c, *p; @@ -112,7 +112,7 @@ statustext_graph(StatusGraph *g, char *str) *\param str String *\return n Length of s */ -int +static int statustext_text(StatusText *s, char *str) { char as; @@ -135,7 +135,7 @@ statustext_text(StatusText *s, char *str) *\param sc Screen *\param str String */ -void +static void statustext_normal(int sc, char *str) { char strwc[MAXSTATUS] = { 0 }; diff --git a/src/tag.c b/src/tag.c index 5e89d61..473ff4a 100644 --- a/src/tag.c +++ b/src/tag.c @@ -303,6 +303,9 @@ uicb_tag_last(uicb_t cmd) return; } +static void tag_swap(int s, int t1, int t2); +static void remove_old_last_tag(int selscreen); + /** Keep that tag the last one *\param cmd uicb_t type unused */ @@ -471,7 +474,7 @@ uicb_tag_toggle_additional(uicb_t cmd) *\param t1 Tag 1 *\param t2 Tag 2 */ -void +static void tag_swap(int s, int t1, int t2) { Client *c; @@ -552,7 +555,7 @@ uicb_tag_swap_previous(uicb_t cmd) *\param s Screen number *\param name New tag name */ -void +static void tag_new(int s, char *name) { char * displayedName; @@ -623,7 +626,7 @@ uicb_tag_new(uicb_t cmd) *\param s Screen number *\param tag Tag number */ -void +static void tag_delete(int s, int tag) { Tag t; @@ -719,7 +722,7 @@ uicb_tag_rename(uicb_t cmd) /** *\param selscreen int */ -void +static void remove_old_last_tag(int selscreen) { int i; diff --git a/src/viwmfs.c b/src/viwmfs.c index a8fc7dd..7b9baf3 100644 --- a/src/viwmfs.c +++ b/src/viwmfs.c @@ -32,7 +32,7 @@ #include "wmfs.h" -vicmd_to_uicb vicmd[] = +static vicmd_to_uicb vicmd[] = { {"r", "reload"}, {"q", "quit"}, @@ -62,7 +62,7 @@ vicmd_to_uicb vicmd[] = {"tf", "toggle_free"}, }; -void +static void viwmfs_help(void) { size_t i; diff --git a/src/wmfs.c b/src/wmfs.c index 800efe3..3821890 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -159,7 +159,7 @@ wait_childs_and_status(void) pthread_mutex_unlock(&mtx); } -void * +static void * thread_status(void *arg) { (void)arg; @@ -186,7 +186,7 @@ thread_status(void *arg) /** WMFS main loop. */ -void +static void mainloop(void) { XEvent ev; @@ -227,7 +227,7 @@ uicb_quit(uicb_t cmd) /** Scan if there are windows on X * for manage it */ -void +static void scan(void) { uint n; @@ -374,7 +374,7 @@ exec_uicb_function(char *func, char *cmd) /** Set statustext *\param str Statustext string */ -void +static void set_statustext(int s, char *str) { int i; @@ -410,7 +410,7 @@ set_statustext(int s, char *str) /** Update status script by ewmh hint */ -void +static void update_status(void) { if(!check_wmfs_running()) diff --git a/src/wmfs.h b/src/wmfs.h index e3ad539..09d31d2 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -138,16 +138,11 @@ void draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_ void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color); void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data); -#ifdef HAVE_IMLIB -void draw_image(Drawable dr, int x, int y, int w, int h, char *name); -#endif /* HAVE_IMLIB */ - ushort textw(char *text); /* infobar.c */ void infobar_init(void); void infobar_draw(int sc); -void infobar_draw_layout(int sc); void infobar_draw_selbar(int sc); void infobar_draw_taglist(int sc); void infobar_update_taglist(int sc); @@ -161,11 +156,7 @@ void uicb_toggle_tagautohide(uicb_t); void client_attach(Client *c); void client_configure(Client *c); void client_detach(Client *c); -void client_above(Client *c); void client_focus(Client *c); -Client* client_get_next(void); -Client* client_get_prev(void); -Client* client_get_next_with_direction(Position pos); /* client_gb_*() {{{ */ Client* client_gb_win(Window w); Client* client_gb_frame(Window w); @@ -189,7 +180,6 @@ void client_unhide(Client *c); void client_focus_next(Client *c); void client_unmanage(Client *c); void client_unmap(Client *c); -void client_set_rules(Client *c); void client_update_attributes(Client *c); void client_urgent(Client *c, Bool u); void uicb_client_raise(uicb_t); @@ -208,7 +198,6 @@ void uicb_client_move(uicb_t cmd); void uicb_client_resize(uicb_t cmd); void uicb_ignore_next_client_rules(uicb_t cmd); void uicb_clientlist(uicb_t cmd); -void uicb_client_select(uicb_t cmd); Bool uicb_checkclist(uicb_t); void uicb_client_ignore_tag(uicb_t); @@ -238,46 +227,20 @@ void init_conf(void); uint color_shade(uint, double); /* event.c */ -void buttonpress(XButtonEvent *ev); -void configureevent(XConfigureRequestEvent *ev); -void clientmessageevent(XClientMessageEvent *ev); -void destroynotify(XDestroyWindowEvent *ev); -void enternotify(XCrossingEvent *ev); -void expose(XExposeEvent *ev); -void focusin(XFocusChangeEvent *ev); void grabkeys(void); -void keypress(XKeyPressedEvent *ev); -void mappingnotify(XMappingEvent *ev); -void mapnotify(XMapEvent *ev); -void maprequest(XMapRequestEvent *ev); -void reparentnotify(XReparentEvent *ev); -void selectionclearevent(XSelectionClearEvent *ev); -void propertynotify(XPropertyEvent *ev); -void unmapnotify(XUnmapEvent *ev); void getevent(XEvent ev); /* menu.c */ void menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n); void menu_new_item(MenuItem *mi, char *name, void *func, char *cmd); void menu_draw(Menu menu, int x, int y); -Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); -Bool menu_activate_item(Menu *menu, int i); -void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]); -void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen); -int menu_get_longer_string(MenuItem *mi, int nitem); void uicb_menu(uicb_t cmd); void menu_clear(Menu *menu); -Bool menu_get_checkstring_needed(MenuItem *mi, int nitem); /* launcher.c */ -void launcher_execute(Launcher *launcher); void uicb_launcher(uicb_t); /* mouse.c */ -void mouse_dragborder(XRectangle geo, GC g); -void mouse_move_tile_client(Client **c); -void mouse_move_tag_client(Client *c); -void mouse_move(Client *c); void mouse_resize(Client *c); void mouse_grabbuttons(Client *c, Bool focused); void uicb_mouse_move(uicb_t); @@ -328,18 +291,14 @@ void uicb_tagtransfert_prev(uicb_t); void uicb_tag_urgent(uicb_t cmd); void tag_additional(int sc, int tag, int adtag); void uicb_tag_toggle_additional(uicb_t); -void tag_swap(int s, int t1, int t2); void uicb_tag_swap(uicb_t); void uicb_tag_swap_next(uicb_t); void uicb_tag_swap_previous(uicb_t); -void tag_new(int s, char *name); void uicb_tag_new(uicb_t); -void tag_delete(int s, int tag); void uicb_tag_del(uicb_t); void uicb_tag_rename(uicb_t cmd); void uicb_tag_last(uicb_t cmd); void uicb_tag_stay_last(uicb_t cmd); -void remove_old_last_tag(int selscreen); /* screen.c */ int screen_count(void); @@ -354,10 +313,6 @@ void uicb_screen_prev(uicb_t); void uicb_screen_prev_sel(uicb_t); /* status.c */ -int statustext_rectangle(StatusRec *r, char *str); -int statustext_graph(StatusGraph *g, char *str); -int statustext_text(StatusText *s, char *str); -void statustext_normal(int sc, char *str); void statustext_handle(int sc, char *str); /* systray.c */ @@ -375,9 +330,7 @@ void arrange(int screen, Bool update_layout); void freelayout(int screen); void layoutswitch(Bool b); void maxlayout(int screen); -Client *tiled_client(int screen, Client *c); /* tile {{{ */ - void grid(int screen, Bool horizontal); void tile(int screen); void tile_left(int screen); void tile_top(int screen); @@ -415,12 +368,8 @@ int errorhandler(Display *d, XErrorEvent *event); int errorhandlerdummy(Display *d, XErrorEvent *event); void quit(void); void *thread_process(void *arg); -void mainloop(void); -void scan(void); Bool check_wmfs_running(void); void exec_uicb_function(char *func, char *cmd); -void set_statustext(int s, char *str); -void update_status(void); void handle_signal(int signum); void uicb_quit(uicb_t); void uicb_reload(uicb_t); From 6291639b24ed01b9646391b12d7a9f136dfa8261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Wed, 23 Feb 2011 22:25:11 +0100 Subject: [PATCH 19/19] Remove a lot of static declarations A lot of functions are also moved in the process. --- src/client.c | 340 +++++++++++++++++++++++----------------------- src/color.c | 56 ++++---- src/draw.c | 81 ++++++----- src/event.c | 42 +++--- src/infobar.c | 32 +++-- src/launcher.c | 293 ++++++++++++++++++++-------------------- src/layout.c | 40 +++--- src/menu.c | 360 ++++++++++++++++++++++++------------------------- src/tag.c | 105 +++++++-------- src/wmfs.c | 2 - 10 files changed, 659 insertions(+), 692 deletions(-) diff --git a/src/client.c b/src/client.c index b1e6f71..ac7dfc5 100644 --- a/src/client.c +++ b/src/client.c @@ -664,7 +664,142 @@ client_map(Client *c) return; } -static void client_set_rules(Client *c); +/** Set the wanted tag or autofree/max of a client + *\param c Client pointer +*/ +static void +client_set_rules(Client *c) +{ + XClassHint xch; + int i, j, k, f; + Atom rf; + ulong n, il; + uchar *data = NULL; + char wwrole[256] = { 0 }; + Bool applied_tag_rule = False; + Bool applied_screen_rule = False; + + memset(&xch, 0, sizeof(xch)); + + if(conf.ignore_next_client_rules) + { + conf.ignore_next_client_rules = False; + return; + } + + /* Get WM_CLASS */ + XGetClassHint(dpy, c->win, &xch); + + /* Get WM_WINDOW_ROLE */ + if(XGetWindowProperty(dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, False, + XA_STRING, &rf, &f, &n, &il, &data) == Success && data) + { + strncpy(wwrole, (char*)data, sizeof(wwrole)); + XFree(data); + } + + /* Following features is *DEPRECATED*, will be removed in some revision. {{{ */ + + /* Auto free */ + if(conf.client.autofree && ((xch.res_name && strstr(conf.client.autofree, xch.res_name)) + || (xch.res_class && strstr(conf.client.autofree, xch.res_class)))) + c->flags |= FreeFlag; + + /* Auto maximize */ + if(conf.client.automax && ((xch.res_name && strstr(conf.client.automax, xch.res_name)) + || (xch.res_class && strstr(conf.client.automax, xch.res_class)))) + { + client_maximize(c); + c->flags |= MaxFlag; + } + + /* Wanted tag */ + for(i = 0; i < screen_count(); ++i) + for(j = 1; j < conf.ntag[i] + 1; ++j) + if(tags[i][j].clients) + for(k = 0; k < tags[i][j].nclients; ++k) + if((xch.res_name && strstr(xch.res_name, tags[i][j].clients[k])) + || (xch.res_class && strstr(xch.res_class, tags[i][j].clients[k]))) + { + c->screen = i; + c->tag = j; + + if(c->tag != (uint)seltag[selscreen]) + tags[c->screen][c->tag].request_update = True; + else + tags[c->screen][c->tag].layout.func(c->screen); + + /* Deprecated but still in use */ + applied_tag_rule = True; + applied_screen_rule = True; + } + + /* }}} */ + + /* Apply Rule if class || instance || role match */ + for(i = 0; i < conf.nrule; ++i) + { + if((xch.res_class && conf.rule[i].class && !strcmp(xch.res_class, conf.rule[i].class)) + || (xch.res_name && conf.rule[i].instance && !strcmp(xch.res_name, conf.rule[i].instance))) + { + if((strlen(wwrole) && conf.rule[i].role && !strcmp(wwrole, conf.rule[i].role)) || (!strlen(wwrole) || !conf.rule[i].role)) + { + if(conf.rule[i].screen != -1) + c->screen = conf.rule[i].screen; + + if(conf.rule[i].tag != -1) + { + c->tag = conf.rule[i].tag; + applied_tag_rule = True; + } + + if(conf.rule[i].free) + c->flags |= FreeFlag; + + if(conf.rule[i].ignoretags) + c->tag = MAXTAG + 1; + + if(conf.rule[i].max) + { + client_maximize(c); + c->flags |= MaxFlag; + } + + if(c->tag != (uint)seltag[selscreen]) + { + tags[c->screen][c->tag].request_update = True; + client_focus(NULL); + } + + if(!conf.rule[i].ignoretags) + tags[c->screen][c->tag].layout.func(c->screen); + + if(conf.rule[i].follow_client) + seltag[c->screen] = c->tag; + } + } + } + + if(!applied_tag_rule && conf.client.default_open_tag > 0 + && conf.client.default_open_tag < (uint)conf.ntag[selscreen]) + { + c->tag = conf.client.default_open_tag; + + client_focus_next(c); + tags[c->screen][c->tag].request_update = True; + } + + if(!applied_screen_rule && conf.client.default_open_screen > -1 + && conf.client.default_open_screen < screen_count()) + { + c->screen = conf.client.default_open_screen; + + client_focus_next(c); + tags[c->screen][c->tag].request_update = True; + } + + return; +} /** Manage a client with a window and his attributes * \param w Cient's futur Window @@ -1036,143 +1171,6 @@ client_swap(Client *c1, Client *c2) return; } -/** Set the wanted tag or autofree/max of a client - *\param c Client pointer -*/ -static void -client_set_rules(Client *c) -{ - XClassHint xch; - int i, j, k, f; - Atom rf; - ulong n, il; - uchar *data = NULL; - char wwrole[256] = { 0 }; - Bool applied_tag_rule = False; - Bool applied_screen_rule = False; - - memset(&xch, 0, sizeof(xch)); - - if(conf.ignore_next_client_rules) - { - conf.ignore_next_client_rules = False; - return; - } - - /* Get WM_CLASS */ - XGetClassHint(dpy, c->win, &xch); - - /* Get WM_WINDOW_ROLE */ - if(XGetWindowProperty(dpy, c->win, ATOM("WM_WINDOW_ROLE"), 0L, 0x7FFFFFFFL, False, - XA_STRING, &rf, &f, &n, &il, &data) == Success && data) - { - strncpy(wwrole, (char*)data, sizeof(wwrole)); - XFree(data); - } - - /* Following features is *DEPRECATED*, will be removed in some revision. {{{ */ - - /* Auto free */ - if(conf.client.autofree && ((xch.res_name && strstr(conf.client.autofree, xch.res_name)) - || (xch.res_class && strstr(conf.client.autofree, xch.res_class)))) - c->flags |= FreeFlag; - - /* Auto maximize */ - if(conf.client.automax && ((xch.res_name && strstr(conf.client.automax, xch.res_name)) - || (xch.res_class && strstr(conf.client.automax, xch.res_class)))) - { - client_maximize(c); - c->flags |= MaxFlag; - } - - /* Wanted tag */ - for(i = 0; i < screen_count(); ++i) - for(j = 1; j < conf.ntag[i] + 1; ++j) - if(tags[i][j].clients) - for(k = 0; k < tags[i][j].nclients; ++k) - if((xch.res_name && strstr(xch.res_name, tags[i][j].clients[k])) - || (xch.res_class && strstr(xch.res_class, tags[i][j].clients[k]))) - { - c->screen = i; - c->tag = j; - - if(c->tag != (uint)seltag[selscreen]) - tags[c->screen][c->tag].request_update = True; - else - tags[c->screen][c->tag].layout.func(c->screen); - - /* Deprecated but still in use */ - applied_tag_rule = True; - applied_screen_rule = True; - } - - /* }}} */ - - /* Apply Rule if class || instance || role match */ - for(i = 0; i < conf.nrule; ++i) - { - if((xch.res_class && conf.rule[i].class && !strcmp(xch.res_class, conf.rule[i].class)) - || (xch.res_name && conf.rule[i].instance && !strcmp(xch.res_name, conf.rule[i].instance))) - { - if((strlen(wwrole) && conf.rule[i].role && !strcmp(wwrole, conf.rule[i].role)) || (!strlen(wwrole) || !conf.rule[i].role)) - { - if(conf.rule[i].screen != -1) - c->screen = conf.rule[i].screen; - - if(conf.rule[i].tag != -1) - { - c->tag = conf.rule[i].tag; - applied_tag_rule = True; - } - - if(conf.rule[i].free) - c->flags |= FreeFlag; - - if(conf.rule[i].ignoretags) - c->tag = MAXTAG + 1; - - if(conf.rule[i].max) - { - client_maximize(c); - c->flags |= MaxFlag; - } - - if(c->tag != (uint)seltag[selscreen]) - { - tags[c->screen][c->tag].request_update = True; - client_focus(NULL); - } - - if(!conf.rule[i].ignoretags) - tags[c->screen][c->tag].layout.func(c->screen); - - if(conf.rule[i].follow_client) - seltag[c->screen] = c->tag; - } - } - } - - if(!applied_tag_rule && conf.client.default_open_tag > 0 - && conf.client.default_open_tag < (uint)conf.ntag[selscreen]) - { - c->tag = conf.client.default_open_tag; - - client_focus_next(c); - tags[c->screen][c->tag].request_update = True; - } - - if(!applied_screen_rule && conf.client.default_open_screen > -1 - && conf.client.default_open_screen < screen_count()) - { - c->screen = conf.client.default_open_screen; - - client_focus_next(c); - tags[c->screen][c->tag].request_update = True; - } - - return; -} - /** Update client attributes (_WMFS_TAG _WMFS_SCREEN) *\param c Client pointer */ @@ -1491,7 +1489,38 @@ uicb_ignore_next_client_rules(uicb_t cmd) return; } -static void uicb_client_select(uicb_t cmd); +/** Select client + *\param cmd uicb_t type clientlist index + */ +static void +uicb_client_select(uicb_t cmd) +{ + int i; + Window w; + int d, x, y; + + + for(i = 0; i < MAXCLIST && clist_index[i].client; ++i) + if(!strcmp(cmd, clist_index[i].key)) + { + if(clist_index[i].client->screen != selscreen) + screen_set_sel(clist_index[i].client->screen); + + if(clist_index[i].client->tag != (uint)seltag[clist_index[i].client->screen]) + tag_set(clist_index[i].client->tag); + + client_focus(clist_index[i].client); + client_raise(clist_index[i].client); + + /* Move pointer on client */ + XQueryPointer(dpy, ROOT, &w, &w, &x, &y, &d, &d, (uint *)&d); + XWarpPointer(dpy, ROOT, ROOT, x, y, d, d, + clist_index[i].client->geo.x + clist_index[i].client->geo.width / 2, + clist_index[i].client->geo.y + clist_index[i].client->geo.height / 2); + } + + return; +} /** Show clientlist menu *\param cmd uicb_t type @@ -1552,39 +1581,6 @@ uicb_clientlist(uicb_t cmd) return; } -/** Select client - *\param cmd uicb_t type clientlist index - */ -static void -uicb_client_select(uicb_t cmd) -{ - int i; - Window w; - int d, x, y; - - - for(i = 0; i < MAXCLIST && clist_index[i].client; ++i) - if(!strcmp(cmd, clist_index[i].key)) - { - if(clist_index[i].client->screen != selscreen) - screen_set_sel(clist_index[i].client->screen); - - if(clist_index[i].client->tag != (uint)seltag[clist_index[i].client->screen]) - tag_set(clist_index[i].client->tag); - - client_focus(clist_index[i].client); - client_raise(clist_index[i].client); - - /* Move pointer on client */ - XQueryPointer(dpy, ROOT, &w, &w, &x, &y, &d, &d, (uint *)&d); - XWarpPointer(dpy, ROOT, ROOT, x, y, d, d, - clist_index[i].client->geo.x + clist_index[i].client->geo.width / 2, - clist_index[i].client->geo.y + clist_index[i].client->geo.height / 2); - } - - return; -} - /** Check clientlist menu fake function * \param cmd uicb_t type unused */ diff --git a/src/color.c b/src/color.c index cd77454..98ef035 100644 --- a/src/color.c +++ b/src/color.c @@ -32,37 +32,6 @@ #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); - -/** Shades a color by the amount. This works by converting a packed RGB - * color to HSL, adding the amount to the lightness, - * and then converting back to RGB. 1.0 is max lightness, 0.0 is min lightness. - * \param shadeVal the amount to shade the lightness by. - * \return the shaded color - */ -uint -color_shade(uint rgb, double shadeVal) -{ - uint r, g, b; - double h, s, l; - - color_unpack_rgb(rgb, &r, &g, &b); - color_rgb_to_hsl(r, g, b, &h, &s, &l); - - l += shadeVal; - - l = color_clamp(l, 0, 1); - - color_hsl_to_rgb(h, s, l, &r, &g, &b); - rgb = color_pack_rgb(r, g, b); - - return rgb; -} - /** Clamp a number x within the range [a, b]. * \param x the number which to clamp * \param a the lowest possible value @@ -227,3 +196,28 @@ color_hsl_to_rgb(double h, double sl, double l, uint *rx, uint *gx, uint *bx) *gx = g * 255.0; *bx = b * 255.0; } + +/** Shades a color by the amount. This works by converting a packed RGB + * color to HSL, adding the amount to the lightness, + * and then converting back to RGB. 1.0 is max lightness, 0.0 is min lightness. + * \param shadeVal the amount to shade the lightness by. + * \return the shaded color + */ +uint +color_shade(uint rgb, double shadeVal) +{ + uint r, g, b; + double h, s, l; + + color_unpack_rgb(rgb, &r, &g, &b); + color_rgb_to_hsl(r, g, b, &h, &s, &l); + + l += shadeVal; + + l = color_clamp(l, 0, 1); + + color_hsl_to_rgb(h, s, l, &r, &g, &b); + rgb = color_pack_rgb(r, g, b); + + return rgb; +} diff --git a/src/draw.c b/src/draw.c index b2a80ad..38d89a9 100644 --- a/src/draw.c +++ b/src/draw.c @@ -33,7 +33,44 @@ #include "wmfs.h" #ifdef HAVE_IMLIB -static void draw_image(Drawable dr, int x, int y, int w, int h, char *name); +/** Draw an image in a drawable + * \param dr Drawable + * \param x X position + * \param y Y position + * \param name Path of the image +*/ +static void draw_image(Drawable dr, int x, int y, int w, int h, char *name) +{ + Imlib_Image image; + + if(!name) + return; + + imlib_set_cache_size(2048 * 1024); + imlib_context_set_display(dpy); + imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy))); + imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy))); + imlib_context_set_drawable(dr); + + image = imlib_load_image(patht(name)); + imlib_context_set_image(image); + + if(w <= 0) + w = imlib_image_get_width(); + + if(h <= 0) + h = imlib_image_get_height(); + + if(image) + { + imlib_render_image_on_drawable_at_size(x, y, w, h); + imlib_free_image(); + } + else + warnx("Can't draw image: '%s'", name); + + return; +} #endif /* HAVE_IMLIB */ void @@ -155,48 +192,6 @@ draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data) return; } -#ifdef HAVE_IMLIB -/** Draw an image in a drawable - * \param dr Drawable - * \param x X position - * \param y Y position - * \param name Path of the image -*/ -void -draw_image(Drawable dr, int x, int y, int w, int h, char *name) -{ - Imlib_Image image; - - if(!name) - return; - - imlib_set_cache_size(2048 * 1024); - imlib_context_set_display(dpy); - imlib_context_set_visual(DefaultVisual(dpy, DefaultScreen(dpy))); - imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy))); - imlib_context_set_drawable(dr); - - image = imlib_load_image(patht(name)); - imlib_context_set_image(image); - - if(w <= 0) - w = imlib_image_get_width(); - - if(h <= 0) - h = imlib_image_get_height(); - - if(image) - { - imlib_render_image_on_drawable_at_size(x, y, w, h); - imlib_free_image(); - } - else - warnx("Can't draw image: '%s'", name); - - return; -} -#endif /* HAVE_IMLIB */ - /** Calculates the text's size relatively to the font * \param text Text string * \return final text width diff --git a/src/event.c b/src/event.c index b38b428..7807c8f 100644 --- a/src/event.c +++ b/src/event.c @@ -439,27 +439,6 @@ focusin(XFocusChangeEvent *ev) return; } -/** Key grabbing function -*/ -void -grabkeys(void) -{ - int i; - KeyCode code; - - XUngrabKey(dpy, AnyKey, AnyModifier, ROOT); - for(i = 0; i < conf.nkeybind; ++i) - if((code = XKeysymToKeycode(dpy, keys[i].keysym))) - { - XGrabKey(dpy, code, keys[i].mod, ROOT, True, GrabModeAsync, GrabModeAsync); - XGrabKey(dpy, code, keys[i].mod | LockMask, ROOT, True, GrabModeAsync, GrabModeAsync); - XGrabKey(dpy, code, keys[i].mod | numlockmask, ROOT, True, GrabModeAsync, GrabModeAsync); - XGrabKey(dpy, code, keys[i].mod | LockMask | numlockmask, ROOT, True, GrabModeAsync, GrabModeAsync); - } - - return; -} - /** KeyPress handle event * \param ev XKeyPressedEvent pointer */ @@ -646,6 +625,27 @@ unmapnotify(XUnmapEvent *ev) return; } +/** Key grabbing function +*/ +void +grabkeys(void) +{ + int i; + KeyCode code; + + XUngrabKey(dpy, AnyKey, AnyModifier, ROOT); + for(i = 0; i < conf.nkeybind; ++i) + if((code = XKeysymToKeycode(dpy, keys[i].keysym))) + { + XGrabKey(dpy, code, keys[i].mod, ROOT, True, GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, code, keys[i].mod | LockMask, ROOT, True, GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, code, keys[i].mod | numlockmask, ROOT, True, GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, code, keys[i].mod | LockMask | numlockmask, ROOT, True, GrabModeAsync, GrabModeAsync); + } + + return; +} + /** Event handle function: execute every function * handle by event * \param ev Event diff --git a/src/infobar.c b/src/infobar.c index 4156355..660c023 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -135,23 +135,6 @@ infobar_init(void) return; } -static void infobar_draw_layout(int sc); - -/** Draw the Infobar - *\param sc Screen number -*/ -void -infobar_draw(int sc) -{ - infobar_draw_taglist(sc); - infobar_draw_layout(sc); - infobar_draw_selbar(sc); - barwin_refresh_color(infobar[sc].bar); - statustext_handle(sc, infobar[sc].statustext); - - return; -} - /** Draw the layout button in the InfoBar *\param sc Screen number */ @@ -170,6 +153,21 @@ infobar_draw_layout(int sc) return; } +/** Draw the Infobar + *\param sc Screen number +*/ +void +infobar_draw(int sc) +{ + infobar_draw_taglist(sc); + infobar_draw_layout(sc); + infobar_draw_selbar(sc); + barwin_refresh_color(infobar[sc].bar); + statustext_handle(sc, infobar[sc].statustext); + + return; +} + /** Draw Selbar (selected client title bar in infobar *\param sc Screen Number */ diff --git a/src/launcher.c b/src/launcher.c index 2df2160..33bb1ca 100644 --- a/src/launcher.c +++ b/src/launcher.c @@ -32,8 +32,151 @@ #include "wmfs.h" -static char *complete_on_command(char*, size_t); -static char *complete_on_files(char*, size_t); +/* + * Just search command in PATH. + * Return the characters to complete the command. + */ +static char * +complete_on_command(char *start, size_t hits) +{ + char *path; + char *dirname; + char *ret = NULL; + DIR *dir; + struct dirent *content; + + char **namelist = NULL; + int n = 0, i; + + if (!getenv("PATH") || !start || hits <= 0) + return NULL; + + path = xstrdup(getenv("PATH")); + dirname = strtok(path, ":"); + + /* recursively open PATH */ + while (dirname != NULL) + { + if ((dir = opendir(dirname))) + { + while ((content = readdir(dir))) + { + if(strncmp(content->d_name, ".", 1)) + { + if (!strncmp(content->d_name, start, strlen(start))) + { + namelist = xrealloc(namelist, ++n, sizeof(*namelist)); + namelist[n-1] = xstrdup(content->d_name); + } + } + } + closedir(dir); + } + dirname = strtok(NULL, ":"); + } + + free(path); + + if(n > 0) + { + qsort(namelist, n, sizeof(char *), qsort_string_compare); + ret = xstrdup(namelist[((hits > 0) ? hits - 1 : 0) % n] + strlen(start)); + + for(i = 0; i < n; i++) + free(namelist[i]); + + free(namelist); + } + + return ret; +} + +/* + * Complete a filename or directory name. + * works like complete_on_command. + */ +static char * +complete_on_files(char *start, size_t hits) +{ + char *ret = NULL; + char *p = NULL; + char *dirname = NULL; + char *path = NULL; + char *filepath = NULL; + DIR *dir = NULL; + struct dirent *content = NULL; + struct stat st; + size_t count = 0; + + if (!start || hits <= 0 || !(p = strrchr(start, ' '))) + return NULL; + + /* + * Search the directory to open and set + * the beginning of file to complete on pointer 'p'. + */ + if (*(++p) == '\0' || !strrchr(p, '/')) + path = xstrdup("."); + else + { + /* remplace ~ by $HOME in dirname */ + if (!strncmp(p, "~/", 2) && getenv("HOME")) + xasprintf(&dirname, "%s%s", getenv("HOME"), p+1); + else + dirname = xstrdup(p); + + /* Set p to filename to be complete + * and path the directory containing the file + * /foooooo/baaaaaar/somethinglikethis + * <---- path - ---><------- p ------> + */ + p = strrchr(dirname, '/'); + if (p != dirname) + { + *(p++) = '\0'; + path = xstrdup(dirname); + } + else + { + path = xstrdup("/"); + p++; + } + } + + if ((dir = opendir(path))) + { + while ((content = readdir(dir))) + { + if (!strcmp(content->d_name, ".") || !strcmp(content->d_name, "..")) + continue; + if (!strncmp(content->d_name, p, strlen(p)) && ++count == hits) + { + /* If it's a directory append '/' to the completion */ + xasprintf(&filepath, "%s/%s", path, content->d_name); + + if (filepath && stat(filepath, &st) != -1) + { + if (S_ISDIR(st.st_mode)) + xasprintf(&ret, "%s/", content->d_name + strlen(p)); + else + ret = xstrdup(content->d_name + strlen(p)); + } + else + warn("%s", filepath); + + free(filepath); + + break; + } + } + closedir(dir); + } + + free(dirname); + free(path); + + return ret; +} static void launcher_execute(Launcher *launcher) @@ -237,149 +380,3 @@ uicb_launcher(uicb_t cmd) return; } - -/* - * Just search command in PATH. - * Return the characters to complete the command. - */ -static char * -complete_on_command(char *start, size_t hits) -{ - char *path; - char *dirname; - char *ret = NULL; - DIR *dir; - struct dirent *content; - - char **namelist = NULL; - int n = 0, i; - - if (!getenv("PATH") || !start || hits <= 0) - return NULL; - - path = xstrdup(getenv("PATH")); - dirname = strtok(path, ":"); - - /* recursively open PATH */ - while (dirname != NULL) - { - if ((dir = opendir(dirname))) - { - while ((content = readdir(dir))) - { - if(strncmp(content->d_name, ".", 1)) - { - if (!strncmp(content->d_name, start, strlen(start))) - { - namelist = xrealloc(namelist, ++n, sizeof(*namelist)); - namelist[n-1] = xstrdup(content->d_name); - } - } - } - closedir(dir); - } - dirname = strtok(NULL, ":"); - } - - free(path); - - if(n > 0) - { - qsort(namelist, n, sizeof(char *), qsort_string_compare); - ret = xstrdup(namelist[((hits > 0) ? hits - 1 : 0) % n] + strlen(start)); - - for(i = 0; i < n; i++) - free(namelist[i]); - - free(namelist); - } - - return ret; -} - -/* - * Complete a filename or directory name. - * works like complete_on_command. - */ -static char * -complete_on_files(char *start, size_t hits) -{ - char *ret = NULL; - char *p = NULL; - char *dirname = NULL; - char *path = NULL; - char *filepath = NULL; - DIR *dir = NULL; - struct dirent *content = NULL; - struct stat st; - size_t count = 0; - - if (!start || hits <= 0 || !(p = strrchr(start, ' '))) - return NULL; - - /* - * Search the directory to open and set - * the beginning of file to complete on pointer 'p'. - */ - if (*(++p) == '\0' || !strrchr(p, '/')) - path = xstrdup("."); - else - { - /* remplace ~ by $HOME in dirname */ - if (!strncmp(p, "~/", 2) && getenv("HOME")) - xasprintf(&dirname, "%s%s", getenv("HOME"), p+1); - else - dirname = xstrdup(p); - - /* Set p to filename to be complete - * and path the directory containing the file - * /foooooo/baaaaaar/somethinglikethis - * <---- path - ---><------- p ------> - */ - p = strrchr(dirname, '/'); - if (p != dirname) - { - *(p++) = '\0'; - path = xstrdup(dirname); - } - else - { - path = xstrdup("/"); - p++; - } - } - - if ((dir = opendir(path))) - { - while ((content = readdir(dir))) - { - if (!strcmp(content->d_name, ".") || !strcmp(content->d_name, "..")) - continue; - if (!strncmp(content->d_name, p, strlen(p)) && ++count == hits) - { - /* If it's a directory append '/' to the completion */ - xasprintf(&filepath, "%s/%s", path, content->d_name); - - if (filepath && stat(filepath, &st) != -1) - { - if (S_ISDIR(st.st_mode)) - xasprintf(&ret, "%s/", content->d_name + strlen(p)); - else - ret = xstrdup(content->d_name + strlen(p)); - } - else - warn("%s", filepath); - - free(filepath); - - break; - } - } - closedir(dir); - } - - free(dirname); - free(path); - - return ret; -} diff --git a/src/layout.c b/src/layout.c index 5cea3c2..73e2dcb 100644 --- a/src/layout.c +++ b/src/layout.c @@ -143,26 +143,6 @@ uicb_layout_prev(uicb_t cmd) return; } -/** Max layout function -*/ -void -maxlayout(int screen) -{ - Client *c; - int i; - - for(i = 0, c = tiled_client(screen, clients); c; c = tiled_client(screen, c->next), ++i) - { - c->flags &= ~TileFlag; - c->flags |= LMaxFlag; - client_maximize(c); - } - - ewmh_update_current_tag_prop(); - - return; -} - /** Sort all the client that can be * tiled * \param c Client pointer @@ -184,6 +164,26 @@ tiled_client(int screen, Client *c) return c; } +/** Max layout function +*/ +void +maxlayout(int screen) +{ + Client *c; + int i; + + for(i = 0, c = tiled_client(screen, clients); c; c = tiled_client(screen, c->next), ++i) + { + c->flags &= ~TileFlag; + c->flags |= LMaxFlag; + client_maximize(c); + } + + ewmh_update_current_tag_prop(); + + return; +} + /** Set the mwfact * \param cmd Mwfact (string) */ diff --git a/src/menu.c b/src/menu.c index 1301353..478359e 100644 --- a/src/menu.c +++ b/src/menu.c @@ -32,100 +32,113 @@ #include "wmfs.h" -static Bool menu_activate_item(Menu *menu, int i); -static Bool menu_get_checkstring_needed(MenuItem *mi, int nitem); -static Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); -static Bool menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]); -static int menu_get_longer_string(MenuItem *mi, int nitem); -static void menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen); -static void menu_focus_item(Menu *menu, int item, BarWindow *winitem[]); - -void -menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n) +static int +menu_get_longer_string(MenuItem *mi, int nitem) { - /* Item */ - menu->nitem = nitem; - menu->item = xcalloc(nitem, sizeof(*menu->item)); - menu->name = name; + int i, w, l = 0; - /* Colors */ - menu->colors.focus.bg = bg_f; - menu->colors.focus.fg = fg_f; - menu->colors.normal.bg = bg_n; - menu->colors.normal.fg = fg_n; + for(i = 0; i < nitem; ++i) + if((w = textw(mi[i].name)) > l) + l = w; + + return l; +} + +static Bool +menu_get_checkstring_needed(MenuItem *mi, int nitem) +{ + (void)mi; + (void)nitem; + return True; +} + +static void +menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen) +{ + int x; + int width = menu_get_longer_string(menu->item, menu->nitem) + chcklen + PAD / 3; + + switch(menu->align) + { + case MA_Left: + x = chcklen + PAD / 2; + break; + case MA_Right: + x = width - textw(menu->item[item].name) + PAD * 3 / 2; + break; + default: + case MA_Center: + x = (width - (chcklen + PAD / 3)) / 2 - textw(menu->item[item].name) / 2 + chcklen + PAD / 3; + break; + } + barwin_draw_image_ofset_text(winitem[item], x, FHINFOBAR, menu->item[item].name, chcklen + PAD / 2, 0); + + if(menu->item[item].check) + if(menu->item[item].check(menu->item[item].cmd)) + barwin_draw_image_ofset_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol, PAD / 3, 0); + + if(menu->item[item].submenu) + barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">"); return; } -void -menu_new_item(MenuItem *mi, char *name, void *func, char *cmd) +static Bool +menu_activate_item(Menu *menu, int i) { - mi->name = name; - mi->func = func; - mi->cmd = cmd; - - return; -} - -void -menu_draw(Menu menu, int x, int y) -{ - int i, width, height, out; - XEvent ev; - BarWindow *item[menu.nitem]; - BarWindow *frame; - + int j, x, y; int chcklen = 0; - if(menu_get_checkstring_needed(menu.item, menu.nitem)) + if(menu_get_checkstring_needed(menu->item, menu->nitem)) chcklen = textw(conf.selected_layout_symbol) + PAD / 3; - width = menu_get_longer_string(menu.item, menu.nitem) + chcklen + textw(">") + PAD * 3; - height = menu.nitem * (INFOBARH - SHADH); - - /* Frame barwin */ - screen_get_sel(); - - if((out = x + width - MAXW) > 0) - x -= out; - if((out = y + height - MAXH) > 0) - y -= out; - - frame = barwin_create(ROOT, x, y, width + SHADH, height + SHADH * 3, - menu.colors.normal.bg, menu.colors.normal.fg, False, False, True); - - barwin_map(frame); - barwin_map_subwin(frame); - barwin_refresh_color(frame); - - for(i = 0; i < menu.nitem; ++i) + if(menu->item[i].submenu) { - item[i] = barwin_create(frame->win, - SHADH, - (i * (INFOBARH - SHADH) + SHADH), - width - SHADH, - INFOBARH, - menu.colors.normal.bg, - menu.colors.normal.fg, - True, False, False); + for(j = 0; j < conf.nmenu; ++j) + if(!strcmp(menu->item[i].submenu, conf.menu[j].name)) + { + y = menu->y + ((i - 1) * INFOBARH + PAD) - SHADH * 2; + x = menu->x + menu_get_longer_string(menu->item, menu->nitem) + chcklen + textw(">") + PAD * 3; - barwin_map(item[i]); - barwin_refresh_color(item[i]); - menu_draw_item_name(&menu, i, item, chcklen); - barwin_refresh(item[i]); + menu_draw(conf.menu[j], x, y); + + return True; + } + } + else if(menu->item[i].func) + { + menu->item[i].func(menu->item[i].cmd); + + return True; } - /* Select the first item */ - menu_focus_item(&menu, 0, item); + return False; +} - XGrabKeyboard(dpy, ROOT, True, GrabModeAsync, GrabModeAsync, CurrentTime); +static void +menu_focus_item(Menu *menu, int item, BarWindow *winitem[]) +{ + int i; - while(!menu_manage_event(&ev, &menu, item)); + int chcklen = 0; + if(menu_get_checkstring_needed(menu->item, menu->nitem)) + chcklen = textw(conf.selected_layout_symbol) + PAD / 3; - XUngrabKeyboard(dpy, CurrentTime); + menu->focus_item = item; - for(i = 0; i < menu.nitem; ++i) - barwin_delete(item[i]); - barwin_delete(frame); + if(menu->focus_item > menu->nitem - 1) + menu->focus_item = 0; + else if(menu->focus_item < 0) + menu->focus_item = menu->nitem - 1; + + for(i = 0; i < menu->nitem; ++i) + { + winitem[i]->fg = ((i == menu->focus_item) ? menu->colors.focus.fg : menu->colors.normal.fg); + winitem[i]->bg = ((i == menu->focus_item) ? menu->colors.focus.bg : menu->colors.normal.bg); + + barwin_refresh_color(winitem[i]); + menu_draw_item_name(menu, i, winitem, chcklen); + barwin_refresh(winitem[i]); + } return; } @@ -216,109 +229,6 @@ menu_manage_event(XEvent *ev, Menu *menu, BarWindow *winitem[]) return quit; } -static Bool -menu_activate_item(Menu *menu, int i) -{ - int j, x, y; - int chcklen = 0; - if(menu_get_checkstring_needed(menu->item, menu->nitem)) - chcklen = textw(conf.selected_layout_symbol) + PAD / 3; - - if(menu->item[i].submenu) - { - for(j = 0; j < conf.nmenu; ++j) - if(!strcmp(menu->item[i].submenu, conf.menu[j].name)) - { - y = menu->y + ((i - 1) * INFOBARH + PAD) - SHADH * 2; - x = menu->x + menu_get_longer_string(menu->item, menu->nitem) + chcklen + textw(">") + PAD * 3; - - menu_draw(conf.menu[j], x, y); - - return True; - } - } - else if(menu->item[i].func) - { - menu->item[i].func(menu->item[i].cmd); - - return True; - } - - return False; -} - -static void -menu_focus_item(Menu *menu, int item, BarWindow *winitem[]) -{ - int i; - - int chcklen = 0; - if(menu_get_checkstring_needed(menu->item, menu->nitem)) - chcklen = textw(conf.selected_layout_symbol) + PAD / 3; - - menu->focus_item = item; - - if(menu->focus_item > menu->nitem - 1) - menu->focus_item = 0; - else if(menu->focus_item < 0) - menu->focus_item = menu->nitem - 1; - - for(i = 0; i < menu->nitem; ++i) - { - winitem[i]->fg = ((i == menu->focus_item) ? menu->colors.focus.fg : menu->colors.normal.fg); - winitem[i]->bg = ((i == menu->focus_item) ? menu->colors.focus.bg : menu->colors.normal.bg); - - barwin_refresh_color(winitem[i]); - menu_draw_item_name(menu, i, winitem, chcklen); - barwin_refresh(winitem[i]); - } - - return; -} - -static void -menu_draw_item_name(Menu *menu, int item, BarWindow *winitem[], int chcklen) -{ - int x; - int width = menu_get_longer_string(menu->item, menu->nitem) + chcklen + PAD / 3; - - switch(menu->align) - { - case MA_Left: - x = chcklen + PAD / 2; - break; - case MA_Right: - x = width - textw(menu->item[item].name) + PAD * 3 / 2; - break; - default: - case MA_Center: - x = (width - (chcklen + PAD / 3)) / 2 - textw(menu->item[item].name) / 2 + chcklen + PAD / 3; - break; - } - barwin_draw_image_ofset_text(winitem[item], x, FHINFOBAR, menu->item[item].name, chcklen + PAD / 2, 0); - - if(menu->item[item].check) - if(menu->item[item].check(menu->item[item].cmd)) - barwin_draw_image_ofset_text(winitem[item], PAD / 3, FHINFOBAR, conf.selected_layout_symbol, PAD / 3, 0); - - if(menu->item[item].submenu) - barwin_draw_text(winitem[item], width + PAD * 2, FHINFOBAR, ">"); - - return; -} - -static int -menu_get_longer_string(MenuItem *mi, int nitem) -{ - int i, w, l = 0; - - for(i = 0; i < nitem; ++i) - if((w = textw(mi[i].name)) > l) - l = w; - - return l; -} - void uicb_menu(uicb_t cmd) { @@ -358,10 +268,92 @@ menu_clear(Menu *menu) return; } -static Bool -menu_get_checkstring_needed(MenuItem *mi, int nitem) +void +menu_init(Menu *menu, char *name, int nitem, uint bg_f, char *fg_f, uint bg_n, char *fg_n) { - (void)mi; - (void)nitem; - return True; + /* Item */ + menu->nitem = nitem; + menu->item = xcalloc(nitem, sizeof(*menu->item)); + menu->name = name; + + /* Colors */ + menu->colors.focus.bg = bg_f; + menu->colors.focus.fg = fg_f; + menu->colors.normal.bg = bg_n; + menu->colors.normal.fg = fg_n; + + return; +} + +void +menu_new_item(MenuItem *mi, char *name, void *func, char *cmd) +{ + mi->name = name; + mi->func = func; + mi->cmd = cmd; + + return; +} + +void +menu_draw(Menu menu, int x, int y) +{ + int i, width, height, out; + XEvent ev; + BarWindow *item[menu.nitem]; + BarWindow *frame; + + int chcklen = 0; + if(menu_get_checkstring_needed(menu.item, menu.nitem)) + chcklen = textw(conf.selected_layout_symbol) + PAD / 3; + + width = menu_get_longer_string(menu.item, menu.nitem) + chcklen + textw(">") + PAD * 3; + height = menu.nitem * (INFOBARH - SHADH); + + /* Frame barwin */ + screen_get_sel(); + + if((out = x + width - MAXW) > 0) + x -= out; + if((out = y + height - MAXH) > 0) + y -= out; + + frame = barwin_create(ROOT, x, y, width + SHADH, height + SHADH * 3, + menu.colors.normal.bg, menu.colors.normal.fg, False, False, True); + + barwin_map(frame); + barwin_map_subwin(frame); + barwin_refresh_color(frame); + + for(i = 0; i < menu.nitem; ++i) + { + item[i] = barwin_create(frame->win, + SHADH, + (i * (INFOBARH - SHADH) + SHADH), + width - SHADH, + INFOBARH, + menu.colors.normal.bg, + menu.colors.normal.fg, + True, False, False); + + barwin_map(item[i]); + barwin_refresh_color(item[i]); + menu_draw_item_name(&menu, i, item, chcklen); + barwin_refresh(item[i]); + } + + /* Select the first item */ + menu_focus_item(&menu, 0, item); + + XGrabKeyboard(dpy, ROOT, True, GrabModeAsync, GrabModeAsync, CurrentTime); + + while(!menu_manage_event(&ev, &menu, item)); + + XUngrabKeyboard(dpy, CurrentTime); + + for(i = 0; i < menu.nitem; ++i) + barwin_delete(item[i]); + barwin_delete(frame); + + return; } diff --git a/src/tag.c b/src/tag.c index 473ff4a..dfd1f36 100644 --- a/src/tag.c +++ b/src/tag.c @@ -303,8 +303,57 @@ uicb_tag_last(uicb_t cmd) return; } -static void tag_swap(int s, int t1, int t2); -static void remove_old_last_tag(int selscreen); +/** + *\param selscreen int +*/ +static void +remove_old_last_tag(int selscreen) +{ + int i; + for(i = 0; i <= conf.ntag[selscreen]; i++) + { + if(tags[selscreen][i].stay_last) + { + tags[selscreen][i].stay_last = False; + break; + } + } + + return; +} + +/** Swap 2 tags + *\param s Screen + *\param t1 Tag 1 + *\param t2 Tag 2 +*/ +static void +tag_swap(int s, int t1, int t2) +{ + Client *c; + Tag t; + + if(t1 > conf.ntag[s] || t1 < 1 + || t2 > conf.ntag[s] || t2 < 1 || t1 == t2) + return; + + t = tags[s][t1]; + tags[s][t1] = tags[s][t2]; + tags[s][t2] = t; + + for(c = clients; c; c = c->next) + { + if(c->screen == s && c->tag == (uint)t1) + c->tag = t2; + else if(c->screen == s && c->tag == (uint)t2) + c->tag = t1; + } + + infobar_update_taglist(s); + tag_set(t2); + + return; +} /** Keep that tag the last one *\param cmd uicb_t type unused @@ -469,39 +518,6 @@ uicb_tag_toggle_additional(uicb_t cmd) return; } -/** Swap 2 tags - *\param s Screen - *\param t1 Tag 1 - *\param t2 Tag 2 -*/ -static void -tag_swap(int s, int t1, int t2) -{ - Client *c; - Tag t; - - if(t1 > conf.ntag[s] || t1 < 1 - || t2 > conf.ntag[s] || t2 < 1 || t1 == t2) - return; - - t = tags[s][t1]; - tags[s][t1] = tags[s][t2]; - tags[s][t2] = t; - - for(c = clients; c; c = c->next) - { - if(c->screen == s && c->tag == (uint)t1) - c->tag = t2; - else if(c->screen == s && c->tag == (uint)t2) - c->tag = t1; - } - - infobar_update_taglist(s); - tag_set(t2); - - return; -} - /** Swap current tag with a specified tag *\param cmd uicb_t type */ @@ -718,22 +734,3 @@ uicb_tag_rename(uicb_t cmd) return; } - -/** - *\param selscreen int -*/ -static void -remove_old_last_tag(int selscreen) -{ - int i; - for(i = 0; i <= conf.ntag[selscreen]; i++) - { - if(tags[selscreen][i].stay_last) - { - tags[selscreen][i].stay_last = False; - break; - } - } - - return; -} diff --git a/src/wmfs.c b/src/wmfs.c index 3821890..f73fb38 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -35,8 +35,6 @@ static volatile Bool exiting = False, sig_chld = False; static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; -static void signal_handle(int); - int errorhandler(Display *d, XErrorEvent *event) {