[ALL] New feature: wmfs read the status text from stdin \o/

This commit is contained in:
Martin Duquesnoy 2008-09-21 17:16:45 +02:00
parent b9632b2fc0
commit ab76865a3a
3 changed files with 65 additions and 34 deletions

View File

@ -154,7 +154,8 @@ init_conf(void)
CFG_INT("tag_sel_fg", 0xFFFFFF, CFGF_NONE),
CFG_INT("tag_sel_bg", 0x354B5C, CFGF_NONE),
CFG_INT("layout_fg", 0xFFFFFF, CFGF_NONE),
CFG_INT("layout_bg", 0x292929, CFGF_NONE), CFG_END()
CFG_INT("layout_bg", 0x292929, CFGF_NONE),
CFG_END()
};
static cfg_opt_t layouts_opts[] =
@ -301,7 +302,7 @@ init_conf(void)
conf.tag[i].layout.func = layout_name_to_layout(cfg_getstr(cfgtmp, "layout"));
}
/* keybind ('tention ça rigole plus) */
/* keybind ('tention ça rigole plus) */
conf.nkeybind = cfg_size(cfg_keys, "key");
for(j = 0; j < cfg_size(cfg_keys, "key"); ++j)
{

16
event.c
View File

@ -298,22 +298,6 @@ unmapnotify(XEvent ev)
void
getevent(void)
{
struct timeval tv;
if(QLength(dpy) > 0)
XNextEvent(dpy, &event);
else
{
XFlush(dpy);
FD_ZERO(&fd);
FD_SET(ConnectionNumber(dpy), &fd);
event.type = LASTEvent;
tv.tv_sec = 60;
tv.tv_usec = 0;
if(select(FD_SETSIZE, &fd, NULL, NULL, &tv) > 0)
XNextEvent(dpy, &event);
}
switch (event.type)
{
case ButtonPress: buttonpress(event); break;

78
wmfs.c
View File

@ -294,17 +294,12 @@ init(void)
root = RootWindow (dpy, screen);
mw = DisplayWidth (dpy, screen);
mh = DisplayHeight (dpy, screen);
taglen[0] = 3;
/* INIT TAG / LAYOUT ATTRIBUTE */
taglen[0] = 3;
seltag = 1;
for(i = 0; i < conf.ntag + 1; ++i)
{
tags[i].nmaster = conf.tag[i-1].nmaster;
tags[i].mwfact = conf.tag[i-1].mwfact;
tags[i].name = conf.tag[i-1].name;
tags[i].layout.func = conf.tag[i-1].layout.func;
}
tags[i] = conf.tag[i-1];
/* INIT FONT */
font = XLoadQueryFont(dpy, conf.font);
@ -638,6 +633,12 @@ mouseaction(Client *c, int x, int y, int type)
XUngrabPointer(dpy, CurrentTime);
return;
}
else if(!conf.bartop && c->y + c->h > bary + 3)
{
moveresize(c, c->x, bary - c->h, c->w, c->h, 1);
XUngrabPointer(dpy, CurrentTime);
return;
}
}
}
return;
@ -698,8 +699,12 @@ moveresize(Client *c, int x, int y, int w, int h, bool r)
c->w = w; c->h = h;
if(conf.bartop)
{
if((y - conf.ttbarheight) <= barheight)
y = barheight+conf.ttbarheight;
} else
if(y - h >= bary)
y = bary - h;
XMoveResizeWindow(dpy, c->win, x, y, w ,h);
@ -779,7 +784,8 @@ setborder(Window win, int color)
}
void
setwinstate(Window win, long state) {
setwinstate(Window win, long state)
{
long data[] = {state, None};
XChangeProperty(dpy, win, wm_atom[WMState], wm_atom[WMState], 32,
@ -1145,11 +1151,6 @@ updatebar(void)
strlen(getlayoutsym(seltag)));
/* Draw status */
sprintf(bartext,"mwfact: %.2f nmaster: %i - %02i:%02i",
tags[seltag].mwfact,
tags[seltag].nmaster,
tm->tm_hour,
tm->tm_min);
j = strlen(bartext);
XSetForeground(dpy, gc, conf.colors.text);
@ -1298,7 +1299,12 @@ int
main(int argc,char **argv)
{
dpy = XOpenDisplay(NULL);
int i;
char *p;
char sbuf[sizeof bartext];
fd_set rd;
int i, r;
Bool readstdin;
uint len, offset = 0;
static struct option long_options[] = {
@ -1349,10 +1355,50 @@ main(int argc,char **argv)
scan();
updatebar();
readstdin = True;
len = sizeof bartext - 1;
sbuf[len] = bartext[len] = '\0';
while(!exiting)
{
getevent();
updateall();
FD_ZERO(&rd);
if(readstdin)
FD_SET(STDIN_FILENO, &rd);
FD_SET(ConnectionNumber(dpy), &rd);
if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, NULL) == -1)
printf("WARNING: Select failed\n");
if(FD_ISSET(STDIN_FILENO, &rd)) {
switch((r = read(STDIN_FILENO, sbuf + offset, len - offset)))
{
case -1:
case 0:
strncpy(bartext, sbuf, strlen(sbuf));
readstdin = False;
break;
default:
for(p = sbuf + offset; r > 0; ++p, --r, ++offset)
{
if(*p == '\n' || *p == '\0')
{
*p = '\0';
strncpy(bartext, sbuf, len);
p += r - 1;
for(r = 0; *(p - r) && *(p - r) != '\n'; ++r);
offset = r;
if(r)
memmove(sbuf, p - r + 1, r);
break;
}
}
break;
}
updatebar();
}
while(XPending(dpy))
{
XNextEvent(dpy, &event);
getevent();
}
}
/* Exiting WMFS :'( */