From 226cb4ec7c122b7394e775c60ea229fc93a48068 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 13 Aug 2008 15:26:33 +0200 Subject: [PATCH] [wmfs.c, local.h] Add true layout system + Fix some bug --- local.h | 4 ++- wmfs.c | 93 +++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 67 insertions(+), 30 deletions(-) diff --git a/local.h b/local.h index 03c9109..1c2f4ce 100644 --- a/local.h +++ b/local.h @@ -51,7 +51,6 @@ struct Client { Window tbar; /* Titlebar? */ Window button; /* Close Button */ Bool max, tile; /* client info */ - int layout; Client *next; /* next client */ Client *prev; /* previous client */ }; @@ -106,6 +105,7 @@ void detach(Client *c); void *emallocz(unsigned int size); int errorhandler(Display *d, XErrorEvent *event); void focus(Client *c); +void freelayout(void); Client* getbutton(Window w); Client* getclient(Window w); Client* getnext(Client *c); @@ -139,6 +139,7 @@ void togglemax(char *cmd); void unhide(Client *c); void unmanage(Client *c); void updatebar(void); +void updatelayout(void); void unmapclient(Client *c); void updateall(void); void updatetitle(Client *c); @@ -170,4 +171,5 @@ Client *sel; /* selected client */ int seltag; char status[16]; float mwfact[MAXTAG]; +int layout[MAXTAG]; #endif /* LOCAL_H */ diff --git a/wmfs.c b/wmfs.c index 28d243b..89e4fb7 100644 --- a/wmfs.c +++ b/wmfs.c @@ -102,6 +102,21 @@ focus(Client *c) { return; } +void +freelayout(void) { + Client *c; + for(c = clients; c; c = c->next){ + if(!ishide(c)) { + if(c->max) { + c->max == False; + moveresize(c, c->ox, c->oy, c->ow, c->oh, 0); + } + } + } + layout[seltag] = Free; + return; +} + Client* getbutton(Window w) { Client *c; @@ -190,8 +205,9 @@ getevent(void) { } break; case ConfigureRequest: - /* configure size and window position */ - + /* configure size and window position required */ + if(layout[seltag] != Free) + return; wc.x = event.xconfigurerequest.x; wc.y = event.xconfigurerequest.y; wc.width = event.xconfigurerequest.width; @@ -202,13 +218,15 @@ getevent(void) { XConfigureWindow(dpy, event.xconfigurerequest.window, event.xconfigurerequest.value_mask, &wc); if((c = getclient(event.xconfigurerequest.window))) { - XResizeWindow(dpy, c->tbar, wc.width, conf.ttbarheight); - XMoveWindow(dpy, c->button, wc.x + wc.width - 10, BUTY(wc.y)); - updatetitle(c); - c->y = wc.y; - c->x = wc.x; - c->w = wc.width; - c->h = wc.height; + if(wc.y < mw && wc.x < mh) { + XResizeWindow(dpy, c->tbar, wc.width, conf.ttbarheight); + XMoveWindow(dpy, c->button, wc.x + wc.width - 10, BUTY(wc.y)); + updatetitle(c); + c->y = wc.y; + c->x = wc.x; + c->w = wc.width; + c->h = wc.height; + } } break; @@ -266,12 +284,10 @@ getevent(void) { } } } - if(sel) { - if(event.xbutton.x >= taglen[conf.ntag] - && event.xbutton.x < taglen[conf.ntag] + strlen(conf.symlayout[sel->layout])+30) { - if(event.xbutton.button == Button1) { - layoutswitch(NULL); - } + if(event.xbutton.x >= taglen[conf.ntag] + && event.xbutton.x < taglen[conf.ntag] + strlen(conf.symlayout[layout[seltag]])+30) { + if(event.xbutton.button == Button1) { + layoutswitch(NULL); } } } @@ -355,8 +371,10 @@ init(void) { mh = DisplayHeight (dpy, screen); seltag = 1; init_conf(); - for(i=0;imax && sel->layout != Tile) { + if(sel && cmd && !ishide(sel) && !sel->max && layout[seltag] != Tile) { int tmp; tmp = sel->x + atoi(cmd); moveresize(sel,tmp, sel->y, sel->w, sel->h, 1); @@ -438,7 +456,7 @@ keymovex(char *cmd) { void keymovey(char *cmd) { - if(sel && cmd && !ishide(sel) && !sel->max && sel->layout != Tile) { + if(sel && cmd && !ishide(sel) && !sel->max && layout[seltag] != Tile) { int tmp; tmp = sel->y + atoi(cmd); moveresize(sel, sel->x, tmp, sel->w, sel->h, 1); @@ -467,7 +485,7 @@ keypress(XEvent *e) { void keyresize(char *cmd) { - if(sel && !ishide(sel) && !sel->max && sel->layout != Tile) { + if(sel && !ishide(sel) && !sel->max && layout[seltag] != Tile) { int temph=0, tempw=0, modh=0, modw=0, tmp=0; @@ -497,16 +515,17 @@ killclient(char *cmd) { ev.xclient.data.l[1] = CurrentTime; XSendEvent(dpy, sel->win, False, NoEventMask, &ev); } + updatelayout(); return; } void layoutswitch(char *cmd) { if(sel) { - switch(sel->layout) { + switch(layout[seltag]) { case Free: tile(NULL); break; case Tile: togglemax(NULL); break; - case Max: togglemax(NULL); break; + case Max: freelayout(); break; } } return; @@ -537,7 +556,6 @@ manage(Window w, XWindowAttributes *wa) { c->h = wa->height; c->border = wa->border_width; c->tag = seltag; - c->layout = Free; setborder(w, conf.colors.bordernormal); @@ -578,6 +596,7 @@ manage(Window w, XWindowAttributes *wa) { updatetitle(c); setborder(c->tbar, conf.colors.bordernormal); focus(c); + updatelayout(); return; } @@ -589,7 +608,7 @@ mouseaction(Client *c, int x, int y, int type) { int ocx, ocy; XEvent ev; - if(c->max || c->layout == Tile) + if(c->max || layout[seltag] == Tile) return; ocx = c->x; @@ -646,7 +665,6 @@ moveresize(Client *c, int x, int y, int w, int h, bool r) { } /* }}} */ - c->layout = Free; c->max = False; if(c->x != x || c->y != y || c->w != w || c->h != h) { c->x = x; @@ -702,6 +720,8 @@ scan(void) { } if(wins) XFree(wins); + updatelayout(); + return; } @@ -768,6 +788,7 @@ tag(char *cmd) { seltag = tmp; sel = NULL; + updatelayout(); return; } @@ -789,6 +810,7 @@ tagswitch(char *cmd) { unhide(c); } sel = NULL; + updatelayout(); return; } @@ -802,6 +824,7 @@ tagtransfert(char *cmd) { hide(sel); if(n == seltag) unhide(sel); + updatelayout(); } void @@ -833,7 +856,7 @@ tile(char *cmd) { moveresize(c, 0, barto, mwf-bord, mh-(bord+barto), 0); else moveresize(c, mwf, (i-1)* h + barto, w, h - (conf.ttbarheight + bord), 0); - c->layout = Tile; + layout[seltag] = Tile; } } } @@ -853,11 +876,11 @@ togglemax(char *cmd) { (mw-(conf.borderheight * 2)), (mh-(conf.borderheight * 2)- conf.ttbarheight - barheight),1); sel->max = True; - sel->layout = Max; + layout[seltag] = Max; } else if(sel->max) { moveresize(sel, sel->ox, sel->oy, sel->ow, sel->oh,0); sel->max = False; - sel->layout = Free; + layout[seltag] = Free; raiseclient(sel); } raiseclient(sel); @@ -894,6 +917,7 @@ unmanage(Client *c) { detach(c); free(c); XSync(dpy, False); + updatelayout(); return; } @@ -938,8 +962,8 @@ updatebar(void) { XSetForeground(dpy, gc, conf.colors.tagselfg); XDrawString(dpy, bar, gc, taglen[conf.ntag], fonth-1, - (sel) ? conf.symlayout[sel->layout] : conf.symlayout[Free], - (sel) ? strlen(conf.symlayout[sel->layout]) :strlen(conf.symlayout[Free]) ); + conf.symlayout[layout[seltag]], + strlen(conf.symlayout[layout[seltag]])); /* Draw date */ sprintf(status, "%02d:%02d WMFS", tm->tm_hour, tm->tm_min); @@ -951,6 +975,17 @@ updatebar(void) { return; } +void +updatelayout(void) { + if(layout[seltag] == Tile) + tile(NULL); + if(layout[seltag] == Max) + togglemax(NULL); + if(layout[seltag] == Free) + freelayout(); + return; +} + void unmapclient(Client *c) { if(c) {