made status bar drawing more robust, implemented togglemax and togglemode, works quite well

This commit is contained in:
arg@10ksloc.org 2006-07-20 15:07:35 +02:00
parent dc5d967ee6
commit 4688ad181d
5 changed files with 59 additions and 33 deletions

View File

@ -70,6 +70,9 @@ focusnext(Arg *arg)
if(!sel) if(!sel)
return; return;
if(sel->ismax)
togglemax(NULL);
if(!(c = getnext(sel->next, tsel))) if(!(c = getnext(sel->next, tsel)))
c = getnext(clients, tsel); c = getnext(clients, tsel);
if(c) { if(c) {
@ -87,6 +90,9 @@ focusprev(Arg *arg)
if(!sel) if(!sel)
return; return;
if(sel->ismax)
togglemax(NULL);
if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
higher(c); higher(c);
focus(c); focus(c);
@ -234,8 +240,6 @@ manage(Window w, XWindowAttributes *wa)
c->next = clients; c->next = clients;
clients = c; clients = c;
XGrabButton(dpy, Button1, ControlMask, c->win, False, ButtonPressMask,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(dpy, Button1, MODKEY, c->win, False, ButtonPressMask, XGrabButton(dpy, Button1, MODKEY, c->win, False, ButtonPressMask,
GrabModeAsync, GrabModeSync, None, None); GrabModeAsync, GrabModeSync, None, None);
XGrabButton(dpy, Button2, MODKEY, c->win, False, ButtonPressMask, XGrabButton(dpy, Button2, MODKEY, c->win, False, ButtonPressMask,
@ -263,19 +267,6 @@ manage(Window w, XWindowAttributes *wa)
} }
} }
void
maximize(Arg *arg)
{
if(!sel)
return;
sel->x = sx;
sel->y = sy + bh;
sel->w = sw - 2 * sel->border;
sel->h = sh - 2 * sel->border - bh;
higher(sel);
resize(sel, False, TopLeft);
}
void void
pop(Client *c) pop(Client *c)
{ {
@ -404,6 +395,38 @@ settitle(Client *c)
resizetitle(c); resizetitle(c);
} }
void
togglemax(Arg *arg)
{
int ox, oy, ow, oh;
XEvent ev;
if(!sel)
return;
if((sel->ismax = !sel->ismax)) {
ox = sel->x;
oy = sel->y;
ow = sel->w;
oh = sel->h;
sel->x = sx;
sel->y = sy + bh;
sel->w = sw - 2 * sel->border;
sel->h = sh - 2 * sel->border - bh;
higher(sel);
resize(sel, False, TopLeft);
sel->x = ox;
sel->y = oy;
sel->w = ow;
sel->h = oh;
}
else
resize(sel, False, TopLeft);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
void void
unmanage(Client *c) unmanage(Client *c)
{ {

13
draw.c
View File

@ -107,7 +107,7 @@ drawall()
void void
drawstatus() drawstatus()
{ {
int i; int i, x;
Bool istile = arrange == dotile; Bool istile = arrange == dotile;
dc.x = dc.y = 0; dc.x = dc.y = 0;
@ -123,15 +123,14 @@ drawstatus()
else else
drawtext(tags[i], (i != tsel), True); drawtext(tags[i], (i != tsel), True);
} }
if(sel) { x = dc.x + dc.w;
dc.x += dc.w;
dc.w = textw(sel->name);
drawtext(sel->name, istile, True);
}
dc.w = textw(stext); dc.w = textw(stext);
dc.x = bx + bw - dc.w; dc.x = bx + bw - dc.w;
drawtext(stext, !istile, False); drawtext(stext, !istile, False);
if(sel && ((dc.w = dc.x - x) >= bh)) {
dc.x = x;
drawtext(sel->name, istile, True);
}
XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
XSync(dpy, False); XSync(dpy, False);
} }

4
dwm.h
View File

@ -74,6 +74,7 @@ struct Client {
unsigned int border; unsigned int border;
long flags; long flags;
Bool isfloat; Bool isfloat;
Bool ismax;
Client *next; Client *next;
Client *revert; Client *revert;
Window win; Window win;
@ -104,11 +105,11 @@ extern void higher(Client *c);
extern void killclient(Arg *arg); extern void killclient(Arg *arg);
extern void lower(Client *c); extern void lower(Client *c);
extern void manage(Window w, XWindowAttributes *wa); extern void manage(Window w, XWindowAttributes *wa);
extern void maximize(Arg *arg);
extern void pop(Client *c); extern void pop(Client *c);
extern void resize(Client *c, Bool inc, Corner sticky); extern void resize(Client *c, Bool inc, Corner sticky);
extern void setsize(Client *c); extern void setsize(Client *c);
extern void settitle(Client *c); extern void settitle(Client *c);
extern void togglemax(Arg *arg);
extern void unmanage(Client *c); extern void unmanage(Client *c);
extern void zoom(Arg *arg); extern void zoom(Arg *arg);
@ -137,6 +138,7 @@ extern Client *getnext(Client *c, unsigned int t);
extern void heretag(Arg *arg); extern void heretag(Arg *arg);
extern void replacetag(Arg *arg); extern void replacetag(Arg *arg);
extern void settags(Client *c); extern void settags(Client *c);
extern void togglemode(Arg *arg);
extern void view(Arg *arg); extern void view(Arg *arg);
/* util.c */ /* util.c */

11
event.c
View File

@ -40,8 +40,8 @@ static Key key[] = {
{ MODKEY, XK_3, view, { .i = Twork } }, { MODKEY, XK_3, view, { .i = Twork } },
{ MODKEY, XK_j, focusnext, { 0 } }, { MODKEY, XK_j, focusnext, { 0 } },
{ MODKEY, XK_k, focusprev, { 0 } }, { MODKEY, XK_k, focusprev, { 0 } },
{ MODKEY, XK_m, maximize, { 0 } }, { MODKEY, XK_m, togglemax, { 0 } },
{ MODKEY, XK_space, dotile, { 0 } }, { MODKEY, XK_space, togglemode, { 0 } },
{ MODKEY, XK_Return, zoom, { 0 } }, { MODKEY, XK_Return, zoom, { 0 } },
{ ControlMask|ShiftMask,XK_0, heretag, { .i = Tscratch } }, { ControlMask|ShiftMask,XK_0, heretag, { .i = Tscratch } },
{ ControlMask|ShiftMask,XK_1, heretag, { .i = Tdev } }, { ControlMask|ShiftMask,XK_1, heretag, { .i = Tdev } },
@ -55,7 +55,6 @@ static Key key[] = {
{ MODKEY|ShiftMask, XK_g, spawn, { .argv = gimp } }, { MODKEY|ShiftMask, XK_g, spawn, { .argv = gimp } },
{ MODKEY|ShiftMask, XK_l, spawn, { .argv = xlock } }, { MODKEY|ShiftMask, XK_l, spawn, { .argv = xlock } },
{ MODKEY|ShiftMask, XK_q, quit, { 0 } }, { MODKEY|ShiftMask, XK_q, quit, { 0 } },
{ MODKEY|ShiftMask, XK_space, dofloat, { 0 } },
{ MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } }, { MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } },
{ MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } },
}; };
@ -170,11 +169,7 @@ buttonpress(XEvent *e)
default: default:
break; break;
case Button1: case Button1:
if(arrange == dotile && !c->isfloat) { if(arrange == dofloat || c->isfloat) {
if((ev->state & ControlMask) && (ev->button == Button1))
zoom(NULL);
}
else {
higher(c); higher(c);
movemouse(c); movemouse(c);
} }

11
tag.c
View File

@ -51,8 +51,8 @@ dofloat(Arg *arg)
{ {
Client *c; Client *c;
arrange = dofloat;
for(c = clients; c; c = c->next) { for(c = clients; c; c = c->next) {
c->ismax = False;
if(c->tags[tsel]) { if(c->tags[tsel]) {
resize(c, True, TopLeft); resize(c, True, TopLeft);
} }
@ -75,7 +75,6 @@ dotile(Arg *arg)
Client *c; Client *c;
w = sw - mw; w = sw - mw;
arrange = dotile;
for(n = 0, c = clients; c; c = c->next) for(n = 0, c = clients; c; c = c->next)
if(c->tags[tsel] && !c->isfloat) if(c->tags[tsel] && !c->isfloat)
n++; n++;
@ -86,6 +85,7 @@ dotile(Arg *arg)
h = sh - bh; h = sh - bh;
for(i = 0, c = clients; c; c = c->next) { for(i = 0, c = clients; c; c = c->next) {
c->ismax = False;
if(c->tags[tsel]) { if(c->tags[tsel]) {
if(c->isfloat) { if(c->isfloat) {
higher(c); higher(c);
@ -212,6 +212,13 @@ settags(Client *c)
c->tags[tsel] = tags[tsel]; c->tags[tsel] = tags[tsel];
} }
void
togglemode(Arg *arg)
{
arrange = arrange == dofloat ? dotile : dofloat;
arrange(NULL);
}
void void
view(Arg *arg) view(Arg *arg)
{ {