Compare commits

..

41 Commits
5.8.2 ... 5.9

Author SHA1 Message Date
cd8bb06af5 enabled release flags 2011-07-10 21:24:17 +01:00
3150a8a1be applied Peters wintoclient/wintomon optimisation in enternotify() 2011-07-10 21:22:22 +01:00
b3c5f5435a removed unneeded offset recalculation, thanks Jukka, let's see if this breaks some other client 2011-07-10 21:18:50 +01:00
a692bdcf2b undo the focus optimisation patch for 5.9 2011-07-10 21:12:05 +01:00
d83454f6b7 applied Peters two patches, please test hg tip, if nothing breaks this is 5.9 2011-07-09 07:57:10 +01:00
27b0142203 applied Garys patch in a slightly modified way 2011-07-02 11:02:22 +02:00
867ba36030 applied Nicolas Capit's patch as interim solution until the multiscreen support is reworked in 6.0 2011-07-01 17:56:53 +01:00
e83f36db10 fixed scroll lock (thanks bogdan) 2011-06-27 20:12:42 +01:00
212f417e44 fix numlock (thanks mikhail) 2011-06-27 19:35:11 +01:00
3a392b8558 making enternotify less focus hungry 2011-06-25 09:07:28 +01:00
92fe06b501 applied Andreas Amann's patch from Oct 2010, thanks 2011-06-24 21:02:32 +01:00
6cf29bff33 applied Rudys barwidth patch, thanks Rudy 2011-06-17 20:22:54 +01:00
60c06a7cb4 don't check for monocle layout in zoom() exit condition 2011-06-14 22:28:16 +01:00
1147546122 Thanks for the pedantic review :) 2011-06-14 05:51:21 +01:00
d384cee751 fixing some minor issues, next week is dwm-5.9 release time 2011-06-11 08:33:20 +01:00
5c710cf89c rm draw.c from 5.9 branch 2011-06-04 23:02:00 +01:00
8a111c181e fix typo 2011-06-04 10:18:54 +01:00
2255bf46a0 cleaner drawing 2011-06-04 10:17:25 +01:00
04797343db update draw.c 2011-05-21 20:26:26 +01:00
e7d41cc188 added draw.h, draw.c 2011-05-20 19:10:26 +01:00
22d8818850 applied Evil_Bobs cleanup patch 2011-05-12 14:16:33 +00:00
6784429c3c applied another minor change to the README 2011-04-27 15:55:18 +00:00
37fea84de8 applied Thomas' README patch 2011-04-27 12:38:59 +00:00
c14d293e51 applied Jack's mplayer fullscreen patch 2011-04-26 08:13:39 +00:00
79b1657a19 missed declaration 2011-04-15 08:13:06 +00:00
d24837f1ad minor fix of the NetActiveWindow multi-monitor flaw, slight rearrangement 2011-04-15 08:12:20 +00:00
3c2d303c0e applied Peter/Andreas NetActiveWindow patch in a slightly modified version 2011-04-14 13:46:25 +00:00
1e20a0f78a applied Brendan MacDonell's WM_TAKE_FOCUS patch, thanks Brendan! 2011-04-12 20:19:32 +00:00
96f9855248 applied another patch of Hiltjo, thanks 2011-03-25 14:06:46 +00:00
3c48858ffa applied Hiltjos' BUGS patch from 23 Mar, sorry took a while :) 2011-03-25 13:57:54 +00:00
dd46d5b588 applied Hiltjo's multimon mouse-based resize fix 2011-03-23 08:58:57 +00:00
0bc4e41ebd applied anonymous patch, I don't think the reversed array access has semantic side-effects 2011-01-07 16:05:22 +00:00
703c4dd253 added a todo 2010-12-02 10:16:47 +00:00
b68528d85d applied Hiltjo's cleanup patch 2010-11-19 11:53:59 +00:00
a644baf674 applied Hiltjo's tiny cleanup fix 2010-09-27 07:53:44 +00:00
c1f8688bfa applied Hiltjo's tiny cleanup patch, thanks! 2010-09-25 13:39:08 +00:00
bea4dd2490 does this make a difference? 2010-09-11 19:00:18 +00:00
83d10be1c1 added TODO and bumped version to 5.9 2010-08-24 13:13:20 +01:00
1529058f27 applied Hiltjo Posthuma's line saver patch 2010-08-23 17:25:53 +01:00
36311d88af applied Hiltjo Posthuma's double-XineramaQueryScreens() patch, thanks Hiltjo! 2010-07-25 09:58:25 +01:00
f1a2a3c850 Added tag 5.8.2 for changeset a043f0800805 2010-06-04 11:41:16 +01:00
7 changed files with 165 additions and 187 deletions

View File

@ -68,3 +68,4 @@ e47a47bd3ed42fd3cf023572147b75ebc2adef82 5.6.1
15761ac5e2f1e9010900f891616a24a22d82f128 5.7.2 15761ac5e2f1e9010900f891616a24a22d82f128 5.7.2
60ea8fed13ab750c6717f2764cbf9c13bb6f0d0a 5.8 60ea8fed13ab750c6717f2764cbf9c13bb6f0d0a 5.8
1ed1e75c9c2e395a2c475b52657a430bd95070c7 5.8.1 1ed1e75c9c2e395a2c475b52657a430bd95070c7 5.8.1
a043f08008051ca02ae87eb170cd066d8c8315a0 5.8.2

28
BUGS
View File

@ -8,34 +8,6 @@ reproducible with xrandr -s but not with --output and --mode, strange
--- ---
> enternotify is handled even when the entered window is already focused
> (eg moving the mouse to the bar and back, scrolling on the border..)
>
> focusing might be expensive for some clients (eg dim/light up)
>
> a possible solution is to modify enternotify:
>
> + c = wintoclient(ev->window);
> if((m = wintomon(ev->window)) && m != selmon) {
> unfocus(selmon->sel);
> selmon = m;
> }
> + else if (c == selmon->sel || c == NULL)
> + return;
---
> another corner case:
a tiled client can be resized with mod+right click, but it only works
on the main monitor
---
dmenu appears on the monitor where the pointer is and not on selmon
---
yet another corner case: yet another corner case:
open a terminal, focus another monitor, but without moving the mouse open a terminal, focus another monitor, but without moving the mouse
pointer there pointer there

View File

@ -1,6 +1,6 @@
MIT/X Consortium License MIT/X Consortium License
© 2006-2010 Anselm R Garbe <anselm@garbe.us> © 2006-2011 Anselm R Garbe <anselm@garbe.us>
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com> © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
© 2006-2009 Jukka Salmi <jukka at salmi dot ch> © 2006-2009 Jukka Salmi <jukka at salmi dot ch>
© 2007-2009 Premysl Hruby <dfenze at gmail dot com> © 2007-2009 Premysl Hruby <dfenze at gmail dot com>
@ -10,7 +10,7 @@ MIT/X Consortium License
© 2007-2008 Peter Hartlich <sgkkr at hartlich dot com> © 2007-2008 Peter Hartlich <sgkkr at hartlich dot com>
© 2008 Martin Hurton <martin dot hurton at gmail dot com> © 2008 Martin Hurton <martin dot hurton at gmail dot com>
© 2008 Neale Pickett <neale dot woozle dot org> © 2008 Neale Pickett <neale dot woozle dot org>
© 2009 Mate Nagy <mnagy@port70.net> © 2009 Mate Nagy <mnagy at port70 dot net>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

5
README
View File

@ -38,10 +38,9 @@ the DISPLAY environment variable is set correctly, e.g.:
In order to display status info in the bar, you can do something In order to display status info in the bar, you can do something
like this in your .xinitrc: like this in your .xinitrc:
while true while xsetroot -name "`date` `uptime | sed 's/.*,//'`"
do do
xsetroot -name "`date` `uptime | sed 's/.*,//'`" sleep 20
sleep 1
done & done &
exec dwm exec dwm

2
TODO Normal file
View File

@ -0,0 +1,2 @@
- add updategeom() hook for external tools like dzen
- consider onscreenkeyboard hooks for tablet deployment

View File

@ -1,5 +1,5 @@
# dwm version # dwm version
VERSION = 5.8.2 VERSION = 5.9
# Customize below to fit your system # Customize below to fit your system
@ -20,10 +20,10 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
# flags # flags
CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -g ${LIBS} #LDFLAGS = -g ${LIBS}
#LDFLAGS = -s ${LIBS} LDFLAGS = -s ${LIBS}
# Solaris # Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"

302
dwm.c
View File

@ -42,7 +42,7 @@
/* macros */ /* macros */
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0]) #define LENGTH(X) (sizeof X / sizeof X[0])
@ -58,8 +58,8 @@
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
enum { NetSupported, NetWMName, NetWMState, enum { NetSupported, NetWMName, NetWMState,
NetWMFullscreen, NetLast }; /* EWMH atoms */ NetWMFullscreen, NetActiveWindow, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@ -88,7 +88,7 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh; int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw; int bw, oldbw;
unsigned int tags; unsigned int tags;
Bool isfixed, isfloating, isurgent, oldstate; Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
Client *next; Client *next;
Client *snext; Client *snext;
Monitor *mon; Monitor *mon;
@ -190,7 +190,6 @@ static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, Bool focused); static void grabbuttons(Client *c, Bool focused);
static void grabkeys(void); static void grabkeys(void);
static void initfont(const char *fontstr); static void initfont(const char *fontstr);
static Bool isprotodel(Client *c);
static void keypress(XEvent *e); static void keypress(XEvent *e);
static void killclient(const Arg *arg); static void killclient(const Arg *arg);
static void manage(Window w, XWindowAttributes *wa); static void manage(Window w, XWindowAttributes *wa);
@ -199,8 +198,9 @@ static void maprequest(XEvent *e);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void movemouse(const Arg *arg); static void movemouse(const Arg *arg);
static Client *nexttiled(Client *c); static Client *nexttiled(Client *c);
static Monitor *ptrtomon(int x, int y); static void pop(Client *);
static void propertynotify(XEvent *e); static void propertynotify(XEvent *e);
static Monitor *ptrtomon(int x, int y);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static void resize(Client *c, int x, int y, int w, int h, Bool interact); static void resize(Client *c, int x, int y, int w, int h, Bool interact);
static void resizeclient(Client *c, int x, int y, int w, int h); static void resizeclient(Client *c, int x, int y, int w, int h);
@ -208,8 +208,10 @@ static void resizemouse(const Arg *arg);
static void restack(Monitor *m); static void restack(Monitor *m);
static void run(void); static void run(void);
static void scan(void); static void scan(void);
static Bool sendevent(Client *c, Atom proto);
static void sendmon(Client *c, Monitor *m); static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state); static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setlayout(const Arg *arg); static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg); static void setmfact(const Arg *arg);
static void setup(void); static void setup(void);
@ -267,7 +269,6 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[UnmapNotify] = unmapnotify [UnmapNotify] = unmapnotify
}; };
static Atom wmatom[WMLast], netatom[NetLast]; static Atom wmatom[WMLast], netatom[NetLast];
static Bool otherwm;
static Bool running = True; static Bool running = True;
static Cursor cursor[CurLast]; static Cursor cursor[CurLast];
static Display *dpy; static Display *dpy;
@ -372,10 +373,8 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
if(c->inch) if(c->inch)
*h -= *h % c->inch; *h -= *h % c->inch;
/* restore base dimensions */ /* restore base dimensions */
*w += c->basew; *w = MAX(*w + c->basew, c->minw);
*h += c->baseh; *h = MAX(*h + c->baseh, c->minh);
*w = MAX(*w, c->minw);
*h = MAX(*h, c->minh);
if(c->maxw) if(c->maxw)
*w = MIN(*w, c->maxw); *w = MIN(*w, c->maxw);
if(c->maxh) if(c->maxh)
@ -443,7 +442,7 @@ buttonpress(XEvent *e) {
} }
else if(ev->x < x + blw) else if(ev->x < x + blw)
click = ClkLtSymbol; click = ClkLtSymbol;
else if(ev->x > selmon->wx + selmon->ww - TEXTW(stext)) else if(ev->x > selmon->ww - TEXTW(stext))
click = ClkStatusText; click = ClkStatusText;
else else
click = ClkWinTitle; click = ClkWinTitle;
@ -460,13 +459,10 @@ buttonpress(XEvent *e) {
void void
checkotherwm(void) { checkotherwm(void) {
otherwm = False;
xerrorxlib = XSetErrorHandler(xerrorstart); xerrorxlib = XSetErrorHandler(xerrorstart);
/* this causes an error if some other window manager is running */ /* this causes an error if some other window manager is running */
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
XSync(dpy, False); XSync(dpy, False);
if(otherwm)
die("dwm: another window manager is already running\n");
XSetErrorHandler(xerror); XSetErrorHandler(xerror);
XSync(dpy, False); XSync(dpy, False);
} }
@ -525,6 +521,48 @@ clearurgent(Client *c) {
XFree(wmh); XFree(wmh);
} }
void
clientmessage(XEvent *e) {
XClientMessageEvent *cme = &e->xclient;
Client *c = wintoclient(cme->window);
if(!c)
return;
if(cme->message_type == netatom[NetWMState] && cme->data.l[1] == netatom[NetWMFullscreen]) {
if(cme->data.l[0] && !c->isfullscreen) {
XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
c->isfullscreen = True;
c->oldstate = c->isfloating;
c->oldbw = c->bw;
c->bw = 0;
c->isfloating = True;
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
XRaiseWindow(dpy, c->win);
}
else {
XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)0, 0);
c->isfullscreen = False;
c->isfloating = c->oldstate;
c->bw = c->oldbw;
c->x = c->oldx;
c->y = c->oldy;
c->w = c->oldw;
c->h = c->oldh;
resizeclient(c, c->x, c->y, c->w, c->h);
arrange(c->mon);
}
}
else if(cme->message_type == netatom[NetActiveWindow]) {
if(!ISVISIBLE(c)) {
c->mon->seltags ^= 1;
c->mon->tagset[c->mon->seltags] = c->tags;
}
pop(c);
}
}
void void
configure(Client *c) { configure(Client *c) {
XConfigureEvent ce; XConfigureEvent ce;
@ -547,11 +585,13 @@ void
configurenotify(XEvent *e) { configurenotify(XEvent *e) {
Monitor *m; Monitor *m;
XConfigureEvent *ev = &e->xconfigure; XConfigureEvent *ev = &e->xconfigure;
Bool dirty;
if(ev->window == root) { if(ev->window == root) {
dirty = (sw != ev->width);
sw = ev->width; sw = ev->width;
sh = ev->height; sh = ev->height;
if(updategeom()) { if(updategeom() || dirty) {
if(dc.drawable != 0) if(dc.drawable != 0)
XFreePixmap(dpy, dc.drawable); XFreePixmap(dpy, dc.drawable);
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
@ -742,32 +782,22 @@ drawbars(void) {
void void
drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
int x; int x;
XGCValues gcv;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
gcv.foreground = col[invert ? ColBG : ColFG]; XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
x = (dc.font.ascent + dc.font.descent + 2) / 4; x = (dc.font.ascent + dc.font.descent + 2) / 4;
r.x = dc.x + 1; if(filled)
r.y = dc.y + 1; XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1);
if(filled) { else if(empty)
r.width = r.height = x + 1; XDrawRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x, x);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
}
else if(empty) {
r.width = r.height = x;
XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
}
} }
void void
drawtext(const char *text, unsigned long col[ColLast], Bool invert) { drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
char buf[256]; char buf[256];
int i, x, y, h, len, olen; int i, x, y, h, len, olen;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h);
if(!text) if(!text)
return; return;
olen = strlen(text); olen = strlen(text);
@ -796,14 +826,15 @@ enternotify(XEvent *e) {
if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
return; return;
if((m = wintomon(ev->window)) && m != selmon) { c = wintoclient(ev->window);
m = c ? c->mon : wintomon(ev->window);
if(m != selmon) {
unfocus(selmon->sel, True); unfocus(selmon->sel, True);
selmon = m; selmon = m;
} }
if((c = wintoclient(ev->window))) else if(!c || c == selmon->sel)
focus(c); return;
else focus(c);
focus(NULL);
} }
void void
@ -831,7 +862,7 @@ focus(Client *c) {
attachstack(c); attachstack(c);
grabbuttons(c, True); grabbuttons(c, True);
XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); setfocus(c);
} }
else else
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
@ -844,12 +875,12 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */
XFocusChangeEvent *ev = &e->xfocus; XFocusChangeEvent *ev = &e->xfocus;
if(selmon->sel && ev->window != selmon->sel->win) if(selmon->sel && ev->window != selmon->sel->win)
XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime); setfocus(selmon->sel);
} }
void void
focusmon(const Arg *arg) { focusmon(const Arg *arg) {
Monitor *m = NULL; Monitor *m;
if(!mons->next) if(!mons->next)
return; return;
@ -990,7 +1021,7 @@ grabkeys(void) {
void void
initfont(const char *fontstr) { initfont(const char *fontstr) {
char *def, **missing; char *def, **missing;
int i, n; int n;
missing = NULL; missing = NULL;
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
@ -1000,14 +1031,13 @@ initfont(const char *fontstr) {
XFreeStringList(missing); XFreeStringList(missing);
} }
if(dc.font.set) { if(dc.font.set) {
XFontSetExtents *font_extents;
XFontStruct **xfonts; XFontStruct **xfonts;
char **font_names; char **font_names;
dc.font.ascent = dc.font.descent = 0; dc.font.ascent = dc.font.descent = 0;
font_extents = XExtentsOfFontSet(dc.font.set); XExtentsOfFontSet(dc.font.set);
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { while(n--) {
dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent); dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
xfonts++; xfonts++;
@ -1023,29 +1053,12 @@ initfont(const char *fontstr) {
dc.font.height = dc.font.ascent + dc.font.descent; dc.font.height = dc.font.ascent + dc.font.descent;
} }
Bool
isprotodel(Client *c) {
int i, n;
Atom *protocols;
Bool ret = False;
if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
for(i = 0; !ret && i < n; i++)
if(protocols[i] == wmatom[WMDelete])
ret = True;
XFree(protocols);
}
return ret;
}
#ifdef XINERAMA #ifdef XINERAMA
static Bool static Bool
isuniquegeom(XineramaScreenInfo *unique, size_t len, XineramaScreenInfo *info) { isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) {
unsigned int i; while(n--)
if(unique[n].x_org == info->x_org && unique[n].y_org == info->y_org
for(i = 0; i < len; i++) && unique[n].width == info->width && unique[n].height == info->height)
if(unique[i].x_org == info->x_org && unique[i].y_org == info->y_org
&& unique[i].width == info->width && unique[i].height == info->height)
return False; return False;
return True; return True;
} }
@ -1068,20 +1081,9 @@ keypress(XEvent *e) {
void void
killclient(const Arg *arg) { killclient(const Arg *arg) {
XEvent ev;
if(!selmon->sel) if(!selmon->sel)
return; return;
if(isprotodel(selmon->sel)) { if(!sendevent(selmon->sel, wmatom[WMDelete])) {
ev.type = ClientMessage;
ev.xclient.window = selmon->sel->win;
ev.xclient.message_type = wmatom[WMProtocols];
ev.xclient.format = 32;
ev.xclient.data.l[0] = wmatom[WMDelete];
ev.xclient.data.l[1] = CurrentTime;
XSendEvent(dpy, selmon->sel->win, False, NoEventMask, &ev);
}
else {
XGrabServer(dpy); XGrabServer(dpy);
XSetErrorHandler(xerrordummy); XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll); XSetCloseDownMode(dpy, DestroyAll);
@ -1094,19 +1096,15 @@ killclient(const Arg *arg) {
void void
manage(Window w, XWindowAttributes *wa) { manage(Window w, XWindowAttributes *wa) {
static Client cz;
Client *c, *t = NULL; Client *c, *t = NULL;
Window trans = None; Window trans = None;
XWindowChanges wc; XWindowChanges wc;
if(!(c = malloc(sizeof(Client)))) if(!(c = calloc(1, sizeof(Client))))
die("fatal: could not malloc() %u bytes\n", sizeof(Client)); die("fatal: could not malloc() %u bytes\n", sizeof(Client));
*c = cz;
c->win = w; c->win = w;
updatetitle(c); updatetitle(c);
if(XGetTransientForHint(dpy, w, &trans)) if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
t = wintoclient(trans);
if(t) {
c->mon = t->mon; c->mon = t->mon;
c->tags = t->tags; c->tags = t->tags;
} }
@ -1115,13 +1113,13 @@ manage(Window w, XWindowAttributes *wa) {
applyrules(c); applyrules(c);
} }
/* geometry */ /* geometry */
c->x = c->oldx = wa->x + c->mon->wx; c->x = c->oldx = wa->x;
c->y = c->oldy = wa->y + c->mon->wy; c->y = c->oldy = wa->y;
c->w = c->oldw = wa->width; c->w = c->oldw = wa->width;
c->h = c->oldh = wa->height; c->h = c->oldh = wa->height;
c->oldbw = wa->border_width; c->oldbw = wa->border_width;
if(c->w == c->mon->mw && c->h == c->mon->mh) { if(c->w == c->mon->mw && c->h == c->mon->mh) {
c->isfloating = 1; c->isfloating = True;
c->x = c->mon->mx; c->x = c->mon->mx;
c->y = c->mon->my; c->y = c->mon->my;
c->bw = 0; c->bw = 0;
@ -1142,6 +1140,7 @@ manage(Window w, XWindowAttributes *wa) {
XSetWindowBorder(dpy, w, dc.norm[ColBorder]); XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
configure(c); /* propagates border_width, if size doesn't change */ configure(c); /* propagates border_width, if size doesn't change */
updatesizehints(c); updatesizehints(c);
updatewmhints(c);
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, False); grabbuttons(c, False);
if(!c->isfloating) if(!c->isfloating)
@ -1211,7 +1210,7 @@ movemouse(const Arg *arg) {
return; return;
do { do {
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
switch (ev.type) { switch(ev.type) {
case ConfigureRequest: case ConfigureRequest:
case Expose: case Expose:
case MapRequest: case MapRequest:
@ -1220,7 +1219,7 @@ movemouse(const Arg *arg) {
case MotionNotify: case MotionNotify:
nx = ocx + (ev.xmotion.x - x); nx = ocx + (ev.xmotion.x - x);
ny = ocy + (ev.xmotion.y - y); ny = ocy + (ev.xmotion.y - y);
if(snap && nx >= selmon->wx && nx <= selmon->wx + selmon->ww if(nx >= selmon->wx && nx <= selmon->wx + selmon->ww
&& ny >= selmon->wy && ny <= selmon->wy + selmon->wh) { && ny >= selmon->wy && ny <= selmon->wy + selmon->wh) {
if(abs(selmon->wx - nx) < snap) if(abs(selmon->wx - nx) < snap)
nx = selmon->wx; nx = selmon->wx;
@ -1253,14 +1252,12 @@ nexttiled(Client *c) {
return c; return c;
} }
Monitor * void
ptrtomon(int x, int y) { pop(Client *c) {
Monitor *m; detach(c);
attach(c);
for(m = mons; m; m = m->next) focus(c);
if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh)) arrange(c->mon);
return m;
return selmon;
} }
void void
@ -1274,11 +1271,11 @@ propertynotify(XEvent *e) {
else if(ev->state == PropertyDelete) else if(ev->state == PropertyDelete)
return; /* ignore */ return; /* ignore */
else if((c = wintoclient(ev->window))) { else if((c = wintoclient(ev->window))) {
switch (ev->atom) { switch(ev->atom) {
default: break; default: break;
case XA_WM_TRANSIENT_FOR: case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans); if(!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
if(!c->isfloating && (c->isfloating = (wintoclient(trans) != NULL))) (c->isfloating = (wintoclient(trans)) != NULL))
arrange(c->mon); arrange(c->mon);
break; break;
case XA_WM_NORMAL_HINTS: case XA_WM_NORMAL_HINTS:
@ -1297,39 +1294,15 @@ propertynotify(XEvent *e) {
} }
} }
void Monitor *
clientmessage(XEvent *e) { ptrtomon(int x, int y) {
XClientMessageEvent *cme = &e->xclient; Monitor *m;
Client *c;
if((c = wintoclient(cme->window)) for(m = mons; m; m = m->next)
&& (cme->message_type == netatom[NetWMState] && cme->data.l[1] == netatom[NetWMFullscreen])) if(INRECT(x, y, m->wx, m->wy, m->ww, m->wh))
{ return m;
if(cme->data.l[0]) { return selmon;
XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
c->oldstate = c->isfloating;
c->oldbw = c->bw;
c->bw = 0;
c->isfloating = 1;
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
XRaiseWindow(dpy, c->win);
}
else {
XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
PropModeReplace, (unsigned char*)0, 0);
c->isfloating = c->oldstate;
c->bw = c->oldbw;
c->x = c->oldx;
c->y = c->oldy;
c->w = c->oldw;
c->h = c->oldh;
resizeclient(c, c->x, c->y, c->w, c->h);
arrange(c->mon);
}
}
} }
void void
quit(const Arg *arg) { quit(const Arg *arg) {
running = False; running = False;
@ -1383,8 +1356,8 @@ resizemouse(const Arg *arg) {
case MotionNotify: case MotionNotify:
nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
if(snap && nw >= selmon->wx && nw <= selmon->wx + selmon->ww if(c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
&& nh >= selmon->wy && nh <= selmon->wy + selmon->wh) && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
{ {
if(!c->isfloating && selmon->lt[selmon->sellt]->arrange if(!c->isfloating && selmon->lt[selmon->sellt]->arrange
&& (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
@ -1489,6 +1462,37 @@ setclientstate(Client *c, long state) {
PropModeReplace, (unsigned char *)data, 2); PropModeReplace, (unsigned char *)data, 2);
} }
Bool
sendevent(Client *c, Atom proto) {
int n;
Atom *protocols;
Bool exists = False;
XEvent ev;
if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
while(!exists && n--)
exists = protocols[n] == proto;
XFree(protocols);
}
if(exists) {
ev.type = ClientMessage;
ev.xclient.window = c->win;
ev.xclient.message_type = wmatom[WMProtocols];
ev.xclient.format = 32;
ev.xclient.data.l[0] = proto;
ev.xclient.data.l[1] = CurrentTime;
XSendEvent(dpy, c->win, False, NoEventMask, &ev);
}
return exists;
}
void
setfocus(Client *c) {
if(!c->neverfocus)
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
sendevent(c, wmatom[WMTakeFocus]);
}
void void
setlayout(const Arg *arg) { setlayout(const Arg *arg) {
if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
@ -1535,6 +1539,8 @@ setup(void) {
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
@ -1577,7 +1583,7 @@ showhide(Client *c) {
return; return;
if(ISVISIBLE(c)) { /* show clients top down */ if(ISVISIBLE(c)) { /* show clients top down */
XMoveWindow(dpy, c->win, c->x, c->y); XMoveWindow(dpy, c->win, c->x, c->y);
if(!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) if((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
resize(c, c->x, c->y, c->w, c->h, False); resize(c, c->x, c->y, c->w, c->h, False);
showhide(c->snext); showhide(c->snext);
} }
@ -1587,7 +1593,6 @@ showhide(Client *c) {
} }
} }
void void
sigchld(int unused) { sigchld(int unused) {
if(signal(SIGCHLD, sigchld) == SIG_ERR) if(signal(SIGCHLD, sigchld) == SIG_ERR)
@ -1604,7 +1609,7 @@ spawn(const Arg *arg) {
execvp(((char **)arg->v)[0], (char **)arg->v); execvp(((char **)arg->v)[0], (char **)arg->v);
fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
perror(" failed"); perror(" failed");
exit(0); exit(EXIT_SUCCESS);
} }
} }
@ -1752,11 +1757,11 @@ unmapnotify(XEvent *e) {
void void
updatebars(void) { updatebars(void) {
Monitor *m; Monitor *m;
XSetWindowAttributes wa; XSetWindowAttributes wa = {
.override_redirect = True,
wa.override_redirect = True; .background_pixmap = ParentRelative,
wa.background_pixmap = ParentRelative; .event_mask = ButtonPressMask|ExposureMask
wa.event_mask = ButtonPressMask|ExposureMask; };
for(m = mons; m; m = m->next) { for(m = mons; m; m = m->next) {
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
@ -1791,7 +1796,6 @@ updategeom(void) {
XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn); XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn);
XineramaScreenInfo *unique = NULL; XineramaScreenInfo *unique = NULL;
info = XineramaQueryScreens(dpy, &nn);
for(n = 0, m = mons; m; m = m->next, n++); for(n = 0, m = mons; m; m = m->next, n++);
/* only consider unique geometries as separate screens */ /* only consider unique geometries as separate screens */
if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn))) if(!(unique = (XineramaScreenInfo *)malloc(sizeof(XineramaScreenInfo) * nn)))
@ -1953,6 +1957,10 @@ updatewmhints(Client *c) {
} }
else else
c->isurgent = (wmh->flags & XUrgencyHint) ? True : False; c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
if(wmh->flags & InputHint)
c->neverfocus = !wmh->input;
else
c->neverfocus = False;
XFree(wmh); XFree(wmh);
} }
} }
@ -2024,7 +2032,7 @@ xerrordummy(Display *dpy, XErrorEvent *ee) {
* is already running. */ * is already running. */
int int
xerrorstart(Display *dpy, XErrorEvent *ee) { xerrorstart(Display *dpy, XErrorEvent *ee) {
otherwm = True; die("dwm: another window manager is already running\n");
return -1; return -1;
} }
@ -2033,22 +2041,18 @@ zoom(const Arg *arg) {
Client *c = selmon->sel; Client *c = selmon->sel;
if(!selmon->lt[selmon->sellt]->arrange if(!selmon->lt[selmon->sellt]->arrange
|| selmon->lt[selmon->sellt]->arrange == monocle
|| (selmon->sel && selmon->sel->isfloating)) || (selmon->sel && selmon->sel->isfloating))
return; return;
if(c == nexttiled(selmon->clients)) if(c == nexttiled(selmon->clients))
if(!c || !(c = nexttiled(c->next))) if(!c || !(c = nexttiled(c->next)))
return; return;
detach(c); pop(c);
attach(c);
focus(c);
arrange(c->mon);
} }
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
if(argc == 2 && !strcmp("-v", argv[1])) if(argc == 2 && !strcmp("-v", argv[1]))
die("dwm-"VERSION", © 2006-2010 dwm engineers, see LICENSE for details\n"); die("dwm-"VERSION", © 2006-2011 dwm engineers, see LICENSE for details\n");
else if(argc != 1) else if(argc != 1)
die("usage: dwm [-v]\n"); die("usage: dwm [-v]\n");
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
@ -2061,5 +2065,5 @@ main(int argc, char *argv[]) {
run(); run();
cleanup(); cleanup();
XCloseDisplay(dpy); XCloseDisplay(dpy);
return 0; return EXIT_SUCCESS;
} }