[ALL] New code stuff for layout/tag , struct...

This commit is contained in:
Martin Duquesnoy
2008-09-19 21:37:41 +02:00
parent 3913713328
commit 3a0f86f2fd
4 changed files with 83 additions and 84 deletions

View File

@@ -51,6 +51,13 @@ func_name_list_t func_list[] =
{"quit", quit} {"quit", quit}
}; };
func_name_list_t layout_list[] =
{
{"tile", tile},
{"max", maxlayout},
{"free", freelayout}
};
key_name_list_t key_list[] = key_name_list_t key_list[] =
{ {
{"Control", ControlMask}, {"Control", ControlMask},
@@ -74,13 +81,6 @@ name_to_uint_t mouse_button_list[] =
{"Button5", Button5} {"Button5", Button5}
}; };
name_to_uint_t layout_list[] =
{
{"tile", Tile},
{"max", Max},
{"free", Free}
};
void* void*
name_to_func(char *name) name_to_func(char *name)
{ {
@@ -117,7 +117,7 @@ char_to_button(char *name)
return 0; return 0;
} }
unsigned int void*
layout_name_to_layout(char *name) layout_name_to_layout(char *name)
{ {
int i; int i;
@@ -125,7 +125,7 @@ layout_name_to_layout(char *name)
if(name) if(name)
for(i=0; layout_list[i].name; ++i) for(i=0; layout_list[i].name; ++i)
if(!strcmp(name, layout_list[i].name)) if(!strcmp(name, layout_list[i].name))
return layout_list[i].button; return layout_list[i].func;
return 0; return 0;
} }
@@ -289,13 +289,13 @@ init_conf(void)
/* tag */ /* tag */
conf.ntag = cfg_size(cfg_tags, "tag"); conf.ntag = cfg_size(cfg_tags, "tag");
for(i=0; i < cfg_size(cfg_tags, "tag"); ++i) for(i = 0; i < conf.ntag + 1; ++i)
{ {
cfgtmp = cfg_getnsec(cfg_tags, "tag", i); cfgtmp = cfg_getnsec(cfg_tags, "tag", ((i > 0) ? i - 1 : i));
conf.tag[i].name = strdup(cfg_getstr(cfgtmp, "name")); tags[i].name = strdup(cfg_getstr(cfgtmp, "name"));
conf.tag[i].mwfact = cfg_getfloat(cfgtmp, "mwfact"); tags[i].mwfact = cfg_getfloat(cfgtmp, "mwfact");
conf.tag[i].nmaster = cfg_getint(cfgtmp, "nmaster"); tags[i].nmaster = cfg_getint(cfgtmp, "nmaster");
conf.tag[i].layout = layout_name_to_layout(cfg_getstr(cfgtmp, "layout")); tags[i].layout.func = layout_name_to_layout(cfg_getstr(cfgtmp, "layout"));
} }
/* keybind ('tention ça rigole plus) */ /* keybind ('tention ça rigole plus) */

View File

@@ -99,7 +99,7 @@ buttonpress(XEvent ev)
/* layout switch */ /* layout switch */
if(ev.xbutton.x >= taglen[conf.ntag] - 3 if(ev.xbutton.x >= taglen[conf.ntag] - 3
&& ev.xbutton.x < taglen[conf.ntag] + && ev.xbutton.x < taglen[conf.ntag] +
(strlen((getlayoutsym(layout[seltag])))*fonty+3) - 3) (strlen((getlayoutsym(seltag)))*fonty+3) - 3)
{ {
if(ev.xbutton.button == Button1 if(ev.xbutton.button == Button1
|| ev.xbutton.button == Button4) || ev.xbutton.button == Button4)
@@ -183,9 +183,16 @@ enternotify(XEvent ev)
void void
expose(XEvent ev) expose(XEvent ev)
{ {
Client *c;
if(ev.xexpose.count == 0 if(ev.xexpose.count == 0
&& (ev.xexpose.window == bar)) && (ev.xexpose.window == bar))
updatebar(); updatebar();
for(c = clients; c; c = c->next)
if(conf.ttbarheight > 10
&& ev.xexpose.window == c->tbar)
updatetitle(c);
return; return;
} }

106
wmfs.c
View File

@@ -44,7 +44,7 @@ arrange(void)
hide(c); hide(c);
focus(NULL); focus(NULL);
layoutfunc[seltag](); tags[seltag].layout.func();
updatebar(); updatebar();
} }
@@ -138,8 +138,7 @@ freelayout(void)
{ {
Client *c; Client *c;
layout[seltag] = Free; tags[seltag].layout.func = freelayout;
layoutfunc[seltag] = freelayout;
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
{ {
@@ -179,14 +178,15 @@ getnext(Client *c)
} }
char* char*
getlayoutsym(int l) getlayoutsym(int tag)
{ {
switch(layout[seltag]) if(tags[tag].layout.func == freelayout)
{ return conf.layouts.free;
case Free: return conf.layouts.free; break; else if(tags[tag].layout.func == tile)
case Tile: return conf.layouts.tile; break; return conf.layouts.tile;
case Max: return conf.layouts.max; break; else if(tags[tag].layout.func == maxlayout)
} return conf.layouts.max;
return NULL; return NULL;
} }
@@ -296,18 +296,6 @@ init(void)
mh = DisplayHeight (dpy, screen); mh = DisplayHeight (dpy, screen);
seltag = 1; seltag = 1;
taglen[0] = 3; taglen[0] = 3;
for(i = 0; i < conf.ntag+1; ++i)
{
mwfact[i] = conf.tag[i-1].mwfact;
layout[i] = conf.tag[i-1].layout;
nmaster[i] = conf.tag[i-1].nmaster;
if(layout[i] == Tile)
layoutfunc[i] = tile;
else if(layout[i] == Max)
layoutfunc[i] = maxlayout;
else
layoutfunc[i] = freelayout;
}
/* INIT FONT */ /* INIT FONT */
font = XLoadQueryFont(dpy, conf.font); font = XLoadQueryFont(dpy, conf.font);
@@ -458,24 +446,28 @@ killclient(char *cmd)
void void
layoutswitch(char *cmd) layoutswitch(char *cmd)
{ {
void (*tmpfunc)(void);
if(cmd[0] == '+') if(cmd[0] == '+')
{ {
switch(layout[seltag]) if(tags[seltag].layout.func == freelayout)
{ tmpfunc = tile;
case Free: layoutfunc[seltag] = tile; break; else if(tags[seltag].layout.func == tile)
case Tile: layoutfunc[seltag] = maxlayout; break; tmpfunc = maxlayout;
case Max: layoutfunc[seltag] = freelayout; break; else if(tags[seltag].layout.func == maxlayout)
} tmpfunc = freelayout;
} }
else if(cmd[0] == '-') else if(cmd[0] == '-')
{ {
switch(layout[seltag]) if(tags[seltag].layout.func == freelayout)
{ tmpfunc = maxlayout;
case Free: layoutfunc[seltag] = maxlayout; break; else if(tags[seltag].layout.func == tile)
case Tile: layoutfunc[seltag] = freelayout; break; tmpfunc = freelayout;
case Max: layoutfunc[seltag] = tile; break; else if(tags[seltag].layout.func == maxlayout)
} tmpfunc = tile;
} }
tags[seltag].layout.func = tmpfunc;
arrange(); arrange();
return; return;
} }
@@ -567,15 +559,14 @@ maxlayout(void)
{ {
Client *c; Client *c;
layout[seltag] = Max; tags[seltag].layout.func = maxlayout;
layoutfunc[seltag] = maxlayout;
for(c = nexttiled(clients); c; c = nexttiled(c->next)) for(c = nexttiled(clients); c; c = nexttiled(c->next))
{ {
c->tile = False; c->tile = False;
c->ox = c->x; c->ox = c->x;
c->oy = c->y; c->oy = c->y;
c->ow = c->w; c->ow = c->w;
c->oh = c->h; c->oh = c->h;
moveresize(c, 0, moveresize(c, 0,
@@ -792,11 +783,11 @@ set_mwfact(char *cmd)
if(!(sscanf(cmd, "%lf", &c))) if(!(sscanf(cmd, "%lf", &c)))
return; return;
if(mwfact[seltag] + c > 0.95 if(tags[seltag].mwfact + c > 0.95
|| mwfact[seltag] + c < 0.05 || tags[seltag].mwfact + c < 0.05
|| layout[seltag] != Tile) || tags[seltag].layout.func != tile)
return; return;
mwfact[seltag] += c; tags[seltag].mwfact += c;
arrange(); arrange();
return; return;
} }
@@ -806,9 +797,9 @@ set_nmaster(char *cmd)
{ {
int n = atoi(cmd); int n = atoi(cmd);
if(nmaster[seltag] + n == 0) if(tags[seltag].nmaster + n == 0)
return; return;
nmaster[seltag] += n; tags[seltag].nmaster += n;
arrange(); arrange();
return; return;
} }
@@ -929,11 +920,10 @@ tile(void)
bord = conf.borderheight * 2; bord = conf.borderheight * 2;
barto = conf.ttbarheight + barheight; barto = conf.ttbarheight + barheight;
mwf = mwfact[seltag] * mw; mwf = tags[seltag].mwfact * mw;
nm = nmaster[seltag]; nm = tags[seltag].nmaster;
layout[seltag] = Tile; tags[seltag].layout.func = tile;
layoutfunc[seltag] = tile;
/* count all the "can-be-tiled" client */ /* count all the "can-be-tiled" client */
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
@@ -1092,9 +1082,9 @@ updatebar(void)
{ {
/* Make the tags string */ /* Make the tags string */
ITOA(p, clientpertag(i+1)); ITOA(p, clientpertag(i+1));
sprintf(buf[i], "%s<%s> ", conf.tag[i].name, (clientpertag(i+1)) ? p : ""); sprintf(buf[i], "%s<%s> ", tags[i].name, (clientpertag(i+1)) ? p : "");
taglen[i+1] = (taglen[i] + fonty * (strlen(conf.tag[i].name) + taglen[i+1] = (taglen[i] + fonty * (strlen(tags[i].name) +
strlen(buf[i]) - strlen(conf.tag[i].name)) + fonty) - 2; strlen(buf[i]) - strlen(tags[i].name)) + fonty) - 2;
/* Rectangle for the tag background */ /* Rectangle for the tag background */
XSetForeground(dpy, gc, (i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar); XSetForeground(dpy, gc, (i+1 == seltag) ? conf.colors.tagselbg : conf.colors.bar);
XFillRectangle(dpy, dr, gc, taglen[i] - 3, 0, (strlen(buf[i])*fonty) -2, barheight); XFillRectangle(dpy, dr, gc, taglen[i] - 3, 0, (strlen(buf[i])*fonty) -2, barheight);
@@ -1107,17 +1097,17 @@ updatebar(void)
/* Draw layout symbol */ /* Draw layout symbol */
XSetForeground(dpy, gc, conf.colors.layout_bg); XSetForeground(dpy, gc, conf.colors.layout_bg);
XFillRectangle(dpy, dr, gc, taglen[conf.ntag] - 5, 0, XFillRectangle(dpy, dr, gc, taglen[conf.ntag] - 5, 0,
(strlen(getlayoutsym(layout[seltag]))*fonty) + 1, barheight); (strlen(getlayoutsym(seltag))*fonty) + 1, barheight);
XSetForeground(dpy, gc, conf.colors.layout_fg); XSetForeground(dpy, gc, conf.colors.layout_fg);
XDrawString(dpy, dr, gc, taglen[conf.ntag] - 4, XDrawString(dpy, dr, gc, taglen[conf.ntag] - 4,
fonth, fonth,
getlayoutsym(layout[seltag]), getlayoutsym(seltag),
strlen(getlayoutsym(layout[seltag]))); strlen(getlayoutsym(seltag)));
/* Draw status */ /* Draw status */
sprintf(bartext,"mwfact: %.2f nmaster: %i - %02i:%02i", sprintf(bartext,"mwfact: %.2f nmaster: %i - %02i:%02i",
mwfact[seltag], tags[seltag].mwfact,
nmaster[seltag], tags[seltag].nmaster,
tm->tm_hour, tm->tm_hour,
tm->tm_min); tm->tm_min);
@@ -1128,6 +1118,7 @@ updatebar(void)
XCopyArea(dpy, dr, bar, gc, 0, 0, mw, barheight, 0, 0); XCopyArea(dpy, dr, bar, gc, 0, 0, mw, barheight, 0, 0);
XSync(dpy, False); XSync(dpy, False);
/* Update Bar Buttons */ /* Update Bar Buttons */
updatebutton(1); updatebutton(1);
free(p); free(p);
@@ -1148,7 +1139,7 @@ updatebutton(Bool c)
at.background_pixmap = ParentRelative; at.background_pixmap = ParentRelative;
at.event_mask = ButtonPressMask | ExposureMask; at.event_mask = ButtonPressMask | ExposureMask;
j = taglen[conf.ntag] + ((strlen(getlayoutsym(layout[seltag]))*fonty) + 2); j = taglen[conf.ntag] + ((strlen(getlayoutsym(seltag))*fonty) + 2);
XSetFont(dpy, gc, font_b->fid); XSetFont(dpy, gc, font_b->fid);
@@ -1186,6 +1177,7 @@ updatebutton(Bool c)
} }
} }
XSetFont(dpy, gc, font->fid); XSetFont(dpy, gc, font->fid);
XSync(dpy, False);
return; return;
} }
@@ -1313,9 +1305,9 @@ main(int argc,char **argv)
init(); init();
scan(); scan();
updatebar(); updatebar();
while(!exiting) while(!exiting)
{ {
// updatebar();
getevent(); getevent();
updateall(); updateall();
} }

22
wmfs.h
View File

@@ -113,13 +113,20 @@ typedef struct
unsigned int mouse[NBUTTON]; unsigned int mouse[NBUTTON];
} BarButton; } BarButton;
/* Layout Structure */
typedef struct
{
char *symbol;
void (*func)(void);
} Layout;
/* Tag Structure */ /* Tag Structure */
typedef struct typedef struct
{ {
char *name; char *name;
float mwfact; float mwfact;
int nmaster; int nmaster;
int layout; Layout layout;
} Tag; } Tag;
/* Configuration structure */ /* Configuration structure */
@@ -148,7 +155,6 @@ typedef struct
char *tile; char *tile;
char *max; char *max;
} layouts; } layouts;
Tag tag[MAXTAG];
BarButton barbutton[64]; BarButton barbutton[64];
int ntag; int ntag;
int nkeybind; int nkeybind;
@@ -176,10 +182,9 @@ typedef struct
/* Enum */ /* Enum */
enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; enum { CurNormal, CurResize, CurMove, CurLast };
enum { WMState, WMProtocols, WMName, WMDelete, WMLast }; enum { WMState, WMProtocols, WMName, WMDelete, WMLast };
enum { NetSupported, NetWMName, NetLast }; enum { NetSupported, NetWMName, NetLast };
enum { Free = 0, Tile, Max};
/* Functions Prototypes */ /* Functions Prototypes */
@@ -216,7 +221,7 @@ void freelayout(void);
Client* getbutton(Window w); Client* getbutton(Window w);
Client* getclient(Window w); Client* getclient(Window w);
Client* getnext(Client *c); Client* getnext(Client *c);
char* getlayoutsym(int l); char* getlayoutsym(int tag);
Client* gettbar(Window w); Client* gettbar(Window w);
void grabbuttons(Client *c, Bool focused); void grabbuttons(Client *c, Bool focused);
void grabkeys(void); void grabkeys(void);
@@ -282,6 +287,7 @@ int fonth, fonty;
/* Bar / Tags */ /* Bar / Tags */
Window bar; Window bar;
Tag tags[MAXTAG];
int barheight; int barheight;
char bartext[1024]; char bartext[1024];
int seltag; int seltag;
@@ -292,12 +298,6 @@ Drawable dr;
Client *clients; Client *clients;
Client *sel; Client *sel;
/* Layout/Tile Important variables */
float mwfact[MAXTAG];
int nmaster[MAXTAG];
int layout[MAXTAG];
void (*layoutfunc[MAXTAG])(void);
/* Other */ /* Other */
unsigned int numlockmask; unsigned int numlockmask;
fd_set fd; fd_set fd;