Make globals static. Fix the long standing off by one error when retrieving the glyph width.

This commit is contained in:
LemonBoy 2014-02-12 15:01:42 +00:00
parent 8ded08b495
commit 6fb75424e8
2 changed files with 21 additions and 31 deletions

50
bar.c
View File

@ -19,23 +19,23 @@
#define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b))
typedef struct font_t { typedef struct font_t {
xcb_font_t ptr; xcb_font_t ptr;
uint32_t descent; uint32_t descent;
uint32_t height; uint32_t height;
uint16_t char_max; uint16_t char_max;
uint16_t char_min; uint16_t char_min;
xcb_charinfo_t *width_lut; xcb_charinfo_t *width_lut;
} font_t; } font_t;
typedef struct monitor_t { typedef struct monitor_t {
uint32_t x; uint32_t x;
uint32_t width; uint32_t width;
xcb_window_t window; xcb_window_t window;
struct monitor_t *prev, *next; struct monitor_t *prev, *next;
} monitor_t; } monitor_t;
struct config_t { static struct config_t {
int place_bottom; int place_bottom;
int force_docking; int force_docking;
int permanent; int permanent;
int width; int width;
@ -53,23 +53,19 @@ enum {
ALIGN_R ALIGN_R
}; };
xcb_connection_t *c; static xcb_connection_t *c;
xcb_screen_t *scr; static xcb_screen_t *scr;
xcb_drawable_t canvas; static xcb_drawable_t canvas;
xcb_gcontext_t draw_gc; static xcb_gcontext_t draw_gc, clear_gc, underl_gc;
xcb_gcontext_t clear_gc;
xcb_gcontext_t underl_gc;
monitor_t *monhead, *montail; static monitor_t *monhead, *montail;
font_t *main_font, *alt_font; static font_t *main_font, *alt_font;
const uint32_t palette[] = { static const uint32_t palette[] = {
COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9,BACKGROUND,FOREGROUND COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9,BACKGROUND,FOREGROUND
}; };
const char *control_characters = "_-fbulcrs";
void void
set_bg (int i) set_bg (int i)
{ {
@ -98,15 +94,11 @@ fill_rect (xcb_gcontext_t gc, int x, int y, int width, int height)
int int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, int underline, uint16_t ch) draw_char (monitor_t *mon, font_t *cur_font, int x, int align, int underline, uint16_t ch)
{ {
int ch_width; /* In the unlikely case that the font doesn't have the glyph wanted just do nothing */
if (ch < cur_font->char_min || ch > cur_font->char_max)
return 0;
ch_width = (ch > cur_font->char_min && ch < cur_font->char_max) ? int ch_width = cur_font->width_lut[ch - cur_font->char_min].character_width;
cur_font->width_lut[ch - cur_font->char_min].character_width :
0;
/* Some fonts (such as anorexia) have the space char with the width set to 0 */
if (ch_width == 0)
ch_width = BAR_FONT_FALLBACK_WIDTH;
switch (align) { switch (align) {
case ALIGN_C: case ALIGN_C:
@ -159,7 +151,7 @@ parse (char *text)
if (*p == '\0' || *p == '\n') if (*p == '\0' || *p == '\n')
return; return;
if (*p == '^' && p++ && *p != '^' && strchr (control_characters, *p)) { if (*p == '^' && p++ && *p != '^' && strchr ("_-fbulcrs", *p)) {
switch (*p++) { switch (*p++) {
case 'f': case 'f':
set_fg (isdigit(*p) ? *p-'0' : 11); set_fg (isdigit(*p) ? *p-'0' : 11);

View File

@ -1,7 +1,5 @@
/* The thickness of the underline (in pixels). Set to 0 to disable. */ /* The thickness of the underline (in pixels). Set to 0 to disable. */
#define BAR_UNDERLINE_HEIGHT 2 #define BAR_UNDERLINE_HEIGHT 2
/* Some fonts don't set the right width for some chars, pheex it */
#define BAR_FONT_FALLBACK_WIDTH 6
/* Color palette */ /* Color palette */
#define BACKGROUND 0x232c31 #define BACKGROUND 0x232c31
#define COLOR0 0x2d3c46 #define COLOR0 0x2d3c46