Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'stebalien/pixel-offset' into xft-port
Browse files Browse the repository at this point in the history
* stebalien/pixel-offset:
  Add pixel offset
  Implement [Issue LemonBoy#161 - Feature request] Feature: add a parametere to set the default underline color. Usage: lemonbar -Ucolor
  • Loading branch information
krypt-n committed Feb 17, 2016
2 parents 73ae9cf + 892e43a commit a43b801
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 20 deletions.
10 changes: 9 additions & 1 deletion README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ lemonbar - Featherweight lemon-scented bar

=head1 SYNOPSIS

I<lemonbar> [-h | -g I<width>B<x>I<height>B<+>I<x>B<+>I<y> | -b | -d | -f I<font> | -p | -n I<name> | -u I<pixel> | -B I<color> | -F I<color> | -o I<offset>]
I<lemonbar> [-h | -g I<width>B<x>I<height>B<+>I<x>B<+>I<y> | -b | -d | -f I<font> | -p | -n I<name> | -u I<pixel> | -B I<color> | -F I<color> | -U I<color> | -o I<offset> ]

=head1 DESCRIPTION

Expand Down Expand Up @@ -65,6 +65,10 @@ Set the foreground color of the bar. Accepts the same color formats as B<-B>.

Add a vertical offset to the text. I<offset> must be a number and can be negative. I<-o -3> will push the text 3 pixels up.

=item B<-U> I<color>

Set the underline color of the bar. Accepts the same color formats as B<-B>.

=back

=head1 FORMATTING
Expand All @@ -89,6 +93,10 @@ Aligns the following text to the center of the screen.

Aligns the following text to the right side of the screen.

=item B<O>I<width>

Offset the current position by I<width> pixels in the alignment direction.

=item B<B>I<color>

Set the text background color. The parameter I<color> can be I<-> or a color in one of the formats mentioned before. The special value I<-> resets the color to the default one.
Expand Down
73 changes: 54 additions & 19 deletions lemonbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static bool topbar = true;
static int bw = -1, bh = -1, bx = 0, by = 0;
static int bu = 1; // Underline height
static rgba_t fgc, bgc, ugc;
static rgba_t dfgc, dbgc;
static rgba_t dfgc, dbgc, dugc;
static area_stack_t area_stack;

static XftColor sel_fg;
Expand Down Expand Up @@ -250,17 +250,8 @@ int xft_char_width (uint16_t ch, font_t *cur_font)
}

int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
shift (monitor_t *mon, int x, int align, int ch_width)
{
int ch_width;

if (cur_font->xft_ft) {
ch_width = xft_char_width(ch, cur_font);
} else {
ch_width = (cur_font->width_lut) ?
cur_font->width_lut[ch - cur_font->char_min].character_width:
cur_font->width;
}
switch (align) {
case ALIGN_C:
xcb_copy_area(c, mon->pixmap, mon->pixmap, gc[GC_DRAW],
Expand All @@ -280,6 +271,40 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)

/* Draw the background first */
fill_rect(mon->pixmap, gc[GC_CLEAR], x, 0, ch_width, bh);
return x;
}

void
draw_lines (monitor_t *mon, int x, int w)
{
/* We can render both at the same time */
if (attrs & ATTR_OVERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, 0, w, bu);
if (attrs & ATTR_UNDERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, bh - bu, w, bu);
}

void
draw_shift (monitor_t *mon, int x, int align, int w)
{
x = shift(mon, x, align, w);
draw_lines(mon, x, w);
}

int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
{
int ch_width;

if (cur_font->xft_ft) {
ch_width = xft_char_width(ch, cur_font);
} else {
ch_width = (cur_font->width_lut) ?
cur_font->width_lut[ch - cur_font->char_min].character_width:
cur_font->width;
}

x = shift(mon, x, align, ch_width);

int y = bh / 2 + cur_font->height / 2- cur_font->descent + offsets_y[offset_y_index];
if (cur_font->xft_ft) {
Expand All @@ -294,11 +319,7 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
1, &ch);
}

// We can render both at the same time
if (attrs & ATTR_OVERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, 0, ch_width, bu);
if (attrs & ATTR_UNDERL)
fill_rect(mon->pixmap, gc[GC_ATTR], x, bh - bu, ch_width, bu);
draw_lines(mon, x, ch_width);

return ch_width;
}
Expand Down Expand Up @@ -586,6 +607,7 @@ parse (char *text)
if (p[0] == '%' && p[1] == '{' && (block_end = strchr(p++, '}'))) {
p++;
while (p < block_end) {
int w;
while (isspace(*p))
p++;

Expand Down Expand Up @@ -616,7 +638,7 @@ parse (char *text)

case 'B': bgc = parse_color(p, &p, dbgc); update_gc(); break;
case 'F': fgc = parse_color(p, &p, dfgc); update_gc(); break;
case 'U': ugc = parse_color(p, &p, dbgc); update_gc(); break;
case 'U': ugc = parse_color(p, &p, dugc); update_gc(); break;

case 'S':
if (*p == '+' && cur_mon->next)
Expand All @@ -642,6 +664,17 @@ parse (char *text)
p++;
pos_x = 0;
break;
case 'O':
errno = 0;
w = (int) strtoul(p, &p, 10);
if (errno)
continue;

draw_shift(cur_mon, pos_x, align, w);

pos_x += w;
area_shift(cur_mon->window, align, w);
break;

case 'T':
if (*p == '-') { //Reset to automatic font selection
Expand Down Expand Up @@ -1384,15 +1417,16 @@ main (int argc, char **argv)
dbgc = bgc = (rgba_t)0x00000000U;
dfgc = fgc = (rgba_t)0xffffffffU;

ugc = fgc;
dugc = ugc = fgc;

// A safe default
areas = 10;
wm_name = NULL;

// Connect to the Xserver and initialize scr
xconn();

while ((ch = getopt(argc, argv, "hg:bdf:a:pu:B:F:n:o:")) != -1) {
while ((ch = getopt(argc, argv, "hg:bdf:a:pu:B:F:U:n:o:")) != -1) {
switch (ch) {
case 'h':
printf ("lemonbar version %s patched with XFT support\n", VERSION);
Expand Down Expand Up @@ -1420,6 +1454,7 @@ main (int argc, char **argv)
case 'o': add_y_offset(strtol(optarg, NULL, 10)); break;
case 'B': dbgc = bgc = parse_color(optarg, NULL, (rgba_t)0x00000000U); break;
case 'F': dfgc = fgc = parse_color(optarg, NULL, (rgba_t)0xffffffffU); break;
case 'U': dugc = ugc = parse_color(optarg, NULL, fgc); break;
case 'a': areas = strtoul(optarg, NULL, 10); break;
}
}
Expand Down

0 comments on commit a43b801

Please sign in to comment.