Merge branch 'master' of github.com:LemonBoy/bar into xinerama-fix

Conflicts:
	bar.c
This commit is contained in:
LemonBoy 2014-02-05 23:24:21 +00:00
commit e8ec2fcfe5
2 changed files with 36 additions and 34 deletions

View File

@ -1,6 +1,6 @@
CC ?= gcc CC ?= gcc
STRIP ?= strip STRIP ?= strip
CFLAGS = -std=c99 -fshort-wchar -Os CFLAGS = -std=c99 -O2
LDFLAGS = -lxcb LDFLAGS = -lxcb
XINERAMA ?= 0 XINERAMA ?= 0
ifneq "$(XINERAMA)" "0" ifneq "$(XINERAMA)" "0"

68
bar.c
View File

@ -17,6 +17,7 @@
// Here be dragons // Here be dragons
#define MAX(a,b) ((a > b) ? a : b) #define MAX(a,b) ((a > b) ? a : b)
#define MIN(a,b) ((a < b) ? a : b)
typedef struct fontset_item_t { typedef struct fontset_item_t {
xcb_font_t xcb_ft; xcb_font_t xcb_ft;
@ -100,7 +101,7 @@ xcb_set_fontset (int i)
} }
int int
draw_char (screen_t *screen, int x, int align, wchar_t ch) draw_char (screen_t *screen, int x, int align, uint16_t ch)
{ {
int ch_width; int ch_width;
@ -155,40 +156,37 @@ parse (char *text)
xcb_fill_rect (clear_gc, 0, 0, bar_width, BAR_HEIGHT); xcb_fill_rect (clear_gc, 0, 0, bar_width, BAR_HEIGHT);
for (;;) { for (;;) {
if (*p == '\0') if (*p == '\0' || *p == '\n')
return;
if (*p == '\n')
return; return;
if (*p == '\\' && p++ && *p != '\\' && strchr (control_characters, *p)) { if (*p == '\\' && p++ && *p != '\\' && strchr (control_characters, *p)) {
switch (*p++) { switch (*p++) {
case 'f': case 'f':
xcb_set_fg (isdigit(*p) ? (*p)-'0' : 11); xcb_set_fg (isdigit(*p) ? *p-'0' : 11);
p++; p++;
break; break;
case 'b': case 'b':
xcb_set_bg (isdigit(*p) ? (*p)-'0' : 10); xcb_set_bg (isdigit(*p) ? *p-'0' : 10);
p++; p++;
break; break;
case 'u': case 'u':
xcb_set_ud (isdigit(*p) ? (*p)-'0' : 10); xcb_set_ud (isdigit(*p) ? *p-'0' : 10);
p++; p++;
break; break;
#if XINERAMA #if XINERAMA
case 's': case 's':
if ((*p) == 'r') { if (*p == 'r')
screen_idx = num_screens - 1; screen_idx = num_screens - 1;
} else if ((*p) == 'l') { else if (*p == 'l')
screen_idx = 0; screen_idx = 0;
} else if ((*p) == 'n') { else if (*p == 'n')
screen_idx++; screen_idx++;
} else if ((*p) == 'p') { else if (*p == 'p')
screen_idx--; screen_idx--;
} else if (isdigit(*p)) { else if (isdigit(*p))
screen_idx = (*p)-'0'; screen_idx = *p-'0';
} else { else
break; break;
}
/* Consume the argument */ /* Consume the argument */
p++; p++;
@ -218,39 +216,38 @@ parse (char *text)
pos_x = 0; pos_x = 0;
break; break;
} }
} else { } else { /* utf-8 -> ucs-2 */
#if XINERAMA #if XINERAMA
if (!screen_ptr->window) if (!screen_ptr->window)
continue; continue;
#endif #endif
uint8_t *utf = (uint8_t *)p;
uint16_t ucs;
/* utf-8 -> ucs-2 */ if (utf[0] < 0x80) {
wchar_t t; ucs = utf[0];
p += 1;
if (!(p[0] & 0x80)) {
t = p[0];
p += 1;
} }
else if ((p[0] & 0xe0) == 0xc0 && (p[1] & 0xc0) == 0x80) { else if ((utf[0] & 0xe0) == 0xc0) {
t = (p[0] & 0x1f) << 6 | (p[1] & 0x3f); ucs = (utf[0] & 0x1f) << 6 | (utf[1] & 0x3f);
p += 2; p += 2;
} }
else if ((p[0] & 0xf0) == 0xe0 && (p[1] & 0xc0) == 0x80 && (p[2] & 0xc0) == 0x80) { else if ((utf[0] & 0xf0) == 0xe0) {
t = (p[0] & 0xf) << 12 | (p[1] & 0x3f) << 6 | (p[2] & 0x3f); ucs = (utf[0] & 0xf) << 12 | (utf[1] & 0x3f) << 6 | (utf[2] & 0x3f);
p += 3; p += 3;
} }
else { /* ASCII chars > 127 go in the extended latin range */ else { /* Handle ascii > 0x80 */
t = 0xc200 + p[0]; ucs = utf[0];
p += 1; p += 1;
} }
/* The character is outside the main font charset, use the fallback */ /* The character is outside the main font charset, use the fallback */
if (t < fontset[FONT_MAIN].char_min || t > fontset[FONT_MAIN].char_max) if (ucs < fontset[FONT_MAIN].char_min || ucs > fontset[FONT_MAIN].char_max)
xcb_set_fontset (FONT_FALLBACK); xcb_set_fontset (FONT_FALLBACK);
else else
xcb_set_fontset (FONT_MAIN); xcb_set_fontset (FONT_MAIN);
pos_x += draw_char (screen_ptr, pos_x, align, t); pos_x += draw_char (screen_ptr, pos_x, align, ucs);
} }
} }
} }
@ -307,7 +304,7 @@ enum {
}; };
void void
set_ewmh_atoms () set_ewmh_atoms (void)
{ {
const char *atom_names[] = { const char *atom_names[] = {
"_NET_WM_WINDOW_TYPE", "_NET_WM_WINDOW_TYPE",
@ -431,7 +428,10 @@ init (void)
screens[i].window = create_window(root, screens[i].x, y, screens[i].width, BAR_HEIGHT, scr->root_visual); screens[i].window = create_window(root, screens[i].x, y, screens[i].width, BAR_HEIGHT, scr->root_visual);
} }
left_offset -= screens[i].width; if (left_offset)
left_offset -= MIN(screens[i].width, left_offset);
xcb_xinerama_screen_info_next (&xinerama_iter);
} }
free(xinerama_reply); free(xinerama_reply);
@ -555,7 +555,9 @@ main (int argc, char **argv)
else break; /* ...bail out */ else break; /* ...bail out */
} }
if (pollin[0].revents & POLLIN) { /* New input, process it */ if (pollin[0].revents & POLLIN) { /* New input, process it */
fgets (input, sizeof(input), stdin); if (fgets (input, sizeof(input), stdin) == NULL)
break; /* EOF received */
parse (input); parse (input);
redraw = 1; redraw = 1;
} }