applied Sanders all5.patch (thanks for your weekend session, Sander!)

This commit is contained in:
Anselm R. Garbe 2007-01-22 10:22:58 +01:00
parent 201c56f6d3
commit b233089815
5 changed files with 63 additions and 71 deletions

View File

@ -79,19 +79,14 @@ configure(Client *c) {
void void
focus(Client *c) { focus(Client *c) {
Client *old; Client *old = sel;
if(!issel || (c && !isvisible(c))) if(!issel || (c && !isvisible(c)))
return; return;
if(!sel)
sel = c; if(old && old != c) {
else if(sel != c) { grabbuttons(old, False);
old = sel; XSetWindowBorder(dpy, old->win, dc.norm[ColBorder]);
sel = c;
if(old) {
grabbuttons(old, False);
XSetWindowBorder(dpy, old->win, dc.norm[ColBorder]);
}
} }
if(c) { if(c) {
detachstack(c); detachstack(c);
@ -103,6 +98,7 @@ focus(Client *c) {
} }
else else
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
sel = c;
drawstatus(); drawstatus();
} }
@ -134,20 +130,27 @@ manage(Window w, XWindowAttributes *wa) {
c = emallocz(sizeof(Client)); c = emallocz(sizeof(Client));
c->tags = emallocz(ntags * sizeof(Bool)); c->tags = emallocz(ntags * sizeof(Bool));
c->win = w; c->win = w;
c->border = 0;
c->x = wa->x; c->x = wa->x;
c->y = wa->y; c->y = wa->y;
c->w = wa->width; c->w = wa->width;
c->h = wa->height; c->h = wa->height;
updatesizehints(c); if(c->w == sw && c->h == sh) {
if(c->x + c->w + 2 * BORDERPX > sw) c->border = 0;
c->x = sw - c->w - 2 * BORDERPX;
if(c->x < sx)
c->x = sx; c->x = sx;
if(c->y + c->h + 2 * BORDERPX > sh) c->y = sy;
c->y = sh - c->h - 2 * BORDERPX; }
if(c->h != sh && c->y < bh) else {
c->y = bh; c->border = BORDERPX;
if(c->x < wax)
c->x = wax;
if(c->y < way)
c->y = way;
if(c->x + c->w + 2 * c->border > wax + waw)
c->x = wax + waw - c->w - 2 * c->border;
if(c->y + c->h + 2 * c->border > way + wah)
c->y = way + wah - c->h - 2 * c->border;
}
updatesizehints(c);
c->proto = getproto(c->win); c->proto = getproto(c->win);
XSelectInput(dpy, c->win, XSelectInput(dpy, c->win,
StructureNotifyMask | PropertyChangeMask | EnterWindowMask); StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
@ -170,9 +173,7 @@ manage(Window w, XWindowAttributes *wa) {
} }
void void
resize(Client *c, Bool sizehints, Corner sticky) { resize(Client *c, Bool sizehints) {
int bottom = c->y + c->h;
int right = c->x + c->w;
XWindowChanges wc; XWindowChanges wc;
if(sizehints) { if(sizehints) {
@ -189,27 +190,24 @@ resize(Client *c, Bool sizehints, Corner sticky) {
if(c->maxh && c->h > c->maxh) if(c->maxh && c->h > c->maxh)
c->h = c->maxh; c->h = c->maxh;
} }
if(sticky == TopRight || sticky == BotRight) if(c->w == sw && c->h == sh)
c->x = right - c->w; c->border = 0;
if(sticky == BotLeft || sticky == BotRight) else
c->y = bottom - c->h; c->border = BORDERPX;
/* offscreen appearance fixes */ /* offscreen appearance fixes */
if(c->x + c->w < sx) if(c->x + c->w + 2 * c->border < sx)
c->x = sx; c->x = sx;
if(c->y + c->h < bh) if(c->y + c->h + 2 * c->border < sy)
c->y = bh; c->y = sy;
if(c->x > sw) if(c->x > sw)
c->x = sw - c->w; c->x = sw - c->w - 2 * c->border;
if(c->y > sh) if(c->y > sh)
c->y = sh - c->h; c->y = sh - c->h - 2 * c->border;
wc.x = c->x; wc.x = c->x;
wc.y = c->y; wc.y = c->y;
wc.width = c->w; wc.width = c->w;
wc.height = c->h; wc.height = c->h;
if(c->w == sw && c->h == sh) wc.border_width = c->border;
wc.border_width = 0;
else
wc.border_width = BORDERPX;
XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
configure(c); configure(c);
XSync(dpy, False); XSync(dpy, False);

6
dwm.h
View File

@ -44,10 +44,6 @@ enum { WMProtocols, WMDelete, WMLast }; /* default atoms */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
typedef enum {
TopLeft, TopRight, BotLeft, BotRight
} Corner; /* window corners */
typedef union { typedef union {
const char *cmd; const char *cmd;
int i; int i;
@ -110,7 +106,7 @@ extern void focus(Client *c); /* focus c, c may be NULL */
extern Client *getclient(Window w); /* return client of w */ extern Client *getclient(Window w); /* return client of w */
extern void killclient(Arg *arg); /* kill c nicely */ extern void killclient(Arg *arg); /* kill c nicely */
extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ extern void manage(Window w, XWindowAttributes *wa); /* manage new client */
extern void resize(Client *c, Bool sizehints, Corner sticky); /* resize c*/ extern void resize(Client *c, Bool sizehints); /* resize c*/
extern void updatesizehints(Client *c); /* update the size hint variables of c */ extern void updatesizehints(Client *c); /* update the size hint variables of c */
extern void updatetitle(Client *c); /* update the name of c */ extern void updatetitle(Client *c); /* update the name of c */
extern void unmanage(Client *c); /* destroy c */ extern void unmanage(Client *c); /* destroy c */

50
event.c
View File

@ -35,14 +35,16 @@ movemouse(Client *c) {
c->ismax = False; c->ismax = False;
XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
for(;;) { for(;;) {
XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev); XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
switch (ev.type) { switch (ev.type) {
case ButtonRelease: case ButtonRelease:
resize(c, True, TopLeft); resize(c, True);
XUngrabPointer(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime);
return; return;
case ConfigureRequest:
case Expose: case Expose:
handler[Expose](&ev); case MapRequest:
handler[ev.type](&ev);
break; break;
case MotionNotify: case MotionNotify:
XSync(dpy, False); XSync(dpy, False);
@ -50,13 +52,13 @@ movemouse(Client *c) {
c->y = ocy + (ev.xmotion.y - y1); c->y = ocy + (ev.xmotion.y - y1);
if(abs(wax + c->x) < SNAP) if(abs(wax + c->x) < SNAP)
c->x = wax; c->x = wax;
else if(abs((wax + waw) - (c->x + c->w)) < SNAP) else if(abs((wax + waw) - (c->x + c->w + 2 * c->border)) < SNAP)
c->x = wax + waw - c->w - 2 * BORDERPX; c->x = wax + waw - c->w - 2 * c->border;
if(abs(way - c->y) < SNAP) if(abs(way - c->y) < SNAP)
c->y = way; c->y = way;
else if(abs((way + wah) - (c->y + c->h)) < SNAP) else if(abs((way + wah) - (c->y + c->h + 2 * c->border)) < SNAP)
c->y = way + wah - c->h - 2 * BORDERPX; c->y = way + wah - c->h - 2 * c->border;
resize(c, False, TopLeft); resize(c, False);
break; break;
} }
} }
@ -66,7 +68,6 @@ static void
resizemouse(Client *c) { resizemouse(Client *c) {
int ocx, ocy; int ocx, ocy;
int nw, nh; int nw, nh;
Corner sticky;
XEvent ev; XEvent ev;
ocx = c->x; ocx = c->x;
@ -75,30 +76,26 @@ resizemouse(Client *c) {
None, cursor[CurResize], CurrentTime) != GrabSuccess) None, cursor[CurResize], CurrentTime) != GrabSuccess)
return; return;
c->ismax = False; c->ismax = False;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
for(;;) { for(;;) {
XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev); XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask , &ev);
switch(ev.type) { switch(ev.type) {
case ButtonRelease: case ButtonRelease:
resize(c, True, TopLeft); resize(c, True);
XUngrabPointer(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime);
return; return;
case ConfigureRequest:
case Expose: case Expose:
handler[Expose](&ev); case MapRequest:
handler[ev.type](&ev);
break; break;
case MotionNotify: case MotionNotify:
XSync(dpy, False); XSync(dpy, False);
if((nw = abs(ocx - ev.xmotion.x))) nw = ev.xmotion.x - ocx - 2 * c->border + 1;
c->w = nw; c->w = nw > 0 ? nw : 1;
if((nh = abs(ocy - ev.xmotion.y))) nh = ev.xmotion.y - ocy - 2 * c->border + 1;
c->h = nh; c->h = nh > 0 ? nh : 1;
c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; resize(c, True);
c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
if(ocx <= ev.xmotion.x)
sticky = (ocy <= ev.xmotion.y) ? TopLeft : BotLeft;
else
sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
resize(c, True, sticky);
break; break;
} }
} }
@ -194,7 +191,7 @@ configurerequest(XEvent *e) {
configure(c); configure(c);
XSync(dpy, False); XSync(dpy, False);
if(c->isfloat) { if(c->isfloat) {
resize(c, False, TopLeft); resize(c, False);
if(!isvisible(c)) if(!isvisible(c))
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
} }
@ -234,7 +231,8 @@ enternotify(XEvent *e) {
focus(c); focus(c);
else if(ev->window == root) { else if(ev->window == root) {
issel = True; issel = True;
focus(sel); for(c = stack; c && !isvisible(c); c = c->snext);
focus(c);
} }
} }

2
main.c
View File

@ -41,7 +41,7 @@ static void
cleanup(void) { cleanup(void) {
close(STDIN_FILENO); close(STDIN_FILENO);
while(stack) { while(stack) {
resize(stack, True, TopLeft); resize(stack, True);
unmanage(stack); unmanage(stack);
} }
if(dc.font.set) if(dc.font.set)

8
view.c
View File

@ -31,7 +31,7 @@ togglemax(Client *c) {
c->w = c->rw; c->w = c->rw;
c->h = c->rh; c->h = c->rh;
} }
resize(c, True, TopLeft); resize(c, True);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
} }
@ -56,7 +56,7 @@ dofloat(void) {
for(c = clients; c; c = c->next) { for(c = clients; c; c = c->next) {
if(isvisible(c)) { if(isvisible(c)) {
resize(c, True, TopLeft); resize(c, True);
} }
else else
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
@ -84,7 +84,7 @@ dotile(void) {
for(i = 0, c = clients; c; c = c->next) for(i = 0, c = clients; c; c = c->next)
if(isvisible(c)) { if(isvisible(c)) {
if(c->isfloat) { if(c->isfloat) {
resize(c, True, TopLeft); resize(c, True);
continue; continue;
} }
c->ismax = False; c->ismax = False;
@ -105,7 +105,7 @@ dotile(void) {
else /* fallback if th < bh */ else /* fallback if th < bh */
c->h = wah - 2 * BORDERPX; c->h = wah - 2 * BORDERPX;
} }
resize(c, False, TopLeft); resize(c, False);
i++; i++;
} }
else else