Redraw on expose (#1).
This commit is contained in:
parent
8beab7672d
commit
a7dbc379bf
36
bar.c
36
bar.c
|
@ -3,6 +3,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -14,10 +17,9 @@ static int ft_height, ft_width;
|
||||||
static xcb_window_t root, win;
|
static xcb_window_t root, win;
|
||||||
static xcb_gcontext_t gc;
|
static xcb_gcontext_t gc;
|
||||||
static int bw, bh;
|
static int bw, bh;
|
||||||
static const int pal[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9};
|
static const uint32_t pal[] = {COLOR0,COLOR1,COLOR2,COLOR3,COLOR4,COLOR5,COLOR6,COLOR7,COLOR8,COLOR9};
|
||||||
static xcb_drawable_t canvas;
|
static xcb_drawable_t canvas;
|
||||||
|
|
||||||
|
|
||||||
#define MIN(a,b) ((a > b ? b : a))
|
#define MIN(a,b) ((a > b ? b : a))
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -42,7 +44,7 @@ draw (int x, int align, int fgcol, int bgcol, char *text)
|
||||||
}
|
}
|
||||||
/* Draw the background first */
|
/* Draw the background first */
|
||||||
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[bgcol] });
|
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[bgcol] });
|
||||||
xcb_poly_fill_rectangle (c, canvas, gc, 1, (const xcb_rectangle_t []){ pos_x, 0, strw, BAR_HEIGHT });
|
xcb_poly_fill_rectangle (c, canvas, gc, 1, (const xcb_rectangle_t []){ {pos_x, 0, strw, BAR_HEIGHT} });
|
||||||
/* Setup the colors */
|
/* Setup the colors */
|
||||||
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[fgcol] });
|
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[fgcol] });
|
||||||
xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[bgcol] });
|
xcb_change_gc (c, gc, XCB_GC_BACKGROUND, (const uint32_t []){ pal[bgcol] });
|
||||||
|
@ -70,7 +72,7 @@ parse (char *text)
|
||||||
int bgcol = 0;
|
int bgcol = 0;
|
||||||
|
|
||||||
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[0] });
|
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[0] });
|
||||||
xcb_poly_fill_rectangle (c, canvas, gc, 1, (const xcb_rectangle_t []){ 0, 0, bw, BAR_HEIGHT });
|
xcb_poly_fill_rectangle (c, canvas, gc, 1, (const xcb_rectangle_t []){ {0, 0, bw, BAR_HEIGHT} });
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (*p == 0x0 || *p == 0xA || (*p == '\\' && p++ && *p != '\\' && strchr ("fblcr", *p))) {
|
if (*p == 0x0 || *p == 0xA || (*p == '\\' && p++ && *p != '\\' && strchr ("fblcr", *p))) {
|
||||||
pos_x += draw (pos_x, align, fgcol, bgcol, parsed_text);
|
pos_x += draw (pos_x, align, fgcol, bgcol, parsed_text);
|
||||||
|
@ -103,8 +105,7 @@ cleanup (void)
|
||||||
void
|
void
|
||||||
sighandle (int signal)
|
sighandle (int signal)
|
||||||
{
|
{
|
||||||
if (signal == SIGINT || signal == SIGTERM)
|
if (signal == SIGINT || signal == SIGTERM) exit (0);
|
||||||
exit (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -138,8 +139,8 @@ init (void)
|
||||||
/* Create the main window */
|
/* Create the main window */
|
||||||
win = xcb_generate_id (c);
|
win = xcb_generate_id (c);
|
||||||
xcb_create_window (c, XCB_COPY_FROM_PARENT, win, root, 0, 0, bw, bh, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
xcb_create_window (c, XCB_COPY_FROM_PARENT, win, root, 0, 0, bw, bh, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
||||||
scr->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT,
|
scr->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
|
||||||
(const uint32_t []){ pal[0], 1 });
|
(const uint32_t []){ pal[0], 1, XCB_EVENT_MASK_EXPOSURE });
|
||||||
/* 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, root, bw, BAR_HEIGHT);
|
xcb_create_pixmap (c, scr->root_depth, canvas, root, bw, BAR_HEIGHT);
|
||||||
|
@ -158,6 +159,7 @@ int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
static char input[1024] = {0, };
|
static char input[1024] = {0, };
|
||||||
|
xcb_expose_event_t *e;
|
||||||
int permanent = 0;
|
int permanent = 0;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
|
@ -174,14 +176,26 @@ main (int argc, char **argv)
|
||||||
signal (SIGTERM, sighandle);
|
signal (SIGTERM, sighandle);
|
||||||
init ();
|
init ();
|
||||||
|
|
||||||
while (fgets (input, sizeof(input), stdin)) {
|
xcb_change_gc (c, gc, XCB_GC_FOREGROUND, (const uint32_t []){ pal[0] });
|
||||||
|
xcb_poly_fill_rectangle (c, canvas, gc, 1, (const xcb_rectangle_t []){ {0, 0, bw, BAR_HEIGHT} });
|
||||||
|
struct pollfd pollin = { .fd = STDIN_FILENO, .events = POLLIN | POLLHUP};
|
||||||
|
for (;;) {
|
||||||
|
if (poll (&pollin, 1, -1) > 0) { /* Read from stdin */
|
||||||
|
if (pollin.revents & POLLHUP) break; /* No more data */
|
||||||
|
fgets (input, sizeof(input), stdin);
|
||||||
parse (input);
|
parse (input);
|
||||||
xcb_copy_area (c, canvas, win, gc, 0, 0, 0, 0, bw, BAR_HEIGHT);
|
xcb_copy_area (c, canvas, win, gc, 0, 0, 0, 0, bw, BAR_HEIGHT);
|
||||||
|
}
|
||||||
|
if ((e = (xcb_expose_event_t *)xcb_poll_for_event (c))) { /* Handle the xcb expose event */
|
||||||
|
if (e && (e->response_type & ~0x80) == XCB_EXPOSE) {
|
||||||
|
xcb_copy_area (c, canvas, win, gc, e->x, e->y, e->x, e->y, e->width, e->height);
|
||||||
|
free (e);
|
||||||
|
}
|
||||||
|
}
|
||||||
xcb_flush (c);
|
xcb_flush (c);
|
||||||
}
|
}
|
||||||
/* There's no more data, but the user still wants to see it */
|
/* There's no more data, but the user still wants to see it */
|
||||||
while (permanent) sleep(1);
|
while (permanent) sleep (1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user