Browse Source

made Layout a static struct in layout.c, added some convenience getters in layout.c, now lt->arrange accesses are not possible anymore, arrange() is the super-arrange function which sets up all layouts

main
Anselm R. Garbe 17 years ago
parent
commit
77044e8765
8 changed files with 62 additions and 42 deletions
  1. +5
    -4
      client.c
  2. +2
    -2
      config.mk
  3. +1
    -1
      draw.c
  4. +4
    -7
      dwm.h
  5. +5
    -5
      event.c
  6. +37
    -10
      layout.c
  7. +4
    -4
      tag.c
  8. +4
    -9
      tile.c

+ 5
- 4
client.c View File

@ -230,13 +230,14 @@ manage(Window w, XWindowAttributes *wa) {
setclientstate(c, IconicState); setclientstate(c, IconicState);
c->isbanned = True; c->isbanned = True;
focus(c); focus(c);
lt->arrange();
arrange();
} }
void void
resize(Client *c, int x, int y, int w, int h, Bool sizehints) { resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
double dx, dy, max, min, ratio; double dx, dy, max, min, ratio;
XWindowChanges wc; XWindowChanges wc;
if(sizehints) { if(sizehints) {
if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) { if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) {
dx = (double)(w - c->basew); dx = (double)(w - c->basew);
@ -297,12 +298,12 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
void void
togglefloating(const char *arg) { togglefloating(const char *arg) {
if(!sel || lt->arrange == floating)
if(!sel || isfloating())
return; return;
sel->isfloating = !sel->isfloating; sel->isfloating = !sel->isfloating;
if(sel->isfloating) if(sel->isfloating)
resize(sel, sel->x, sel->y, sel->w, sel->h, True); resize(sel, sel->x, sel->y, sel->w, sel->h, True);
lt->arrange();
arrange();
} }
void void
@ -334,7 +335,7 @@ unmanage(Client *c) {
XSync(dpy, False); XSync(dpy, False);
XSetErrorHandler(xerror); XSetErrorHandler(xerror);
XUngrabServer(dpy); XUngrabServer(dpy);
lt->arrange();
arrange();
} }
void void


+ 2
- 2
config.mk View File

@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
# flags # flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = -s ${LIBS} LDFLAGS = -s ${LIBS}
CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = -g ${LIBS}
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}
# Solaris # Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"


+ 1
- 1
draw.c View File

@ -66,7 +66,7 @@ drawstatus(void) {
dc.x += dc.w; dc.x += dc.w;
} }
dc.w = blw; dc.w = blw;
drawtext(lt->symbol, dc.norm);
drawtext(getsymbol(), dc.norm);
x = dc.x + dc.w; x = dc.x + dc.w;
dc.w = textw(stext); dc.w = textw(stext);
dc.x = sw - dc.w; dc.x = sw - dc.w;


+ 4
- 7
dwm.h View File

@ -74,11 +74,6 @@ typedef struct {
} font; } font;
} DC; /* draw context */ } DC; /* draw context */
typedef struct {
const char *symbol;
void (*arrange)(void);
} Layout;
extern const char *tags[]; /* all tags */ extern const char *tags[]; /* all tags */
extern char stext[256]; /* status text */ extern char stext[256]; /* status text */
extern int screen, sx, sy, sw, sh; /* screen geometry */ extern int screen, sx, sy, sw, sh; /* screen geometry */
@ -92,7 +87,6 @@ extern Client *clients, *sel, *stack; /* global client list and stack */
extern Cursor cursor[CurLast]; extern Cursor cursor[CurLast];
extern DC dc; /* global draw context */ extern DC dc; /* global draw context */
extern Display *dpy; extern Display *dpy;
extern Layout *lt;
extern Window root, barwin; extern Window root, barwin;
/* client.c */ /* client.c */
@ -120,8 +114,11 @@ unsigned int textw(const char *text); /* return the width of text in px*/
void grabkeys(void); /* grab all keys defined in config.h */ void grabkeys(void); /* grab all keys defined in config.h */
/* layout.c */ /* layout.c */
void floating(void); /* arranges all windows floating, fallback layout */
void arrange(void); /* arranges all windows depending on the layout in use */
void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */ void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */
const char *getsymbol(void); /* returns True symbol of enabled layout */
Bool isfloating(void); /* returns True if floating layout is enabled */
Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
void initlayouts(void); /* initialize layout array */ void initlayouts(void); /* initialize layout array */
Client *nexttiled(Client *c); /* returns tiled successor of c */ Client *nexttiled(Client *c); /* returns tiled successor of c */
void restack(void); /* restores z layers of all clients */ void restack(void); /* restores z layers of all clients */


+ 5
- 5
event.c View File

@ -145,14 +145,14 @@ buttonpress(XEvent *e) {
focus(c); focus(c);
if(CLEANMASK(ev->state) != MODKEY) if(CLEANMASK(ev->state) != MODKEY)
return; return;
if(ev->button == Button1 && (lt->arrange == floating || c->isfloating)) {
if(ev->button == Button1 && (isfloating() || c->isfloating)) {
restack(); restack();
movemouse(c); movemouse(c);
} }
else if(ev->button == Button2) else if(ev->button == Button2)
zoom(NULL); zoom(NULL);
else if(ev->button == Button3 else if(ev->button == Button3
&& (lt->arrange == floating || c->isfloating) && !c->isfixed)
&& (isfloating() || c->isfloating) && !c->isfixed)
{ {
restack(); restack();
resizemouse(c); resizemouse(c);
@ -170,7 +170,7 @@ configurerequest(XEvent *e) {
c->ismax = False; c->ismax = False;
if(ev->value_mask & CWBorderWidth) if(ev->value_mask & CWBorderWidth)
c->border = ev->border_width; c->border = ev->border_width;
if(c->isfixed || c->isfloating || (lt->arrange == floating)) {
if(c->isfixed || c->isfloating || isfloating()) {
if(ev->value_mask & CWX) if(ev->value_mask & CWX)
c->x = ev->x; c->x = ev->x;
if(ev->value_mask & CWY) if(ev->value_mask & CWY)
@ -216,7 +216,7 @@ configurenotify(XEvent *e) {
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
XResizeWindow(dpy, barwin, sw, bh); XResizeWindow(dpy, barwin, sw, bh);
updatebarpos(); updatebarpos();
lt->arrange();
arrange();
} }
} }
@ -317,7 +317,7 @@ propertynotify(XEvent *e) {
case XA_WM_TRANSIENT_FOR: case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans); XGetTransientForHint(dpy, c->win, &trans);
if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
lt->arrange();
arrange();
break; break;
case XA_WM_NORMAL_HINTS: case XA_WM_NORMAL_HINTS:
updatesizehints(c); updatesizehints(c);


+ 37
- 10
layout.c View File

@ -2,11 +2,25 @@
#include "dwm.h" #include "dwm.h"
#include <stdlib.h> #include <stdlib.h>
typedef struct {
const char *symbol;
void (*arrange)(void);
} Layout;
unsigned int blw = 0; unsigned int blw = 0;
Layout *lt = NULL;
static Layout *lt = NULL;
/* static */ /* static */
static void
floating(void) {
Client *c;
for(c = clients; c; c = c->next)
if(isvisible(c))
resize(c, c->x, c->y, c->w, c->h, True);
}
static unsigned int nlayouts = 0; static unsigned int nlayouts = 0;
LAYOUTS LAYOUTS
@ -14,19 +28,15 @@ LAYOUTS
/* extern */ /* extern */
void void
floating(void) {
arrange(void) {
Client *c; Client *c;
if(lt->arrange != floating)
return;
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(isvisible(c)) {
if(isvisible(c))
unban(c); unban(c);
resize(c, c->x, c->y, c->w, c->h, True);
}
else else
ban(c); ban(c);
lt->arrange();
focus(NULL); focus(NULL);
restack(); restack();
} }
@ -55,6 +65,23 @@ focusclient(const char *arg) {
} }
} }
const char *
getsymbol(void)
{
return lt->symbol;
}
Bool
isfloating(void) {
return lt->arrange == floating;
}
Bool
isarrange(void (*func)())
{
return func == lt->arrange;
}
void void
initlayouts(void) { initlayouts(void) {
unsigned int i, w; unsigned int i, w;
@ -119,7 +146,7 @@ setlayout(const char *arg) {
lt = &layout[i]; lt = &layout[i];
} }
if(sel) if(sel)
lt->arrange();
arrange();
else else
drawstatus(); drawstatus();
} }
@ -131,7 +158,7 @@ togglebar(const char *arg) {
else else
bpos = BarOff; bpos = BarOff;
updatebarpos(); updatebarpos();
lt->arrange();
arrange();
} }
void void


+ 4
- 4
tag.c View File

@ -110,7 +110,7 @@ tag(const char *arg) {
i = arg ? atoi(arg) : 0; i = arg ? atoi(arg) : 0;
if(i >= 0 && i < ntags) if(i >= 0 && i < ntags)
sel->tags[i] = True; sel->tags[i] = True;
lt->arrange();
arrange();
} }
void void
@ -124,7 +124,7 @@ toggletag(const char *arg) {
for(j = 0; j < ntags && !sel->tags[j]; j++); for(j = 0; j < ntags && !sel->tags[j]; j++);
if(j == ntags) if(j == ntags)
sel->tags[i] = True; sel->tags[i] = True;
lt->arrange();
arrange();
} }
void void
@ -136,7 +136,7 @@ toggleview(const char *arg) {
for(j = 0; j < ntags && !seltag[j]; j++); for(j = 0; j < ntags && !seltag[j]; j++);
if(j == ntags) if(j == ntags)
seltag[i] = True; /* cannot toggle last view */ seltag[i] = True; /* cannot toggle last view */
lt->arrange();
arrange();
} }
void void
@ -148,5 +148,5 @@ view(const char *arg) {
i = arg ? atoi(arg) : 0; i = arg ? atoi(arg) : 0;
if(i >= 0 && i < ntags) if(i >= 0 && i < ntags)
seltag[i] = True; seltag[i] = True;
lt->arrange();
arrange();
} }

+ 4
- 9
tile.c View File

@ -12,7 +12,7 @@ void
addtomwfact(const char *arg) { addtomwfact(const char *arg) {
double delta; double delta;
if(lt->arrange != tile)
if(isarrange(tile))
return; return;
/* arg handling, manipulate mwfact */ /* arg handling, manipulate mwfact */
@ -20,7 +20,7 @@ addtomwfact(const char *arg) {
if(delta + mwfact > 0.1 && delta + mwfact < 0.9) if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
mwfact += delta; mwfact += delta;
} }
lt->arrange();
arrange();
} }
void void
@ -41,7 +41,6 @@ tile(void) {
ny = way; ny = way;
for(i = 0, c = clients; c; c = c->next) for(i = 0, c = clients; c; c = c->next)
if(isvisible(c)) { if(isvisible(c)) {
unban(c);
if(c->isfloating) if(c->isfloating)
continue; continue;
c->ismax = False; c->ismax = False;
@ -65,17 +64,13 @@ tile(void) {
ny += nh + 2 * c->border; ny += nh + 2 * c->border;
i++; i++;
} }
else
ban(c);
focus(NULL);
restack();
} }
void void
zoom(const char *arg) { zoom(const char *arg) {
Client *c; Client *c;
if(!sel || lt->arrange == floating || sel->isfloating)
if(!sel || !isarrange(tile) || sel->isfloating)
return; return;
if((c = sel) == nexttiled(clients)) if((c = sel) == nexttiled(clients))
if(!(c = nexttiled(c->next))) if(!(c = nexttiled(c->next)))
@ -83,5 +78,5 @@ zoom(const char *arg) {
detach(c); detach(c);
attach(c); attach(c);
focus(c); focus(c);
lt->arrange();
arrange();
} }

Loading…
Cancel
Save