lemonbar-xft-font-offset.diff (2400B)
1 diff --git a/lemonbar.c b/lemonbar.c 2 index de4cf73..6a2f7cd 100644 3 --- a/lemonbar.c 4 +++ b/lemonbar.c 5 @@ -26,6 +26,8 @@ 6 #define max(a,b) ((a) > (b) ? (a) : (b)) 7 #define min(a,b) ((a) < (b) ? (a) : (b)) 8 9 +#define MAX_FONT_COUNT 5 10 + 11 typedef struct font_t { 12 xcb_font_t ptr; 13 int descent, height, width; 14 @@ -98,6 +100,9 @@ static int font_index = -1; 15 static uint32_t attrs = 0; 16 static bool dock = false; 17 static bool topbar = true; 18 +static int offsets_y[MAX_FONT_COUNT]; 19 +static int offset_y_count = 0; 20 +static int offset_y_index = 0; 21 static int bw = -1, bh = -1, bx = 0, by = 0; 22 static int bu = 1; // Underline height 23 static rgba_t fgc, bgc, ugc; 24 @@ -260,7 +265,7 @@ int xft_char_width (uint16_t ch, font_t *cur_font) { 25 int draw_char_xft(monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch) { 26 int ch_width = xft_char_width(ch, cur_font); 27 x = shift(mon, x, align, ch_width); 28 - int y = bh / 2 + cur_font->height / 2- cur_font->descent; 29 + int y = bh / 2 + cur_font->height / 2- cur_font->descent + offsets_y[offset_y_index]; 30 XftDrawString16(xft_draw, &sel_fg, cur_font->xft_font, x, y, &ch, 1); 31 draw_lines(mon, x, ch_width); 32 return ch_width; 33 @@ -530,8 +535,10 @@ select_drawable_font (const uint16_t c) 34 // If the end is reached without finding an appropriate font, return NULL. 35 // If the font can draw the character, return it. 36 for (int i = 0; i < font_count; i++) { 37 - if (font_has_glyph(font_list[i], c)) 38 + if (font_has_glyph(font_list[i], c)) { 39 + offset_y_index = i; 40 return font_list[i]; 41 + } 42 } 43 return NULL; 44 } 45 @@ -1583,7 +1590,14 @@ main (int argc, char **argv) 46 "\t-F Set foreground color in #AARRGGBB\n", argv[0]); 47 exit (EXIT_SUCCESS); 48 case 'g': (void)parse_geometry_string(optarg, geom_v); break; 49 - case 'o': (void)parse_output_string(optarg); break; 50 + case 'o': offsets_y[offset_y_count] = strtol(optarg, NULL, 10); 51 + if (offset_y_count == 0) { 52 + for (int i=1; i<MAX_FONT_COUNT; i++) { 53 + offsets_y[i] = offsets_y[0]; 54 + } 55 + } 56 + ++offset_y_count; 57 + break; 58 case 'p': permanent = true; break; 59 case 'n': wm_name = xstrdup(optarg); break; 60 case 'b': topbar = false; break;