Make textbox foreground and background configurable.

This commit is contained in:
Aldo Cortesi 2007-12-19 13:20:21 +11:00 committed by Julien Danjou
parent eb57f68ed3
commit 9bb28772ed
4 changed files with 49 additions and 29 deletions

View File

@ -31,6 +31,7 @@
#include "rules.h" #include "rules.h"
#include "screen.h" #include "screen.h"
#include "widget.h" #include "widget.h"
#include "xutil.h"
#include "defconfig.h" #include "defconfig.h"
#define AWESOME_CONFIG_FILE ".awesomerc" #define AWESOME_CONFIG_FILE ".awesomerc"
@ -55,19 +56,7 @@ extern const NameFuncLink UicbList[];
extern const NameFuncLink WidgetList[]; extern const NameFuncLink WidgetList[];
extern const NameFuncLink LayoutsList[]; extern const NameFuncLink LayoutsList[];
/** Initialize color from X side
* \param disp Display ref
* \param scr Screen number
* \param colorstr Color code
*/
static XColor
initxcolor(Display *disp, int scr, const char *colstr)
{
XColor color;
if(!XAllocNamedColor(disp, DefaultColormap(disp, scr), colstr, &color, &color))
die("awesome: error, cannot allocate color '%s'\n", colstr);
return color;
}
static unsigned int static unsigned int
get_numlockmask(Display *disp) get_numlockmask(Display *disp)
{ {
@ -346,6 +335,8 @@ config_parse(const char *confpatharg)
static cfg_opt_t widget_textbox_opts[] = static cfg_opt_t widget_textbox_opts[] =
{ {
CFG_STR((char *) "default", (char *) NULL, CFGF_NONE), CFG_STR((char *) "default", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t statusbar_opts[] = static cfg_opt_t statusbar_opts[] =
@ -542,23 +533,17 @@ config_parse(const char *confpatharg)
if(!virtscreen->font) if(!virtscreen->font)
eprint("awesome: cannot init font\n"); eprint("awesome: cannot init font\n");
/* Colors */ /* Colors */
virtscreen->colors_normal[ColBorder] = initxcolor(globalconf.display, virtscreen->colors_normal[ColBorder] = initxcolor(screen,
get_phys_screen(screen),
cfg_getstr(cfg_colors, "normal_border")); cfg_getstr(cfg_colors, "normal_border"));
virtscreen->colors_normal[ColBG] = initxcolor(globalconf.display, virtscreen->colors_normal[ColBG] = initxcolor(screen,
get_phys_screen(screen),
cfg_getstr(cfg_colors, "normal_bg")); cfg_getstr(cfg_colors, "normal_bg"));
virtscreen->colors_normal[ColFG] = initxcolor(globalconf.display, virtscreen->colors_normal[ColFG] = initxcolor(screen,
get_phys_screen(screen),
cfg_getstr(cfg_colors, "normal_fg")); cfg_getstr(cfg_colors, "normal_fg"));
virtscreen->colors_selected[ColBorder] = initxcolor(globalconf.display, virtscreen->colors_selected[ColBorder] = initxcolor(screen,
get_phys_screen(screen),
cfg_getstr(cfg_colors, "focus_border")); cfg_getstr(cfg_colors, "focus_border"));
virtscreen->colors_selected[ColBG] = initxcolor(globalconf.display, virtscreen->colors_selected[ColBG] = initxcolor(screen,
get_phys_screen(screen),
cfg_getstr(cfg_colors, "focus_bg")); cfg_getstr(cfg_colors, "focus_bg"));
virtscreen->colors_selected[ColFG] = initxcolor(globalconf.display, virtscreen->colors_selected[ColFG] = initxcolor(screen,
get_phys_screen(screen),
cfg_getstr(cfg_colors, "focus_fg")); cfg_getstr(cfg_colors, "focus_fg"));
/* Statusbar */ /* Statusbar */

View File

@ -1,6 +1,7 @@
#include <confuse.h> #include <confuse.h>
#include "util.h" #include "util.h"
#include "widget.h" #include "widget.h"
#include "xutil.h"
extern awesome_config globalconf; extern awesome_config globalconf;
@ -9,6 +10,8 @@ typedef struct Data Data;
struct Data struct Data
{ {
char *text; char *text;
XColor fg;
XColor bg;
}; };
@ -36,9 +39,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
offset, offset,
widget->alignment); widget->alignment);
drawtext(ctx, location, 0, width, vscreen.statusbar->height, drawtext(ctx, location, 0, width, vscreen.statusbar->height,
vscreen.font, d->text, vscreen.font, d->text, d->fg, d->bg);
vscreen.colors_normal[ColFG],
vscreen.colors_normal[ColBG]);
return width; return width;
} }
@ -55,15 +56,27 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
{ {
Widget *w; Widget *w;
Data *d; Data *d;
char *color;
w = p_new(Widget, 1); w = p_new(Widget, 1);
common_new(w, statusbar, config); common_new(w, statusbar, config);
w->draw = textbox_draw; w->draw = textbox_draw;
w->tell = textbox_tell; w->tell = textbox_tell;
d = p_new(Data, 1); d = p_new(Data, 1);
w->data = (void*) d; w->data = (void*) d;
if ((color = cfg_getstr(config, "fg")))
d->fg = initxcolor(statusbar->screen, color);
else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if ((color = cfg_getstr(config, "bg")))
d->bg = initxcolor(statusbar->screen, color);
else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
update(w, cfg_getstr(config, "default")); update(w, cfg_getstr(config, "default"));
return w; return w;
} }

22
xutil.c
View File

@ -18,7 +18,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
*/ */
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/extensions/Xinerama.h> #include <X11/extensions/Xinerama.h>
@ -113,4 +112,25 @@ xgettextprop(Display *disp, Window w, Atom atom, char *text, ssize_t textlen)
return True; return True;
} }
/** Initialize an X color
* \param screen Screen number
* \param colorstr Color specification
*/
XColor
initxcolor(int screen, const char *colstr)
{
XColor screenColor, exactColor;
int ret, physcreen = get_phys_screen(screen);
ret = XAllocNamedColor(globalconf.display,
DefaultColormap(globalconf.display, physcreen),
colstr,
&screenColor,
&exactColor);
if(!ret)
die("awesome: error, cannot allocate color '%s'\n", colstr);
return screenColor;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -23,8 +23,10 @@
#define AWESOME_XUTIL_H #define AWESOME_XUTIL_H
#include "common.h" #include "common.h"
#include "screen.h"
Bool xgettextprop(Display *, Window, Atom, char *, ssize_t); Bool xgettextprop(Display *, Window, Atom, char *, ssize_t);
XColor initxcolor(int, const char *);
UICB_PROTO(uicb_spawn); UICB_PROTO(uicb_spawn);
UICB_PROTO(uicb_exec); UICB_PROTO(uicb_exec);