mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
- switch border colors to Xft
- merge border/menu color structures/functions since they now both use Xft - switch xu_xorcolor to operating on XftColor instead of just XRenderColor (basically adding pixel) - if color name allocation fails, revert back to default (this, along with font validation should occur during config parse, but we don't have screens setup yet - likely to change at some point)
This commit is contained in:
parent
c84145661e
commit
dac00a232f
29
calmwm.h
29
calmwm.h
|
@ -85,20 +85,16 @@ union arg {
|
||||||
int i;
|
int i;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum menucolor {
|
enum color {
|
||||||
CWM_COLOR_MENU_FG,
|
|
||||||
CWM_COLOR_MENU_BG,
|
|
||||||
CWM_COLOR_MENU_FONT,
|
|
||||||
CWM_COLOR_MENU_FONT_SEL,
|
|
||||||
CWM_COLOR_MENU_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
enum bordercolor {
|
|
||||||
CWM_COLOR_BORDER_ACTIVE,
|
CWM_COLOR_BORDER_ACTIVE,
|
||||||
CWM_COLOR_BORDER_INACTIVE,
|
CWM_COLOR_BORDER_INACTIVE,
|
||||||
CWM_COLOR_BORDER_GROUP,
|
CWM_COLOR_BORDER_GROUP,
|
||||||
CWM_COLOR_BORDER_UNGROUP,
|
CWM_COLOR_BORDER_UNGROUP,
|
||||||
CWM_COLOR_BORDER_MAX
|
CWM_COLOR_MENU_FG,
|
||||||
|
CWM_COLOR_MENU_BG,
|
||||||
|
CWM_COLOR_MENU_FONT,
|
||||||
|
CWM_COLOR_MENU_FONT_SEL,
|
||||||
|
CWM_COLOR_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
struct geom {
|
struct geom {
|
||||||
|
@ -213,13 +209,12 @@ struct screen_ctx {
|
||||||
Colormap colormap;
|
Colormap colormap;
|
||||||
Window rootwin;
|
Window rootwin;
|
||||||
Window menuwin;
|
Window menuwin;
|
||||||
unsigned long color[CWM_COLOR_BORDER_MAX];
|
|
||||||
int cycling;
|
int cycling;
|
||||||
struct geom view; /* viewable area */
|
struct geom view; /* viewable area */
|
||||||
struct geom work; /* workable area, gap-applied */
|
struct geom work; /* workable area, gap-applied */
|
||||||
struct gap gap;
|
struct gap gap;
|
||||||
struct cycle_entry_q mruq;
|
struct cycle_entry_q mruq;
|
||||||
XftColor xftcolor[CWM_COLOR_MENU_MAX];
|
XftColor xftcolor[CWM_COLOR_MAX];
|
||||||
XftDraw *xftdraw;
|
XftDraw *xftdraw;
|
||||||
XftFont *xftfont;
|
XftFont *xftfont;
|
||||||
int xinerama_no;
|
int xinerama_no;
|
||||||
|
@ -293,8 +288,7 @@ struct conf {
|
||||||
#define CONF_SNAPDIST 0
|
#define CONF_SNAPDIST 0
|
||||||
int snapdist;
|
int snapdist;
|
||||||
struct gap gap;
|
struct gap gap;
|
||||||
char *color[CWM_COLOR_BORDER_MAX];
|
char *color[CWM_COLOR_MAX];
|
||||||
char *menucolor[CWM_COLOR_MENU_MAX];
|
|
||||||
char termpath[MAXPATHLEN];
|
char termpath[MAXPATHLEN];
|
||||||
char lockpath[MAXPATHLEN];
|
char lockpath[MAXPATHLEN];
|
||||||
char known_hosts[MAXPATHLEN];
|
char known_hosts[MAXPATHLEN];
|
||||||
|
@ -452,8 +446,7 @@ void conf_ungrab(struct conf *, struct keybinding *);
|
||||||
|
|
||||||
void font_draw(struct screen_ctx *, const char *,
|
void font_draw(struct screen_ctx *, const char *,
|
||||||
Drawable, int, int, int);
|
Drawable, int, int, int);
|
||||||
void font_init(struct screen_ctx *, const char *,
|
void font_init(struct screen_ctx *, const char *);
|
||||||
const char **);
|
|
||||||
int font_width(XftFont *, const char *, int);
|
int font_width(XftFont *, const char *, int);
|
||||||
|
|
||||||
void xev_loop(void);
|
void xev_loop(void);
|
||||||
|
@ -462,7 +455,6 @@ void xu_btn_grab(Window, int, u_int);
|
||||||
void xu_btn_ungrab(Window, int, u_int);
|
void xu_btn_ungrab(Window, int, u_int);
|
||||||
void xu_configure(struct client_ctx *);
|
void xu_configure(struct client_ctx *);
|
||||||
void xu_getatoms(void);
|
void xu_getatoms(void);
|
||||||
unsigned long xu_getcolor(struct screen_ctx *, char *);
|
|
||||||
int xu_getprop(Window, Atom, Atom, long, u_char **);
|
int xu_getprop(Window, Atom, Atom, long, u_char **);
|
||||||
int xu_get_wm_state(Window, int *);
|
int xu_get_wm_state(Window, int *);
|
||||||
int xu_getstrprop(Window, Atom, char **);
|
int xu_getstrprop(Window, Atom, char **);
|
||||||
|
@ -475,8 +467,7 @@ void xu_ptr_setpos(Window, int, int);
|
||||||
void xu_ptr_ungrab(void);
|
void xu_ptr_ungrab(void);
|
||||||
void xu_sendmsg(Window, Atom, long);
|
void xu_sendmsg(Window, Atom, long);
|
||||||
void xu_set_wm_state(Window win, int);
|
void xu_set_wm_state(Window win, int);
|
||||||
void xu_xorcolor(XRenderColor, XRenderColor,
|
void xu_xorcolor(XftColor, XftColor, XftColor *);
|
||||||
XRenderColor *);
|
|
||||||
|
|
||||||
void xu_ewmh_net_supported(struct screen_ctx *);
|
void xu_ewmh_net_supported(struct screen_ctx *);
|
||||||
void xu_ewmh_net_supported_wm_check(struct screen_ctx *);
|
void xu_ewmh_net_supported_wm_check(struct screen_ctx *);
|
||||||
|
|
8
client.c
8
client.c
|
@ -480,17 +480,17 @@ client_draw_border(struct client_ctx *cc)
|
||||||
if (cc->active)
|
if (cc->active)
|
||||||
switch (cc->flags & CLIENT_HIGHLIGHT) {
|
switch (cc->flags & CLIENT_HIGHLIGHT) {
|
||||||
case CLIENT_GROUP:
|
case CLIENT_GROUP:
|
||||||
pixel = sc->color[CWM_COLOR_BORDER_GROUP];
|
pixel = sc->xftcolor[CWM_COLOR_BORDER_GROUP].pixel;
|
||||||
break;
|
break;
|
||||||
case CLIENT_UNGROUP:
|
case CLIENT_UNGROUP:
|
||||||
pixel = sc->color[CWM_COLOR_BORDER_UNGROUP];
|
pixel = sc->xftcolor[CWM_COLOR_BORDER_UNGROUP].pixel;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pixel = sc->color[CWM_COLOR_BORDER_ACTIVE];
|
pixel = sc->xftcolor[CWM_COLOR_BORDER_ACTIVE].pixel;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pixel = sc->color[CWM_COLOR_BORDER_INACTIVE];
|
pixel = sc->xftcolor[CWM_COLOR_BORDER_INACTIVE].pixel;
|
||||||
|
|
||||||
XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth);
|
XSetWindowBorderWidth(X_Dpy, cc->win, cc->bwidth);
|
||||||
XSetWindowBorder(X_Dpy, cc->win, pixel);
|
XSetWindowBorder(X_Dpy, cc->win, pixel);
|
||||||
|
|
47
conf.c
47
conf.c
|
@ -84,31 +84,49 @@ conf_ignore(struct conf *c, char *val)
|
||||||
TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry);
|
TAILQ_INSERT_TAIL(&c->ignoreq, wm, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *menu_color_binds[CWM_COLOR_MENU_MAX] = {
|
static char *color_binds[CWM_COLOR_MAX] = {
|
||||||
|
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
|
||||||
|
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
|
||||||
|
"blue", /* CWM_COLOR_BORDER_GROUP */
|
||||||
|
"red", /* CWM_COLOR_BORDER_UNGROUP */
|
||||||
"black", /* CWM_COLOR_MENU_FG */
|
"black", /* CWM_COLOR_MENU_FG */
|
||||||
"white", /* CWM_COLOR_MENU_BG */
|
"white", /* CWM_COLOR_MENU_BG */
|
||||||
"black", /* CWM_COLOR_MENU_FONT */
|
"black", /* CWM_COLOR_MENU_FONT */
|
||||||
"", /* CWM_COLOR_MENU_FONT_SEL */
|
"", /* CWM_COLOR_MENU_FONT_SEL */
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *color_binds[CWM_COLOR_BORDER_MAX] = {
|
|
||||||
"#CCCCCC", /* CWM_COLOR_BORDER_ACTIVE */
|
|
||||||
"#666666", /* CWM_COLOR_BORDER_INACTIVE */
|
|
||||||
"blue", /* CWM_COLOR_BORDER_GROUP */
|
|
||||||
"red", /* CWM_COLOR_BORDER_UNGROUP */
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
conf_screen(struct screen_ctx *sc)
|
conf_screen(struct screen_ctx *sc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
XftColor xc;
|
||||||
|
|
||||||
sc->gap = Conf.gap;
|
sc->gap = Conf.gap;
|
||||||
|
|
||||||
font_init(sc, Conf.font, (const char **)Conf.menucolor);
|
font_init(sc, Conf.font);
|
||||||
|
|
||||||
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
for (i = 0; i < CWM_COLOR_MAX; i++) {
|
||||||
sc->color[i] = xu_getcolor(sc, Conf.color[i]);
|
if (*Conf.color[i] == '\0')
|
||||||
|
break;
|
||||||
|
if (XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||||
|
Conf.color[i], &xc)) {
|
||||||
|
sc->xftcolor[i] = xc;
|
||||||
|
XftColorFree(X_Dpy, sc->visual, sc->colormap, &xc);
|
||||||
|
} else {
|
||||||
|
warnx("XftColorAllocName: '%s'", Conf.color[i]);
|
||||||
|
XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
||||||
|
color_binds[i], &sc->xftcolor[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == CWM_COLOR_MAX)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG],
|
||||||
|
sc->xftcolor[CWM_COLOR_MENU_FG], &xc);
|
||||||
|
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT], xc, &xc);
|
||||||
|
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
|
||||||
|
&xc.color, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
||||||
|
warnx("XftColorAllocValue: '%s'", Conf.color[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
@ -210,9 +228,6 @@ conf_init(struct conf *c)
|
||||||
for (i = 0; i < nitems(color_binds); i++)
|
for (i = 0; i < nitems(color_binds); i++)
|
||||||
c->color[i] = xstrdup(color_binds[i]);
|
c->color[i] = xstrdup(color_binds[i]);
|
||||||
|
|
||||||
for (i = 0; i < nitems(menu_color_binds); i++)
|
|
||||||
c->menucolor[i] = xstrdup(menu_color_binds[i]);
|
|
||||||
|
|
||||||
/* Default term/lock */
|
/* Default term/lock */
|
||||||
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
(void)strlcpy(c->termpath, "xterm", sizeof(c->termpath));
|
||||||
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
(void)strlcpy(c->lockpath, "xlock", sizeof(c->lockpath));
|
||||||
|
@ -260,7 +275,7 @@ conf_clear(struct conf *c)
|
||||||
free(mb);
|
free(mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
for (i = 0; i < CWM_COLOR_MAX; i++)
|
||||||
free(c->color[i]);
|
free(c->color[i]);
|
||||||
|
|
||||||
free(c->font);
|
free(c->font);
|
||||||
|
|
22
font.c
22
font.c
|
@ -31,11 +31,8 @@
|
||||||
#include "calmwm.h"
|
#include "calmwm.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
font_init(struct screen_ctx *sc, const char *name, const char **color)
|
font_init(struct screen_ctx *sc, const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
XRenderColor c;
|
|
||||||
|
|
||||||
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
|
sc->xftdraw = XftDrawCreate(X_Dpy, sc->rootwin,
|
||||||
sc->visual, sc->colormap);
|
sc->visual, sc->colormap);
|
||||||
if (sc->xftdraw == NULL)
|
if (sc->xftdraw == NULL)
|
||||||
|
@ -44,23 +41,6 @@ font_init(struct screen_ctx *sc, const char *name, const char **color)
|
||||||
sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name);
|
sc->xftfont = XftFontOpenName(X_Dpy, sc->which, name);
|
||||||
if (sc->xftfont == NULL)
|
if (sc->xftfont == NULL)
|
||||||
errx(1, "XftFontOpenName");
|
errx(1, "XftFontOpenName");
|
||||||
|
|
||||||
for (i = 0; i < CWM_COLOR_MENU_MAX; i++) {
|
|
||||||
if (*color[i] == '\0')
|
|
||||||
break;
|
|
||||||
if (!XftColorAllocName(X_Dpy, sc->visual, sc->colormap,
|
|
||||||
color[i], &sc->xftcolor[i]))
|
|
||||||
errx(1, "XftColorAllocName");
|
|
||||||
}
|
|
||||||
if (i == CWM_COLOR_MENU_MAX)
|
|
||||||
return;
|
|
||||||
|
|
||||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_BG].color,
|
|
||||||
sc->xftcolor[CWM_COLOR_MENU_FG].color, &c);
|
|
||||||
xu_xorcolor(sc->xftcolor[CWM_COLOR_MENU_FONT].color, c, &c);
|
|
||||||
if (!XftColorAllocValue(X_Dpy, sc->visual, sc->colormap,
|
|
||||||
&c, &sc->xftcolor[CWM_COLOR_MENU_FONT_SEL]))
|
|
||||||
errx(1, "XftColorAllocValue");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
21
parse.y
21
parse.y
|
@ -198,20 +198,20 @@ colors : ACTIVEBORDER STRING {
|
||||||
conf->color[CWM_COLOR_BORDER_UNGROUP] = $2;
|
conf->color[CWM_COLOR_BORDER_UNGROUP] = $2;
|
||||||
}
|
}
|
||||||
| MENUBG STRING {
|
| MENUBG STRING {
|
||||||
free(conf->menucolor[CWM_COLOR_MENU_BG]);
|
free(conf->color[CWM_COLOR_MENU_BG]);
|
||||||
conf->menucolor[CWM_COLOR_MENU_BG] = $2;
|
conf->color[CWM_COLOR_MENU_BG] = $2;
|
||||||
}
|
}
|
||||||
| MENUFG STRING {
|
| MENUFG STRING {
|
||||||
free(conf->menucolor[CWM_COLOR_MENU_FG]);
|
free(conf->color[CWM_COLOR_MENU_FG]);
|
||||||
conf->menucolor[CWM_COLOR_MENU_FG] = $2;
|
conf->color[CWM_COLOR_MENU_FG] = $2;
|
||||||
}
|
}
|
||||||
| FONTCOLOR STRING {
|
| FONTCOLOR STRING {
|
||||||
free(conf->menucolor[CWM_COLOR_MENU_FONT]);
|
free(conf->color[CWM_COLOR_MENU_FONT]);
|
||||||
conf->menucolor[CWM_COLOR_MENU_FONT] = $2;
|
conf->color[CWM_COLOR_MENU_FONT] = $2;
|
||||||
}
|
}
|
||||||
| FONTSELCOLOR STRING {
|
| FONTSELCOLOR STRING {
|
||||||
free(conf->menucolor[CWM_COLOR_MENU_FONT_SEL]);
|
free(conf->color[CWM_COLOR_MENU_FONT_SEL]);
|
||||||
conf->menucolor[CWM_COLOR_MENU_FONT_SEL] = $2;
|
conf->color[CWM_COLOR_MENU_FONT_SEL] = $2;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
%%
|
%%
|
||||||
|
@ -589,12 +589,9 @@ parse_config(const char *filename, struct conf *xconf)
|
||||||
(void)strlcpy(xconf->lockpath, conf->lockpath,
|
(void)strlcpy(xconf->lockpath, conf->lockpath,
|
||||||
sizeof(xconf->lockpath));
|
sizeof(xconf->lockpath));
|
||||||
|
|
||||||
for (i = 0; i < CWM_COLOR_BORDER_MAX; i++)
|
for (i = 0; i < CWM_COLOR_MAX; i++)
|
||||||
xconf->color[i] = conf->color[i];
|
xconf->color[i] = conf->color[i];
|
||||||
|
|
||||||
for (i = 0; i < CWM_COLOR_MENU_MAX; i++)
|
|
||||||
xconf->menucolor[i] = conf->menucolor[i];
|
|
||||||
|
|
||||||
xconf->font = conf->font;
|
xconf->font = conf->font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
xutil.c
24
xutil.c
|
@ -420,24 +420,12 @@ xu_ewmh_net_wm_desktop(struct client_ctx *cc)
|
||||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1);
|
XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&no, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
|
||||||
xu_getcolor(struct screen_ctx *sc, char *name)
|
|
||||||
{
|
|
||||||
XColor color, tmp;
|
|
||||||
|
|
||||||
if (!XAllocNamedColor(X_Dpy, sc->colormap, name, &color, &tmp)) {
|
|
||||||
warnx("XAllocNamedColor error: '%s'", name);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (color.pixel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
xu_xorcolor(XRenderColor a, XRenderColor b, XRenderColor *r)
|
xu_xorcolor(XftColor a, XftColor b, XftColor *r)
|
||||||
{
|
{
|
||||||
r->red = a.red ^ b.red;
|
r->pixel = a.pixel ^ b.pixel;
|
||||||
r->green = a.green ^ b.green;
|
r->color.red = a.color.red ^ b.color.red;
|
||||||
r->blue = a.blue ^ b.blue;
|
r->color.green = a.color.green ^ b.color.green;
|
||||||
r->alpha = 0xffff;
|
r->color.blue = a.color.blue ^ b.color.blue;
|
||||||
|
r->color.alpha = 0xffff;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user