Add status.c/h, status uicb cmd

This commit is contained in:
Martin Duquesnoy 2012-01-06 17:30:46 +01:00
parent f066c6dc26
commit abbb955217
6 changed files with 83 additions and 24 deletions

View File

@ -94,7 +94,7 @@ config_bars(void)
/* [bar] */
for(i = 0; i < n; ++i)
{
name = fetch_opt_first(ks[i], "infobar", "name").str;
name = fetch_opt_first(ks[i], "default", "name").str;
elem = fetch_opt_first(ks[i], "", "elements").str;
screenid = fetch_opt_first(ks[i], "-1", "screen").num;
t = name_to_theme(fetch_opt_first(ks[i], "default", "theme").str);

View File

@ -14,6 +14,7 @@
#include "util.h"
#include "tag.h"
#include "client.h"
#include "status.h"
#define THEME_DEFAULT (SLIST_FIRST(&W->h.theme))
@ -62,6 +63,10 @@ static const struct { char *name; void (*func)(Uicb cmd); } uicb_list[] =
{ "client_swap_next", uicb_client_swapsel_next },
{ "client_swap_prev", uicb_client_swapsel_prev },
{ "client_untab", uicb_client_untab },
/* Status */
{ "status" , uicb_status },
{ NULL, NULL }
};

View File

@ -34,7 +34,7 @@ static void
fifo_parse(char *cmd)
{
void (*func)(Uicb);
char *p = NULL;
char *p = NULL, *arg;
/* remove trailing newline */
if((p = strchr(cmd, '\n')))
@ -44,9 +44,12 @@ fifo_parse(char *cmd)
if((p = strchr(cmd, ' ')))
*p = '\0';
/* Avoid pointer out of bound if no arg */
arg = ((p + 1 == 1) ? NULL : p + 1);
/* call the UICB function, p + 1 is command or NULL */
if((func = uicb_name_func(cmd)))
func(p + 1);
func(arg);
XSync(W->dpy, false);
}

View File

@ -9,11 +9,11 @@
#include "barwin.h"
#include "util.h"
#include "tag.h"
#include "status.h"
static void infobar_elem_tag_init(struct element *e);
static void infobar_elem_tag_update(struct element *e);
static void infobar_elem_status_init(struct element *e);
static void infobar_elem_status_update(struct element *e);
const struct elem_funcs
{
@ -22,8 +22,8 @@ const struct elem_funcs
void (*func_update)(struct element *e);
} elem_funcs[] =
{
{ 't', infobar_elem_tag_init, infobar_elem_tag_update },
{ 's', infobar_elem_status_init, infobar_elem_status_update },
{ 't', infobar_elem_tag_init, infobar_elem_tag_update },
{ 's', infobar_elem_status_init, status_manage },
/* { 'l', infobar_elem_layout_init, infobar_elem_layout_update },
{ 'S', infobar_elem_selbar_init, infobar_elem_selbar_update },
@ -138,24 +138,6 @@ infobar_elem_status_init(struct element *e)
e->infobar->status = strdup("wmfs2");
}
static void
infobar_elem_status_update(struct element *e)
{
struct barwin *b = SLIST_FIRST(&e->bars);
int l;
barwin_refresh_color(b);
/* TODO: status_manage, status.c */
if(e->infobar->status)
{
l = draw_textw(e->infobar->theme, e->infobar->status);
draw_text(b->dr, e->infobar->theme, e->geo.w - l,
TEXTY(e->infobar->theme, e->geo.h), b->fg, e->infobar->status);
barwin_refresh(b);
}
}
#define ELEM_INIT(a) \
do { \
e = xcalloc(1, sizeof(struct element)); \

55
src/status.c Normal file
View File

@ -0,0 +1,55 @@
/*
* wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
* For license, see COPYING.
*/
#include "status.h"
#include "barwin.h"
#include "infobar.h"
#include "util.h"
void
status_manage(struct element *e)
{
struct barwin *b = SLIST_FIRST(&e->bars);
int l;
barwin_refresh_color(b);
if(e->infobar->status)
{
l = draw_textw(e->infobar->theme, e->infobar->status);
draw_text(b->dr, e->infobar->theme, e->geo.w - l,
TEXTY(e->infobar->theme, e->geo.h), b->fg, e->infobar->status);
barwin_refresh(b);
}
}
/* Syntax: "<infobar name> <status string>" */
void
uicb_status(Uicb cmd)
{
struct infobar *ib;
struct screen *s;
int i = 0;
char si[128] = { 0 };
if(!cmd)
return;
/* Get infobar name */
while(cmd[i] && cmd[i] != ' ')
si[i] = cmd[i++];
++i;
SLIST_FOREACH(s, &W->h.screen, next)
{
SLIST_FOREACH(ib, &s->infobars, next)
if(!strcmp(si, ib->name))
{
free(ib->status);
ib->status = xstrdup(cmd + i);
infobar_elem_screen_update(s, ElemStatus);
}
}
}

14
src/status.h Normal file
View File

@ -0,0 +1,14 @@
/*
* wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
* For license, see COPYING.
*/
#ifndef STATUS_H
#define STATUS_H
#include "wmfs.h"
void status_manage(struct element *e);
void uicb_status(Uicb cmd);
#endif /* STATUS_H */