Add infobar creation

This commit is contained in:
Martin Duquesnoy 2011-08-25 18:13:42 +02:00
parent a0f82a1135
commit 7f346c150c
8 changed files with 128 additions and 17 deletions

View File

@ -201,13 +201,13 @@ event_expose(XEvent *e)
{
XExposeEvent *ev = &e->xexpose;
Barwin *b;
/*
SLIST_FOREACH(b, &W->h.barwin, next)
if(b->win == ev->window)
{
barwin_refresh(b);
return;
}
}*/
}
static void

View File

@ -5,6 +5,80 @@
#include "wmfs.h"
#include "infobar.h"
#include "barwin.h"
#include "util.h"
#define ELEM_DEFAULT_ORDER "tlsS"
#define INFOBAR_DEF_W (12)
void
infobar_init(void)
{
Infobar *i;
Scr33n *s;
SLIST_FOREACH(s, &W->h.screen, next)
{
i = (Infobar*)xcalloc(1, sizeof(Infobar));
i->screen = s;
i->elemorder = xstrdup(ELEM_DEFAULT_ORDER);
STAILQ_INIT(&i->elements);
/* Positions TODO: geo = infobar_position(Position {Top,Bottom,Hidden}) */
i->geo = s->geo;
i->geo.h = INFOBAR_DEF_W;
/* Barwin create */
i->bar = barwin_new(W->root, i->geo.x, i->geo.y, i->geo.w, i->geo.h, 0x222222, 0xCCCCCC, false);
/* Render */
barwin_map(i->bar);
barwin_map_subwin(i->bar);
barwin_refresh_color(i->bar);
/* TODO: infobar_elem_init(i) */
infobar_refresh(i);
SLIST_INSERT_HEAD(&s->infobars, i, next);
i = NULL;
}
}
void
infobar_refresh(Infobar *i)
{
barwin_refresh(i->bar);
}
void
infobar_remove(Infobar *i)
{
free(i->elemorder);
/* TODO: infobar_elem_free */
barwin_remove(i->bar);
SLIST_REMOVE(&i->screen->infobars, i, Infobar, next);
free(i);
}
void
infobar_free(Scr33n *s)
{
Infobar *i;
while(!SLIST_EMPTY(&s->infobars))
{
i = SLIST_FIRST(&s->infobars);
infobar_remove(i);
}
}

View File

@ -19,5 +19,10 @@ const struct elem_funcs { char c; void (*func_init)(Infobar *i); void (*func_upd
{ '\0', NULL, NULL }
};*/
void infobar_init(void);
Infobar *infobar_new(Scr33n *s);
void infobar_refresh(Infobar *i);
void infobar_remove(Infobar *i);
void infobar_free(Scr33n *s);
#endif /* INFOBAR_H */

View File

@ -13,14 +13,16 @@
#include "util.h"
static Scr33n*
screen_new(Geo *g)
screen_new(Geo *g, int id)
{
Scr33n *s = xcalloc(1, sizeof(Scr33n));
s->geo = *g;
s->seltag = NULL;
s->id = id;
SLIST_INIT(&s->tags);
SLIST_INIT(&s->infobars);
SLIST_INSERT_HEAD(&W->h.screen, s, next);
@ -40,26 +42,22 @@ screen_init(void)
#ifdef HAVE_XINERAMA
XineramaScreenInfo *xsi;
int i = 0, n;
int i, n = 0;
if(XineramaIsActive(W->dpy))
{
xsi = XineramaQueryScreens(W->dpy, &n);
for(; i < n; ++i)
for(i = 0; i < n; ++i)
{
s = NULL;
g.x = xsi[i].x_org;
g.y = xsi[i].y_org;
g.w = xsi[i].width;
g.h = xsi[i].height;
s = screen_new(&g);
s = screen_new(&g, i);
tag_screen(s, tag_new(s, "tag")); /* tmp */
SLIST_INSERT_HEAD(&W->h.screen, s, next);
printf("%d: %d %d %d %d\n", i, s->geo.x, s->geo.y, s->geo.w, s->geo.h);
s = NULL;
}
XFree(xsi);
@ -67,21 +65,30 @@ screen_init(void)
else
#endif /* HAVE_XINERAMA */
{
g.x = g.y = 0;
g.w = DisplayWidth(W->dpy, W->xscreen);
g.h = DisplayHeight(W->dpy, W->xscreen);
s = screen_new(&g);
s = screen_new(&g, 0);
tag_screen(s, tag_new(s, "tag"));
SLIST_INSERT_HEAD(&W->h.screen, s, next);
printf("%d: %d %d %d %d\n", i, s->geo.x, s->geo.y, s->geo.w, s->geo.h);
}
SLIST_FOREACH(s, &W->h.screen, next)
printf("%d: %d %d %d %d\n", s->id, s->geo.x, s->geo.y, s->geo.w, s->geo.h);
}
void
screen_free(void)
{
FREE_LIST(Scr33n, W->h.screen);
Scr33n *s;
while(!SLIST_EMPTY(&W->h.screen))
{
s = SLIST_FIRST(&W->h.screen);
SLIST_REMOVE_HEAD(&W->h.screen, next);
infobar_free(s);
/*tag_free(s);*/
free(s);
}
}

View File

@ -4,6 +4,7 @@
*/
#include <stdint.h>
#include <string.h>
#include "util.h"
@ -64,6 +65,21 @@ xasprintf(char **strp, const char *fmt, ...)
return ret;
}
/** strdup with error support
* \param str char pointer
* \retun non null void pointer
*/
char *
xstrdup(const char *str)
{
char *ret;
if (str == NULL || (ret = strdup(str)) == NULL)
err(EXIT_FAILURE, "strdup(%s)", str);
return ret;
}
/** Execute a system command
* \param cmd Command
* \return child pid

View File

@ -24,6 +24,7 @@
void *xmalloc(size_t nmemb, size_t size);
void *xcalloc(size_t nmemb, size_t size);
int xasprintf(char **strp, const char *fmt, ...);
char *xstrdup(const char *str);
pid_t spawn(const char *format, ...);
#endif /* UTIL_H */

View File

@ -9,6 +9,7 @@
#include "wmfs.h"
#include "event.h"
#include "util.h"
/*#include "infobar.h" */
int
wmfs_error_handler(Display *d, XErrorEvent *event)
@ -222,6 +223,9 @@ wmfs_init(void)
/* Screen init */
screen_init();
/* Infobar init */
infobar_init();
}
void
@ -262,5 +266,7 @@ main(int argc, char **argv)
wmfs_loop();
wmfs_quit();
return 1;
}

View File

@ -78,6 +78,7 @@ struct Infobar
Barwin *bar;
Geo geo;
Scr33n *screen;
char *elemorder;
STAILQ_HEAD(, Element) elements;
SLIST_ENTRY(Infobar) next;
};
@ -87,7 +88,9 @@ struct Scr33n
{
Geo geo;
Tag *seltag;
int id;
SLIST_HEAD(, Tag) tags;
SLIST_HEAD(, Infobar) infobars;
SLIST_ENTRY(Scr33n) next;
};
@ -168,7 +171,6 @@ struct Wmfs
{
SLIST_HEAD(, Scr33n) screen;
SLIST_HEAD(, Client) client;
SLIST_HEAD(, Infobar) infobar;
SLIST_HEAD(, Keybind) keybind;
SLIST_HEAD(, Barwin) barwin;
} h;