Xinqi Bao's Git

man page updated
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 5b0c792..556d934 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -129,6 +129,7 @@ struct Monitor {
        int by;               /* bar geometry */
        int mx, my, mw, mh;   /* screen size */
        int wx, wy, ww, wh;   /* window area  */
        int by;               /* bar geometry */
        int mx, my, mw, mh;   /* screen size */
        int wx, wy, ww, wh;   /* window area  */
+       int gappx;            /* gaps between windows */
        unsigned int seltags;
        unsigned int sellt;
        unsigned int tagset[2];
        unsigned int seltags;
        unsigned int sellt;
        unsigned int tagset[2];
@@ -212,18 +213,22 @@ static void sendmon(Client *c, Monitor *m);
 static void setclientstate(Client *c, long state);
 static void setfocus(Client *c);
 static void setfullscreen(Client *c, int fullscreen);
 static void setclientstate(Client *c, long state);
 static void setfocus(Client *c);
 static void setfullscreen(Client *c, int fullscreen);
+static void setgaps(const Arg *arg);
 static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
 static void setup(void);
 static void seturgent(Client *c, int urg);
 static void showhide(Client *c);
 static void sigchld(int unused);
 static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
 static void setup(void);
 static void seturgent(Client *c, int urg);
 static void showhide(Client *c);
 static void sigchld(int unused);
+static void sighup(int unused);
+static void sigterm(int unused);
 static void spawn(const Arg *arg);
 static void tag(const Arg *arg);
 static void tagmon(const Arg *arg);
 static void tile(Monitor *);
 static void togglebar(const Arg *arg);
 static void togglefloating(const Arg *arg);
 static void spawn(const Arg *arg);
 static void tag(const Arg *arg);
 static void tagmon(const Arg *arg);
 static void tile(Monitor *);
 static void togglebar(const Arg *arg);
 static void togglefloating(const Arg *arg);
+static void togglefullscr(const Arg *arg);
 static void toggletag(const Arg *arg);
 static void toggleview(const Arg *arg);
 static void unfocus(Client *c, int setfocus);
 static void toggletag(const Arg *arg);
 static void toggleview(const Arg *arg);
 static void unfocus(Client *c, int setfocus);
@@ -280,6 +285,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
        [UnmapNotify] = unmapnotify
 };
 static Atom wmatom[WMLast], netatom[NetLast];
        [UnmapNotify] = unmapnotify
 };
 static Atom wmatom[WMLast], netatom[NetLast];
+static int restart = 0;
 static int running = 1;
 static Cur *cursor[CurLast];
 static Clr **scheme;
 static int running = 1;
 static Cur *cursor[CurLast];
 static Clr **scheme;
@@ -715,6 +721,7 @@ createmon(void)
        m->nmaster = nmaster;
        m->showbar = showbar;
        m->topbar = topbar;
        m->nmaster = nmaster;
        m->showbar = showbar;
        m->topbar = topbar;
+       m->gappx = gappx;
        m->lt[0] = &layouts[0];
        m->lt[1] = &layouts[1 % LENGTH(layouts)];
        strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
        m->lt[0] = &layouts[0];
        m->lt[1] = &layouts[1 % LENGTH(layouts)];
        strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
@@ -1335,6 +1342,7 @@ propertynotify(XEvent *e)
 void
 quit(const Arg *arg)
 {
 void
 quit(const Arg *arg)
 {
+       if(arg->i) restart = 1;
        running = 0;
 }
 
        running = 0;
 }
 
@@ -1584,6 +1592,16 @@ setfullscreen(Client *c, int fullscreen)
        }
 }
 
        }
 }
 
+void
+setgaps(const Arg *arg)
+{
+       if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
+               selmon->gappx = 0;
+       else
+               selmon->gappx += arg->i;
+       arrange(selmon);
+}
+
 void
 setlayout(const Arg *arg)
 {
 void
 setlayout(const Arg *arg)
 {
@@ -1623,6 +1641,9 @@ setup(void)
        /* clean up any zombies immediately */
        sigchld(0);
 
        /* clean up any zombies immediately */
        sigchld(0);
 
+       signal(SIGHUP, sighup);
+       signal(SIGTERM, sigterm);
+
        /* init screen */
        screen = DefaultScreen(dpy);
        sw = DisplayWidth(dpy, screen);
        /* init screen */
        screen = DefaultScreen(dpy);
        sw = DisplayWidth(dpy, screen);
@@ -1724,6 +1745,20 @@ sigchld(int unused)
        while (0 < waitpid(-1, NULL, WNOHANG));
 }
 
        while (0 < waitpid(-1, NULL, WNOHANG));
 }
 
+void
+sighup(int unused)
+{
+       Arg a = {.i = 1};
+       quit(&a);
+}
+
+void
+sigterm(int unused)
+{
+       Arg a = {.i = 0};
+       quit(&a);
+}
+
 void
 spawn(const Arg *arg)
 {
 void
 spawn(const Arg *arg)
 {
@@ -1771,18 +1806,18 @@ tile(Monitor *m)
        if (n > m->nmaster)
                mw = m->nmaster ? m->ww * m->mfact : 0;
        else
        if (n > m->nmaster)
                mw = m->nmaster ? m->ww * m->mfact : 0;
        else
-               mw = m->ww;
-       for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+               mw = m->ww - m->gappx;
+       for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
                if (i < m->nmaster) {
                if (i < m->nmaster) {
-                       h = (m->wh - my) / (MIN(n, m->nmaster) - i);
-                       resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
-                       if (my + HEIGHT(c) < m->wh)
-                               my += HEIGHT(c);
+                       h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
+                       resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0);
+                       if (my + HEIGHT(c) + m->gappx < m->wh)
+                               my += HEIGHT(c) + m->gappx;
                } else {
                } else {
-                       h = (m->wh - ty) / (n - i);
-                       resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
-                       if (ty + HEIGHT(c) < m->wh)
-                               ty += HEIGHT(c);
+                       h = (m->wh - ty) / (n - i) - m->gappx;
+                       resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
+                       if (ty + HEIGHT(c) + m->gappx < m->wh)
+                               ty += HEIGHT(c) + m->gappx;
                }
 }
 
                }
 }
 
@@ -1809,6 +1844,13 @@ togglefloating(const Arg *arg)
        arrange(selmon);
 }
 
        arrange(selmon);
 }
 
+void
+togglefullscr(const Arg *arg)
+{
+  if(selmon->sel)
+    setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
+}
+
 void
 toggletag(const Arg *arg)
 {
 void
 toggletag(const Arg *arg)
 {
@@ -2421,6 +2463,7 @@ main(int argc, char *argv[])
 #endif /* __OpenBSD__ */
        scan();
        run();
 #endif /* __OpenBSD__ */
        scan();
        run();
+       if(restart) execvp(argv[0], argv);
        cleanup();
        XCloseDisplay(dpy);
        return EXIT_SUCCESS;
        cleanup();
        XCloseDisplay(dpy);
        return EXIT_SUCCESS;