[ALL] Add new tile with nmaster, buttons in the conf for it...

This commit is contained in:
Martin Duquesnoy 2008-09-09 07:24:24 +02:00
parent 01fef420f9
commit a0a75186e6
4 changed files with 263 additions and 187 deletions

View File

@ -20,7 +20,7 @@ func_name_list_t func_list[] = {
{"tag", tag}, {"tag", tag},
{"tagtransfert", tagtransfert}, {"tagtransfert", tagtransfert},
{"set_mwfact", set_mwfact}, {"set_mwfact", set_mwfact},
{"tile_switch", tile_switch} {"set_nmaster", set_nmaster}
}; };
key_name_list_t key_list[] = { key_name_list_t key_list[] = {
@ -115,17 +115,18 @@ init_conf(void) {
CFG_END() CFG_END()
}; };
static cfg_opt_t layout_opts[] = { static cfg_opt_t layouts_opts[] = {
CFG_STR_LIST("free","[Free]", CFGF_NONE), CFG_STR_LIST("free", "[Free]", CFGF_NONE),
CFG_STR_LIST("tile","[Tile]", CFGF_NONE), CFG_STR_LIST("tile", "[Tile]", CFGF_NONE),
CFG_STR_LIST("max","[Max]", CFGF_NONE), CFG_STR_LIST("max", "[Max]", CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t tag_opts[] = { static cfg_opt_t tag_opts[] = {
CFG_STR("name", "", CFGF_NONE), CFG_STR("name", "", CFGF_NONE),
CFG_FLOAT("mwfact", 0.65, CFGF_NONE), CFG_FLOAT("mwfact", 0.65, CFGF_NONE),
CFG_INT("nmaster", 1, CFGF_NONE),
CFG_STR("layout", "tile", CFGF_NONE), CFG_STR("layout", "tile", CFGF_NONE),
CFG_END() CFG_END()
}; };
@ -180,7 +181,7 @@ init_conf(void) {
CFG_SEC("misc", misc_opts, CFGF_NONE), CFG_SEC("misc", misc_opts, CFGF_NONE),
CFG_SEC("colors", colors_opts, CFGF_NONE), CFG_SEC("colors", colors_opts, CFGF_NONE),
CFG_SEC("layout", layout_opts, CFGF_NONE), CFG_SEC("layouts", layouts_opts, CFGF_NONE),
CFG_SEC("tags", tags_opts, CFGF_NONE), CFG_SEC("tags", tags_opts, CFGF_NONE),
CFG_SEC("keys", keys_opts, CFGF_NONE), CFG_SEC("keys", keys_opts, CFGF_NONE),
CFG_SEC("buttons", buttons_opts, CFGF_NONE), CFG_SEC("buttons", buttons_opts, CFGF_NONE),
@ -190,7 +191,7 @@ init_conf(void) {
cfg_t *cfg; cfg_t *cfg;
cfg_t *cfg_misc; cfg_t *cfg_misc;
cfg_t *cfg_colors; cfg_t *cfg_colors;
cfg_t *cfg_layout; cfg_t *cfg_layouts;
cfg_t *cfg_tags; cfg_t *cfg_tags;
cfg_t *cfg_keys; cfg_t *cfg_keys;
cfg_t *cfg_buttons; cfg_t *cfg_buttons;
@ -215,7 +216,7 @@ init_conf(void) {
cfg_misc = cfg_getsec(cfg, "misc"); cfg_misc = cfg_getsec(cfg, "misc");
cfg_colors = cfg_getsec(cfg, "colors"); cfg_colors = cfg_getsec(cfg, "colors");
cfg_layout = cfg_getsec(cfg, "layout"); cfg_layouts = cfg_getsec(cfg, "layouts");
cfg_tags = cfg_getsec(cfg, "tags"); cfg_tags = cfg_getsec(cfg, "tags");
cfg_keys = cfg_getsec(cfg, "keys"); cfg_keys = cfg_getsec(cfg, "keys");
cfg_buttons = cfg_getsec(cfg, "buttons"); cfg_buttons = cfg_getsec(cfg, "buttons");
@ -236,9 +237,9 @@ init_conf(void) {
conf.colors.tagselbg = cfg_getint(cfg_colors, "tag_sel_bg"); conf.colors.tagselbg = cfg_getint(cfg_colors, "tag_sel_bg");
/* layout */ /* layout */
conf.layouts.free = strdup(cfg_getstr(cfg_layout, "free")); conf.layouts.free = strdup(cfg_getstr(cfg_layouts, "free"));
conf.layouts.tile = strdup(cfg_getstr(cfg_layout, "tile")); conf.layouts.tile = strdup(cfg_getstr(cfg_layouts, "tile"));
conf.layouts.max = strdup(cfg_getstr(cfg_layout, "max")); conf.layouts.max = strdup(cfg_getstr(cfg_layouts, "max"));
/* tag */ /* tag */
conf.ntag = cfg_size(cfg_tags, "tag"); conf.ntag = cfg_size(cfg_tags, "tag");
@ -246,6 +247,7 @@ init_conf(void) {
cfgtmp = cfg_getnsec(cfg_tags, "tag", i); cfgtmp = cfg_getnsec(cfg_tags, "tag", i);
conf.tag[i].name = strdup(cfg_getstr(cfgtmp, "name")); conf.tag[i].name = strdup(cfg_getstr(cfgtmp, "name"));
conf.tag[i].mwfact = cfg_getfloat(cfgtmp, "mwfact"); conf.tag[i].mwfact = cfg_getfloat(cfgtmp, "mwfact");
conf.tag[i].nmaster = cfg_getint(cfgtmp, "nmaster");
conf.tag[i].layout = layout_name_to_layout(cfg_getstr(cfgtmp, "layout")); conf.tag[i].layout = layout_name_to_layout(cfg_getstr(cfgtmp, "layout"));
} }

16
local.h
View File

@ -77,11 +77,11 @@ typedef struct {
typedef struct { typedef struct {
char *name; char *name;
float mwfact; float mwfact;
int nmaster;
int layout; int layout;
} Tag; } Tag;
typedef struct { typedef struct {
/* bool and size */
char *font; char *font;
bool raisefocus; bool raisefocus;
bool raiseswitch; bool raiseswitch;
@ -114,6 +114,7 @@ enum { NetSupported, NetWMName, NetLast };
enum { Free=0, Tile, Max}; enum { Free=0, Tile, Max};
/* wmfs.c */ /* wmfs.c */
void arrange(void);
void attach(Client *c); void attach(Client *c);
void buttonpress(XEvent *event); void buttonpress(XEvent *event);
int clienthintpertag(int tag); int clienthintpertag(int tag);
@ -137,27 +138,30 @@ void hide(Client *c);
void init(void); void init(void);
Bool ishide(Client *c); Bool ishide(Client *c);
void keymovex(char *cmd); void keymovex(char *cmd);
void keymovey(char *cmd); void keymovey(char *cmd);
void keypress(XEvent *e); void keypress(XEvent *e);
void keyresize(char *cmd); void keyresize(char *cmd);
void killclient(char *cmd); void killclient(char *cmd);
void layoutswitch(char *cmd); void layoutswitch(char *cmd);
void lowerclient(Client *c);
void mapclient(Client *c); void mapclient(Client *c);
void manage(Window w, XWindowAttributes *wa); void manage(Window w, XWindowAttributes *wa);
void maxlayout(void); void maxlayout(void);
void mouseaction(Client *c, int x, int y, int type); void mouseaction(Client *c, int x, int y, int type);
void moveresize(Client *c, int x, int y, int w, int h, bool r); void moveresize(Client *c, int x, int y, int w, int h, bool r);
Client *nexttiled(Client *c);
void raiseclient(Client *c); void raiseclient(Client *c);
void scan(void); void scan(void);
void setborder(Window win, int color); void setborder(Window win, int color);
void set_mwfact(char *cmd); void set_mwfact(char *cmd);
void set_nmaster(char *cmd);
void setsizehints(Client *c); void setsizehints(Client *c);
void spawn(char *cmd); void spawn(char *cmd);
void tag(char *cmd); void tag(char *cmd);
void tagswitch(char *cmd); void tagswitch(char *cmd);
void tagtransfert(char *cmd); void tagtransfert(char *cmd);
void tile(void); void tile(void);
void tile_switch(char *cmd);
void togglemax(char *cmd); void togglemax(char *cmd);
void unhide(Client *c); void unhide(Client *c);
void unmanage(Client *c); void unmanage(Client *c);
@ -191,15 +195,17 @@ int mw, mh;
int fonth; int fonth;
int fonty; int fonty;
int barheight; int barheight;
Client *master[MAXTAG]; /* Master client by tag */ int seltag;
Client *clients; /* First Client */ Client *clients; /* First Client */
Client *sel; /* selected client */ Client *sel; /* selected client */
int seltag; /* selected tag */
Client *selbytag[MAXTAG]; Client *selbytag[MAXTAG];
char status[16]; char status[16];
/* layout */
float mwfact[MAXTAG]; float mwfact[MAXTAG];
int nmaster[MAXTAG];
int layout[MAXTAG]; int layout[MAXTAG];
/**/
char bartext[256]; char bartext[256];
char *ptrb, bufbt[sizeof bartext]; char *ptrb, bufbt[sizeof bartext];
int readp; int readp;

292
wmfs.c
View File

@ -29,6 +29,19 @@
unsigned int numlockmask = 0; unsigned int numlockmask = 0;
int taglen[MAXTAG] = {3}; int taglen[MAXTAG] = {3};
void
arrange(void) {
Client *c;
for(c = clients; c; c = c->next)
if(!ishide(c))
unhide(c);
else
hide(c);
updatelayout();
updateall();
focus(NULL);
}
void void
attach(Client *c) { attach(Client *c) {
if(clients) if(clients)
@ -48,10 +61,11 @@ buttonpress(XEvent *event) {
/* Tbar'n'Button */ /* Tbar'n'Button */
if(conf.ttbarheight) { if(conf.ttbarheight) {
if((c = gettbar(ev->window))) { if((c = gettbar(ev->window))) {
focus(c);
if(ev->button == Button1) if(ev->button == Button1)
mouseaction(c, ev->x_root, ev->y_root, Move); /* type 0 for move */ mouseaction(c, ev->x_root, ev->y_root, Move); /* type 0 for move */
else if(ev->button == Button2) else if(ev->button == Button2)
tile_switch(NULL); togglemax(NULL);
else if(ev->button == Button3) else if(ev->button == Button3)
mouseaction(c, ev->x_root, ev->y_root, Resize); /* type 1 for resize */ mouseaction(c, ev->x_root, ev->y_root, Resize); /* type 1 for resize */
} else if((c = getbutton(ev->window))) { } else if((c = getbutton(ev->window))) {
@ -68,7 +82,7 @@ buttonpress(XEvent *event) {
if(ev->button == Button1) if(ev->button == Button1)
mouseaction(c, ev->x_root, ev->y_root, Move); /* type 0 for move */ mouseaction(c, ev->x_root, ev->y_root, Move); /* type 0 for move */
else if(ev->button == Button2) else if(ev->button == Button2)
tile_switch(NULL); togglemax(NULL);
else if(ev->button == Button3) else if(ev->button == Button3)
mouseaction(c, ev->x_root, ev->y_root, Resize); /* type 1 for resize */ mouseaction(c, ev->x_root, ev->y_root, Resize); /* type 1 for resize */
} }
@ -125,10 +139,9 @@ int
clienthintpertag(int tag) { clienthintpertag(int tag) {
Client *c; Client *c;
int i = 0; int i = 0;
for(c = clients; c; c = c->next) { for(c = clients; c; c = c->next)
if(c->tag == tag && c->hint) if(c->tag == tag && c->hint)
++i; ++i;
}
return i; return i;
} }
@ -136,10 +149,9 @@ int
clientpertag(int tag) { clientpertag(int tag) {
Client *c; Client *c;
int i = 0; int i = 0;
for(c = clients; c; c = c->next) { for(c = clients; c; c = c->next)
if(c->tag == tag) if(c->tag == tag)
++i; ++i;
}
return i; return i;
} }
@ -169,6 +181,7 @@ configurerequest(XEvent event) {
XResizeWindow(dpy, c->tbar, wc.width, conf.ttbarheight); XResizeWindow(dpy, c->tbar, wc.width, conf.ttbarheight);
XMoveWindow(dpy, c->button, wc.x + wc.width - 10, BUTY(wc.y)); XMoveWindow(dpy, c->button, wc.x + wc.width - 10, BUTY(wc.y));
} }
updatetitle(c); updatetitle(c);
c->y = wc.y; c->y = wc.y;
c->x = wc.x; c->x = wc.x;
@ -251,7 +264,6 @@ freelayout(void) {
Client* Client*
getbutton(Window w) { getbutton(Window w) {
Client *c; Client *c;
if(conf.ttbarheight)
for(c = clients; c && c->button != w; c = c->next); for(c = clients; c && c->button != w; c = c->next);
return c; return c;
} }
@ -283,7 +295,6 @@ getlayoutsym(int l) {
Client* Client*
gettbar(Window w) { gettbar(Window w) {
Client *c; Client *c;
if(conf.ttbarheight)
for(c = clients; c && c->tbar != w; c = c->next); for(c = clients; c && c->tbar != w; c = c->next);
return c; return c;
} }
@ -310,7 +321,8 @@ getevent(void) {
switch (event.type) { switch (event.type) {
case EnterNotify: case EnterNotify:
if(event.xcrossing.mode != NotifyNormal if(event.xcrossing.mode != NotifyNormal
|| event.xcrossing.detail == NotifyInferior) return; || event.xcrossing.detail == NotifyInferior)
return;
if((c = getclient(event.xcrossing.window)) if((c = getclient(event.xcrossing.window))
|| (c = gettbar(event.xcrossing.window))) || (c = gettbar(event.xcrossing.window)))
if(c->win != bar) if(c->win != bar)
@ -446,17 +458,17 @@ hide(Client *c) {
/* unmapclient(c); */ /* unmapclient(c); */
/* Just hide for now... */ /* Just hide for now... */
XMoveWindow(dpy, c->win, c->x, c->y+mh*2);
XMoveWindow(dpy, c->win, c->x, c->y+mh*2);
if(conf.ttbarheight) { if(conf.ttbarheight) {
XMoveWindow(dpy, c->tbar, c->x, c->y+mh*2); XMoveWindow(dpy, c->tbar, c->x, c->y+mh*2);
XMoveWindow(dpy, c->button, c->x, c->y+mh*2); XMoveWindow(dpy, c->button, c->x, c->y+mh*2);
} }
c->hide = True;
XChangeProperty(dpy, c->win, XInternAtom(dpy, "WM_STATE", False), XChangeProperty(dpy, c->win, XInternAtom(dpy, "WM_STATE", False),
XInternAtom(dpy, "WM_STATE", False), 32, XInternAtom(dpy, "WM_STATE", False), 32,
PropModeReplace, (unsigned char *) data, 2); PropModeReplace, (unsigned char *) data, 2);
c->hide = True;
} }
void void
@ -472,10 +484,10 @@ init(void) {
mw = DisplayWidth (dpy, screen); mw = DisplayWidth (dpy, screen);
mh = DisplayHeight (dpy, screen); mh = DisplayHeight (dpy, screen);
seltag = 1; seltag = 1;
init_conf(); for(i = 0; i< conf.ntag+1; ++i) {
for(i = 0; i< conf.ntag; ++i) {
mwfact[i] = conf.tag[i-1].mwfact; mwfact[i] = conf.tag[i-1].mwfact;
layout[i] = conf.tag[i-1].layout; layout[i] = conf.tag[i-1].layout;
nmaster[i] = conf.tag[i-1].nmaster;
} }
/* INIT FONT */ /* INIT FONT */
@ -644,7 +656,7 @@ killclient(char *cmd) {
ev.xclient.data.l[1] = CurrentTime; ev.xclient.data.l[1] = CurrentTime;
XSendEvent(dpy, sel->win, False, NoEventMask, &ev); XSendEvent(dpy, sel->win, False, NoEventMask, &ev);
} }
updatelayout(); arrange();
return; return;
} }
@ -667,16 +679,28 @@ layoutswitch(char *cmd) {
return; return;
} }
void
lowerclient(Client *c) {
if(!c)
return;
if(conf.ttbarheight) {
XLowerWindow(dpy,c->button);
XLowerWindow(dpy,c->tbar);
}
XLowerWindow(dpy,c->win);
return;
}
void void
mapclient(Client *c) { mapclient(Client *c) {
if(!c) if(!c)
return; return;
XMapWindow(dpy, c->win); XMapWindow(dpy, c->win);
XMapSubwindows(dpy, c->win);
if(conf.ttbarheight) { if(conf.ttbarheight) {
XMapWindow(dpy, c->tbar); XMapWindow(dpy, c->tbar);
XMapWindow(dpy, c->button); XMapWindow(dpy, c->button);
} }
XMapSubwindows(dpy, c->win);
return; return;
} }
@ -695,19 +719,14 @@ manage(Window w, XWindowAttributes *wa) {
c->h = wa->height; c->h = wa->height;
c->border = wa->border_width; c->border = wa->border_width;
c->tag = seltag; c->tag = seltag;
switch(layout[seltag]) {
setborder(w, conf.colors.bordernormal); case Tile: c->tile = True; break;
case Max: c->max = True; break;
XConfigureWindow(dpy, w, CWBorderWidth, &winc); }
XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask |
PropertyChangeMask | StructureNotifyMask);
if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
for(t = clients; t && t->win != trans; t = t->next);
if(conf.ttbarheight) { if(conf.ttbarheight) {
c->tbar = XCreateSimpleWindow(dpy, root, c->tbar =
XCreateSimpleWindow(dpy, root,
c->x, c->x,
c->y - conf.ttbarheight, c->y - conf.ttbarheight,
c->w, c->w,
@ -715,10 +734,8 @@ manage(Window w, XWindowAttributes *wa) {
conf.borderheight, conf.borderheight,
conf.colors.bordernormal, conf.colors.bordernormal,
conf.colors.bar); conf.colors.bar);
XSelectInput(dpy, c->tbar, ExposureMask | EnterWindowMask); c->button =
setborder(c->tbar, conf.colors.bordernormal); XCreateSimpleWindow(dpy, root,
c->button = XCreateSimpleWindow(dpy, root,
c->x + c->w - 10, c->x + c->w - 10,
BUTY(c->y), BUTY(c->y),
5, 5,
@ -728,14 +745,28 @@ manage(Window w, XWindowAttributes *wa) {
conf.colors.borderfocus); conf.colors.borderfocus);
} }
XConfigureWindow(dpy, w, CWBorderWidth, &winc);
setborder(w, conf.colors.bordernormal);
grabbuttons(c, False); grabbuttons(c, False);
XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask |
PropertyChangeMask | StructureNotifyMask);
setsizehints(c); setsizehints(c);
updatetitle(c);
if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
for(t = clients; t && t->win != trans; t = t->next);
if(t)
c->tag = t->tag;
attach(c); attach(c);
moveresize(c, c->x, c->y, c->w, c->h, 1); moveresize(c, c->x, c->y, c->w, c->h, 1);
/* for when there are a free client
over the tiled client */
//if(c->tile)
// lowerclient(c);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
mapclient(c); mapclient(c);
updatetitle(c);
focus(c);
updatelayout(); updatelayout();
return; return;
} }
@ -773,7 +804,8 @@ mouseaction(Client *c, int x, int y, int type) {
int ocx, ocy; int ocx, ocy;
XEvent ev; XEvent ev;
if((c->max && !c->hint) || (layout[seltag] == Tile && !c->hint)) if((c->max && !c->hint)
|| (layout[seltag] == Tile && !c->hint))
return; return;
ocx = c->x; ocx = c->x;
ocy = c->y; ocy = c->y;
@ -821,21 +853,25 @@ moveresize(Client *c, int x, int y, int w, int h, bool r) {
if(c->minw > 0 && w < c->minw) { if(c->minw > 0 && w < c->minw) {
w = c->minw; w = c->minw;
c->hint = c->free = True; c->hint = c->free = True;
c->tile = False;
} }
if(c->minh > 0 && h < c->minh) { if(c->minh > 0 && h < c->minh) {
h = c->minh; h = c->minh;
c->hint = c->free = True; c->hint = c->free = True;
c->tile = False;
} }
if(c->maxw > 0 && w > c->maxw) { if(c->maxw > 0 && w > c->maxw) {
w = c->maxw; w = c->maxw;
c->hint = c->free = True; c->hint = c->free = True;
c->tile = False;
} }
if(c->maxh > 0 && h > c->maxh) { if(c->maxh > 0 && h > c->maxh) {
h = c->maxh; h = c->maxh;
c->hint = c-> free = True; c->hint = c-> free = True;
c->tile = False;
} }
if(w <= 0 || h <= 0) if(w <= 0 || h <= 0)
@ -854,6 +890,7 @@ moveresize(Client *c, int x, int y, int w, int h, bool r) {
y = barheight+conf.ttbarheight; y = barheight+conf.ttbarheight;
XMoveResizeWindow(dpy, c->win, x, y, w ,h); XMoveResizeWindow(dpy, c->win, x, y, w ,h);
if(conf.ttbarheight) { if(conf.ttbarheight) {
XMoveResizeWindow(dpy, c->tbar, x, y - conf.ttbarheight, w, conf.ttbarheight); XMoveResizeWindow(dpy, c->tbar, x, y - conf.ttbarheight, w, conf.ttbarheight);
XMoveResizeWindow(dpy, c->button, XMoveResizeWindow(dpy, c->button,
@ -869,16 +906,22 @@ moveresize(Client *c, int x, int y, int w, int h, bool r) {
return; return;
} }
Client *
nexttiled(Client *c) {
for(; c && (c->hint || ishide(c)); c = c->next);
return c;
}
void void
raiseclient(Client *c) { raiseclient(Client *c) {
if(c) { if(!c)
return;
XRaiseWindow(dpy,c->win); XRaiseWindow(dpy,c->win);
if(conf.ttbarheight) { if(conf.ttbarheight) {
XRaiseWindow(dpy,c->tbar); XRaiseWindow(dpy,c->tbar);
XRaiseWindow(dpy,c->button); XRaiseWindow(dpy,c->button);
} }
}
return; return;
} }
@ -901,7 +944,7 @@ scan(void) {
} }
if(wins) if(wins)
XFree(wins); XFree(wins);
updatelayout(); arrange();
return; return;
} }
@ -918,12 +961,23 @@ set_mwfact(char *cmd) {
double c; double c;
if(!(sscanf(cmd, "%lf", &c))) if(!(sscanf(cmd, "%lf", &c)))
return; return;
if(mwfact[seltag] + c > 0.9 if(mwfact[seltag] + c > 0.95
|| mwfact[seltag] + c < 0.1 || mwfact[seltag] + c < 0.05
|| layout[seltag] != Tile) || layout[seltag] != Tile)
return; return;
mwfact[seltag] += c; mwfact[seltag] += c;
tile(); arrange();
return;
}
void
set_nmaster(char *cmd) {
int n = atoi(cmd);
if(nmaster[seltag] + n == 0)
return;
nmaster[seltag] += n;
arrange();
return;
} }
void void
@ -959,60 +1013,49 @@ setsizehints(Client *c) {
void void
spawn(char *cmd) { spawn(char *cmd) {
if(strlen(cmd) > 0 && !fork()) { if(!strlen(cmd))
execl(getenv("SHELL"), "sh", "-c", cmd, NULL); return;
if(fork() == 0) {
if(fork() == 0) {
if(dpy)
close(ConnectionNumber(dpy));
setsid();
execl(getenv("SHELL"), getenv("SHELL"), "-c", cmd, (char*)NULL);
exit(1); exit(1);
}
exit(0);
} }
return; return;
} }
void void
tag(char *cmd) { tag(char *cmd) {
Client *c;
int tmp = atoi(cmd); int tmp = atoi(cmd);
if(tmp > conf.ntag || tmp < 1 || tmp == seltag) if(tmp > conf.ntag || tmp < 1 || tmp == seltag)
return; return;
for(c = clients; c; c = c->next) {
if(!ishide(c))
hide(c);
if(c->tag == tmp)
unhide(c);
}
seltag = tmp; seltag = tmp;
if(selbytag[seltag]) if(selbytag[seltag])
focus(selbytag[seltag]); focus(selbytag[seltag]);
updateall(); arrange();
return; return;
} }
void void
tagswitch(char *cmd) { tagswitch(char *cmd) {
Client *c;
int tmp; int tmp;
tmp = atoi(cmd); tmp = atoi(cmd);
if(seltag + tmp > conf.ntag || seltag + tmp < 1) if(seltag + tmp > conf.ntag || seltag + tmp < 1)
return; return;
for(c = clients; c; c = c->next) {
if(c->tag == seltag)
hide(c);
if(c && c->tag == seltag + tmp)
unhide(c);
}
seltag += tmp; seltag += tmp;
if(selbytag[seltag]) if(selbytag[seltag])
focus(selbytag[seltag]); focus(selbytag[seltag]);
updateall(); arrange();
return; return;
} }
@ -1023,93 +1066,68 @@ tagtransfert(char *cmd) {
if(!sel) if(!sel)
return; return;
sel->tag = n; sel->tag = n;
if(n != seltag) arrange();
hide(sel);
if(n == seltag)
unhide(sel);
updatelayout();
updateall();
} }
/* Testing for now */
void void
tile(void) { tile(void) {
layout[seltag] = Tile; unsigned int i, n, x, y, w, h, ww, hh, th;
unsigned int barto, bord, mwf, nm;
Client *c; Client *c;
int i;
unsigned int y, h, wm, n;
unsigned int barto, mwf, bord;
barto = conf.ttbarheight + barheight;
bord = conf.borderheight * 2;
mwf = mw*mwfact[seltag];
n = clientpertag(seltag) - clienthintpertag(seltag); n = clientpertag(seltag) - clienthintpertag(seltag);
bord = conf.borderheight * 2;
barto = conf.ttbarheight + barheight;
mwf = mwfact[seltag] * mw;
nm = nmaster[seltag];
layout[seltag] = Tile;
/* window geoms */
hh = ((n <= nm) ? mh / (n > 0 ? n : 1) : mh / nm) - bord*2;
ww = (n <= nm) ? mw : mwf;
th = (n > nm) ? mh / (n - nm) : 0;
if(n > nm && th < barheight)
th = mh;
x = 0;
y = barto; y = barto;
wm = (mh-bord) - conf.ttbarheight - barheight;
if(n-1) for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) {
h = (mh - barheight) / (n - 1) - (conf.ttbarheight + bord);
for(i = 0, c = clients; c; c = c->next, ++i) {
if(!ishide(c)) {
c->max = c->free = False; c->max = c->free = False;
c->tile = True; c->tile = True;
c->ox = c->x; c->oy = c->y; c->ox = c->x; c->oy = c->y;
c->ow = c->w; c->oh = c->h; c->ow = c->w; c->oh = c->h;
/* MASTER CLIENT */
/* 1 clients, maximize it */ if(i < nm) {
if(n == 1) y = barto + i * hh;
moveresize(c, 0, barto, mw-bord, wm, 0); w = ww - bord;
/* 2 and more... , master client */ h = hh;
else if(i == 0) { /* remainder */
moveresize(c, 0, barto, mwf-conf.borderheight, wm, 0); if(i + 1 == (n < nm ? n : nm))
master[seltag] = c; h = (mh - hh*i) - barheight ;
h -= bord + conf.ttbarheight;
} }
/* other clients */ /* TILE CLIENT */
else { else {
moveresize(c, (mwf+conf.borderheight), y, (mw-mwf-bord-conf.borderheight), h, 0); if(i == nm) {
if(i < i + 1) y = barto;
y += h + bord + conf.ttbarheight; x += ww;
}
/* when a client is out of screen */
if(c->y > mh) {
moveresize(c, 0, barto, mwf - conf.borderheight, wm, 0);
master[seltag] = c;
} }
w = mw - ww - bord;
/* remainder */
if(i + 1 == n)
h = (barto + mh) - y - (bord + barto);
else
h = th - (bord + conf.ttbarheight) - bord*2;
} }
moveresize(c, x, y, w, h, 0);
if(n > nm && th != mh)
y = c->y + c->h + bord + conf.ttbarheight;
} }
return; return;
} }
void
tile_switch(char *cmd) {
if(layout[seltag] != Tile)
return;
Client *tmp;
int sx, sy, sw, sh;
if(sel == master[seltag]
|| !master[seltag])
return;
sx = sel->x;
sy = sel->y;
sw = sel->w;
sh = sel->h;
moveresize(sel,
master[seltag]->x,
master[seltag]->y,
master[seltag]->w,
master[seltag]->h, 0);
moveresize(master[seltag], sx, sy, sw, sh, 0);
tmp = master[seltag];
master[seltag] = sel;
focus(tmp);
}
void void
togglemax(char *cmd) { togglemax(char *cmd) {
@ -1144,22 +1162,23 @@ unhide(Client *c) {
long data[] = { NormalState, None }; long data[] = { NormalState, None };
/* mapclient(c); */ /* mapclient(c); */
XMoveWindow(dpy,c->win,c->x,c->y); XMoveWindow(dpy,c->win,c->x,c->y);
if(conf.ttbarheight) { if(conf.ttbarheight) {
XMoveWindow(dpy,c->tbar,c->x, (c->y - conf.ttbarheight)); XMoveWindow(dpy,c->tbar,c->x, (c->y - conf.ttbarheight));
XMoveWindow(dpy,c->button, (c->x + c->w -10), (c->y - 9)); XMoveWindow(dpy,c->button, (c->x + c->w -10), (c->y - 9));
} }
c->hide = False;
XChangeProperty(dpy, c->win, XInternAtom(dpy, "WM_STATE", False), XChangeProperty(dpy, c->win, XInternAtom(dpy, "WM_STATE", False),
XInternAtom(dpy, "WM_STATE", False), 32, XInternAtom(dpy, "WM_STATE", False), 32,
PropModeReplace, (unsigned char *) data, 2); PropModeReplace, (unsigned char *) data, 2);
c->hide = False;
} }
void void
unmanage(Client *c) { unmanage(Client *c) {
XSetErrorHandler(errorhandler); XSetErrorHandler(errorhandler);
int i; int i;
c->hide = True;
sel = (sel == c) ? c->next : NULL; sel = (sel == c) ? c->next : NULL;
for(i = 0; i < conf.ntag; ++i) for(i = 0; i < conf.ntag; ++i)
@ -1173,8 +1192,7 @@ unmanage(Client *c) {
detach(c); detach(c);
free(c); free(c);
updatelayout(); arrange();
updateall();
XSync(dpy, False); XSync(dpy, False);
return; return;
} }
@ -1193,6 +1211,7 @@ updatebar(void) {
char buf[conf.ntag][100]; char buf[conf.ntag][100];
char p[3]; char p[3];
tm = localtime(&lt); tm = localtime(&lt);
lt = time(NULL); lt = time(NULL);
@ -1222,6 +1241,13 @@ updatebar(void) {
strlen(getlayoutsym(layout[seltag]))); strlen(getlayoutsym(layout[seltag])));
/* Draw stdin */ /* Draw stdin */
sprintf(bartext,"mwfact: %.2f nmaster: %i - %02i:%02i",
mwfact[seltag],
nmaster[seltag],
tm->tm_hour,
tm->tm_min);
j = strlen(bartext); j = strlen(bartext);
XSetForeground(dpy, gc, conf.colors.text); XSetForeground(dpy, gc, conf.colors.text);
XDrawString(dpy, bar, gc, mw - j * fonty, fonth-1 , bartext ,j); XDrawString(dpy, bar, gc, mw - j * fonty, fonth-1 , bartext ,j);
@ -1390,6 +1416,7 @@ main(int argc,char **argv) {
if(!dpy) { printf("wmfs: cannot open X server\n"); exit(1); } if(!dpy) { printf("wmfs: cannot open X server\n"); exit(1); }
init_conf();
init(); init();
scan(); scan();
for(;;) { for(;;) {
@ -1397,6 +1424,7 @@ main(int argc,char **argv) {
/* getstdin(); */ /* getstdin(); */
updatebar(); updatebar();
getevent(); getevent();
updateall();
} }
XCloseDisplay(dpy); XCloseDisplay(dpy);

46
wmfsrc
View File

@ -19,7 +19,7 @@ colors
tag_sel_bg = 0x354B5C tag_sel_bg = 0x354B5C
} }
layout layouts
{ {
free = "[Free]" free = "[Free]"
tile = "[Tile]" tile = "[Tile]"
@ -28,7 +28,7 @@ layout
tags tags
{ {
tag { name = "one" mwfact = 0.65 layout = "tile"} tag { name = "one" mwfact = 0.65 nmaster = 2 layout = "tile"}
tag { name = "two" } tag { name = "two" }
tag { name = "three" } tag { name = "three" }
tag { name = "four" } tag { name = "four" }
@ -43,6 +43,47 @@ buttons
{ {
buttons_font = "*-*-medium-*-10-*" buttons_font = "*-*-medium-*-10-*"
# MWFACT BUTTON {{{
button
{
text = "[-]"
mouse { button = "Button1" func = "set_mwfact" cmd = "-0.01"}
fg_color = 0xFFFFFF
bg_color = 0x090909
}
button
{
text = "Mwfact" fg_color = 0xFFFFFF bg_color = 0x3E3E3E
mouse { button = "Button4" func = "set_mwfact" cmd = "+0.01"}
mouse { button = "Button5" func = "set_mwfact" cmd = "-0.01"}
}
button
{
text = "[+] "
mouse { button = "Button1" func = "set_mwfact" cmd = "+0.01"}
fg_color = 0xFFFFFF
bg_color = 0x090909
}
# }}}
# NMASTER BUTTON {{{
button
{
text = "[-]"
mouse { button = "Button1" func = "set_nmaster" cmd = "-1"}
fg_color = 0xFFFFFF
bg_color = 0x090909
}
button { text = "Nmaster" fg_color = 0xFFFFFF bg_color = 0x3E3E3E }
button
{
text = "[+] "
mouse { button = "Button1" func = "set_nmaster" cmd = "+1"}
fg_color = 0xFFFFFF
bg_color = 0x090909
}
# }}}
button button
{ {
text = "Terminal" text = "Terminal"
@ -67,7 +108,6 @@ keys
key { mod = {"Control"} key = "Down" func = "layoutswitch" cmd = "-" } key { mod = {"Control"} key = "Down" func = "layoutswitch" cmd = "-" }
key { mod = {"Alt", "Shift"} key = "l" func = "set_mwfact" cmd = "+0.025" } key { mod = {"Alt", "Shift"} key = "l" func = "set_mwfact" cmd = "+0.025" }
key { mod = {"Alt", "Shift"} key = "h" func = "set_mwfact" cmd = "-0.025" } key { mod = {"Alt", "Shift"} key = "h" func = "set_mwfact" cmd = "-0.025" }
key { mod = {"Alt"} key = "d" func = "tile_switch" }
# moving client keybind # moving client keybind