JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied Sylvain Laurent's EWMH fullscreen state patch, simplified his patch a bit
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index b3a389d..3b18b2b 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -57,7 +57,8 @@
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
-enum { NetSupported, NetWMName, 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 */
@@ -161,6 +162,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);
@@ -249,6 +251,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,
@@ -847,7 +850,8 @@ focusmon(const Arg *arg) {
 
        if(!mons->next)
                return;
-       m = dirtomon(arg->i);
+       if((m = dirtomon(arg->i)) == selmon)
+               return;
        unfocus(selmon->sel);
        selmon = m;
        focus(NULL);
@@ -1291,6 +1295,20 @@ propertynotify(XEvent *e) {
 }
 
 void
+clientmessage(XEvent *e) {
+       XClientMessageEvent *cme = &e->xclient;
+
+       if(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);
+               else
+                       XChangeProperty(dpy, cme->window, netatom[NetWMState], XA_ATOM, 32,
+                                       PropModeReplace, (unsigned char*)0, 0);
+       }
+}
+
+void
 quit(const Arg *arg) {
        running = False;
 }
@@ -1388,12 +1406,27 @@ restack(Monitor *m) {
 void
 run(void) {
        XEvent ev;
-
+       static const char *evname[LASTEvent] = {
+               [ButtonPress] = "buttonpress",
+               [ClientMessage] = "clientmessage",
+               [ConfigureRequest] = "configurerequest",
+               [ConfigureNotify] = "configurenotify",
+               [DestroyNotify] = "destroynotify",
+               [EnterNotify] = "enternotify",
+               [Expose] = "expose",
+               [FocusIn] = "focusin",
+               [KeyPress] = "keypress",
+               [MappingNotify] = "mappingnotify",
+               [MapRequest] = "maprequest",
+               [PropertyNotify] = "propertynotify",
+               [UnmapNotify] = "unmapnotify"
+       };
        /* main event loop */
        XSync(dpy, False);
-       while(running && !XNextEvent(dpy, &ev))
+       while(running && !XNextEvent(dpy, &ev)) {
                if(handler[ev.type])
                        handler[ev.type](&ev); /* call handler */
+       }
 }
 
 void
@@ -1449,10 +1482,9 @@ void
 setlayout(const Arg *arg) {
        if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
                selmon->sellt ^= 1;
-       if(arg && arg->v) {
+       if(arg && arg->v)
                selmon->lt[selmon->sellt] = (Layout *)arg->v;
-               strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
-       }
+       strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
        if(selmon->sel)
                arrange(selmon);
        else
@@ -1494,6 +1526,8 @@ setup(void) {
        wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
        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);