General cleanup. New formatting syntax. More cleanup. Documentation. Did I say cleanup ?
This commit is contained in:
parent
3f4ed1600a
commit
b60e45ee08
20
Makefile
20
Makefile
|
@ -1,6 +1,6 @@
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
STRIP ?= strip
|
STRIP ?= strip
|
||||||
CFLAGS = -std=c99 -O2
|
CFLAGS = -std=c99 -Os
|
||||||
LDFLAGS = -lxcb -lxcb-xinerama -lxcb-randr
|
LDFLAGS = -lxcb -lxcb-xinerama -lxcb-randr
|
||||||
CFDEBUG = -g3 -pedantic -Wall -Wunused-parameter -Wlong-long\
|
CFDEBUG = -g3 -pedantic -Wall -Wunused-parameter -Wlong-long\
|
||||||
-Wsign-conversion -Wconversion -Wimplicit-function-declaration
|
-Wsign-conversion -Wconversion -Wimplicit-function-declaration
|
||||||
|
@ -14,15 +14,12 @@ BINDIR=${PREFIX}/bin
|
||||||
|
|
||||||
all: ${EXEC}
|
all: ${EXEC}
|
||||||
|
|
||||||
|
doc: README.pod
|
||||||
|
pod2man --section=1 --center="bar Manual" --name "bar" --release="bar $(shell git describe --always)" README.pod > bar.1
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
${CC} ${CFLAGS} -o $@ -c $<
|
${CC} ${CFLAGS} -o $@ -c $<
|
||||||
|
|
||||||
${OBJS}: config.h
|
|
||||||
|
|
||||||
config.h:
|
|
||||||
@echo creating $@ from config.def.h
|
|
||||||
@cp config.def.h $@
|
|
||||||
|
|
||||||
${EXEC}: ${OBJS}
|
${EXEC}: ${OBJS}
|
||||||
${CC} -o ${EXEC} ${OBJS} ${LDFLAGS}
|
${CC} -o ${EXEC} ${OBJS} ${LDFLAGS}
|
||||||
${STRIP} -s ${EXEC}
|
${STRIP} -s ${EXEC}
|
||||||
|
@ -31,14 +28,15 @@ debug: ${EXEC}
|
||||||
debug: CC += ${CFDEBUG}
|
debug: CC += ${CFDEBUG}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f ./*.o
|
rm -f ./*.o ./*.1
|
||||||
rm -f ./${EXEC}
|
rm -f ./${EXEC}
|
||||||
|
|
||||||
install: bar
|
install: bar doc
|
||||||
test -d ${DESTDIR}${BINDIR} || mkdir -p ${DESTDIR}${BINDIR}
|
install -D -m 755 bar ${DESTDIR}${BINDIR}/bar
|
||||||
install -m755 bar ${DESTDIR}${BINDIR}/bar
|
install -D -m 644 bar.1 ${DESTDIR}${PREFIX}/share/man/man1/bar.1
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f ${DESTDIR}${BINDIR}/bar
|
rm -f ${DESTDIR}${BINDIR}/bar
|
||||||
|
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/bar.1
|
||||||
|
|
||||||
.PHONY: all debug clean install
|
.PHONY: all debug clean install
|
||||||
|
|
70
README.md
70
README.md
|
@ -1,70 +0,0 @@
|
||||||
b(ar) a(in't) r(ecursive)
|
|
||||||
=========================
|
|
||||||
2012-2013 (C) The Lemon Man
|
|
||||||
|
|
||||||
A lightweight bar based on XCB (yay). Provides foreground/background color
|
|
||||||
switching along with text alignment (screw you dzen!), full utf8 support
|
|
||||||
and reduced memory footprint. It also supports transparency when using a
|
|
||||||
compositor such as compton. Nothing less and nothing more.
|
|
||||||
|
|
||||||
Xinerama support
|
|
||||||
----------------
|
|
||||||
Thanks to @Stebalien now bar is Xinerama compliant, just compile it with
|
|
||||||
XINERAMA=1 and you're good to go!
|
|
||||||
|
|
||||||
Options
|
|
||||||
-------
|
|
||||||
bar accepts a couple of command line switches.
|
|
||||||
|
|
||||||
```
|
|
||||||
-h Show the help and bail out.
|
|
||||||
-p Make the bar permanent.
|
|
||||||
-f Force docking (use this if your WM isn't EWMH compliant)
|
|
||||||
-b Show the bar at the bottom of the screen.
|
|
||||||
```
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
Change the config.h file and you're good to go!
|
|
||||||
The text background and foreground are respectively the first and the second
|
|
||||||
entries in the palette (COLOR0 and COLOR1).
|
|
||||||
|
|
||||||
Colors
|
|
||||||
------
|
|
||||||
Attached there's palette.pl, an handy tool that extracts a palette from your
|
|
||||||
X colors and returns it ready to be pasted in the configuration file.
|
|
||||||
|
|
||||||
```
|
|
||||||
palette.pl <.Xresources / .Xdefaults path>
|
|
||||||
```
|
|
||||||
|
|
||||||
If you keep your colors in a separate file just feed that file and you're good
|
|
||||||
to go.
|
|
||||||
|
|
||||||
Text formatting
|
|
||||||
---------------
|
|
||||||
All the format commands are preceded by a backslash (\\).
|
|
||||||
To draw a backslash just backslash escape it (\\\\).
|
|
||||||
|
|
||||||
```
|
|
||||||
f<0-9> Selects the text foreground color from the palette.
|
|
||||||
b<0-9> Selects the text background color from the palette.
|
|
||||||
u<0-9> Selects the underline color from the palette.
|
|
||||||
To reset the bg/fg/underline color just pass 'r' as the color index.
|
|
||||||
|
|
||||||
l Aligns the text to the left.
|
|
||||||
c Aligns the text to the center.
|
|
||||||
r Aligns the text to the right.
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
The options below are valid only if compiled with Xinerama support.
|
|
||||||
|
|
||||||
|
|
||||||
```
|
|
||||||
s<0-9> Switches to screen 0-9
|
|
||||||
sn Switches to next screen
|
|
||||||
sp Switches to previous screen
|
|
||||||
sr Switches to the rightmost screen (the latest)
|
|
||||||
sl Switches to the leftmost screen (the first)
|
|
||||||
```
|
|
153
README.pod
Normal file
153
README.pod
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
bar - bar ain't recursive
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
I<bar> [-h | -g I<width>B<x>I<height> | -b | -d | -f I<font> | -a I<alpha>| -p | -B I<color> | -F I<color>]
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
B<bar> is a lightweight bar entirely based on XCB. Provides full UTF-8 support, basic formatting, RandR and Xinerama support and EWMH compliance without wasting your precious memory.
|
||||||
|
|
||||||
|
=head1 OPTIONS
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<-h>
|
||||||
|
|
||||||
|
Display the help and exit.
|
||||||
|
|
||||||
|
=item B<-g> I<width>B<x>I<height>
|
||||||
|
|
||||||
|
Set the window geometry. Both the parameters can be omitted, bar defaults the former to the whole width and the height to the font height + 1 pixel.
|
||||||
|
|
||||||
|
=item B<-b>
|
||||||
|
|
||||||
|
Dock the bar at the bottom of the screen.
|
||||||
|
|
||||||
|
=item B<-d>
|
||||||
|
|
||||||
|
Force docking without asking the window manager. This is needed if the window manager isn't EWMH compliant.
|
||||||
|
|
||||||
|
=item B<-f> I<font>
|
||||||
|
|
||||||
|
Comma separated list of fonts, bar supports a maximum of two fonts.
|
||||||
|
|
||||||
|
=item B<-a> I<alpha>
|
||||||
|
|
||||||
|
Set the bar alpha in range 0.0 to 1.0. This requires a compositor manager such as Compton.
|
||||||
|
|
||||||
|
=item B<-p>
|
||||||
|
|
||||||
|
Make bar permanent, don't exit after the standard input is closed.
|
||||||
|
|
||||||
|
=item B<-B> I<color>
|
||||||
|
|
||||||
|
Set the background color of the bar. I<color> might be either in hex format (#rrggbb) or in the symbolic name format (eg. white, brightred, darkgray).
|
||||||
|
|
||||||
|
=item B<-F> I<color>
|
||||||
|
|
||||||
|
Set the foreground color of the bar. Accepts the same color formats as B<-B>.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 FORMATTING
|
||||||
|
|
||||||
|
bar provides a screenrc-inspired formatting syntax to allow full customization at runtime. Every formatting block is opened with B<%{> and closed by B<}> and accepts the following commands, the parser tries it's best to handle malformed input.
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<R>
|
||||||
|
|
||||||
|
Swap the current background and foreground colors.
|
||||||
|
|
||||||
|
=item B<l>
|
||||||
|
|
||||||
|
Aligns the following text to the left side of the screen.
|
||||||
|
|
||||||
|
=item B<c>
|
||||||
|
|
||||||
|
Aligns the following text to the center of the screen.
|
||||||
|
|
||||||
|
=item B<r>
|
||||||
|
|
||||||
|
Aligns the following text to the right side of the screen.
|
||||||
|
|
||||||
|
=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.
|
||||||
|
|
||||||
|
=item B<F>I<color>
|
||||||
|
|
||||||
|
Set the text foreground 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.
|
||||||
|
|
||||||
|
=item B<U>I<color>
|
||||||
|
|
||||||
|
Set the text underline 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.
|
||||||
|
|
||||||
|
=item B<S>I<dir>
|
||||||
|
|
||||||
|
Change the monitor bar is rendering to. I<dir> can be either
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<+>/B<->
|
||||||
|
|
||||||
|
Next/previous monitor.
|
||||||
|
|
||||||
|
=item B<f>/B<l>
|
||||||
|
|
||||||
|
First/last monitor.
|
||||||
|
|
||||||
|
=item I<0-9>
|
||||||
|
|
||||||
|
Nth monitor.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
B<Attribute modifiers>
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<+>I<attribute>
|
||||||
|
|
||||||
|
Set the attribute I<attribute> for the following text.
|
||||||
|
|
||||||
|
=item B<->I<attribute>
|
||||||
|
|
||||||
|
Unset the attribute I<attribute> for the following text.
|
||||||
|
|
||||||
|
=item B<!>I<attribute>
|
||||||
|
|
||||||
|
Toggle the attribute I<attribute> for the following text.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
Where I<attribute> is one of the following
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<o>
|
||||||
|
|
||||||
|
Draw a line over the text.
|
||||||
|
|
||||||
|
=item B<u>
|
||||||
|
|
||||||
|
Draw a line under the text.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 WWW
|
||||||
|
|
||||||
|
L<git repository|https://github.com/LemonBoy/bar>
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
2012-2014 (C) The Lemon Man
|
||||||
|
|
||||||
|
Xinerama support was kindly contributed by Stebalien
|
||||||
|
|
||||||
|
RandR support was kindly contributed by jvvv
|
519
bar.c
519
bar.c
|
@ -11,12 +11,11 @@
|
||||||
#include <xcb/xinerama.h>
|
#include <xcb/xinerama.h>
|
||||||
#include <xcb/randr.h>
|
#include <xcb/randr.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
// 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))
|
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||||
|
#define indexof(c,s) (strchr(s,c)-s)
|
||||||
|
|
||||||
typedef struct font_t {
|
typedef struct font_t {
|
||||||
xcb_font_t ptr;
|
xcb_font_t ptr;
|
||||||
|
@ -34,17 +33,9 @@ typedef struct monitor_t {
|
||||||
struct monitor_t *prev, *next;
|
struct monitor_t *prev, *next;
|
||||||
} monitor_t;
|
} monitor_t;
|
||||||
|
|
||||||
static struct config_t {
|
enum {
|
||||||
int place_bottom;
|
ATTR_OVERL = (1<<0),
|
||||||
int force_docking;
|
ATTR_UNDERL = (1<<1),
|
||||||
int permanent;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
float alpha;
|
|
||||||
char main_font[64];
|
|
||||||
char alt_font[64];
|
|
||||||
} cfg = {
|
|
||||||
0, 0, 0, -1, 18, 1.0f, "fixed", "fixed",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -55,34 +46,25 @@ enum {
|
||||||
|
|
||||||
static xcb_connection_t *c;
|
static xcb_connection_t *c;
|
||||||
static xcb_screen_t *scr;
|
static xcb_screen_t *scr;
|
||||||
|
|
||||||
static xcb_drawable_t canvas;
|
static xcb_drawable_t canvas;
|
||||||
static xcb_gcontext_t draw_gc, clear_gc, underl_gc;
|
static xcb_gcontext_t gc[3];
|
||||||
|
|
||||||
static monitor_t *monhead, *montail;
|
static monitor_t *monhead, *montail;
|
||||||
static font_t *main_font, *alt_font;
|
static font_t *main_font, *alt_font;
|
||||||
|
static uint32_t attrs = 0;
|
||||||
static const uint32_t palette[] = {
|
static float ba = 1.0f;
|
||||||
COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9,BACKGROUND,FOREGROUND
|
static bool dock = false;
|
||||||
};
|
static bool topbar = true;
|
||||||
|
static int bw = -1, bh = -1;
|
||||||
|
static char *mfont, *afont;
|
||||||
|
static uint32_t fgc, bgc, ugc;
|
||||||
|
static uint32_t dfgc, dbgc;
|
||||||
|
|
||||||
void
|
void
|
||||||
set_bg (int i)
|
update_gc (void)
|
||||||
{
|
{
|
||||||
xcb_change_gc (c, draw_gc , XCB_GC_BACKGROUND, (const unsigned []){ palette[i] });
|
xcb_change_gc(c, gc[0], XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, (const uint32_t []){ fgc, bgc });
|
||||||
xcb_change_gc (c, clear_gc , XCB_GC_FOREGROUND, (const unsigned []){ palette[i] });
|
xcb_change_gc(c, gc[1], XCB_GC_FOREGROUND, (const uint32_t []){ bgc });
|
||||||
}
|
xcb_change_gc(c, gc[2], XCB_GC_FOREGROUND, (const uint32_t []){ ugc });
|
||||||
|
|
||||||
void
|
|
||||||
set_fg (int i)
|
|
||||||
{
|
|
||||||
xcb_change_gc (c, draw_gc , XCB_GC_FOREGROUND, (const uint32_t []){ palette[i] });
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_ud (int i)
|
|
||||||
{
|
|
||||||
xcb_change_gc (c, underl_gc, XCB_GC_FOREGROUND, (const uint32_t []){ palette[i] });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -92,7 +74,7 @@ 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, uint16_t ch)
|
||||||
{
|
{
|
||||||
/* In the unlikely case that the font doesn't have the glyph wanted just do nothing */
|
/* 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)
|
if (ch < cur_font->char_min || ch > cur_font->char_max)
|
||||||
|
@ -102,119 +84,165 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, int underline, ui
|
||||||
|
|
||||||
switch (align) {
|
switch (align) {
|
||||||
case ALIGN_C:
|
case ALIGN_C:
|
||||||
xcb_copy_area (c, canvas, canvas, draw_gc, mon->width / 2 - x / 2 + mon->x, 0,
|
xcb_copy_area(c, canvas, canvas, gc[0], mon->width / 2 - x / 2 + mon->x, 0,
|
||||||
mon->width / 2 - (x + ch_width) / 2 + mon->x, 0, x, cfg.height);
|
mon->width / 2 - (x + ch_width) / 2 + mon->x, 0, x, bh);
|
||||||
x = mon->width / 2 - (x + ch_width) / 2 + x;
|
x = mon->width / 2 - (x + ch_width) / 2 + x;
|
||||||
break;
|
break;
|
||||||
case ALIGN_R:
|
case ALIGN_R:
|
||||||
xcb_copy_area (c, canvas, canvas, draw_gc, mon->width - x + mon->x, 0,
|
xcb_copy_area(c, canvas, canvas, gc[0], mon->width - x + mon->x, 0,
|
||||||
mon->width - x - ch_width + mon->x, 0, x, cfg.height);
|
mon->width - x - ch_width + mon->x, 0, x, bh);
|
||||||
x = mon->width - ch_width;
|
x = mon->width - ch_width;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Draw the background first */
|
/* Draw the background first */
|
||||||
fill_rect (clear_gc, x + mon->x, 0, ch_width, cfg.height);
|
fill_rect(gc[1], x + mon->x, 0, ch_width, bh);
|
||||||
|
|
||||||
/* xcb accepts string in UCS-2 BE, so swap */
|
/* xcb accepts string in UCS-2 BE, so swap */
|
||||||
ch = (ch >> 8) | (ch << 8);
|
ch = (ch >> 8) | (ch << 8);
|
||||||
|
|
||||||
/* String baseline coordinates */
|
/* String baseline coordinates */
|
||||||
xcb_image_text_16 (c, 1, canvas, draw_gc, x + mon->x, cfg.height / 2 + cur_font->height / 2 - cur_font->descent,
|
xcb_image_text_16(c, 1, canvas, gc[0], x + mon->x, bh / 2 + cur_font->height / 2 - cur_font->descent,
|
||||||
(xcb_char2b_t *)&ch);
|
(xcb_char2b_t *)&ch);
|
||||||
|
|
||||||
/* Draw the underline if -1, an overline if 1 */
|
/* We can render both at the same time */
|
||||||
if (BAR_UNDERLINE_HEIGHT && underline)
|
if (attrs & ATTR_OVERL)
|
||||||
fill_rect (underl_gc, x + mon->x, (underline < 0)*(cfg.height-BAR_UNDERLINE_HEIGHT), ch_width, BAR_UNDERLINE_HEIGHT);
|
fill_rect(gc[2], x + mon->x, 0, ch_width, 1);
|
||||||
|
if (attrs & ATTR_UNDERL)
|
||||||
|
fill_rect(gc[2], x + mon->x, bh-1, ch_width, 1);
|
||||||
|
|
||||||
return ch_width;
|
return ch_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
parse_color (const char *str, char **end, const uint32_t def)
|
||||||
|
{
|
||||||
|
xcb_alloc_named_color_reply_t *nc_reply;
|
||||||
|
int str_len;
|
||||||
|
uint32_t ret;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return def;
|
||||||
|
|
||||||
|
/* Reset */
|
||||||
|
if (str[0] == '-') {
|
||||||
|
if (end)
|
||||||
|
*end = (char *)str + 1;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hex rapresentation */
|
||||||
|
if (str[0] == '#')
|
||||||
|
return strtoul(str + 1, end, 16);
|
||||||
|
|
||||||
|
/* Actual color name, resolve it */
|
||||||
|
str_len = 0;
|
||||||
|
while (isalpha(str[str_len]))
|
||||||
|
str_len++;
|
||||||
|
|
||||||
|
nc_reply = xcb_alloc_named_color_reply(c, xcb_alloc_named_color(c, scr->default_colormap, str_len, str), NULL);
|
||||||
|
|
||||||
|
if (!nc_reply)
|
||||||
|
fprintf(stderr, "Could not alloc color \"%.*s\"\n", str_len, str);
|
||||||
|
ret = (nc_reply) ? nc_reply->pixel : def;
|
||||||
|
free(nc_reply);
|
||||||
|
|
||||||
|
printf("k?\n");
|
||||||
|
|
||||||
|
if (end)
|
||||||
|
*end = (char *)str + str_len;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
set_attribute (const char modifier, const char attribute)
|
||||||
|
{
|
||||||
|
int pos = indexof(attribute, "ou");
|
||||||
|
|
||||||
|
if (pos < 0) {
|
||||||
|
fprintf(stderr, "Invalid attribute \"%c\" found\n", attribute);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (modifier) {
|
||||||
|
case '+': attrs |= (1<<pos); break;
|
||||||
|
case '-': attrs &=~(1<<pos); break;
|
||||||
|
case '!': attrs ^= (1<<pos); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
parse (char *text)
|
parse (char *text)
|
||||||
{
|
{
|
||||||
char *p = text;
|
|
||||||
|
|
||||||
int pos_x = 0;
|
|
||||||
int align = 0;
|
|
||||||
int underline_flag = 0;
|
|
||||||
|
|
||||||
font_t *cur_font;
|
font_t *cur_font;
|
||||||
monitor_t *cur_mon;
|
monitor_t *cur_mon;
|
||||||
|
int pos_x;
|
||||||
|
int align;
|
||||||
|
char *p = text, *end;
|
||||||
|
uint32_t tmp;
|
||||||
|
|
||||||
|
pos_x = 0;
|
||||||
|
align = ALIGN_L;
|
||||||
cur_font = main_font;
|
cur_font = main_font;
|
||||||
cur_mon = monhead;
|
cur_mon = monhead;
|
||||||
|
|
||||||
fill_rect (clear_gc, 0, 0, cfg.width, cfg.height);
|
fill_rect(gc[1], 0, 0, bw, bh);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (*p == '\0' || *p == '\n')
|
if (*p == '\0' || *p == '\n')
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (*p == '^' && p++ && *p != '^' && strchr ("_-fbulcrs", *p)) {
|
if (*p == '%' && p++ && *p == '{' && (end = strchr(p++, '}'))) {
|
||||||
|
while (p < end) {
|
||||||
|
while (isspace(*p))
|
||||||
|
p++;
|
||||||
|
|
||||||
switch (*p++) {
|
switch (*p++) {
|
||||||
case 'f':
|
case '+': set_attribute('+', *p++); break;
|
||||||
set_fg (isdigit(*p) ? *p-'0' : 11);
|
case '-': set_attribute('-', *p++); break;
|
||||||
p++;
|
case '!': set_attribute('!', *p++); break;
|
||||||
break;
|
|
||||||
case 'b':
|
case 'R':
|
||||||
set_bg (isdigit(*p) ? *p-'0' : 10);
|
tmp = fgc;
|
||||||
p++;
|
fgc = bgc;
|
||||||
break;
|
bgc = tmp;
|
||||||
case 'u':
|
update_gc();
|
||||||
set_ud (isdigit(*p) ? *p-'0' : 10);
|
|
||||||
p++;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '_':
|
case 'l': pos_x = 0; align = ALIGN_L; break;
|
||||||
underline_flag = (underline_flag == -1) ? 0 : -1;
|
case 'c': pos_x = 0; align = ALIGN_C; break;
|
||||||
break;
|
case 'r': pos_x = 0; align = ALIGN_R; break;
|
||||||
case '-':
|
|
||||||
underline_flag = (underline_flag == 1) ? 0 : 1;
|
case 'B': bgc = parse_color(p, &p, dbgc); update_gc(); break;
|
||||||
break;
|
case 'F': fgc = parse_color(p, &p, dfgc); update_gc(); break;
|
||||||
case 's':
|
case 'U': ugc = parse_color(p, &p, dbgc); update_gc(); break;
|
||||||
/* montail only gets set with multiple monitors */
|
|
||||||
if (montail) {
|
case 'S':
|
||||||
if (*p == 'r') {
|
if (*p == '+' && cur_mon->next)
|
||||||
cur_mon = montail;
|
{ cur_mon = cur_mon->next; pos_x = 0; }
|
||||||
} else if (*p == 'l') {
|
if (*p == '-' && cur_mon->prev)
|
||||||
cur_mon = monhead;
|
{ cur_mon = cur_mon->prev; pos_x = 0; }
|
||||||
} else if (*p == 'n') {
|
if (*p == 'f')
|
||||||
if (cur_mon->next)
|
{ cur_mon = monhead; pos_x = 0; }
|
||||||
cur_mon = cur_mon->next;
|
if (*p == 'l')
|
||||||
} else if (*p == 'p') {
|
{ cur_mon = montail ? montail : monhead; pos_x = 0; }
|
||||||
if (cur_mon->prev)
|
if (isdigit(*p))
|
||||||
cur_mon = cur_mon->prev;
|
{ cur_mon = monhead;
|
||||||
} else if (isdigit(*p)) {
|
|
||||||
cur_mon = monhead;
|
|
||||||
/* Start at 0 */
|
|
||||||
for (int i = 0; i != *p-'0' && cur_mon->next; i++)
|
for (int i = 0; i != *p-'0' && cur_mon->next; i++)
|
||||||
cur_mon = cur_mon->next;
|
cur_mon = cur_mon->next;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
p++;
|
p++;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
/* Consume the argument */
|
/* In case of error keep parsing after the closing } */
|
||||||
|
default:
|
||||||
|
p = end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Eat the trailing } */
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
align = ALIGN_L;
|
|
||||||
pos_x = 0;
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
align = ALIGN_L;
|
|
||||||
pos_x = 0;
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
align = ALIGN_C;
|
|
||||||
pos_x = 0;
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
align = ALIGN_R;
|
|
||||||
pos_x = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else { /* utf-8 -> ucs-2 */
|
} else { /* utf-8 -> ucs-2 */
|
||||||
uint8_t *utf = (uint8_t *)p;
|
uint8_t *utf = (uint8_t *)p;
|
||||||
uint16_t ucs;
|
uint16_t ucs;
|
||||||
|
@ -239,15 +267,15 @@ parse (char *text)
|
||||||
/* If the character is outside the main font charset use the alternate font */
|
/* If the character is outside the main font charset use the alternate font */
|
||||||
cur_font = (ucs < main_font->char_min || ucs > main_font->char_max) ? alt_font : main_font;
|
cur_font = (ucs < main_font->char_min || ucs > main_font->char_max) ? alt_font : main_font;
|
||||||
|
|
||||||
xcb_change_gc (c, draw_gc , XCB_GC_FONT, (const uint32_t []){ cur_font->ptr });
|
xcb_change_gc(c, gc[0] , XCB_GC_FONT, (const uint32_t []){ cur_font->ptr });
|
||||||
|
|
||||||
pos_x += draw_char (cur_mon, cur_font, pos_x, align, underline_flag, ucs);
|
pos_x += draw_char(cur_mon, cur_font, pos_x, align, ucs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
font_t *
|
font_t *
|
||||||
font_load (char *font_string)
|
font_load (const char *str)
|
||||||
{
|
{
|
||||||
xcb_query_font_cookie_t queryreq;
|
xcb_query_font_cookie_t queryreq;
|
||||||
xcb_query_font_reply_t *font_info;
|
xcb_query_font_reply_t *font_info;
|
||||||
|
@ -256,9 +284,9 @@ font_load (char *font_string)
|
||||||
|
|
||||||
font = xcb_generate_id(c);
|
font = xcb_generate_id(c);
|
||||||
|
|
||||||
cookie = xcb_open_font_checked (c, font, strlen (font_string), font_string);
|
cookie = xcb_open_font_checked(c, font, strlen(str), str);
|
||||||
if (xcb_request_check (c, cookie)) {
|
if (xcb_request_check (c, cookie)) {
|
||||||
fprintf (stderr, "Could not load font %s\n", font_string);
|
fprintf(stderr, "Could not load font %s\n", str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,11 +299,11 @@ font_load (char *font_string)
|
||||||
font_info = xcb_query_font_reply(c, queryreq, NULL);
|
font_info = xcb_query_font_reply(c, queryreq, NULL);
|
||||||
|
|
||||||
ret->ptr = font;
|
ret->ptr = font;
|
||||||
ret->width_lut = xcb_query_font_char_infos (font_info);
|
|
||||||
ret->descent = font_info->font_descent;
|
ret->descent = font_info->font_descent;
|
||||||
|
ret->height = font_info->font_ascent + font_info->font_descent;
|
||||||
ret->char_max = font_info->max_byte1 << 8 | font_info->max_char_or_byte2;
|
ret->char_max = font_info->max_byte1 << 8 | font_info->max_char_or_byte2;
|
||||||
ret->char_min = font_info->min_byte1 << 8 | font_info->min_char_or_byte2;
|
ret->char_min = font_info->min_byte1 << 8 | font_info->min_char_or_byte2;
|
||||||
ret->height = font_info->font_ascent + font_info->font_descent;
|
ret->width_lut = xcb_query_font_char_infos(font_info);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -328,17 +356,17 @@ set_ewmh_atoms (void)
|
||||||
/* Prepare the strut array */
|
/* Prepare the strut array */
|
||||||
for (monitor_t *mon = monhead; mon; mon = mon->next) {
|
for (monitor_t *mon = monhead; mon; mon = mon->next) {
|
||||||
int strut[12] = {0};
|
int strut[12] = {0};
|
||||||
if (cfg.place_bottom) {
|
if (topbar) {
|
||||||
strut[3] = cfg.height;
|
strut[2] = bh;
|
||||||
strut[10] = mon->x;
|
|
||||||
strut[11] = mon->x + mon->width;
|
|
||||||
} else {
|
|
||||||
strut[2] = cfg.height;
|
|
||||||
strut[8] = mon->x;
|
strut[8] = mon->x;
|
||||||
strut[9] = mon->x + mon->width;
|
strut[9] = mon->x + mon->width;
|
||||||
|
} else {
|
||||||
|
strut[3] = bh;
|
||||||
|
strut[10] = mon->x;
|
||||||
|
strut[11] = mon->x + mon->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_change_property (c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_WINDOW_OPACITY], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ (uint32_t)(cfg.alpha * 0xffffffff) } );
|
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_WINDOW_OPACITY], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ (uint32_t)(ba * 0xffffffff) } );
|
||||||
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_WINDOW_TYPE], XCB_ATOM_ATOM, 32, 1, &atom_list[NET_WM_WINDOW_TYPE_DOCK]);
|
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_WINDOW_TYPE], XCB_ATOM_ATOM, 32, 1, &atom_list[NET_WM_WINDOW_TYPE_DOCK]);
|
||||||
xcb_change_property(c, XCB_PROP_MODE_APPEND, mon->window, atom_list[NET_WM_STATE], XCB_ATOM_ATOM, 32, 2, &atom_list[NET_WM_STATE_STICKY]);
|
xcb_change_property(c, XCB_PROP_MODE_APPEND, mon->window, atom_list[NET_WM_STATE], XCB_ATOM_ATOM, 32, 2, &atom_list[NET_WM_STATE_STICKY]);
|
||||||
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_DESKTOP], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ -1 } );
|
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_DESKTOP], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ -1 } );
|
||||||
|
@ -362,17 +390,17 @@ monitor_new (int x, int y, int width, int height)
|
||||||
ret->width = width;
|
ret->width = width;
|
||||||
ret->next = ret->prev = NULL;
|
ret->next = ret->prev = NULL;
|
||||||
|
|
||||||
int win_y = (cfg.place_bottom ? (height - cfg.height) : 0) + y;
|
int win_y = (topbar ? 0 : height - bh) + y;
|
||||||
ret->window = xcb_generate_id(c);
|
ret->window = xcb_generate_id(c);
|
||||||
|
|
||||||
xcb_create_window(c, XCB_COPY_FROM_PARENT, ret->window, scr->root,
|
xcb_create_window(c, XCB_COPY_FROM_PARENT, ret->window, scr->root,
|
||||||
x, win_y, width, cfg.height, 0,
|
x, win_y, width, bh, 0,
|
||||||
XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
|
XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
|
||||||
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
|
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
|
||||||
(const uint32_t []){ palette[10], XCB_EVENT_MASK_EXPOSURE });
|
(const uint32_t []){ bgc, XCB_EVENT_MASK_EXPOSURE });
|
||||||
|
|
||||||
xcb_change_window_attributes(c, ret->window, XCB_CW_OVERRIDE_REDIRECT,
|
xcb_change_window_attributes(c, ret->window, XCB_CW_OVERRIDE_REDIRECT,
|
||||||
(const uint32_t []){ cfg.force_docking });
|
(const uint32_t []){ dock });
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -408,106 +436,97 @@ rect_sort_cb (const void *p1, const void *p2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
get_randr_outputs(void)
|
get_randr_monitors (void)
|
||||||
{
|
{
|
||||||
xcb_generic_error_t *err;
|
xcb_generic_error_t *err;
|
||||||
xcb_randr_get_screen_resources_current_cookie_t rres_query;
|
|
||||||
xcb_randr_get_screen_resources_current_reply_t *rres_reply;
|
xcb_randr_get_screen_resources_current_reply_t *rres_reply;
|
||||||
xcb_randr_output_t *outputs;
|
xcb_randr_output_t *outputs;
|
||||||
xcb_timestamp_t config_timestamp;
|
int num, valid = 0;
|
||||||
int i, j, num, cnt = 0;
|
int width = bw;
|
||||||
int width = cfg.width;
|
|
||||||
|
|
||||||
rres_query = xcb_randr_get_screen_resources_current(c, scr->root);
|
rres_reply = xcb_randr_get_screen_resources_current_reply(c,
|
||||||
rres_reply = xcb_randr_get_screen_resources_current_reply(c, rres_query, &err);
|
xcb_randr_get_screen_resources_current(c, scr->root), NULL);
|
||||||
if (rres_reply == NULL || err != NULL) {
|
|
||||||
|
if (!rres_reply) {
|
||||||
fprintf(stderr, "Failed to get current randr screen resources\n");
|
fprintf(stderr, "Failed to get current randr screen resources\n");
|
||||||
free(rres_reply);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
num = xcb_randr_get_screen_resources_current_outputs_length(rres_reply);
|
num = xcb_randr_get_screen_resources_current_outputs_length(rres_reply);
|
||||||
outputs = xcb_randr_get_screen_resources_current_outputs(rres_reply);
|
outputs = xcb_randr_get_screen_resources_current_outputs(rres_reply);
|
||||||
config_timestamp = rres_reply->config_timestamp;
|
|
||||||
|
|
||||||
if (num < 1) {
|
|
||||||
fprintf(stderr, "Failed to get current randr outputs\n");
|
|
||||||
free(rres_reply);
|
free(rres_reply);
|
||||||
|
|
||||||
|
/* There should be at least one output */
|
||||||
|
if (num < 1)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
xcb_rectangle_t rects[num];
|
xcb_rectangle_t rects[num];
|
||||||
|
|
||||||
/* get all outputs */
|
/* Get all outputs */
|
||||||
for (i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
xcb_randr_get_output_info_cookie_t output_query;
|
xcb_randr_get_output_info_reply_t *oi_reply;
|
||||||
xcb_randr_get_output_info_reply_t *output_reply;
|
xcb_randr_get_crtc_info_reply_t *ci_reply;
|
||||||
xcb_randr_get_crtc_info_cookie_t crtc_query;
|
|
||||||
xcb_randr_get_crtc_info_reply_t *crtc_reply;
|
|
||||||
|
|
||||||
output_query = xcb_randr_get_output_info(c, outputs[i], config_timestamp);
|
oi_reply = xcb_randr_get_output_info_reply(c, xcb_randr_get_output_info(c, outputs[i], XCB_CURRENT_TIME), NULL);
|
||||||
output_reply = xcb_randr_get_output_info_reply(c, output_query, &err);
|
|
||||||
if (err != NULL || output_reply == NULL || output_reply->crtc == XCB_NONE) {
|
/* Output disconnected or not attached to any CRTC ? */
|
||||||
|
if (!oi_reply || oi_reply->crtc == XCB_NONE) {
|
||||||
rects[i].width = 0;
|
rects[i].width = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
crtc_query = xcb_randr_get_crtc_info(c, output_reply->crtc, config_timestamp);
|
|
||||||
crtc_reply = xcb_randr_get_crtc_info_reply(c, crtc_query, &err);
|
|
||||||
if (err != NULL | crtc_reply == NULL) {
|
|
||||||
fprintf(stderr, "Failed to get randr ctrc info\n");
|
|
||||||
rects[i].width = 0;
|
|
||||||
free(output_reply);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (crtc_reply->rotation&(XCB_RANDR_ROTATION_ROTATE_90|XCB_RANDR_ROTATION_ROTATE_270))
|
ci_reply = xcb_randr_get_crtc_info_reply(c,
|
||||||
rects[i] = (xcb_rectangle_t){ crtc_reply->x, crtc_reply->y, crtc_reply->height, crtc_reply->width };
|
xcb_randr_get_crtc_info(c, oi_reply->crtc, XCB_CURRENT_TIME), NULL);
|
||||||
else
|
|
||||||
rects[i] = (xcb_rectangle_t){ crtc_reply->x, crtc_reply->y, crtc_reply->width, crtc_reply->height };
|
|
||||||
|
|
||||||
free(crtc_reply);
|
free(oi_reply);
|
||||||
free(output_reply);
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(rres_reply);
|
if (!ci_reply) {
|
||||||
|
fprintf(stderr, "Failed to get RandR ctrc info\n");
|
||||||
if (cnt < 1) {
|
|
||||||
fprintf(stderr, "No usable randr outputs\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for clones and inactive outputs */
|
if (ci_reply->rotation & (XCB_RANDR_ROTATION_ROTATE_90|XCB_RANDR_ROTATION_ROTATE_270))
|
||||||
for (i = 0; i < num; i++) {
|
rects[i] = (xcb_rectangle_t){ ci_reply->x, ci_reply->y, ci_reply->height, ci_reply->width };
|
||||||
|
else
|
||||||
|
rects[i] = (xcb_rectangle_t){ ci_reply->x, ci_reply->y, ci_reply->width, ci_reply->height };
|
||||||
|
|
||||||
|
free(ci_reply);
|
||||||
|
|
||||||
|
valid++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for clones and inactive outputs */
|
||||||
|
for (int i = 0; i < num; i++) {
|
||||||
if (rects[i].width == 0)
|
if (rects[i].width == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (j = 0; j < num; j++) {
|
for (int j = 0; j < num; j++) {
|
||||||
/* Does I countain J ? */
|
/* Does I countain J ? */
|
||||||
if (i != j && rects[j].width) {
|
if (i != j && rects[j].width) {
|
||||||
if (rects[j].x >= rects[i].x && rects[j].x <= rects[i].x + rects[j].width &&
|
if (rects[j].x >= rects[i].x && rects[j].x <= rects[i].x + rects[j].width &&
|
||||||
rects[j].y >= rects[i].y && rects[j].y <= rects[i].y + rects[i].height) {
|
rects[j].y >= rects[i].y && rects[j].y <= rects[i].y + rects[i].height) {
|
||||||
rects[j].width = 0;
|
rects[j].width = 0;
|
||||||
cnt--;
|
valid--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cnt < 1) {
|
if (valid < 1) {
|
||||||
fprintf(stderr, "No usable randr outputs\n");
|
fprintf(stderr, "No usable RandR output found\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sort by X */
|
/* Sort before use */
|
||||||
qsort(rects, cnt, sizeof(xcb_rectangle_t), rect_sort_cb);
|
qsort(rects, num, sizeof(xcb_rectangle_t), rect_sort_cb);
|
||||||
|
|
||||||
for (i = j = 0; i < num && j < cnt; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
if (rects[i].width) {
|
if (rects[i].width) {
|
||||||
monitor_t *mon = monitor_new(
|
monitor_t *mon = monitor_new(
|
||||||
rects[i].x,
|
rects[i].x,
|
||||||
rects[i].y,
|
rects[i].y,
|
||||||
MIN(width, rects[i].width),
|
min(width, rects[i].width),
|
||||||
rects[i].height);
|
rects[i].height);
|
||||||
|
|
||||||
monitor_add(mon);
|
monitor_add(mon);
|
||||||
|
@ -517,28 +536,27 @@ get_randr_outputs(void)
|
||||||
/* No need to check for other monitors */
|
/* No need to check for other monitors */
|
||||||
if (width <= 0)
|
if (width <= 0)
|
||||||
break;
|
break;
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
get_xinerama_screens (void)
|
get_xinerama_monitors (void)
|
||||||
{
|
{
|
||||||
xcb_xinerama_query_screens_reply_t *xqs_reply;
|
xcb_xinerama_query_screens_reply_t *xqs_reply;
|
||||||
xcb_xinerama_screen_info_iterator_t iter;
|
xcb_xinerama_screen_info_iterator_t iter;
|
||||||
int width = cfg.width;
|
int screens, width = bw;
|
||||||
int i, screens;
|
|
||||||
|
|
||||||
xqs_reply = xcb_xinerama_query_screens_reply(c,
|
xqs_reply = xcb_xinerama_query_screens_reply(c,
|
||||||
xcb_xinerama_query_screens_unchecked(c), NULL);
|
xcb_xinerama_query_screens_unchecked(c), NULL);
|
||||||
|
|
||||||
iter = xcb_xinerama_query_screens_screen_info_iterator(xqs_reply);
|
iter = xcb_xinerama_query_screens_screen_info_iterator(xqs_reply);
|
||||||
|
screens = iter.rem;
|
||||||
|
|
||||||
xcb_rectangle_t rects[iter.rem];
|
xcb_rectangle_t rects[screens];
|
||||||
|
|
||||||
/* Fetch all the screens first */
|
/* Fetch all the screens first */
|
||||||
for (i = 0; iter.rem; i++) {
|
for (int i = 0; iter.rem; i++) {
|
||||||
rects[i].x = iter.data->x_org;
|
rects[i].x = iter.data->x_org;
|
||||||
rects[i].y = iter.data->y_org;
|
rects[i].y = iter.data->y_org;
|
||||||
rects[i].width = iter.data->width;
|
rects[i].width = iter.data->width;
|
||||||
|
@ -546,17 +564,15 @@ get_xinerama_screens (void)
|
||||||
xcb_xinerama_screen_info_next(&iter);
|
xcb_xinerama_screen_info_next(&iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
screens = i;
|
/* Sort before use */
|
||||||
|
|
||||||
/* Sort by X */
|
|
||||||
qsort(rects, screens, sizeof(xcb_rectangle_t), rect_sort_cb);
|
qsort(rects, screens, sizeof(xcb_rectangle_t), rect_sort_cb);
|
||||||
|
|
||||||
/* The width is consumed across all the screens */
|
/* The width is consumed across all the screens */
|
||||||
for (i = 0; i < screens; i++) {
|
for (int i = 0; i < screens; i++) {
|
||||||
monitor_t *mon = monitor_new(
|
monitor_t *mon = monitor_new(
|
||||||
rects[i].x,
|
rects[i].x,
|
||||||
rects[i].y,
|
rects[i].y,
|
||||||
MIN(width, rects[i].width),
|
min(width, rects[i].width),
|
||||||
rects[i].height);
|
rects[i].height);
|
||||||
|
|
||||||
monitor_add(mon);
|
monitor_add(mon);
|
||||||
|
@ -572,7 +588,7 @@ get_xinerama_screens (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init (void)
|
xconn (void)
|
||||||
{
|
{
|
||||||
/* Connect to X */
|
/* Connect to X */
|
||||||
c = xcb_connect (NULL, NULL);
|
c = xcb_connect (NULL, NULL);
|
||||||
|
@ -583,26 +599,33 @@ init (void)
|
||||||
|
|
||||||
/* Grab infos from the first screen */
|
/* Grab infos from the first screen */
|
||||||
scr = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
|
scr = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init (void)
|
||||||
|
{
|
||||||
/* If I fits I sits */
|
/* If I fits I sits */
|
||||||
if (cfg.width < 0 || cfg.width > scr->width_in_pixels)
|
if (bw < 0 || bw > scr->width_in_pixels)
|
||||||
cfg.width = scr->width_in_pixels;
|
bw = scr->width_in_pixels;
|
||||||
|
|
||||||
/* Load the fonts */
|
/* Load the fonts */
|
||||||
main_font = font_load((char *)cfg.main_font);
|
main_font = font_load(mfont ? mfont : "fixed");
|
||||||
if (!main_font)
|
if (!main_font)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
alt_font = font_load((char *)cfg.alt_font);
|
alt_font = font_load(afont ? afont : "fixed");
|
||||||
if (!alt_font)
|
if (!alt_font)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
/* To make the alignment uniform */
|
/* To make the alignment uniform */
|
||||||
main_font->height = alt_font->height = MAX(main_font->height, alt_font->height);
|
main_font->height = alt_font->height = max(main_font->height, alt_font->height);
|
||||||
|
|
||||||
|
/* Adjust the height */
|
||||||
|
if (bh < 0 || bh > scr->height_in_pixels)
|
||||||
|
bh = main_font->height + 1;
|
||||||
|
|
||||||
/* Generate a list of screens */
|
/* Generate a list of screens */
|
||||||
const xcb_query_extension_reply_t *qe_reply;
|
const xcb_query_extension_reply_t *qe_reply;
|
||||||
int width = cfg.width;
|
|
||||||
|
|
||||||
/* Initialiaze monitor list head and tail */
|
/* Initialiaze monitor list head and tail */
|
||||||
monhead = montail = NULL;
|
monhead = montail = NULL;
|
||||||
|
@ -611,7 +634,7 @@ init (void)
|
||||||
qe_reply = xcb_get_extension_data(c, &xcb_randr_id);
|
qe_reply = xcb_get_extension_data(c, &xcb_randr_id);
|
||||||
|
|
||||||
if (qe_reply && qe_reply->present) {
|
if (qe_reply && qe_reply->present) {
|
||||||
get_randr_outputs ();
|
get_randr_monitors();
|
||||||
} else {
|
} else {
|
||||||
qe_reply = xcb_get_extension_data(c, &xcb_xinerama_id);
|
qe_reply = xcb_get_extension_data(c, &xcb_xinerama_id);
|
||||||
|
|
||||||
|
@ -621,7 +644,7 @@ init (void)
|
||||||
xia_reply = xcb_xinerama_is_active_reply(c, xcb_xinerama_is_active(c), NULL);
|
xia_reply = xcb_xinerama_is_active_reply(c, xcb_xinerama_is_active(c), NULL);
|
||||||
|
|
||||||
if (xia_reply && xia_reply->state)
|
if (xia_reply && xia_reply->state)
|
||||||
get_xinerama_screens ();
|
get_xinerama_monitors();
|
||||||
|
|
||||||
free(xia_reply);
|
free(xia_reply);
|
||||||
}
|
}
|
||||||
|
@ -629,7 +652,7 @@ init (void)
|
||||||
|
|
||||||
if (!monhead)
|
if (!monhead)
|
||||||
/* If no RandR outputs or Xinerama screens, fall back to using whole screen */
|
/* If no RandR outputs or Xinerama screens, fall back to using whole screen */
|
||||||
monhead = monitor_new (0, 0, width, scr->height_in_pixels);
|
monhead = monitor_new(0, 0, bw, scr->height_in_pixels);
|
||||||
|
|
||||||
if (!monhead)
|
if (!monhead)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -639,17 +662,20 @@ init (void)
|
||||||
|
|
||||||
/* Create a temporary canvas */
|
/* Create a temporary canvas */
|
||||||
canvas = xcb_generate_id(c);
|
canvas = xcb_generate_id(c);
|
||||||
xcb_create_pixmap (c, scr->root_depth, canvas, scr->root, cfg.width, cfg.height);
|
xcb_create_pixmap(c, scr->root_depth, canvas, scr->root, bw, bh);
|
||||||
|
|
||||||
|
/* Default to the classic B/W combo */
|
||||||
|
ugc = fgc;
|
||||||
|
|
||||||
/* Create the gc for drawing */
|
/* Create the gc for drawing */
|
||||||
draw_gc = xcb_generate_id (c);
|
gc[0] = xcb_generate_id(c);
|
||||||
xcb_create_gc (c, draw_gc, scr->root, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, (const uint32_t []){ palette[11], palette[10] });
|
xcb_create_gc(c, gc[0], scr->root, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, (const uint32_t []){ fgc, bgc });
|
||||||
|
|
||||||
clear_gc = xcb_generate_id (c);
|
gc[1] = xcb_generate_id(c);
|
||||||
xcb_create_gc (c, clear_gc, scr->root, XCB_GC_FOREGROUND, (const uint32_t []){ palette[10] });
|
xcb_create_gc(c, gc[1], scr->root, XCB_GC_FOREGROUND, (const uint32_t []){ bgc });
|
||||||
|
|
||||||
underl_gc = xcb_generate_id (c);
|
gc[2] = xcb_generate_id(c);
|
||||||
xcb_create_gc (c, underl_gc, scr->root, XCB_GC_FOREGROUND, (const uint32_t []){ palette[10] });
|
xcb_create_gc(c, gc[2], scr->root, XCB_GC_FOREGROUND, (const uint32_t []){ bgc });
|
||||||
|
|
||||||
/* Make the bar visible */
|
/* Make the bar visible */
|
||||||
for (monitor_t *mon = monhead; mon; mon = mon->next)
|
for (monitor_t *mon = monhead; mon; mon = mon->next)
|
||||||
|
@ -679,12 +705,12 @@ cleanup (void)
|
||||||
|
|
||||||
if (canvas)
|
if (canvas)
|
||||||
xcb_free_pixmap(c, canvas);
|
xcb_free_pixmap(c, canvas);
|
||||||
if (draw_gc)
|
if (gc[0])
|
||||||
xcb_free_gc (c, draw_gc);
|
xcb_free_gc(c, gc[0]);
|
||||||
if (clear_gc)
|
if (gc[1])
|
||||||
xcb_free_gc (c, clear_gc);
|
xcb_free_gc(c, gc[1]);
|
||||||
if (underl_gc)
|
if (gc[2])
|
||||||
xcb_free_gc (c, underl_gc);
|
xcb_free_gc(c, gc[2]);
|
||||||
if (c)
|
if (c)
|
||||||
xcb_disconnect(c);
|
xcb_disconnect(c);
|
||||||
}
|
}
|
||||||
|
@ -711,14 +737,14 @@ parse_geometry_string (char *str)
|
||||||
|
|
||||||
tmp = strtoul(p, &q, 10);
|
tmp = strtoul(p, &q, 10);
|
||||||
if (p != q)
|
if (p != q)
|
||||||
cfg.width = tmp;
|
bw = tmp;
|
||||||
|
|
||||||
/* P now might point to a NULL char, strtoul takes care of that */
|
/* P now might point to a NULL char, strtoul takes care of that */
|
||||||
p = q + 1;
|
p = q + 1;
|
||||||
|
|
||||||
tmp = strtoul(p, &q, 10);
|
tmp = strtoul(p, &q, 10);
|
||||||
if (p != q)
|
if (p != q)
|
||||||
cfg.height = tmp;
|
bh = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -731,10 +757,10 @@ parse_font_list (char *str)
|
||||||
|
|
||||||
tok = strtok(str, ",");
|
tok = strtok(str, ",");
|
||||||
if (tok)
|
if (tok)
|
||||||
strncpy(cfg.main_font, tok, sizeof(cfg.main_font));
|
mfont = tok;
|
||||||
tok = strtok(NULL, ",");
|
tok = strtok(NULL, ",");
|
||||||
if (tok)
|
if (tok)
|
||||||
strncpy(cfg.alt_font, tok, sizeof(cfg.alt_font));
|
afont = tok;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -742,59 +768,72 @@ parse_font_list (char *str)
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char input[1024] = {0, };
|
char input[2048] = {0, };
|
||||||
struct pollfd pollin[2] = {
|
struct pollfd pollin[2] = {
|
||||||
{ .fd = STDIN_FILENO, .events = POLLIN },
|
{ .fd = STDIN_FILENO, .events = POLLIN },
|
||||||
{ .fd = -1 , .events = POLLIN },
|
{ .fd = -1 , .events = POLLIN },
|
||||||
};
|
};
|
||||||
|
|
||||||
xcb_generic_event_t *ev;
|
xcb_generic_event_t *ev;
|
||||||
xcb_expose_event_t *expose_ev;
|
xcb_expose_event_t *expose_ev;
|
||||||
|
bool permanent = false;
|
||||||
|
|
||||||
|
/* Install the parachute! */
|
||||||
|
atexit(cleanup);
|
||||||
|
signal(SIGINT, sighandle);
|
||||||
|
signal(SIGTERM, sighandle);
|
||||||
|
|
||||||
|
/* Connect to the Xserver and initialize scr */
|
||||||
|
xconn();
|
||||||
|
|
||||||
|
/* B/W combo */
|
||||||
|
dbgc = bgc = scr->black_pixel;
|
||||||
|
dfgc = fgc = scr->white_pixel;
|
||||||
|
|
||||||
char ch;
|
char ch;
|
||||||
while ((ch = getopt (argc, argv, "hg:bdf:a:o:p")) != -1) {
|
while ((ch = getopt(argc, argv, "hg:bdf:a:pB:F:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
printf ("usage: %s [-h | -g | -b | -d | -f | -a | -o | -p ]\n"
|
printf ("usage: %s [-h | -g | -b | -d | -f | -a | -p | -B | -F]\n"
|
||||||
"\t-h Show this help\n"
|
"\t-h Show this help\n"
|
||||||
"\t-g Set the bar geometry {width}x{height})\n"
|
"\t-g Set the bar geometry {width}x{height})\n"
|
||||||
"\t-b Put bar at the bottom of the screen\n"
|
"\t-b Put bar at the bottom of the screen\n"
|
||||||
"\t-d Force docking (use this if your WM isn't EWMH compliant)\n"
|
"\t-d Force docking (use this if your WM isn't EWMH compliant)\n"
|
||||||
"\t-f Bar font list, comma separated\n"
|
"\t-f Bar font list, comma separated\n"
|
||||||
"\t-a Set the bar alpha ranging from 0.0 to 1.0 (requires a compositor)\n"
|
"\t-a Set the bar alpha ranging from 0.0 to 1.0 (requires a compositor)\n"
|
||||||
"\t-p Don't close after the data ends\n", argv[0]);
|
"\t-p Don't close after the data ends\n"
|
||||||
|
"\t-B Set background color in #RRGGBB\n"
|
||||||
|
"\t-F Set foreground color in #RRGGBB\n", argv[0]);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
case 'a': cfg.alpha = strtof(optarg, NULL); break;
|
case 'a': ba = strtof(optarg, NULL); break;
|
||||||
case 'g': parse_geometry_string(optarg); break;
|
case 'g': parse_geometry_string(optarg); break;
|
||||||
case 'p': cfg.permanent = 1; break;
|
case 'p': permanent = true; break;
|
||||||
case 'b': cfg.place_bottom = 1; break;
|
case 'b': topbar = false; break;
|
||||||
case 'd': cfg.force_docking = 1; break;
|
case 'd': dock = true; break;
|
||||||
case 'f': parse_font_list(optarg); break;
|
case 'f': parse_font_list(optarg); break;
|
||||||
|
case 'B': dbgc = bgc = parse_color(optarg, NULL, scr->black_pixel); break;
|
||||||
|
case 'F': dfgc = fgc = parse_color(optarg, NULL, scr->white_pixel); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanitize the arguments */
|
/* Sanitize the arguments */
|
||||||
if (cfg.alpha > 1.0f)
|
if (ba > 1.0f)
|
||||||
cfg.alpha = 1.0f;
|
ba = 1.0f;
|
||||||
if (cfg.alpha < 0.0f)
|
if (ba < 0.0f)
|
||||||
cfg.alpha = 0.0f;
|
ba = 0.0f;
|
||||||
|
|
||||||
atexit (cleanup);
|
/* Do the heavy lifting */
|
||||||
signal (SIGINT, sighandle);
|
|
||||||
signal (SIGTERM, sighandle);
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
/* Get the fd to Xserver */
|
/* Get the fd to Xserver */
|
||||||
pollin[1].fd = xcb_get_file_descriptor(c);
|
pollin[1].fd = xcb_get_file_descriptor(c);
|
||||||
|
/* Clear the bar */
|
||||||
fill_rect (clear_gc, 0, 0, cfg.width, cfg.height);
|
fill_rect(gc[1], 0, 0, bw, bh);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int redraw = 0;
|
bool redraw = false;
|
||||||
|
|
||||||
if (poll(pollin, 2, -1) > 0) {
|
if (poll(pollin, 2, -1) > 0) {
|
||||||
if (pollin[0].revents & POLLHUP) { /* No more data... */
|
if (pollin[0].revents & POLLHUP) { /* No more data... */
|
||||||
if (cfg.permanent) pollin[0].fd = -1; /* ...null the fd and continue polling :D */
|
if (permanent) pollin[0].fd = -1; /* ...null the fd and continue polling :D */
|
||||||
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 */
|
||||||
|
@ -802,7 +841,7 @@ main (int argc, char **argv)
|
||||||
break; /* EOF received */
|
break; /* EOF received */
|
||||||
|
|
||||||
parse(input);
|
parse(input);
|
||||||
redraw = 1;
|
redraw = true;
|
||||||
}
|
}
|
||||||
if (pollin[1].revents & POLLIN) { /* Xserver broadcasted an event */
|
if (pollin[1].revents & POLLIN) { /* Xserver broadcasted an event */
|
||||||
while ((ev = xcb_poll_for_event(c))) {
|
while ((ev = xcb_poll_for_event(c))) {
|
||||||
|
@ -810,7 +849,7 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
switch (ev->response_type & 0x7F) {
|
switch (ev->response_type & 0x7F) {
|
||||||
case XCB_EXPOSE:
|
case XCB_EXPOSE:
|
||||||
if (expose_ev->count == 0) redraw = 1;
|
if (expose_ev->count == 0) redraw = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -821,7 +860,7 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
if (redraw) { /* Copy our temporary pixmap onto the window */
|
if (redraw) { /* Copy our temporary pixmap onto the window */
|
||||||
for (monitor_t *mon = monhead; mon; mon = mon->next) {
|
for (monitor_t *mon = monhead; mon; mon = mon->next) {
|
||||||
xcb_copy_area (c, canvas, mon->window, draw_gc, mon->x, 0, 0, 0, mon->width, cfg.height);
|
xcb_copy_area(c, canvas, mon->window, gc[0], mon->x, 0, 0, 0, mon->width, bh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
config.def.h
15
config.def.h
|
@ -1,15 +0,0 @@
|
||||||
/* The thickness of the underline (in pixels). Set to 0 to disable. */
|
|
||||||
#define BAR_UNDERLINE_HEIGHT 2
|
|
||||||
/* Color palette */
|
|
||||||
#define BACKGROUND 0x232c31
|
|
||||||
#define COLOR0 0x2d3c46
|
|
||||||
#define COLOR1 0xac4142
|
|
||||||
#define COLOR2 0x90a959
|
|
||||||
#define COLOR3 0xde935f
|
|
||||||
#define COLOR4 0x6a9fb5
|
|
||||||
#define COLOR5 0xaa759f
|
|
||||||
#define COLOR6 0x75b5aa
|
|
||||||
#define COLOR7 0x6c7a80
|
|
||||||
#define COLOR8 0x425059
|
|
||||||
#define COLOR9 0xcc6666
|
|
||||||
#define FOREGROUND 0xc5c8c6
|
|
Loading…
Reference in New Issue
Block a user