Revamped palette.pl. Support separate colors for bg/fg.

This commit is contained in:
LemonBoy 2013-08-31 15:36:32 +00:00
parent 42ab142e74
commit 3a207cf9ba
3 changed files with 37 additions and 30 deletions

19
bar.c
View File

@ -47,7 +47,7 @@ static int bar_bottom = BAR_BOTTOM;
static fontset_item_t fontset[FONT_MAX];
static fontset_item_t *sel_font = NULL;
static const unsigned palette[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9};
static const unsigned palette[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9,BACKGROUND,FOREGROUND};
static inline void
xcb_set_bg (int i)
@ -145,16 +145,13 @@ parse (char *text)
if (*p == '\\' && p++ && *p != '\\' && strchr ("fbulcr", *p)) {
switch (*p++) {
case 'f':
if (!isdigit (*p)) *p = '1';
xcb_set_fg ((*p++)-'0');
xcb_set_fg (!isdigit(*p) ? (*p++)-'0' : 11);
break;
case 'b':
if (!isdigit (*p)) *p = '0';
xcb_set_bg ((*p++)-'0');
xcb_set_bg (!isdigit(*p) ? (*p++)-'0' : 10);
break;
case 'u':
if (!isdigit (*p)) *p = '0';
xcb_set_ud ((*p++)-'0');
xcb_set_ud (!isdigit(*p) ? (*p++)-'0' : 10);
break;
case 'l':
@ -338,7 +335,7 @@ init (void)
win = xcb_generate_id (c);
xcb_create_window (c, XCB_COPY_FROM_PARENT, win, root, BAR_OFFSET, y, bar_width,
BAR_HEIGHT, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, (const uint32_t []){ palette[0], XCB_EVENT_MASK_EXPOSURE });
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, (const uint32_t []){ palette[10], XCB_EVENT_MASK_EXPOSURE });
/* Set EWMH hints */
int ewmh_docking = set_ewmh_atoms (root);
@ -352,13 +349,13 @@ init (void)
/* Create the gc for drawing */
draw_gc = xcb_generate_id (c);
xcb_create_gc (c, draw_gc, root, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, (const uint32_t []){ palette[1], palette[0] });
xcb_create_gc (c, draw_gc, root, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, (const uint32_t []){ palette[11], palette[10] });
clear_gc = xcb_generate_id (c);
xcb_create_gc (c, clear_gc, root, XCB_GC_FOREGROUND, (const uint32_t []){ palette[0] });
xcb_create_gc (c, clear_gc, root, XCB_GC_FOREGROUND, (const uint32_t []){ palette[10] });
underl_gc = xcb_generate_id (c);
xcb_create_gc (c, underl_gc, root, XCB_GC_FOREGROUND, (const uint32_t []){ palette[0] });
xcb_create_gc (c, underl_gc, root, XCB_GC_FOREGROUND, (const uint32_t []){ palette[10] });
/* Make the bar visible */
xcb_map_window (c, win);

View File

@ -15,14 +15,15 @@
/* Some fonts don't set the right width for some chars, pheex it */
#define BAR_FONT_FALLBACK_WIDTH 6
/* Color palette */
#define COLOR0 0x1A1A1A /* background */
#define COLOR1 0xA9A9A9 /* foreground */
#define COLOR2 0x303030
#define COLOR3 0xF92672
#define COLOR4 0xA6E22E
#define COLOR5 0xFD971F
#define COLOR6 0x66D9EF
#define COLOR7 0x9E6FFE
#define COLOR8 0xAF875F
#define COLOR9 0xCCCCC6
#define BACKGROUND 0x232c31
#define COLOR0 0x2d3c46
#define COLOR1 0xac4142
#define COLOR2 0x90a959
#define COLOR3 0xde935f
#define COLOR4 0x6a9fb5
#define COLOR5 0xaa759f
#define COLOR6 0x75b5aa
#define COLOR7 0x6c7a80
#define COLOR8 0x425059
#define COLOR9 0xcc6666
#define FOREGROUND 0xc5c8c6

View File

@ -12,16 +12,25 @@ use warnings;
open (F, "<".$ARGV[0]) || die "Can't open!";
our %vars = ();
while (<F>) {
if ($_ =~ m/^\s*(?:\w+\.|\*)(color|background|foreground)(\d+)?\s*:\s*#([0-9A-Fa-f]*)/) {
if ($1 eq "background") {
printf "#define COLOR0\t0x$3\n";
# Don't match comments
if ($_ !~ m/^\s*!/) {
# It's a define!
if ($_ =~ m/^\s*#define\s+(\w+)\s+#([0-9A-Fa-f]{1,6})/) {
$vars{"$1"} = hex($2);
}
elsif ($1 eq "foreground") {
printf "#define COLOR1\t0x$3\n"
}
elsif ($1 eq "color" && $2 < 8) {
printf "#define COLOR%i\t0x$3\n", $2 + 2;
elsif ($_ =~ m/^\s*\w*\*(background|foreground|color\d)\s*:\s*([\w\d#]+)/) {
my ($name, $value) = (uc $1, $2);
# Check if it's a color
if (substr($value, 1) eq '#') {
$value = hex(substr($value, 1));
} else {
$value = $vars{"$value"};
}
printf "#define $name 0x%06x\n", $value;
}
}
}