Fix fifo code

This commit is contained in:
Martin Duquesnoy 2011-10-27 15:01:13 +02:00
parent 1642779b8c
commit d1ec33ed53
2 changed files with 15 additions and 31 deletions

View File

@ -528,9 +528,7 @@ client_frame_new(struct client *c)
struct client*
client_new(Window w, XWindowAttributes *wa)
{
struct client *c = NULL;
c = xcalloc(1, sizeof(struct client));
struct client *c = xcalloc(1, sizeof(struct client));
/* C attributes */
c->win = w;
@ -794,7 +792,7 @@ client_apply_tgeo(struct tag *t)
do { \
SLIST_FOREACH(gc, &c->tag->clients, tnext) \
draw_reversed_rect(W->root, &gc->tgeo); \
draw_reversed_cross(W->root, &c->tag->sel->tgeo); \
/* draw_reversed_cross(W->root, &c->tag->sel->tgeo);*/ \
} while(/* CONSTCOND */ 0);
void
client_fac_resize(struct client *c, enum position p, int fac)

View File

@ -14,38 +14,30 @@ fifo_init(void)
{
xasprintf(&(W->fifo.path), "%s/wmfs-%s.fifo", P_tmpdir, DisplayString(W->dpy));
if(mkfifo(W->fifo.path, 0644) < 0 || !(W->fifo.fd = open(W->fifo.path, O_NONBLOCK, 0)))
if(mkfifo(W->fifo.path, 0644) < 0)
warnx("Can't create FIFO: %s\n", strerror(errno));
if(!(W->fifo.fd = open(W->fifo.path, O_NONBLOCK, 0)))
warnx("Can't open FIFO: %s\n", strerror(errno));
}
static void
fifo_parse(char *cmd)
{
void (*func)(Uicb);
char *uicb = NULL;
char *arg = NULL;
char *p = NULL;
char *p = NULL;
/* remove trailing newline */
if((p = strchr(cmd, '\n')))
*p = 0;
*p = '\0';
/* Check if an argument is present */
/* If an argument is present, delimit function string */
if((p = strchr(cmd, ' ')))
{
*p = 0;
arg = xstrdup(p + 1);
}
uicb = xstrdup(cmd);
*p = '\0';
/* call the UICB function */
func = uicb_name_func(uicb);
if(func)
func(arg);
if(arg)
free(arg);
free(uicb);
/* call the UICB function, p + 1 is command or NULL */
if((func = uicb_name_func(cmd)))
func(p + 1);
XSync(W->dpy, false);
}
@ -53,14 +45,8 @@ fifo_parse(char *cmd)
void
fifo_read(void)
{
char buf[256] = {0};
static char buf[256] = { 0 };
/* Don't read it if not open */
if(!(W->fifo.fd))
return;
read(W->fifo.fd, buf, sizeof(buf) - 1);
if(buf[0])
if(read(W->fifo.fd, buf, sizeof(buf) - 1) > 0)
fifo_parse(buf);
}