Compare commits

..

3 Commits

Author SHA1 Message Date
Hiltjo Posthuma
7c3abae4e6 drw.c: drw_scm_free: call free inside
Because drw_scm_create() allocates it.
2025-09-29 18:48:27 +02:00
Hiltjo Posthuma
93f26863d1 cleanup schemes and colors 2025-09-27 12:10:17 +02:00
Hiltjo Posthuma
74edc27caa config: make refreshrate for mouse move/resize a config option
Bump the default from 60 to 120.
2025-08-12 19:17:20 +02:00
6 changed files with 80 additions and 555 deletions

View File

@@ -2,7 +2,6 @@
/* appearance */ /* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int gappx = 6; /* gaps between windows */
static const unsigned int snap = 32; /* snap pixel */ static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */ static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */ static const int topbar = 1; /* 0 means bottom bar */
@@ -13,17 +12,10 @@ static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb"; static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee"; static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577"; static const char col_cyan[] = "#005577";
static const char *colorsdark[][3] = { static const char *colors[][3] = {
/* fg bg border */ /* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan }, [SchemeSel] = { col_gray4, col_cyan, col_cyan },
[SchemeHid] = { col_cyan, col_gray1, col_cyan },
};
static const char *colorslight[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray1, col_gray3, col_gray2 },
[SchemeSel] = { col_cyan, col_gray4, col_cyan },
[SchemeHid] = { col_cyan, col_gray1, col_cyan },
}; };
/* tagging */ /* tagging */
@@ -44,6 +36,7 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95]
static const int nmaster = 1; /* number of clients in master area */ static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const int refreshrate = 120; /* refresh rate (per second) for client move/resize */
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol arrange function */ /* symbol arrange function */
@@ -64,21 +57,17 @@ static const Layout layouts[] = {
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */ /* commands */
static char dmenumon[2] = "0"; /* component of dmenu{dark,light}, manipulated in spawndmenu() */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenudark[] = { "dmenu_run", "-m", dmenumon, "-i", "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *dmenulight[] = { "dmenu_run", "-m", dmenumon, "-i", "-fn", dmenufont, "-nb", col_gray3, "-nf", col_gray1, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL }; static const char *termcmd[] = { "st", NULL };
#include "exitdwm.c"
static const Key keys[] = { static const Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
{ MODKEY, XK_p, spawndmenu, {0} }, { MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstackvis, {.i = +1 } }, { MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstackvis, {.i = -1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY|ShiftMask, XK_j, focusstackhid, {.i = +1 } },
{ MODKEY|ShiftMask, XK_k, focusstackhid, {.i = -1 } },
{ MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_h, setmfact, {.f = -0.05} },
@@ -97,9 +86,6 @@ static const Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
{ MODKEY, XK_s, show, {0} },
{ MODKEY|ShiftMask, XK_s, showall, {0} },
{ MODKEY, XK_h, hide, {0} },
TAGKEYS( XK_1, 0) TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1) TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2) TAGKEYS( XK_3, 2)
@@ -109,17 +95,7 @@ static const Key keys[] = {
TAGKEYS( XK_7, 6) TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7) TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8) TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_j, focusbynum, {.i = 0} },
{ MODKEY|ShiftMask, XK_k, focusbynum, {.i = 1} },
{ MODKEY|ShiftMask, XK_l, focusbynum, {.i = 2} },
{ MODKEY|ShiftMask, XK_colon, focusbynum, {.i = 3} },
{ MODKEY|ShiftMask, XK_f, focusbynum, {.i = 4} },
{ MODKEY|ShiftMask, XK_d, focusbynum, {.i = 5} },
{ MODKEY|ShiftMask, XK_s, focusbynum, {.i = 6} },
{ MODKEY|ShiftMask, XK_a, focusbynum, {.i = 7} },
{ MODKEY|ShiftMask, XK_q, quit, {0} }, { MODKEY|ShiftMask, XK_q, quit, {0} },
{ MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} },
{ MODKEY|ShiftMask, XK_e, exitdwm, {0} },
}; };
/* button definitions */ /* button definitions */
@@ -128,7 +104,6 @@ static const Button buttons[] = {
/* click event mask button function argument */ /* click event mask button function argument */
{ ClkLtSymbol, 0, Button1, setlayout, {0} }, { ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkWinTitle, 0, Button1, togglewin, {0} },
{ ClkWinTitle, 0, Button2, zoom, {0} }, { ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button1, movemouse, {0} },

29
drw.c
View File

@@ -178,8 +178,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
die("error, cannot allocate color '%s'", clrname); die("error, cannot allocate color '%s'", clrname);
} }
/* Wrapper to create color schemes. The caller has to call free(3) on the /* Create color schemes. */
* returned color scheme when done using it. */
Clr * Clr *
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
{ {
@@ -187,7 +186,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
Clr *ret; Clr *ret;
/* need at least two colors for a scheme */ /* need at least two colors for a scheme */
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(Clr))))
return NULL; return NULL;
for (i = 0; i < clrcount; i++) for (i = 0; i < clrcount; i++)
@@ -195,6 +194,30 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
return ret; return ret;
} }
void
drw_clr_free(Drw *drw, Clr *c)
{
if (!drw || !c)
return;
/* c is typedef XftColor Clr */
XftColorFree(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen), c);
}
void
drw_scm_free(Drw *drw, Clr *scm, size_t clrcount)
{
size_t i;
if (!drw || !scm)
return;
for (i = 0; i < clrcount; i++)
drw_clr_free(drw, &scm[i]);
free(scm);
}
void void
drw_setfontset(Drw *drw, Fnt *set) drw_setfontset(Drw *drw, Fnt *set)
{ {

2
drw.h
View File

@@ -40,7 +40,9 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
/* Colorscheme abstraction */ /* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
void drw_clr_free(Drw *drw, Clr *c);
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
void drw_scm_free(Drw *drw, Clr *scm, size_t clrcount);
/* Cursor abstraction */ /* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape); Cur *drw_cur_create(Drw *drw, int shape);

10
dwm.1
View File

@@ -142,9 +142,6 @@ Add/remove all windows with nth tag to/from the view.
.TP .TP
.B Mod1\-Shift\-q .B Mod1\-Shift\-q
Quit dwm. Quit dwm.
.TP
.B Mod1\-Control\-Shift\-q
Restart dwm.
.SS Mouse commands .SS Mouse commands
.TP .TP
.B Mod1\-Button1 .B Mod1\-Button1
@@ -158,13 +155,6 @@ Resize focused window while dragging. Tiled windows will be toggled to the float
.SH CUSTOMIZATION .SH CUSTOMIZATION
dwm is customized by creating a custom config.h and (re)compiling the source dwm is customized by creating a custom config.h and (re)compiling the source
code. This keeps it fast, secure and simple. code. This keeps it fast, secure and simple.
.SH SIGNALS
.TP
.B SIGHUP - 1
Restart the dwm process.
.TP
.B SIGTERM - 15
Cleanly terminate the dwm process.
.SH SEE ALSO .SH SEE ALSO
.BR dmenu (1), .BR dmenu (1),
.BR st (1) .BR st (1)

468
dwm.c
View File

@@ -50,20 +50,18 @@
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define HIDDEN(C) ((getstate(C->win) == IconicState))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw + gappx) #define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw + gappx) #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define TAGMASK ((1 << LENGTH(tags)) - 1) #define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */ /* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel, SchemeHid }; /* color schemes */ enum { SchemeNorm, SchemeSel }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck, enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMFullscreen, NetActiveWindow, NetWMWindowType,
NetWMWindowTypeDialog, NetClientList, NetClientInfo, NetLast }; /* EWMH atoms */ NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, 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 */
@@ -118,8 +116,6 @@ struct Monitor {
int nmaster; int nmaster;
int num; int num;
int by; /* bar geometry */ int by; /* bar geometry */
int btw; /* width of tasks portion of bar */
int bt; /* number of tasks */
int mx, my, mw, mh; /* screen size */ int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */ int wx, wy, ww, wh; /* window area */
unsigned int seltags; unsigned int seltags;
@@ -127,7 +123,6 @@ struct Monitor {
unsigned int tagset[2]; unsigned int tagset[2];
int showbar; int showbar;
int topbar; int topbar;
int hidsel;
Client *clients; Client *clients;
Client *sel; Client *sel;
Client *stack; Client *stack;
@@ -157,7 +152,6 @@ static void checkotherwm(void);
static void cleanup(void); static void cleanup(void);
static void cleanupmon(Monitor *mon); static void cleanupmon(Monitor *mon);
static void clientmessage(XEvent *e); static void clientmessage(XEvent *e);
static void colormodehandler(int sig);
static void configure(Client *c); static void configure(Client *c);
static void configurenotify(XEvent *e); static void configurenotify(XEvent *e);
static void configurerequest(XEvent *e); static void configurerequest(XEvent *e);
@@ -173,17 +167,13 @@ static void expose(XEvent *e);
static void focus(Client *c); static void focus(Client *c);
static void focusin(XEvent *e); static void focusin(XEvent *e);
static void focusmon(const Arg *arg); static void focusmon(const Arg *arg);
static void focusstackvis(const Arg *arg); static void focusstack(const Arg *arg);
static void focusstackhid(const Arg *arg);
static void focusstack(int inc, int vis);
static Atom getatomprop(Client *c, Atom prop); static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y); static int getrootptr(int *x, int *y);
static long getstate(Window w); static long getstate(Window w);
static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, int focused); static void grabbuttons(Client *c, int focused);
static void grabkeys(void); static void grabkeys(void);
static void hide(const Arg *arg);
static void hidewin(Client *c);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void keypress(XEvent *e); static void keypress(XEvent *e);
static void killclient(const Arg *arg); static void killclient(const Arg *arg);
@@ -207,32 +197,21 @@ static void scan(void);
static int sendevent(Client *c, Atom proto); static int 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 setclienttagprop(Client *c);
static void setcolormode(void);
static void setfocus(Client *c); static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen); static void setfullscreen(Client *c, int fullscreen);
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);
static void seturgent(Client *c, int urg); static void seturgent(Client *c, int urg);
static void show(const Arg *arg);
static void showall(const Arg *arg);
static void showwin(Client *c);
static void showhide(Client *c); 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 spawn(const Arg *arg);
static void spawndmenu(const Arg *arg);
static void tag(const Arg *arg); static void tag(const Arg *arg);
static void tagmon(const Arg *arg); static void tagmon(const Arg *arg);
static void tile(Monitor *m); static void tile(Monitor *m);
static void togglebar(const Arg *arg); static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg); static void togglefloating(const Arg *arg);
static void focusbynum(const Arg *arg);
static void toggletag(const Arg *arg); static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg); static void toggleview(const Arg *arg);
static void togglewin(const Arg *arg);
static void unfocus(Client *c, int setfocus); static void unfocus(Client *c, int setfocus);
static void unmanage(Client *c, int destroyed); static void unmanage(Client *c, int destroyed);
static void unmapnotify(XEvent *e); static void unmapnotify(XEvent *e);
@@ -247,7 +226,6 @@ static void updatetitle(Client *c);
static void updatewindowtype(Client *c); static void updatewindowtype(Client *c);
static void updatewmhints(Client *c); static void updatewmhints(Client *c);
static void view(const Arg *arg); static void view(const Arg *arg);
static void warp(const Client *c);
static Client *wintoclient(Window w); static Client *wintoclient(Window w);
static Monitor *wintomon(Window w); static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee); static int xerror(Display *dpy, XErrorEvent *ee);
@@ -281,16 +259,13 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[UnmapNotify] = unmapnotify [UnmapNotify] = unmapnotify
}; };
static Atom wmatom[WMLast], netatom[NetLast]; static Atom wmatom[WMLast], netatom[NetLast];
static int restart = 0;
static int running = 1; static int running = 1;
static Cur *cursor[CurLast]; static Cur *cursor[CurLast];
static Clr **scheme, **schemedark, **schemelight; static Clr **scheme;
static Display *dpy; static Display *dpy;
static Drw *drw; static Drw *drw;
static Monitor *mons, *selmon; static Monitor *mons, *selmon;
static Window root, wmcheckwin; static Window root, wmcheckwin;
static const char **dmenucmd;
static int colormodechanged;
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
#include "config.h" #include "config.h"
@@ -465,25 +440,10 @@ buttonpress(XEvent *e)
arg.ui = 1 << i; arg.ui = 1 << i;
} else if (ev->x < x + TEXTW(selmon->ltsymbol)) } else if (ev->x < x + TEXTW(selmon->ltsymbol))
click = ClkLtSymbol; click = ClkLtSymbol;
/* 2px right padding */ else if (ev->x > selmon->ww - (int)TEXTW(stext))
else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - 2)
click = ClkStatusText; click = ClkStatusText;
else { else
x += TEXTW(selmon->ltsymbol); click = ClkWinTitle;
c = m->clients;
if (c) {
do {
if (!ISVISIBLE(c))
continue;
else
x +=(1.0 / (double)m->bt) * m->btw;
} while (ev->x > x && (c = c->next));
click = ClkWinTitle;
arg.v = c;
}
}
} else if ((c = wintoclient(ev->window))) { } else if ((c = wintoclient(ev->window))) {
focus(c); focus(c);
restack(selmon); restack(selmon);
@@ -493,7 +453,7 @@ buttonpress(XEvent *e)
for (i = 0; i < LENGTH(buttons); i++) for (i = 0; i < LENGTH(buttons); i++)
if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
} }
void void
@@ -525,12 +485,9 @@ cleanup(void)
cleanupmon(mons); cleanupmon(mons);
for (i = 0; i < CurLast; i++) for (i = 0; i < CurLast; i++)
drw_cur_free(drw, cursor[i]); drw_cur_free(drw, cursor[i]);
for (i = 0; i < LENGTH(colorsdark); i++) { for (i = 0; i < LENGTH(colors); i++)
free(schemedark[i]); drw_scm_free(drw, scheme[i], 3);
free(schemelight[i]); free(scheme);
}
free(schemedark);
free(schemelight);
XDestroyWindow(dpy, wmcheckwin); XDestroyWindow(dpy, wmcheckwin);
drw_free(drw); drw_free(drw);
XSync(dpy, False); XSync(dpy, False);
@@ -573,12 +530,6 @@ clientmessage(XEvent *e)
} }
} }
void
colormodehandler(int sig)
{
colormodechanged = 1;
}
void void
configure(Client *c) configure(Client *c)
{ {
@@ -746,7 +697,7 @@ dirtomon(int dir)
void void
drawbar(Monitor *m) drawbar(Monitor *m)
{ {
int x, w, tw = 0, n = 0, scm; int x, w, tw = 0;
int boxs = drw->fonts->h / 9; int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2; int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0; unsigned int i, occ = 0, urg = 0;
@@ -763,8 +714,6 @@ drawbar(Monitor *m)
} }
for (c = m->clients; c; c = c->next) { for (c = m->clients; c; c = c->next) {
if (ISVISIBLE(c))
n++;
occ |= c->tags; occ |= c->tags;
if (c->isurgent) if (c->isurgent)
urg |= c->tags; urg |= c->tags;
@@ -785,36 +734,16 @@ drawbar(Monitor *m)
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
if ((w = m->ww - tw - x) > bh) { if ((w = m->ww - tw - x) > bh) {
if (n > 0) { if (m->sel) {
int remainder = w % n; drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
int tabw = (1.0 / (double)n) * w + 1; drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
for (c = m->clients; c; c = c->next) { if (m->sel->isfloating)
if (!ISVISIBLE(c)) drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
continue;
if (m->sel == c)
scm = SchemeSel;
else if (HIDDEN(c))
scm = SchemeHid;
else
scm = SchemeNorm;
drw_setscheme(drw, scheme[scm]);
if (remainder >= 0) {
if (remainder == 0) {
tabw--;
}
remainder--;
}
drw_text(drw, x, 0, tabw, bh, lrpad / 2, c->name, 0);
x += tabw;
}
} else { } else {
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1); drw_rect(drw, x, 0, w, bh, 1, 1);
} }
} }
m->bt = n;
m->btw = w;
drw_map(drw, m->barwin, 0, 0, m->ww, bh); drw_map(drw, m->barwin, 0, 0, m->ww, bh);
} }
@@ -860,17 +789,9 @@ void
focus(Client *c) focus(Client *c)
{ {
if (!c || !ISVISIBLE(c)) if (!c || !ISVISIBLE(c))
for (c = selmon->stack; c && (!ISVISIBLE(c) || HIDDEN(c)); c = c->snext); for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
if (selmon->sel && selmon->sel != c) { if (selmon->sel && selmon->sel != c)
unfocus(selmon->sel, 0); unfocus(selmon->sel, 0);
if (selmon->hidsel) {
hidewin(selmon->sel);
if (c)
arrange(c->mon);
selmon->hidsel = 0;
}
}
if (c) { if (c) {
if (c->mon != selmon) if (c->mon != selmon)
selmon = c->mon; selmon = c->mon;
@@ -911,56 +832,31 @@ focusmon(const Arg *arg)
unfocus(selmon->sel, 0); unfocus(selmon->sel, 0);
selmon = m; selmon = m;
focus(NULL); focus(NULL);
warp(selmon->sel);
} }
void void
focusstackvis(const Arg *arg) { focusstack(const Arg *arg)
focusstack(arg->i, 0);
}
void
focusstackhid(const Arg *arg) {
focusstack(arg->i, 1);
}
void
focusstack(int inc, int hid)
{ {
Client *c = NULL, *i; Client *c = NULL, *i;
// if no client selected AND exclude hidden client; if client selected but fullscreened
if ((!selmon->sel && !hid) || (selmon->sel && selmon->sel->isfullscreen && lockfullscreen)) if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
return; return;
if (!selmon->clients) if (arg->i > 0) {
return; for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
if (inc > 0) {
if (selmon->sel)
for (c = selmon->sel->next;
c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
c = c->next);
if (!c) if (!c)
for (c = selmon->clients; for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
c && (!ISVISIBLE(c) || (!hid && HIDDEN(c)));
c = c->next);
} else { } else {
if (selmon->sel) { for (i = selmon->clients; i != selmon->sel; i = i->next)
for (i = selmon->clients; i != selmon->sel; i = i->next) if (ISVISIBLE(i))
if (ISVISIBLE(i) && !(!hid && HIDDEN(i))) c = i;
c = i;
} else
c = selmon->clients;
if (!c) if (!c)
for (; i; i = i->next) for (; i; i = i->next)
if (ISVISIBLE(i) && !(!hid && HIDDEN(i))) if (ISVISIBLE(i))
c = i; c = i;
} }
if (c) { if (c) {
focus(c); focus(c);
restack(selmon); restack(selmon);
if (HIDDEN(c)) {
showwin(c);
c->mon->hidsel = 1;
}
} }
} }
@@ -1080,36 +976,6 @@ grabkeys(void)
} }
} }
void
hide(const Arg *arg)
{
hidewin(selmon->sel);
focus(NULL);
arrange(selmon);
}
void
hidewin(Client *c) {
if (!c || HIDDEN(c))
return;
Window w = c->win;
static XWindowAttributes ra, ca;
// more or less taken directly from blackbox's hide() function
XGrabServer(dpy);
XGetWindowAttributes(dpy, root, &ra);
XGetWindowAttributes(dpy, w, &ca);
// prevent UnmapNotify events
XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask);
XSelectInput(dpy, w, ca.your_event_mask & ~StructureNotifyMask);
XUnmapWindow(dpy, w);
setclientstate(c, IconicState);
XSelectInput(dpy, root, ra.your_event_mask);
XSelectInput(dpy, w, ca.your_event_mask);
XUngrabServer(dpy);
}
void void
incnmaster(const Arg *arg) incnmaster(const Arg *arg)
{ {
@@ -1201,26 +1067,6 @@ manage(Window w, XWindowAttributes *wa)
updatewindowtype(c); updatewindowtype(c);
updatesizehints(c); updatesizehints(c);
updatewmhints(c); updatewmhints(c);
{
int format;
unsigned long *data, n, extra;
Monitor *m;
Atom atom;
if (XGetWindowProperty(dpy, c->win, netatom[NetClientInfo], 0L, 2L, False, XA_CARDINAL,
&atom, &format, &n, &extra, (unsigned char **)&data) == Success && n == 2) {
c->tags = *data;
for (m = mons; m; m = m->next) {
if (m->num == *(data+1)) {
c->mon = m;
break;
}
}
}
if (n > 0)
XFree(data);
}
setclienttagprop(c);
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, 0); grabbuttons(c, 0);
if (!c->isfloating) if (!c->isfloating)
@@ -1232,14 +1078,12 @@ manage(Window w, XWindowAttributes *wa)
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1); (unsigned char *) &(c->win), 1);
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
if (!HIDDEN(c)) setclientstate(c, NormalState);
setclientstate(c, NormalState);
if (c->mon == selmon) if (c->mon == selmon)
unfocus(selmon->sel, 0); unfocus(selmon->sel, 0);
c->mon->sel = c; c->mon->sel = c;
arrange(c->mon); arrange(c->mon);
if (!HIDDEN(c)) XMapWindow(dpy, c->win);
XMapWindow(dpy, c->win);
focus(NULL); focus(NULL);
} }
@@ -1327,7 +1171,7 @@ movemouse(const Arg *arg)
handler[ev.type](&ev); handler[ev.type](&ev);
break; break;
case MotionNotify: case MotionNotify:
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate))
continue; continue;
lasttime = ev.xmotion.time; lasttime = ev.xmotion.time;
@@ -1360,7 +1204,7 @@ movemouse(const Arg *arg)
Client * Client *
nexttiled(Client *c) nexttiled(Client *c)
{ {
for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next); for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
return c; return c;
} }
@@ -1380,10 +1224,6 @@ propertynotify(XEvent *e)
Window trans; Window trans;
XPropertyEvent *ev = &e->xproperty; XPropertyEvent *ev = &e->xproperty;
if (colormodechanged) {
setcolormode();
colormodechanged = 0;
}
if ((ev->window == root) && (ev->atom == XA_WM_NAME)) if ((ev->window == root) && (ev->atom == XA_WM_NAME))
updatestatus(); updatestatus();
else if (ev->state == PropertyDelete) else if (ev->state == PropertyDelete)
@@ -1417,17 +1257,6 @@ propertynotify(XEvent *e)
void void
quit(const Arg *arg) quit(const Arg *arg)
{ {
if(arg->i) restart = 1;
// fix: reloading dwm keeps all the hidden clients hidden
Monitor *m;
Client *c;
for (m = mons; m; m = m->next) {
if (m) {
for (c = m->stack; c; c = c->next)
if (c && HIDDEN(c)) showwin(c);
}
}
running = 0; running = 0;
} }
@@ -1456,36 +1285,12 @@ void
resizeclient(Client *c, int x, int y, int w, int h) resizeclient(Client *c, int x, int y, int w, int h)
{ {
XWindowChanges wc; XWindowChanges wc;
unsigned int n;
unsigned int gapoffset;
unsigned int gapincr;
Client *nbc;
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; wc.border_width = c->bw;
/* Get number of clients for the selected monitor */
for (n = 0, nbc = nexttiled(selmon->clients); nbc; nbc = nexttiled(nbc->next), n++);
/* Do nothing if layout is floating */
if (c->isfloating || selmon->lt[selmon->sellt]->arrange == NULL) {
gapincr = gapoffset = 0;
} else {
/* Remove border and gap if layout is monocle or only one client */
if (selmon->lt[selmon->sellt]->arrange == monocle || n == 1) {
gapoffset = 0;
gapincr = -2 * borderpx;
wc.border_width = 0;
} else {
gapoffset = gappx;
gapincr = 2 * gappx;
}
}
c->oldx = c->x; c->x = wc.x = x + gapoffset;
c->oldy = c->y; c->y = wc.y = y + gapoffset;
c->oldw = c->w; c->w = wc.width = w - gapincr;
c->oldh = c->h; c->h = wc.height = h - gapincr;
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);
@@ -1520,7 +1325,7 @@ resizemouse(const Arg *arg)
handler[ev.type](&ev); handler[ev.type](&ev);
break; break;
case MotionNotify: case MotionNotify:
if ((ev.xmotion.time - lasttime) <= (1000 / 60)) if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate))
continue; continue;
lasttime = ev.xmotion.time; lasttime = ev.xmotion.time;
@@ -1569,8 +1374,6 @@ restack(Monitor *m)
wc.sibling = c->win; wc.sibling = c->win;
} }
} }
if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && m->lt[m->sellt]->arrange != &monocle)
warp(m->sel);
XSync(dpy, False); XSync(dpy, False);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
} }
@@ -1625,7 +1428,6 @@ sendmon(Client *c, Monitor *m)
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
attach(c); attach(c);
attachstack(c); attachstack(c);
setclienttagprop(c);
focus(NULL); focus(NULL);
arrange(NULL); arrange(NULL);
} }
@@ -1639,32 +1441,6 @@ setclientstate(Client *c, long state)
PropModeReplace, (unsigned char *)data, 2); PropModeReplace, (unsigned char *)data, 2);
} }
void
setcolormode(void)
{
static const char *file = ".lightmode";
static char *path = NULL;
const char *home;
size_t size;
if (!path && (home = getenv("HOME"))) {
size = strlen(home) + 1 + strlen(file) + 1;
path = malloc(size);
if (!path)
die("dwm: malloc failed");
snprintf(path, size, "%s/%s", home, file);
}
if (access(path, F_OK) == 0) {
scheme = schemelight;
dmenucmd = dmenulight;
} else {
scheme = schemedark;
dmenucmd = dmenudark;
}
}
int int
sendevent(Client *c, Atom proto) sendevent(Client *c, Atom proto)
{ {
@@ -1773,17 +1549,9 @@ setup(void)
sa.sa_handler = SIG_IGN; sa.sa_handler = SIG_IGN;
sigaction(SIGCHLD, &sa, NULL); sigaction(SIGCHLD, &sa, NULL);
/* set color mode on SIGUSR1 */
sigemptyset(&sa.sa_mask);
sa.sa_handler = colormodehandler;
sigaction(SIGUSR1, &sa, NULL);
/* clean up any zombies (inherited from .xinitrc etc) immediately */ /* clean up any zombies (inherited from .xinitrc etc) immediately */
while (waitpid(-1, NULL, WNOHANG) > 0); while (waitpid(-1, NULL, WNOHANG) > 0);
signal(SIGHUP, sighup);
signal(SIGTERM, sigterm);
/* init screen */ /* init screen */
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
sw = DisplayWidth(dpy, screen); sw = DisplayWidth(dpy, screen);
@@ -1810,19 +1578,14 @@ setup(void)
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
netatom[NetClientInfo] = XInternAtom(dpy, "_NET_CLIENT_INFO", False);
/* init cursors */ /* init cursors */
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur); cursor[CurMove] = drw_cur_create(drw, XC_fleur);
/* init appearance */ /* init appearance */
schemedark = ecalloc(LENGTH(colorsdark), sizeof(Clr *)); scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
schemelight = ecalloc(LENGTH(colorslight), sizeof(Clr *)); for (i = 0; i < LENGTH(colors); i++)
for (i = 0; i < LENGTH(colorsdark); i++) { scheme[i] = drw_scm_create(drw, colors[i], 3);
schemedark[i] = drw_scm_create(drw, colorsdark[i], 3);
schemelight[i] = drw_scm_create(drw, colorslight[i], 3);
}
setcolormode();
/* init bars */ /* init bars */
updatebars(); updatebars();
updatestatus(); updatestatus();
@@ -1838,7 +1601,6 @@ setup(void)
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) netatom, NetLast); PropModeReplace, (unsigned char *) netatom, NetLast);
XDeleteProperty(dpy, root, netatom[NetClientList]); XDeleteProperty(dpy, root, netatom[NetClientList]);
XDeleteProperty(dpy, root, netatom[NetClientInfo]);
/* select events */ /* select events */
wa.cursor = cursor[CurNormal]->cursor; wa.cursor = cursor[CurNormal]->cursor;
wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
@@ -1863,42 +1625,6 @@ seturgent(Client *c, int urg)
XFree(wmh); XFree(wmh);
} }
void
show(const Arg *arg)
{
if (selmon->hidsel)
selmon->hidsel = 0;
showwin(selmon->sel);
}
void
showall(const Arg *arg)
{
Client *c = NULL;
selmon->hidsel = 0;
for (c = selmon->clients; c; c = c->next) {
if (ISVISIBLE(c))
showwin(c);
}
if (!selmon->sel) {
for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
if (c)
focus(c);
}
restack(selmon);
}
void
showwin(Client *c)
{
if (!c || !HIDDEN(c))
return;
XMapWindow(dpy, c->win);
setclientstate(c, NormalState);
arrange(c->mon);
}
void void
showhide(Client *c) showhide(Client *c)
{ {
@@ -1917,33 +1643,13 @@ showhide(Client *c)
} }
} }
void
sigchld(int unused)
{
if (signal(SIGCHLD, sigchld) == SIG_ERR)
die("can't install SIGCHLD handler:");
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 void
spawn(const Arg *arg) spawn(const Arg *arg)
{ {
struct sigaction sa; struct sigaction sa;
if (arg->v == dmenucmd)
dmenumon[0] = '0' + selmon->num;
if (fork() == 0) { if (fork() == 0) {
if (dpy) if (dpy)
close(ConnectionNumber(dpy)); close(ConnectionNumber(dpy));
@@ -1959,29 +1665,11 @@ spawn(const Arg *arg)
} }
} }
void
setclienttagprop(Client *c)
{
long data[] = { (long) c->tags, (long) c->mon->num };
XChangeProperty(dpy, c->win, netatom[NetClientInfo], XA_CARDINAL, 32,
PropModeReplace, (unsigned char *) data, 2);
}
void
spawndmenu(const Arg *arg)
{
dmenumon[0] = '0' + selmon->num;
spawn(&(const Arg){.v = dmenucmd});
}
void void
tag(const Arg *arg) tag(const Arg *arg)
{ {
Client *c;
if (selmon->sel && arg->ui & TAGMASK) { if (selmon->sel && arg->ui & TAGMASK) {
c = selmon->sel;
selmon->sel->tags = arg->ui & TAGMASK; selmon->sel->tags = arg->ui & TAGMASK;
setclienttagprop(c);
focus(NULL); focus(NULL);
arrange(selmon); arrange(selmon);
} }
@@ -2046,19 +1734,6 @@ togglefloating(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void
focusbynum(const Arg *arg)
{
int i;
Client *c;
i = 0;
c = nexttiled(selmon->clients);
for (; c && i < arg->i; c = nexttiled(c->next), i++);
focus(c);
}
void void
toggletag(const Arg *arg) toggletag(const Arg *arg)
{ {
@@ -2069,7 +1744,6 @@ toggletag(const Arg *arg)
newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
if (newtags) { if (newtags) {
selmon->sel->tags = newtags; selmon->sel->tags = newtags;
setclienttagprop(selmon->sel);
focus(NULL); focus(NULL);
arrange(selmon); arrange(selmon);
} }
@@ -2087,23 +1761,6 @@ toggleview(const Arg *arg)
} }
} }
void
togglewin(const Arg *arg)
{
Client *c = (Client*)arg->v;
if (c == selmon->sel) {
hidewin(c);
focus(NULL);
arrange(c->mon);
} else {
if (HIDDEN(c))
showwin(c);
focus(c);
restack(selmon);
}
}
void void
unfocus(Client *c, int setfocus) unfocus(Client *c, int setfocus)
{ {
@@ -2206,16 +1863,6 @@ updateclientlist(void)
(unsigned char *) &(c->win), 1); (unsigned char *) &(c->win), 1);
} }
#ifdef XINERAMA
// Custom comparator: sort monitors by x_org to match physical layout left-to-right
static int
compare_xinerama_x(const void *a, const void *b) {
const XineramaScreenInfo *sa = (const XineramaScreenInfo *)a;
const XineramaScreenInfo *sb = (const XineramaScreenInfo *)b;
return sa->x_org - sb->x_org;
}
#endif /* XINERAMA */
int int
updategeom(void) updategeom(void)
{ {
@@ -2232,8 +1879,6 @@ updategeom(void)
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 */
unique = ecalloc(nn, sizeof(XineramaScreenInfo)); unique = ecalloc(nn, sizeof(XineramaScreenInfo));
// Sort monitors by x_org so dwm handles screens in left-to-right order
qsort(info, nn, sizeof(XineramaScreenInfo), compare_xinerama_x);
for (i = 0, j = 0; i < nn; i++) for (i = 0, j = 0; i < nn; i++)
if (isuniquegeom(unique, j, &info[i])) if (isuniquegeom(unique, j, &info[i]))
memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
@@ -2416,28 +2061,6 @@ view(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void
warp(const Client *c)
{
int x, y;
if (!c) {
XWarpPointer(dpy, None, root, 0, 0, 0, 0, selmon->wx + selmon->ww / 2, selmon->wy + selmon->wh / 2);
return;
}
if (!getrootptr(&x, &y) ||
(x > c->x - c->bw &&
y > c->y - c->bw &&
x < c->x + c->w + c->bw*2 &&
y < c->y + c->h + c->bw*2) ||
(y > c->mon->by && y < c->mon->by + bh) ||
(c->mon->topbar && !y))
return;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
}
Client * Client *
wintoclient(Window w) wintoclient(Window w)
{ {
@@ -2535,7 +2158,6 @@ main(int argc, char *argv[])
#endif /* __OpenBSD__ */ #endif /* __OpenBSD__ */
scan(); scan();
run(); run();
if(restart) execvp(argv[0], argv);
cleanup(); cleanup();
XCloseDisplay(dpy); XCloseDisplay(dpy);
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@@ -1,87 +0,0 @@
# include <stdio.h>
# include <string.h>
void exitdwm ()
{
# if \
defined S_LOCK || \
defined S_RESTART_DWM || \
defined S_OFFSCREEN || \
defined S_EXIT || \
defined S_REBOOT || \
defined S_SHUTDOWN || \
defined S_LOCK_ICON || \
defined S_RESTART_DWM_ICON || \
defined S_OFFSCREEN_ICON || \
defined S_EXIT_ICON || \
defined S_REBOOT_ICON || \
defined S_SHUTDOWN_ICON || \
defined S_FORMAT || \
defined S_FORMAT_CLEAR
# error (conflicting macro names)
# endif
# define S_LOCK "Lock"
# define S_RESTART_DWM "restart Dwm"
# define S_OFFSCREEN "Off-screen"
# define S_EXIT "Exit"
# define S_REBOOT "Reboot"
# define S_SHUTDOWN "Shutdown"
# define S_LOCK_ICON "\uf023" // <= FontAwesome icons
# define S_RESTART_DWM_ICON "\uf01e"
# define S_OFFSCREEN_ICON "\uf108"
# define S_EXIT_ICON "\uf2f5"
# define S_REBOOT_ICON "\uf021"
# define S_SHUTDOWN_ICON "\uf011"
# define S_FORMAT(ACTION) S_##ACTION##_ICON " " S_##ACTION
# define S_FORMAT_CLEAR "sed 's/^..//'"
FILE * exit_menu = popen (
"echo \""
S_FORMAT (LOCK) "\n"
S_FORMAT (RESTART_DWM) "\n"
S_FORMAT (OFFSCREEN) "\n"
S_FORMAT (EXIT) "\n"
S_FORMAT (REBOOT) "\n"
S_FORMAT (SHUTDOWN)
"\" | dmenu -p exit: | " S_FORMAT_CLEAR
,
"r"
);
char exit_action [16];
if (
exit_menu == NULL ||
fscanf (exit_menu, "%15[a-zA-Z -]", exit_action) == EOF
) {
fputs ("Error. Failure in exit_dwm.", stderr);
goto close_streams;
}
if (strcmp (exit_action, S_LOCK) == 0) system ("slock & sleep .5; xset dpms force off");
else if (strcmp (exit_action, S_RESTART_DWM) == 0) quit (& (const Arg) {1});
else if (strcmp (exit_action, S_OFFSCREEN) == 0) system ("sleep .5; xset dpms force off");
else if (strcmp (exit_action, S_EXIT) == 0) quit (& (const Arg) {0});
else if (strcmp (exit_action, S_REBOOT) == 0) system ("systemctl reboot");
else if (strcmp (exit_action, S_SHUTDOWN) == 0) system ("systemctl poweroff -i");
close_streams:
pclose (exit_menu);
# undef S_LOCK
# undef S_RESTART_DWM
# undef S_OFFSCREEN
# undef S_EXIT
# undef S_REBOOT
# undef S_SHUTDOWN
# undef S_LOCK_ICON
# undef S_RESTART_DWM_ICON
# undef S_OFFSCREEN_ICON
# undef S_EXIT_ICON
# undef S_REBOOT_ICON
# undef S_SHUTDOWN_ICON
# undef S_FORMAT
# undef S_FORMAT_CLEAR
}