Permalink
Browse files

dwm.c: alter pertag functionality to not care about status bar per tag

  • Loading branch information...
falconindy committed Jun 15, 2010
1 parent 604d94a commit bd7482a0042caf6c3712b2ec74a25037fe812748
Showing with 76 additions and 42 deletions.
  1. +76 −42 dwm.c
View
118 dwm.c
@@ -57,7 +57,8 @@
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
-enum { NetSupported, NetWMName, NetWMState, NetLast }; /* EWMH atoms */
+enum { NetSupported, NetWMName, NetWMState,
+ NetWMFullscreen, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -83,10 +84,11 @@ struct Client {
char name[256];
float mina, maxa;
int x, y, w, h;
+ int oldx, oldy, oldw, oldh;
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
unsigned int tags;
- Bool isfixed, isfloating, isurgent;
+ Bool isfixed, isfloating, isurgent, oldstate;
Client *next;
Client *snext;
Monitor *mon;
@@ -142,6 +144,7 @@ static void checkotherwm(void);
static void cleanup(void);
static void cleanupmon(Monitor *mon);
static void clearurgent(Client *c);
+static void clientmessage(XEvent *e);
static void configure(Client *c);
static void configurenotify(XEvent *e);
static void configurerequest(XEvent *e);
@@ -181,6 +184,7 @@ static Monitor *ptrtomon(int x, int y);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
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 resizemouse(const Arg *arg);
static void restack(Monitor *m);
static void run(void);
@@ -201,7 +205,7 @@ static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
-static void unfocus(Client *c);
+static void unfocus(Client *c, Bool setfocus);
static void unmanage(Client *c, Bool destroyed);
static void unmapnotify(XEvent *e);
static Bool updategeom(void);
@@ -230,6 +234,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0;
static void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress,
+ [ClientMessage] = clientmessage,
[ConfigureRequest] = configurerequest,
[ConfigureNotify] = configurenotify,
[DestroyNotify] = destroynotify,
@@ -276,7 +281,6 @@ struct Monitor {
int prevtag;
const Layout *lts[LENGTH(tags) + 1];
double mfacts[LENGTH(tags) + 1];
- Bool showbars[LENGTH(tags) + 1];
};
/* compile-time check if all tags fit into an unsigned int bit array. */
@@ -459,7 +463,7 @@ buttonpress(XEvent *e) {
click = ClkRootWin;
/* focus monitor if necessary */
if((m = wintomon(ev->window)) && m != selmon) {
- unfocus(selmon->sel);
+ unfocus(selmon->sel, True);
selmon = m;
focus(NULL);
}
@@ -828,7 +832,7 @@ enternotify(XEvent *e) {
if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
return;
if((m = wintomon(ev->window)) && m != selmon) {
- unfocus(selmon->sel);
+ unfocus(selmon->sel, True);
selmon = m;
}
if((c = wintoclient(ev->window)))
@@ -850,8 +854,9 @@ void
focus(Client *c) {
if(!c || !ISVISIBLE(c))
for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
- if(selmon->sel)
- unfocus(selmon->sel);
+ /* was if(selmon->sel) */
+ if(selmon->sel && selmon->sel != c)
+ unfocus(selmon->sel, False);
if(c) {
if(c->mon != selmon)
selmon = c->mon;
@@ -885,7 +890,7 @@ focusmon(const Arg *arg) {
return;
if((m = dirtomon(arg->i)) == selmon)
return;
- unfocus(selmon->sel);
+ unfocus(selmon->sel, True);
selmon = m;
focus(NULL);
}
@@ -937,15 +942,14 @@ getrootptr(int *x, int *y) {
long
getstate(Window w) {
- int format, status;
+ int format;
long result = -1;
unsigned char *p = NULL;
unsigned long n, extra;
Atom real;
- status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
- &real, &format, &n, &extra, (unsigned char **)&p);
- if(status != Success)
+ if(XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
+ &real, &format, &n, &extra, (unsigned char **)&p) != Success)
return -1;
if(n != 0)
result = *p;
@@ -1146,12 +1150,13 @@ manage(Window w, XWindowAttributes *wa) {
applyrules(c);
}
/* geometry */
- c->x = wa->x + c->mon->wx;
- c->y = wa->y + c->mon->wy;
- c->w = wa->width;
- c->h = wa->height;
+ c->x = c->oldx = wa->x + c->mon->wx;
+ c->y = c->oldy = wa->y + c->mon->wy;
+ c->w = c->oldw = wa->width;
+ c->h = c->oldh = wa->height;
c->oldbw = wa->border_width;
if(c->w == c->mon->mw && c->h == c->mon->mh) {
+ c->isfloating = 1;
c->x = c->mon->mx;
c->y = c->mon->my;
c->bw = 0;
@@ -1175,7 +1180,7 @@ manage(Window w, XWindowAttributes *wa) {
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, False);
if(!c->isfloating)
- c->isfloating = trans != None || c->isfixed;
+ c->isfloating = c->oldstate = trans != None || c->isfixed;
if(c->isfloating)
XRaiseWindow(dpy, c->win);
attach(c);
@@ -1327,25 +1332,62 @@ propertynotify(XEvent *e) {
}
}
+void
+clientmessage(XEvent *e) {
+ XClientMessageEvent *cme = &e->xclient;
+ Client *c;
+
+ if((c = wintoclient(cme->window))
+ && (cme->message_type == netatom[NetWMState] && cme->data.l[1] == netatom[NetWMFullscreen]))
+ {
+ if(cme->data.l[0]) {
+ 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
quit(const Arg *arg) {
running = False;
}
void
resize(Client *c, int x, int y, int w, int h, Bool interact) {
+ if(applysizehints(c, &x, &y, &w, &h, interact))
+ resizeclient(c, x, y, w, h);
+}
+
+void
+resizeclient(Client *c, int x, int y, int w, int h) {
XWindowChanges wc;
- if(applysizehints(c, &x, &y, &w, &h, interact)) {
- c->x = wc.x = x;
- c->y = wc.y = y;
- c->w = wc.width = w;
- c->h = wc.height = h;
- wc.border_width = c->bw;
- XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
- configure(c);
- XSync(dpy, False);
- }
+ c->oldx = c->x; c->x = wc.x = x;
+ c->oldy = c->y; c->y = wc.y = y;
+ c->oldw = c->w; c->w = wc.width = w;
+ c->oldh = c->h; c->h = wc.height = h;
+ wc.border_width = c->bw;
+ XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
+ configure(c);
+ XSync(dpy, False);
}
void
@@ -1463,7 +1505,7 @@ void
sendmon(Client *c, Monitor *m) {
if(c->mon == m)
return;
- unfocus(c);
+ unfocus(c, True);
detach(c);
detachstack(c);
c->mon = m;
@@ -1533,6 +1575,7 @@ setup(void) {
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
+ netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
/* init cursors */
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1564,12 +1607,6 @@ setup(void) {
m->lts[i] = &layouts[0];
}
}
- /* init bars */
- for(m = mons; m; m = m->next) {
- for(i=0; i < LENGTH(tags) + 1; i++) {
- m->showbars[i] = m->showbar;
- }
- }
updatebars();
updatestatus();
/* EWMH support per view */
@@ -1680,7 +1717,7 @@ tile(Monitor *m) {
void
togglebar(const Arg *arg) {
- selmon->showbar = selmon->showbars[selmon->curtag] = !selmon->showbar;
+ selmon->showbar = !selmon->showbar;
updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
arrange(selmon);
@@ -1719,8 +1756,6 @@ toggletag(const Arg *arg) {
selmon->sel->tags = newtags;
selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag];
selmon->mfact = selmon->mfacts[selmon->curtag];
- if (selmon->showbar != selmon->showbars[selmon->curtag])
- togglebar(NULL);
arrange(selmon);
}
}
@@ -1736,12 +1771,13 @@ toggleview(const Arg *arg) {
}
void
-unfocus(Client *c) {
+unfocus(Client *c, Bool setfocus) {
if(!c)
return;
grabbuttons(c, False);
XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
- XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+ if(setfocus)
+ XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
}
void
@@ -2008,8 +2044,6 @@ view(const Arg *arg) {
}
selmon->lt[selmon->sellt]= selmon->lts[selmon->curtag];
selmon->mfact = selmon->mfacts[selmon->curtag];
- if(selmon->showbar != selmon->showbars[selmon->curtag])
- togglebar(NULL);
arrange(selmon);
}

0 comments on commit bd7482a

Please sign in to comment.