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 fontset[FONT_MAX];
static fontset_item_t *sel_font = NULL; 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 static inline void
xcb_set_bg (int i) xcb_set_bg (int i)
@ -145,16 +145,13 @@ parse (char *text)
if (*p == '\\' && p++ && *p != '\\' && strchr ("fbulcr", *p)) { if (*p == '\\' && p++ && *p != '\\' && strchr ("fbulcr", *p)) {
switch (*p++) { switch (*p++) {
case 'f': case 'f':
if (!isdigit (*p)) *p = '1'; xcb_set_fg (!isdigit(*p) ? (*p++)-'0' : 11);
xcb_set_fg ((*p++)-'0');
break; break;
case 'b': case 'b':
if (!isdigit (*p)) *p = '0'; xcb_set_bg (!isdigit(*p) ? (*p++)-'0' : 10);
xcb_set_bg ((*p++)-'0');
break; break;
case 'u': case 'u':
if (!isdigit (*p)) *p = '0'; xcb_set_ud (!isdigit(*p) ? (*p++)-'0' : 10);
xcb_set_ud ((*p++)-'0');
break; break;
case 'l': case 'l':
@ -338,7 +335,7 @@ init (void)
win = xcb_generate_id (c); win = xcb_generate_id (c);
xcb_create_window (c, XCB_COPY_FROM_PARENT, win, root, BAR_OFFSET, y, bar_width, 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, 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 */ /* Set EWMH hints */
int ewmh_docking = set_ewmh_atoms (root); int ewmh_docking = set_ewmh_atoms (root);
@ -352,13 +349,13 @@ init (void)
/* Create the gc for drawing */ /* Create the gc for drawing */
draw_gc = xcb_generate_id (c); 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); 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); 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 */ /* Make the bar visible */
xcb_map_window (c, win); xcb_map_window (c, win);

View File

@ -15,14 +15,15 @@
/* Some fonts don't set the right width for some chars, pheex it */ /* Some fonts don't set the right width for some chars, pheex it */
#define BAR_FONT_FALLBACK_WIDTH 6 #define BAR_FONT_FALLBACK_WIDTH 6
/* Color palette */ /* Color palette */
#define COLOR0 0x1A1A1A /* background */ #define BACKGROUND 0x232c31
#define COLOR1 0xA9A9A9 /* foreground */ #define COLOR0 0x2d3c46
#define COLOR2 0x303030 #define COLOR1 0xac4142
#define COLOR3 0xF92672 #define COLOR2 0x90a959
#define COLOR4 0xA6E22E #define COLOR3 0xde935f
#define COLOR5 0xFD971F #define COLOR4 0x6a9fb5
#define COLOR6 0x66D9EF #define COLOR5 0xaa759f
#define COLOR7 0x9E6FFE #define COLOR6 0x75b5aa
#define COLOR8 0xAF875F #define COLOR7 0x6c7a80
#define COLOR9 0xCCCCC6 #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!"; open (F, "<".$ARGV[0]) || die "Can't open!";
our %vars = ();
while (<F>) { while (<F>) {
if ($_ =~ m/^\s*(?:\w+\.|\*)(color|background|foreground)(\d+)?\s*:\s*#([0-9A-Fa-f]*)/) { # Don't match comments
if ($1 eq "background") { if ($_ !~ m/^\s*!/) {
printf "#define COLOR0\t0x$3\n"; # 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") { elsif ($_ =~ m/^\s*\w*\*(background|foreground|color\d)\s*:\s*([\w\d#]+)/) {
printf "#define COLOR1\t0x$3\n" my ($name, $value) = (uc $1, $2);
} # Check if it's a color
elsif ($1 eq "color" && $2 < 8) { if (substr($value, 1) eq '#') {
printf "#define COLOR%i\t0x$3\n", $2 + 2; $value = hex(substr($value, 1));
} else {
$value = $vars{"$value"};
}
printf "#define $name 0x%06x\n", $value;
} }
} }
} }