Add bars/tags section in conf, dynamique bar/element
This commit is contained in:
parent
cbbc7cb8dd
commit
434666421e
@ -6,9 +6,84 @@
|
||||
#include "config.h"
|
||||
#include "wmfs.h"
|
||||
#include "parse.h"
|
||||
#include "tag.h"
|
||||
#include "screen.h"
|
||||
#include "infobar.h"
|
||||
|
||||
#define CONFIG_DEFAULT_PATH ".config/wmfs/wmfsrc2" /* tmp */
|
||||
|
||||
static void
|
||||
config_bars(void)
|
||||
{
|
||||
Scr33n *s;
|
||||
size_t i, n, j, m;
|
||||
struct conf_sec *sec, **ks, **es;
|
||||
int screenid;
|
||||
|
||||
/* [bars] */
|
||||
sec = fetch_section_first(NULL, "bars");
|
||||
ks = fetch_section(sec, "bar");
|
||||
n = fetch_section_count(ks);
|
||||
|
||||
/* [bar] */
|
||||
for(i = 0; i < n; ++i)
|
||||
{
|
||||
char elem[128] = { 0 };
|
||||
|
||||
/* [element] */
|
||||
es = fetch_section(ks[i], "element");
|
||||
m = fetch_section_count(es);
|
||||
for(j = 0; j < m; ++j)
|
||||
elem[j] = fetch_opt_first(es[j], "t", "type").str[0];
|
||||
|
||||
screenid = fetch_opt_first(ks[i], "-1", "screen").num;
|
||||
|
||||
SLIST_FOREACH(s, &W->h.screen, next)
|
||||
if(screenid == s->id || screenid == -1)
|
||||
(Infobar*)infobar_new(s, elem);
|
||||
|
||||
free(es);
|
||||
}
|
||||
|
||||
free(ks);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
config_tag(void)
|
||||
{
|
||||
Scr33n *s;
|
||||
Tag *t;
|
||||
size_t i, n;
|
||||
struct conf_sec *sec, **ks;
|
||||
char *name;
|
||||
int screenid;
|
||||
|
||||
/* [tags] */
|
||||
sec = fetch_section_first(NULL, "tags");
|
||||
ks = fetch_section(sec, "tag");
|
||||
n = fetch_section_count(ks);
|
||||
|
||||
/* [tag] */
|
||||
for(i = 0; i < n; ++i)
|
||||
{
|
||||
name = fetch_opt_first(ks[i], "tag", "name").str;
|
||||
screenid = fetch_opt_first(ks[i], "-1", "screen").num;
|
||||
|
||||
SLIST_FOREACH(s, &W->h.screen, next)
|
||||
if(screenid == s->id || screenid == -1)
|
||||
{
|
||||
t = tag_new(s, name);
|
||||
|
||||
/* Set first tag as seltag */
|
||||
if(t == TAILQ_FIRST(&s->tags))
|
||||
s->seltag = t;
|
||||
}
|
||||
}
|
||||
|
||||
free(ks);
|
||||
}
|
||||
|
||||
static void
|
||||
config_keybind(void)
|
||||
{
|
||||
@ -18,17 +93,19 @@ config_keybind(void)
|
||||
struct opt_type *opt;
|
||||
Keybind *k;
|
||||
|
||||
/* [keys] */
|
||||
sec = fetch_section_first(NULL, "keys");
|
||||
ks = fetch_section(sec, "key");
|
||||
n = fetch_section_count(ks);
|
||||
|
||||
SLIST_INIT(&W->h.keybind);
|
||||
|
||||
/* [key] */
|
||||
for(i = 0; i < n; ++i)
|
||||
{
|
||||
opt = fetch_opt(ks[i], "", "mod");
|
||||
|
||||
k = xcalloc(1, sizeof(Keybind));
|
||||
k = (Keybind*)xcalloc(1, sizeof(Keybind));
|
||||
|
||||
for(j = 0; j < fetch_opt_count(opt); ++j)
|
||||
k->mod |= modkey_keysym(opt[j].str);
|
||||
@ -39,15 +116,14 @@ config_keybind(void)
|
||||
|
||||
if(!(k->func = uicb_name_func(fetch_opt_first(ks[i], "", "func").str)))
|
||||
{
|
||||
warnx("configuration : Unknown Function \"%s\".", fetch_opt_first(ks[i], "", "func").str);
|
||||
warnx("configuration: Unknown Function \"%s\".",
|
||||
fetch_opt_first(ks[i], "", "func").str);
|
||||
k->func = uicb_spawn;
|
||||
}
|
||||
|
||||
k->cmd = fetch_opt_first(ks[i], "", "cmd").str;
|
||||
|
||||
SLIST_INSERT_HEAD(&W->h.keybind, k, next);
|
||||
|
||||
k = NULL;
|
||||
}
|
||||
|
||||
free(ks);
|
||||
@ -64,6 +140,8 @@ config_init(void)
|
||||
errx(1, "parsing configuration file (%s) failed.", path);
|
||||
|
||||
config_keybind();
|
||||
config_tag();
|
||||
config_bars();
|
||||
|
||||
free(path);
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#include "wmfs.h"
|
||||
|
||||
#define TEXTY(w) ((W->font.height - W->font.de) + ((w - W->font.height) >> 1))
|
||||
#define PAD (4)
|
||||
#define PAD (8)
|
||||
|
||||
static inline void
|
||||
draw_text(Drawable d, int x, int y, Color fg, const char *str)
|
||||
|
||||
@ -19,6 +19,8 @@ event_buttonpress(XEvent *e)
|
||||
Mousebind *m;
|
||||
Barwin *b;
|
||||
|
||||
screen_update_sel();
|
||||
|
||||
SLIST_FOREACH(b, &W->h.barwin, next)
|
||||
if(b->win == ev->window)
|
||||
{
|
||||
@ -201,6 +203,8 @@ event_keypress(XEvent *e)
|
||||
KeySym keysym = XKeycodeToKeysym(EVDPY(e), (KeyCode)ev->keycode, 0);
|
||||
Keybind *k;
|
||||
|
||||
screen_update_sel();
|
||||
|
||||
SLIST_FOREACH(k, &W->h.keybind, next)
|
||||
if(k->keysym == keysym && KEYPRESS_MASK(k->mod) == KEYPRESS_MASK(ev->state))
|
||||
if(k->func)
|
||||
|
||||
@ -10,8 +10,8 @@
|
||||
#include "util.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define ELEM_DEFAULT_ORDER "ttlsS"
|
||||
#define INFOBAR_DEF_W (12)
|
||||
#define INFOBAR_DEF_W (14)
|
||||
#define ELEM_TAG_BORDER (1)
|
||||
|
||||
static void infobar_elem_tag_init(Element *e);
|
||||
static void infobar_elem_tag_update(Element *e);
|
||||
@ -32,13 +32,13 @@ const struct elem_funcs
|
||||
{ '\0', NULL, NULL }
|
||||
};
|
||||
|
||||
/* Basic placement of elements */
|
||||
static inline void
|
||||
infobar_elem_placement(Element *e)
|
||||
{
|
||||
Element *p = TAILQ_PREV(e, esub, next);
|
||||
|
||||
e->geo.y = 0;
|
||||
e->geo.w = 0;
|
||||
e->geo.y = e->geo.w = 0;
|
||||
e->geo.h = e->infobar->geo.h;
|
||||
e->geo.x = (p ? p->geo.x + p->geo.w + PAD : 0);
|
||||
}
|
||||
@ -54,6 +54,7 @@ infobar_elem_tag_init(Element *e)
|
||||
infobar_elem_placement(e);
|
||||
|
||||
j = e->geo.x;
|
||||
e->geo.h -= (ELEM_TAG_BORDER << 1);
|
||||
|
||||
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
|
||||
{
|
||||
@ -61,6 +62,14 @@ infobar_elem_tag_init(Element *e)
|
||||
|
||||
/* Init barwin */
|
||||
b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0x009900, 0x777777, false);
|
||||
|
||||
/* Set border */
|
||||
if(ELEM_TAG_BORDER)
|
||||
{
|
||||
XSetWindowBorder(W->dpy, b->win, 0x1B3500);
|
||||
XSetWindowBorderWidth(W->dpy, b->win, ELEM_TAG_BORDER);
|
||||
}
|
||||
|
||||
b->ptr = (void*)t;
|
||||
barwin_map(b);
|
||||
|
||||
@ -111,6 +120,7 @@ infobar_elem_tag_update(Element *e)
|
||||
|
||||
barwin_refresh(b);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -152,6 +162,8 @@ infobar_elem_update(Infobar *i)
|
||||
TAILQ_FOREACH(e, &i->elements, next)
|
||||
if(i->elemupdate & FLAGINT(e->type))
|
||||
e->func_update(e);
|
||||
|
||||
i->elemupdate = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -169,22 +181,32 @@ infobar_elem_remove(Element *e)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
infobar_init(void)
|
||||
static inline void
|
||||
infobar_placement(Infobar *i)
|
||||
{
|
||||
Infobar *i;
|
||||
Scr33n *s;
|
||||
Infobar *h = SLIST_FIRST(&i->screen->infobars);
|
||||
|
||||
SLIST_FOREACH(s, &W->h.screen, next)
|
||||
{
|
||||
i = (Infobar*)xcalloc(1, sizeof(Infobar));
|
||||
i->geo = i->screen->geo;
|
||||
i->geo.h = INFOBAR_DEF_W;
|
||||
i->geo.y += (h ? h->geo.y + h->geo.h : i->screen->geo.y);
|
||||
}
|
||||
|
||||
Infobar*
|
||||
infobar_new(Scr33n *s, const char *elem)
|
||||
{
|
||||
int n;
|
||||
|
||||
Infobar *i = (Infobar*)xcalloc(1, sizeof(Infobar));
|
||||
|
||||
i->screen = s;
|
||||
i->elemorder = xstrdup(ELEM_DEFAULT_ORDER);
|
||||
i->elemorder = xstrdup(elem);
|
||||
|
||||
/* Positions TODO: geo = infobar_position(Position {Top,Bottom,Hidden}) */
|
||||
i->geo = s->geo;
|
||||
i->geo.h = INFOBAR_DEF_W;
|
||||
/* Active all flag for first refresh */
|
||||
/* TODO: Find something else */
|
||||
for(n = 0; n < ElemLast; i->elemupdate |= FLAGINT(n++));
|
||||
|
||||
/* TODO: Position top/bottom */
|
||||
infobar_placement(i);
|
||||
|
||||
/* Barwin create */
|
||||
i->bar = barwin_new(W->root, i->geo.x, i->geo.y, i->geo.w, i->geo.h, 0x222222, 0xCCCCCC, false);
|
||||
@ -200,13 +222,13 @@ infobar_init(void)
|
||||
infobar_refresh(i);
|
||||
|
||||
SLIST_INSERT_HEAD(&s->infobars, i, next);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
void
|
||||
infobar_refresh(Infobar *i)
|
||||
{
|
||||
i->elemupdate |= FLAGINT(ElemTag);
|
||||
infobar_elem_update(i);
|
||||
|
||||
barwin_refresh(i->bar);
|
||||
|
||||
@ -8,10 +8,9 @@
|
||||
|
||||
#include "wmfs.h"
|
||||
|
||||
enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom };
|
||||
enum { ElemTag = 0, ElemLayout, ElemSelbar, ElemStatus, ElemCustom, ElemLast };
|
||||
|
||||
void infobar_init(void);
|
||||
Infobar *infobar_new(Scr33n *s);
|
||||
Infobar *infobar_new(Scr33n *s, const char *elem);
|
||||
void infobar_elem_update(Infobar *i);
|
||||
void infobar_refresh(Infobar *i);
|
||||
void infobar_remove(Infobar *i);
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
static Scr33n*
|
||||
screen_new(Geo *g, int id)
|
||||
{
|
||||
Scr33n *s = xcalloc(1, sizeof(Scr33n));
|
||||
Scr33n *s = (Scr33n*)xcalloc(1, sizeof(Scr33n));
|
||||
|
||||
s->geo = *g;
|
||||
s->seltag = NULL;
|
||||
@ -58,14 +58,6 @@ screen_init(void)
|
||||
g.h = xsi[i].height;
|
||||
|
||||
s = screen_new(&g, i);
|
||||
tag_screen(s, tag_new(s, "tag")); /* tmp */
|
||||
|
||||
{
|
||||
tag_new(s, "tag2");
|
||||
tag_new(s, "tag3");
|
||||
}
|
||||
|
||||
s = NULL;
|
||||
}
|
||||
|
||||
XFree(xsi);
|
||||
@ -73,16 +65,38 @@ 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, 0);
|
||||
tag_screen(s, tag_new(s, "tag"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update selected screen with mouse location
|
||||
*/
|
||||
Scr33n*
|
||||
screen_update_sel(void)
|
||||
{
|
||||
#ifdef HAVE_XINERAMA
|
||||
if(XineramaIsActive(W->dpy))
|
||||
{
|
||||
Scr33n *s;
|
||||
Window w;
|
||||
int d, x, y;
|
||||
|
||||
XQueryPointer(W->dpy, W->root, &w, &w, &x, &y, &d, &d, (unsigned int *)&d);
|
||||
|
||||
SLIST_FOREACH(s, &W->h.screen, next)
|
||||
if(INAREA(x, y, s->geo))
|
||||
break;
|
||||
|
||||
W->screen = s;
|
||||
}
|
||||
#endif /* HAVE_XINERAMA */
|
||||
}
|
||||
|
||||
void
|
||||
screen_free(void)
|
||||
{
|
||||
|
||||
@ -8,7 +8,20 @@
|
||||
|
||||
#include "wmfs.h"
|
||||
|
||||
static inline Scr33n*
|
||||
screen_gb_id(int id)
|
||||
{
|
||||
Scr33n *s;
|
||||
|
||||
SLIST_FOREACH(s, &W->h.screen, next)
|
||||
if(s->id == id)
|
||||
return s;
|
||||
|
||||
return SLIST_FIRST(&W->h.screen);
|
||||
}
|
||||
|
||||
void screen_init(void);
|
||||
Scr33n* screen_update_sel(void);
|
||||
void screen_free(void);
|
||||
|
||||
#endif /* SCREEN_H */
|
||||
|
||||
@ -217,26 +217,14 @@ wmfs_loop(void)
|
||||
HANDLE_EVENT(&ev);
|
||||
}
|
||||
|
||||
static void
|
||||
static inline void
|
||||
wmfs_init(void)
|
||||
{
|
||||
/* X init */
|
||||
wmfs_xinit();
|
||||
|
||||
/* EWMH init */
|
||||
ewmh_init();
|
||||
|
||||
config_init();
|
||||
|
||||
/* Event init */
|
||||
event_init();
|
||||
|
||||
/* Screen init */
|
||||
screen_init();
|
||||
|
||||
/* Infobar init */
|
||||
infobar_init();
|
||||
|
||||
event_init();
|
||||
config_init();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
47
wmfs2/wmfsrc2
Normal file
47
wmfs2/wmfsrc2
Normal file
@ -0,0 +1,47 @@
|
||||
#
|
||||
# WMFS2 configuration file
|
||||
#
|
||||
|
||||
[bars]
|
||||
|
||||
# element type:
|
||||
# t Tag list
|
||||
# S statustext
|
||||
|
||||
[bar]
|
||||
screen = 0
|
||||
[element] type = "t" [/element]
|
||||
[/bar]
|
||||
|
||||
[bar]
|
||||
screen = 1
|
||||
[element] type = "t" [/element]
|
||||
[/bar]
|
||||
|
||||
[/bars]
|
||||
|
||||
[tags]
|
||||
|
||||
[tag] screen = 0 name = "one" [/tag]
|
||||
[tag] screen = 0 name = "two" [/tag]
|
||||
[tag] screen = 0 name = "three" [/tag]
|
||||
|
||||
[tag] screen = 1 name = "four" [/tag]
|
||||
[tag] screen = 1 name = "five" [/tag]
|
||||
|
||||
[tag] name = "universal tag" [/tag]
|
||||
|
||||
[/tags]
|
||||
|
||||
[keys]
|
||||
|
||||
[key] mod = {"Control"} key = "Return" func = "spawn" cmd = "xterm" [/key]
|
||||
[key] mod = {"Control","Alt"} key = "q" func = "quit" [/key]
|
||||
[key] mod = {"Super"} key = "1" func = "tag_set" cmd = "1" [/key]
|
||||
[key] mod = {"Super"} key = "2" func = "tag_set" cmd = "2" [/key]
|
||||
[key] mod = {"Super"} key = "3" func = "tag_set" cmd = "3" [/key]
|
||||
[key] mod = {"Super"} key = "s" func = "tag_next" [/key]
|
||||
[key] mod = {"Super"} key = "a" func = "tag_prev" [/key]
|
||||
[key] mod = {"Super"} key = "z" func = "tag" cmd = "tag2" [/key]
|
||||
|
||||
[/keys]
|
||||
Loading…
x
Reference in New Issue
Block a user