dwm

my fork of dwm
Index Commits Files Refs README LICENSE
commit 324908b0bc92e82b574cad7a01968c7e6c463760
parent a786211d6cb794fba0ea406d86002c7618998afc
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Fri,  4 Feb 2022 22:18:27 -0300

Update

Diffstat:
MMakefile | 2+-
Mconfig.def.h | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
Mdrw.c | 12+++++++-----
Mdwm.1 | 23+++++++++++++++++++++++
Mdwm.c | 753+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Apatches/dwm-alwayscenter-20200625-f04cac6.diff | 12++++++++++++
Apatches/dwm-autostart-20210120-cb3f58a.diff | 179+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-floatrules-6.2.diff | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-noborderfloatingfix-6.2.diff | 31+++++++++++++++++++++++++++++++
Apatches/dwm-pertag-20200914-61bb8b2.diff | 177+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-scratchpad-6.2.diff | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-smartborders-6.2.diff | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-systray-20210418-67d76bd.diff | 754+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-systray-dwmblocks-6.2.diff | 439+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-titlecolor-20210815-ed3ab6b4.diff | 47+++++++++++++++++++++++++++++++++++++++++++++++
15 files changed, 2841 insertions(+), 90 deletions(-)
diff --git a/Makefile b/Makefile
@@ -26,7 +26,7 @@ dwm: ${OBJ}
     ${CC} -o $@ ${OBJ} ${LDFLAGS}
 
 clean:
-    rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
+    rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz config.h
 
 dist: clean
     mkdir -p dwm-${VERSION}
diff --git a/config.def.h b/config.def.h
@@ -1,42 +1,73 @@
 /* See LICENSE file for copyright and license details. */
 
 /* appearance */
-static const unsigned int borderpx  = 1;        /* border pixel of windows */
-static const unsigned int snap      = 32;       /* snap pixel */
+static const unsigned int borderpx  = 3;        /* border pixel of windows */
+static const unsigned int snap      = 16;       /* snap pixel */
+static const unsigned int systraypinning = 0;   /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
+static const unsigned int systrayonleft = 0;       /* 0: systray in the right corner, >0: systray on left of status text */
+static const unsigned int systrayspacing = 2;   /* systray spacing */
+static const int systraypinningfailfirst = 1;   /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
+static const int showsystray        = 1;     /* 0 means no systray */
 static const int showbar            = 1;        /* 0 means no bar */
-static const int topbar             = 1;        /* 0 means bottom bar */
-static const char *fonts[]          = { "monospace:size=10" };
-static const char dmenufont[]       = "monospace:size=10";
-static const char col_gray1[]       = "#222222";
+static const int topbar             = 0;        /* 0 means bottom bar */
+static const char *fonts[]          = { "Source Code Pro:style=Regular:size=8", "JoyPixels:style=Regular:size=7:antialias=true:autohint=true", "DejaVu Sans" };
+static const char dmenufont[]       = "DejaVuSansMono Nerd Font:style=Regular:size=8";
+static const char col_gray1[]       = "#000000";
 static const char col_gray2[]       = "#444444";
-static const char col_gray3[]       = "#bbbbbb";
+static const char col_gray3[]       = "#cccccc";
 static const char col_gray4[]       = "#eeeeee";
-static const char col_cyan[]        = "#005577";
+static const char col_gray5[]       = "#111111";
+static const char col_darkmagenta[] = "#8B008B";
+static const char col1[]            = "#ff0000";
+static const char col2[]            = "#00ff00";
+static const char col3[]            = "#0000ff";
+static const char col4[]            = "#ffff00";
+static const char col5[]            = "#ffff00";
+static const char col6[]            = "#ffff00";
+
+enum { SchemeNorm, SchemeCol1, SchemeCol2, SchemeCol3, SchemeCol4,
+       SchemeCol5, SchemeCol6, SchemeSel, SchemeTitle }; /* color schemes */
+
+
 static const char *colors[][3]      = {
     /*               fg         bg         border   */
-    [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
-    [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
+    /* [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, */
+    /* [SchemeSel]  = { col_gray4, col_darkmagenta,  col_darkmagenta  }, */
+    [SchemeNorm]  = { col_gray3, col_gray1, col_gray1 },
+    [SchemeCol1]  = { col1,      col_gray1, col_gray2 },
+    [SchemeCol2]  = { col2,      col_gray1, col_gray2 },
+    [SchemeCol3]  = { col3,      col_gray1, col_gray2 },
+    [SchemeCol4]  = { col4,      col_gray1, col_gray2 },
+    [SchemeCol5]  = { col5,      col_gray1, col_gray2 },
+    [SchemeCol6]  = { col6,      col_gray1, col_gray2 },
+    [SchemeSel]   = { col_gray4, col_darkmagenta,  "#444444"  },
+    [SchemeTitle]  = { col_gray4, col_gray5,  col_darkmagenta  },
 };
 
 /* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
 
 static const Rule rules[] = {
     /* xprop(1):
      *    WM_CLASS(STRING) = instance, class
      *    WM_NAME(STRING) = title
      */
-    /* class      instance    title       tags mask     isfloating   monitor */
-    { "Gimp",     NULL,       NULL,       0,            1,           -1 },
-    { "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
+    /* class          instance    title       tags mask     isfloating   monitor    float x,y,w,h         floatborderpx*/
+    { "Gimp",         NULL,       NULL,       0,            1,           -1,        50,50,500,500,        2 },
+    { "Firefox",      NULL,       NULL,       1 << 8,       0,           -1,        50,50,500,500,        2 },
+    { "calculator", NULL,        NULL,        0,              1,           -1,          80,50,400,300,        2 },
+    { "floating",    NULL,        NULL,        0,              1,           -1,          80,50,800,600,        0 },
+    { "scratchpad",    NULL,        NULL,        0,              1,           -1,          80,50,995,668,        0 },
 };
 
 /* layout(s) */
-static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
+static const float mfact     = 0.5; /* factor of master area size [0.05..0.95] */
 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 lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
 
+#define FORCE_VSPLIT 1  /* nrowgrid layout: force two clients to always split vertically */
+
 static const Layout layouts[] = {
     /* symbol     arrange function */
     { "[]=",      tile },    /* first entry is default */
@@ -45,7 +76,9 @@ static const Layout layouts[] = {
 };
 
 /* key definitions */
-#define MODKEY Mod1Mask
+#define MODKEY Mod4Mask
+#define MOD2KEY Mod1Mask    /* MOD2KEY to altkey    */
+
 #define TAGKEYS(KEY,TAG) \
     { MODKEY,                       KEY,      view,           {.ui = 1 << TAG} }, \
     { MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
@@ -57,29 +90,59 @@ static const Layout layouts[] = {
 
 /* commands */
 static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
-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 *termcmd[]  = { "st", NULL };
+/* static const char *dmenucmd[] = { "dmenu_run_history", "-h", "16", "-b", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_darkmagenta, "-sf", col_gray4, NULL }; */
+static const char *dmenucmd[] = { "dmenu_centered", NULL };
+static const char *termcmd[]  = { "kitty", NULL };
+static const char *webcmd[]  = { "firefox", NULL };
+static const char *ftermcmd[]  = { "kitty", "--class", "floating", NULL };
+static const char *filescmd[]  = { "alacritty", "-e", "ranger", NULL };
+static const char *gfilescmd[]  = { "pcmanfm-qt", "-n", NULL };
+static const char *bookscmd[] = { "openbook", "-nb", col_gray1, "-nf", col_gray3, "-sb", col_darkmagenta, "-sf", col_gray4, NULL };
+static const char *spotifycmd[]  = { "spotify", NULL };
+static const char *virtualboxcmd[]  = { "virtualbox", NULL };
+static const char *calccmd[]  = { "gnome-calculator", NULL };
+static const char *lutriscmd[]  = { "lutris", NULL };
+static const char *switchkblayout[]  = { "switchkblayout", NULL };
+static const char *lockscreen[]  = { "lockscreen", NULL };
+
+/* static const char scratchpadname[] = "scratchpad"; */
+/* static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL }; */
+
+static const char scratchpadname[] = "scratchpad";
+static const char *scratchpadcmd[] = { "kitty", "--title", scratchpadname, "--class", "scratchpad", NULL };
 
 static Key keys[] = {
     /* modifier                     key        function        argument */
-    { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
-    { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
-    { MODKEY,                       XK_b,      togglebar,      {0} },
+    { MODKEY,                       XK_d,      spawn,          {.v = dmenucmd } },
+    { MODKEY,                        XK_Return, spawn,          {.v = termcmd } },
+    { MODKEY|ShiftMask,                XK_Return, spawn,          {.v = ftermcmd } },
+    { MODKEY,                        XK_w,       spawn,          {.v = webcmd } },
+    { MODKEY,                        XK_e,       spawn,          {.v = gfilescmd } },
+    { MODKEY,                        XK_z,       spawn,          {.v = lutriscmd } },
+    { MODKEY|ShiftMask,                XK_e,       spawn,          {.v = filescmd } },
+    { MODKEY,                        XK_v,       spawn,          {.v = virtualboxcmd } },
+    { MODKEY,                        XK_b,       spawn,          {.v = bookscmd } },
+    { MODKEY,                        XK_s,       spawn,          {.v = spotifycmd } },
+    { MODKEY,                        XK_c,       spawn,          {.v = calccmd } },
+    { MODKEY|MOD2KEY,                XK_l,       spawn,          {.v = switchkblayout } },
+    { MODKEY,                        XK_x,       spawn,          {.v = lockscreen } },
+    { MODKEY,                       XK_grave,  togglescratch,  {.v = scratchpadcmd } },
+    { MODKEY|ShiftMask,             XK_b,      togglebar,      {0} },
     { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
-    { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
-    { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
+    { MODKEY|ShiftMask,             XK_i,      incnmaster,     {.i = +1 } },
+    { MODKEY|ShiftMask,             XK_d,      incnmaster,     {.i = -1 } },
     { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
     { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
-    { MODKEY,                       XK_Return, zoom,           {0} },
+    { MODKEY|ShiftMask,             XK_j,      zoom,           {0} },
     { MODKEY,                       XK_Tab,    view,           {0} },
-    { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
+    { MODKEY,                        XK_q,      killclient,     {0} },
     { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
     { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
     { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
     { MODKEY,                       XK_space,  setlayout,      {0} },
     { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
-    { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
+    /* { MODKEY,                       XK_0,      view,           {.ui = ~0 } }, */
     { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
     { MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
     { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
@@ -94,6 +157,7 @@ static Key keys[] = {
     TAGKEYS(                        XK_7,                      6)
     TAGKEYS(                        XK_8,                      7)
     TAGKEYS(                        XK_9,                      8)
+    TAGKEYS(                        XK_0,                      9)
     { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
 };
 
@@ -104,7 +168,11 @@ static Button buttons[] = {
     { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
     { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
     { ClkWinTitle,          0,              Button2,        zoom,           {0} },
-    { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
+    { ClkStatusText,        0,              Button1,        sigdwmblocks,   {.i = 1} },
+    { ClkStatusText,        0,              Button2,        sigdwmblocks,   {.i = 2} },
+    { ClkStatusText,        0,              Button3,        sigdwmblocks,   {.i = 3} },
+    { ClkStatusText,        0,              Button4,        sigdwmblocks,   {.i = 4} },
+    { ClkStatusText,        0,              Button5,        sigdwmblocks,   {.i = 5} },
     { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
     { ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
     { ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
@@ -113,4 +181,3 @@ static Button buttons[] = {
     { ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
     { ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
 };
-
diff --git a/drw.c b/drw.c
@@ -140,11 +140,11 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
      * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349
      * and lots more all over the internet.
      */
-    FcBool iscol;
-    if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
-        XftFontClose(drw->dpy, xfont);
-        return NULL;
-    }
+    /* FcBool iscol; */
+    /* if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { */
+    /*     XftFontClose(drw->dpy, xfont); */
+    /*     return NULL; */
+    /* } */
 
     font = ecalloc(1, sizeof(Fnt));
     font->xfont = xfont;
@@ -203,6 +203,8 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
                            DefaultColormap(drw->dpy, drw->screen),
                            clrname, dest))
         die("error, cannot allocate color '%s'", clrname);
+
+    dest->pixel |= 0xff << 24;
 }
 
 /* Wrapper to create color schemes. The caller has to call free(3) on the
diff --git a/dwm.1 b/dwm.1
@@ -30,6 +30,14 @@ top left corner.  The tags which are applied to one or more windows are
 indicated with an empty square in the top left corner.
 .P
 dwm draws a small border around windows to indicate the focus state.
+.P
+On start, dwm can start additional programs that may be specified in two special
+shell scripts (see the FILES section below), autostart_blocking.sh and
+autostart.sh.  The former is executed first and dwm will wait for its
+termination before starting.  The latter is executed in the background before
+dwm enters its handler loop.
+.P
+Either of these files may be omitted.
 .SH OPTIONS
 .TP
 .B \-v
@@ -152,6 +160,21 @@ Toggles focused window between floating and tiled state.
 .TP
 .B Mod1\-Button3
 Resize focused window while dragging. Tiled windows will be toggled to the floating state.
+.SH FILES
+The files containing programs to be started along with dwm are searched for in
+the following directories:
+.IP "1. $XDG_DATA_HOME/dwm"
+.IP "2. $HOME/.local/share/dwm"
+.IP "3. $HOME/.dwm"
+.P
+The first existing directory is scanned for any of the autostart files below.
+.TP 15
+autostart.sh
+This file is started as a shell background process before dwm enters its handler
+loop.
+.TP 15
+autostart_blocking.sh
+This file is started before any autostart.sh; dwm waits for its termination.
 .SH CUSTOMIZATION
 dwm is customized by creating a custom config.h and (re)compiling the source
 code. This keeps it fast, secure and simple.
diff --git a/dwm.c b/dwm.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/wait.h>
 #include <X11/cursorfont.h>
 #include <X11/keysym.h>
@@ -40,6 +41,7 @@
 #include <X11/extensions/Xinerama.h>
 #endif /* XINERAMA */
 #include <X11/Xft/Xft.h>
+#include <fcntl.h>
 
 #include "drw.h"
 #include "util.h"
@@ -56,13 +58,37 @@
 #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
 #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
 #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define TTEXTW(X)               (drw_fontset_getwidth(drw, (X)))
+
+#define STATUSLENGTH            256
+#define DWMBLOCKSLOCKFILE       "/var/local/dwmblocks/dwmblocks.pid"
+#define DELIMITERENDCHAR        10
+#define LSPAD                   (lrpad / 2) /* padding on left side of status text */
+#define RSPAD                   (lrpad / 2) /* padding on right side of status text */
+
+#define SYSTEM_TRAY_REQUEST_DOCK    0
+
+/* XEMBED messages */
+#define XEMBED_EMBEDDED_NOTIFY      0
+#define XEMBED_WINDOW_ACTIVATE      1
+#define XEMBED_FOCUS_IN             4
+#define XEMBED_MODALITY_ON         10
+
+#define XEMBED_MAPPED              (1 << 0)
+#define XEMBED_WINDOW_ACTIVATE      1
+#define XEMBED_WINDOW_DEACTIVATE    2
+
+#define VERSION_MAJOR               0
+#define VERSION_MINOR               0
+#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
 
 /* enums */
-enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
-enum { SchemeNorm, SchemeSel }; /* color schemes */
+enum { CurNormal, CurHand, CurResize, CurMove, CurLast }; /* cursor */
 enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+       NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
        ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -93,6 +119,7 @@ struct Client {
     int bw, oldbw;
     unsigned int tags;
     int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+    int floatborderpx;
     Client *next;
     Client *snext;
     Monitor *mon;
@@ -124,6 +151,7 @@ struct Monitor {
     unsigned int tagset[2];
     int showbar;
     int topbar;
+    int statushandcursor;
     Client *clients;
     Client *sel;
     Client *stack;
@@ -139,8 +167,16 @@ typedef struct {
     unsigned int tags;
     int isfloating;
     int monitor;
+    int floatx, floaty, floatw, floath;
+    int floatborderpx;
 } Rule;
 
+typedef struct Systray   Systray;
+struct Systray {
+    Window win;
+    Client *icons;
+};
+
 /* function declarations */
 static void applyrules(Client *c);
 static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -172,6 +208,7 @@ static void focusstack(const Arg *arg);
 static Atom getatomprop(Client *c, Atom prop);
 static int getrootptr(int *x, int *y);
 static long getstate(Window w);
+static unsigned int getsystraywidth();
 static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
 static void grabbuttons(Client *c, int focused);
 static void grabkeys(void);
@@ -189,13 +226,17 @@ static void pop(Client *);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
 static Monitor *recttomon(int x, int y, int w, int h);
+static void removesystrayicon(Client *i);
 static void resize(Client *c, int x, int y, int w, int h, int interact);
+static void resizebarwin(Monitor *m);
 static void resizeclient(Client *c, int x, int y, int w, int h);
 static void resizemouse(const Arg *arg);
+static void resizerequest(XEvent *e);
 static void restack(Monitor *m);
 static void run(void);
-static void scan(void);
-static int sendevent(Client *c, Atom proto);
+static void runautostart(void);
+/* static int sendevent(Client *c, Atom proto); */
+static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
 static void sendmon(Client *c, Monitor *m);
 static void setclientstate(Client *c, long state);
 static void setfocus(Client *c);
@@ -206,12 +247,15 @@ static void setup(void);
 static void seturgent(Client *c, int urg);
 static void showhide(Client *c);
 static void sigchld(int unused);
+static void sigdwmblocks(const Arg *arg);
 static void spawn(const Arg *arg);
+static Monitor *systraytomon(Monitor *m);
 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 togglescratch(const Arg *arg);
 static void toggletag(const Arg *arg);
 static void toggleview(const Arg *arg);
 static void unfocus(Client *c, int setfocus);
@@ -220,29 +264,45 @@ static void unmapnotify(XEvent *e);
 static void updatebarpos(Monitor *m);
 static void updatebars(void);
 static void updateclientlist(void);
+static void updatedwmblockssig(int x);
 static int updategeom(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
+static void updatesystray(void);
+static void updatesystrayicongeom(Client *i, int w, int h);
+static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
 static void updatetitle(Client *c);
 static void updatewindowtype(Client *c);
 static void updatewmhints(Client *c);
 static void view(const Arg *arg);
 static Client *wintoclient(Window w);
 static Monitor *wintomon(Window w);
+static Client *wintosystrayicon(Window w);
 static int xerror(Display *dpy, XErrorEvent *ee);
 static int xerrordummy(Display *dpy, XErrorEvent *ee);
 static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
 
 /* variables */
+/* static Systray *systray =  NULL; */
+static const char autostartblocksh[] = "autostart_blocking.sh";
+static const char autostartsh[] = "autostart.sh";
 static const char broken[] = "broken";
-static char stext[256];
+static const char dwmdir[] = "dwm";
+static const char localshare[] = ".local/share";
+/* static char stext[256]; */
+static char stextc[STATUSLENGTH];
+static char stexts[STATUSLENGTH];
 static int screen;
 static int sw, sh;           /* X display screen geometry width, height */
-static int bh, blw = 0;      /* bar geometry */
+/* static int bh, blw = 0;      /1* bar geometry *1/ */
+static int bh, blw, ble;     /* bar geometry */
+static int wsbar;            /* width of selmon bar */
+static int wstext;           /* width of status text */
 static int lrpad;            /* sum of left and right padding for text */
 static int (*xerrorxlib)(Display *, XErrorEvent *);
+static unsigned int dwmblockssig;
 static unsigned int numlockmask = 0;
 static void (*handler[LASTEvent]) (XEvent *) = {
     [ButtonPress] = buttonpress,
@@ -258,9 +318,10 @@ static void (*handler[LASTEvent]) (XEvent *) = {
     [MapRequest] = maprequest,
     [MotionNotify] = motionnotify,
     [PropertyNotify] = propertynotify,
+    [ResizeRequest] = resizerequest,
     [UnmapNotify] = unmapnotify
 };
-static Atom wmatom[WMLast], netatom[NetLast];
+static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
 static int running = 1;
 static Cur *cursor[CurLast];
 static Clr **scheme;
@@ -268,10 +329,13 @@ static Display *dpy;
 static Drw *drw;
 static Monitor *mons, *selmon;
 static Window root, wmcheckwin;
+static Systray *systray =  NULL;
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
+static unsigned int scratchtag = 1 << LENGTH(tags);
+
 /* compile-time check if all tags fit into an unsigned int bit array. */
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
 
@@ -300,6 +364,13 @@ applyrules(Client *c)
         {
             c->isfloating = r->isfloating;
             c->tags |= r->tags;
+            c->floatborderpx = r->floatborderpx;
+            if (r->isfloating) {
+                c->x = r->floatx;
+                c->y = r->floaty;
+                c->w = r->floatw;
+                c->h = r->floath;
+            }
             for (m = mons; m && m->num != r->monitor; m = m->next);
             if (m)
                 c->mon = m;
@@ -417,13 +488,13 @@ attachstack(Client *c)
 void
 buttonpress(XEvent *e)
 {
-    unsigned int i, x, click;
+        int i, x;
+        unsigned int click;
     Arg arg = {0};
     Client *c;
     Monitor *m;
     XButtonPressedEvent *ev = &e->xbutton;
 
-    click = ClkRootWin;
     /* focus monitor if necessary */
     if ((m = wintomon(ev->window)) && m != selmon) {
         unfocus(selmon->sel, 1);
@@ -431,25 +502,29 @@ buttonpress(XEvent *e)
         focus(NULL);
     }
     if (ev->window == selmon->barwin) {
-        i = x = 0;
-        do
-            x += TEXTW(tags[i]);
-        while (ev->x >= x && ++i < LENGTH(tags));
-        if (i < LENGTH(tags)) {
+        if (ev->x < ble - blw) {
+            i = -1, x = -ev->x;
+            do
+                x += TEXTW(tags[++i]);
+            while (x <= 0);
             click = ClkTagBar;
             arg.ui = 1 << i;
-        } else if (ev->x < x + blw)
+        } else if (ev->x < ble)
             click = ClkLtSymbol;
-        else if (ev->x > selmon->ww - (int)TEXTW(stext))
-            click = ClkStatusText;
-        else
+        else if (ev->x < wsbar - wstext)
             click = ClkWinTitle;
+        else if ((x = wsbar - RSPAD - ev->x) > 0 && (x -= wstext - LSPAD - RSPAD) <= 0) {
+            updatedwmblockssig(x);
+            click = ClkStatusText;
+        } else
+            return;
     } else if ((c = wintoclient(ev->window))) {
         focus(c);
         restack(selmon);
         XAllowEvents(dpy, ReplayPointer, CurrentTime);
         click = ClkClientWin;
-    }
+    } else
+                click = ClkRootWin;
     for (i = 0; i < LENGTH(buttons); i++)
         if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
         && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
@@ -483,6 +558,11 @@ cleanup(void)
     XUngrabKey(dpy, AnyKey, AnyModifier, root);
     while (mons)
         cleanupmon(mons);
+    if (showsystray) {
+        XUnmapWindow(dpy, systray->win);
+        XDestroyWindow(dpy, systray->win);
+        free(systray);
+    }
     for (i = 0; i < CurLast; i++)
         drw_cur_free(drw, cursor[i]);
     for (i = 0; i < LENGTH(colors); i++)
@@ -513,9 +593,57 @@ cleanupmon(Monitor *mon)
 void
 clientmessage(XEvent *e)
 {
+    XWindowAttributes wa;
+    XSetWindowAttributes swa;
     XClientMessageEvent *cme = &e->xclient;
     Client *c = wintoclient(cme->window);
 
+    if (showsystray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) {
+        /* add systray icons */
+        if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
+            if (!(c = (Client *)calloc(1, sizeof(Client))))
+                die("fatal: could not malloc() %u bytes\n", sizeof(Client));
+            if (!(c->win = cme->data.l[2])) {
+                free(c);
+                return;
+            }
+            c->mon = selmon;
+            c->next = systray->icons;
+            systray->icons = c;
+            if (!XGetWindowAttributes(dpy, c->win, &wa)) {
+                /* use sane defaults */
+                wa.width = bh;
+                wa.height = bh;
+                wa.border_width = 0;
+            }
+            c->x = c->oldx = c->y = c->oldy = 0;
+            c->w = c->oldw = wa.width;
+            c->h = c->oldh = wa.height;
+            c->oldbw = wa.border_width;
+            c->bw = 0;
+            c->isfloating = True;
+            /* reuse tags field as mapped status */
+            c->tags = 1;
+            updatesizehints(c);
+            updatesystrayicongeom(c, wa.width, wa.height);
+            XAddToSaveSet(dpy, c->win);
+            XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
+            XReparentWindow(dpy, c->win, systray->win, 0, 0);
+            /* use parents background color */
+            swa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
+            XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa);
+            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+            /* FIXME not sure if I have to send these events, too */
+            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+            XSync(dpy, False);
+            resizebarwin(selmon);
+            updatesystray();
+            setclientstate(c, NormalState);
+        }
+        return;
+    }
     if (!c)
         return;
     if (cme->message_type == netatom[NetWMState]) {
@@ -568,7 +696,7 @@ configurenotify(XEvent *e)
                 for (c = m->clients; c; c = c->next)
                     if (c->isfullscreen)
                         resizeclient(c, m->mx, m->my, m->mw, m->mh);
-                XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
+                resizebarwin(m);
             }
             focus(NULL);
             arrange(NULL);
@@ -653,6 +781,11 @@ destroynotify(XEvent *e)
 
     if ((c = wintoclient(ev->window)))
         unmanage(c, 1);
+    else if ((c = wintosystrayicon(ev->window))) {
+        removesystrayicon(c);
+        resizebarwin(selmon);
+        updatesystray();
+    }
 }
 
 void
@@ -696,17 +829,48 @@ dirtomon(int dir)
 void
 drawbar(Monitor *m)
 {
-    int x, w, tw = 0;
+    int x, w;
+    int wbar = m->ww;
     int boxs = drw->fonts->h / 9;
     int boxw = drw->fonts->h / 6 + 2;
     unsigned int i, occ = 0, urg = 0;
     Client *c;
 
+    if (showsystray && m == systraytomon(m))
+        wbar -= getsystraywidth();
+
     /* draw status first so it can be overdrawn by tags later */
     if (m == selmon) { /* status is only drawn on selected monitor */
+        char *stc = stextc;
+        char *stp = stextc;
+        char tmp;
+
+        wsbar = wbar;
+
+        /* Sets the color of the bar */
+        drw_setscheme(drw, scheme[SchemeNorm]);
+
+        x = wbar - wstext;
+        drw_rect(drw, x, 0, LSPAD, bh, 1, 1); x += LSPAD; /* to keep left padding clean */
+        for (;;) {
+            if ((unsigned char)*stc >= ' ') {
+                stc++;
+                continue;
+            }
+            tmp = *stc;
+            if (stp != stc) {
+                *stc = '\0';
+                x = drw_text(drw, x, 0, TTEXTW(stp), bh, 0, stp, 0);
+            }
+            if (tmp == '\0')
+                break;
+            if (tmp - DELIMITERENDCHAR - 1 < LENGTH(colors))
+                drw_setscheme(drw, scheme[tmp - DELIMITERENDCHAR - 1]);
+            *stc = tmp;
+            stp = ++stc;
+        }
         drw_setscheme(drw, scheme[SchemeNorm]);
-        tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
-        drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+        drw_rect(drw, x, 0, wbar - x, bh, 1, 1); /* to keep right padding clean */
     }
 
     for (c = m->clients; c; c = c->next) {
@@ -725,13 +889,19 @@ drawbar(Monitor *m)
                 urg & 1 << i);
         x += w;
     }
-    w = blw = TEXTW(m->ltsymbol);
+    w = TEXTW(m->ltsymbol);
     drw_setscheme(drw, scheme[SchemeNorm]);
     x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
 
-    if ((w = m->ww - tw - x) > bh) {
+    if (m == selmon) {
+        blw = w, ble = x;
+        w = wbar - wstext - x;
+    } else
+        w = wbar - x;
+
+    if (w > bh) {
         if (m->sel) {
-            drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+            drw_setscheme(drw, scheme[m == selmon ? SchemeTitle : SchemeNorm]);
             drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
             if (m->sel->isfloating)
                 drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
@@ -740,7 +910,9 @@ drawbar(Monitor *m)
             drw_rect(drw, x, 0, w, bh, 1, 1);
         }
     }
-    drw_map(drw, m->barwin, 0, 0, m->ww, bh);
+
+    XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, wbar, bh);
+    drw_map(drw, m->barwin, 0, 0, wbar, bh);
 }
 
 void
@@ -777,8 +949,11 @@ expose(XEvent *e)
     Monitor *m;
     XExposeEvent *ev = &e->xexpose;
 
-    if (ev->count == 0 && (m = wintomon(ev->window)))
+    if (ev->count == 0 && (m = wintomon(ev->window))) {
         drawbar(m);
+        if (m == selmon)
+            updatesystray();
+    }
 }
 
 void
@@ -863,10 +1038,17 @@ getatomprop(Client *c, Atom prop)
     unsigned long dl;
     unsigned char *p = NULL;
     Atom da, atom = None;
+    /* FIXME getatomprop should return the number of items and a pointer to
+     * the stored data instead of this workaround */
+    Atom req = XA_ATOM;
+    if (prop == xatom[XembedInfo])
+        req = xatom[XembedInfo];
 
-    if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
+    if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, req,
         &da, &di, &dl, &dl, &p) == Success && p) {
         atom = *(Atom *)p;
+        if (da == xatom[XembedInfo] && dl == 2)
+            atom = ((Atom *)p)[1];
         XFree(p);
     }
     return atom;
@@ -900,6 +1082,16 @@ getstate(Window w)
     return result;
 }
 
+unsigned int
+getsystraywidth()
+{
+    unsigned int w = 0;
+    Client *i;
+    if(showsystray)
+        for(i = systray->icons; i; w += i->w + systrayspacing, i = i->next) ;
+    return w ? w + systrayspacing : 1;
+}
+
 int
 gettextprop(Window w, Atom atom, char *text, unsigned int size)
 {
@@ -1004,7 +1196,7 @@ killclient(const Arg *arg)
 {
     if (!selmon->sel)
         return;
-    if (!sendevent(selmon->sel, wmatom[WMDelete])) {
+    if (!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0 , 0, 0)) {
         XGrabServer(dpy);
         XSetErrorHandler(xerrordummy);
         XSetCloseDownMode(dpy, DestroyAll);
@@ -1050,6 +1242,14 @@ manage(Window w, XWindowAttributes *wa)
         && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
     c->bw = borderpx;
 
+    selmon->tagset[selmon->seltags] &= ~scratchtag;
+    if (!strcmp(c->name, scratchpadname)) {
+        c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
+        c->isfloating = True;
+        c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
+        c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
+    }
+
     wc.border_width = c->bw;
     XConfigureWindow(dpy, w, CWBorderWidth, &wc);
     XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
@@ -1057,6 +1257,8 @@ manage(Window w, XWindowAttributes *wa)
     updatewindowtype(c);
     updatesizehints(c);
     updatewmhints(c);
+    c->x = c->mon->mx + (c->mon->mw - WIDTH(c)) / 2;
+    c->y = c->mon->my + (c->mon->mh - HEIGHT(c)) / 2;
     XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
     grabbuttons(c, 0);
     if (!c->isfloating)
@@ -1092,6 +1294,12 @@ maprequest(XEvent *e)
 {
     static XWindowAttributes wa;
     XMapRequestEvent *ev = &e->xmaprequest;
+    Client *i;
+    if ((i = wintosystrayicon(ev->window))) {
+        sendevent(i->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, systray->win, XEMBED_EMBEDDED_VERSION);
+        resizebarwin(selmon);
+        updatesystray();
+    }
 
     if (!XGetWindowAttributes(dpy, ev->window, &wa))
         return;
@@ -1120,17 +1328,23 @@ void
 motionnotify(XEvent *e)
 {
     static Monitor *mon = NULL;
+        int x;
     Monitor *m;
     XMotionEvent *ev = &e->xmotion;
 
-    if (ev->window != root)
-        return;
-    if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
-        unfocus(selmon->sel, 1);
-        selmon = m;
-        focus(NULL);
+    if (ev->window == root) {
+        if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
+            unfocus(selmon->sel, 1);
+            selmon = m;
+            focus(NULL);
+        }
+        mon = m;
+    } else if (ev->window == selmon->barwin && (x = wsbar - RSPAD - ev->x) > 0 && (x -= wstext - LSPAD - RSPAD) <= 0)
+        updatedwmblockssig(x);
+    else if (selmon->statushandcursor) {
+        selmon->statushandcursor = 0;
+        XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor);
     }
-    mon = m;
 }
 
 void
@@ -1216,6 +1430,16 @@ propertynotify(XEvent *e)
     Window trans;
     XPropertyEvent *ev = &e->xproperty;
 
+    if ((c = wintosystrayicon(ev->window))) {
+        if (ev->atom == XA_WM_NORMAL_HINTS) {
+            updatesizehints(c);
+            updatesystrayicongeom(c, c->w, c->h);
+        }
+        else
+            updatesystrayiconstate(c, ev);
+        resizebarwin(selmon);
+        updatesystray();
+    }
     if ((ev->window == root) && (ev->atom == XA_WM_NAME))
         updatestatus();
     else if (ev->state == PropertyDelete)
@@ -1267,6 +1491,20 @@ recttomon(int x, int y, int w, int h)
 }
 
 void
+removesystrayicon(Client *i)
+{
+    Client **ii;
+
+    if (!showsystray || !i)
+        return;
+    for (ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next);
+    if (ii)
+        *ii = i->next;
+    free(i);
+}
+
+
+void
 resize(Client *c, int x, int y, int w, int h, int interact)
 {
     if (applysizehints(c, &x, &y, &w, &h, interact))
@@ -1274,6 +1512,14 @@ resize(Client *c, int x, int y, int w, int h, int interact)
 }
 
 void
+resizebarwin(Monitor *m) {
+    unsigned int w = m->ww;
+    if (showsystray && m == systraytomon(m) && !systrayonleft)
+        w -= getsystraywidth();
+    XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh);
+}
+
+void
 resizeclient(Client *c, int x, int y, int w, int h)
 {
     XWindowChanges wc;
@@ -1282,7 +1528,18 @@ resizeclient(Client *c, int x, int y, int w, int h)
     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;
+    if (c->isfloating)
+        wc.border_width = c->floatborderpx;
+    else 
+        wc.border_width = c->bw;
+    if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
+        || &monocle == c->mon->lt[c->mon->sellt]->arrange)
+        && !c->isfullscreen && !c->isfloating
+        && NULL != c->mon->lt[c->mon->sellt]->arrange) {
+        c->w = wc.width += c->bw * 2;
+        c->h = wc.height += c->bw * 2;
+        wc.border_width = 0;
+    }
     XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
     configure(c);
     XSync(dpy, False);
@@ -1346,6 +1603,19 @@ resizemouse(const Arg *arg)
 }
 
 void
+resizerequest(XEvent *e)
+{
+    XResizeRequestEvent *ev = &e->xresizerequest;
+    Client *i;
+
+    if ((i = wintosystrayicon(ev->window))) {
+        updatesystrayicongeom(i, ev->width, ev->height);
+        resizebarwin(selmon);
+        updatesystray();
+    }
+}
+
+void
 restack(Monitor *m)
 {
     Client *c;
@@ -1382,6 +1652,83 @@ run(void)
 }
 
 void
+runautostart(void)
+{
+    char *pathpfx;
+    char *path;
+    char *xdgdatahome;
+    char *home;
+    struct stat sb;
+
+    if ((home = getenv("HOME")) == NULL)
+        /* this is almost impossible */
+        return;
+
+    /* if $XDG_DATA_HOME is set and not empty, use $XDG_DATA_HOME/dwm,
+     * otherwise use ~/.local/share/dwm as autostart script directory
+     */
+    xdgdatahome = getenv("XDG_DATA_HOME");
+    if (xdgdatahome != NULL && *xdgdatahome != '\0') {
+        /* space for path segments, separators and nul */
+        pathpfx = ecalloc(1, strlen(xdgdatahome) + strlen(dwmdir) + 2);
+
+        if (sprintf(pathpfx, "%s/%s", xdgdatahome, dwmdir) <= 0) {
+            free(pathpfx);
+            return;
+        }
+    } else {
+        /* space for path segments, separators and nul */
+        pathpfx = ecalloc(1, strlen(home) + strlen(localshare)
+                             + strlen(dwmdir) + 3);
+
+        if (sprintf(pathpfx, "%s/%s/%s", home, localshare, dwmdir) < 0) {
+            free(pathpfx);
+            return;
+        }
+    }
+
+    /* check if the autostart script directory exists */
+    if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) {
+        /* the XDG conformant path does not exist or is no directory
+         * so we try ~/.dwm instead
+         */
+        char *pathpfx_new = realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3);
+        if(pathpfx_new == NULL) {
+            free(pathpfx);
+            return;
+        }
+        pathpfx = pathpfx_new;
+
+        if (sprintf(pathpfx, "%s/.%s", home, dwmdir) <= 0) {
+            free(pathpfx);
+            return;
+        }
+    }
+
+    /* try the blocking script first */
+    path = ecalloc(1, strlen(pathpfx) + strlen(autostartblocksh) + 2);
+    if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) {
+        free(path);
+        free(pathpfx);
+    }
+
+    if (access(path, X_OK) == 0)
+        system(path);
+
+    /* now the non-blocking script */
+    if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) {
+        free(path);
+        free(pathpfx);
+    }
+
+    if (access(path, X_OK) == 0)
+        system(strcat(path, " &"));
+
+    free(pathpfx);
+    free(path);
+}
+
+void
 scan(void)
 {
     unsigned int i, num;
@@ -1434,26 +1781,36 @@ setclientstate(Client *c, long state)
 }
 
 int
-sendevent(Client *c, Atom proto)
+sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d3, long d4)
 {
     int n;
-    Atom *protocols;
+    Atom *protocols, mt;
     int exists = 0;
     XEvent ev;
 
-    if (XGetWMProtocols(dpy, c->win, &protocols, &n)) {
-        while (!exists && n--)
-            exists = protocols[n] == proto;
-        XFree(protocols);
+    if (proto == wmatom[WMTakeFocus] || proto == wmatom[WMDelete]) {
+        mt = wmatom[WMProtocols];
+        if (XGetWMProtocols(dpy, w, &protocols, &n)) {
+            while (!exists && n--)
+                exists = protocols[n] == proto;
+            XFree(protocols);
+        }
+    }
+    else {
+        exists = True;
+        mt = proto;
     }
     if (exists) {
         ev.type = ClientMessage;
-        ev.xclient.window = c->win;
-        ev.xclient.message_type = wmatom[WMProtocols];
+        ev.xclient.window = w;
+        ev.xclient.message_type = mt;
         ev.xclient.format = 32;
-        ev.xclient.data.l[0] = proto;
-        ev.xclient.data.l[1] = CurrentTime;
-        XSendEvent(dpy, c->win, False, NoEventMask, &ev);
+        ev.xclient.data.l[0] = d0;
+        ev.xclient.data.l[1] = d1;
+        ev.xclient.data.l[2] = d2;
+        ev.xclient.data.l[3] = d3;
+        ev.xclient.data.l[4] = d4;
+        XSendEvent(dpy, w, False, mask, &ev);
     }
     return exists;
 }
@@ -1467,7 +1824,7 @@ setfocus(Client *c)
             XA_WINDOW, 32, PropModeReplace,
             (unsigned char *) &(c->win), 1);
     }
-    sendevent(c, wmatom[WMTakeFocus]);
+    sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0);
 }
 
 void
@@ -1556,6 +1913,10 @@ setup(void)
     wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
     netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
     netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
+    netatom[NetSystemTray] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_S0", False);
+    netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
+    netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False);
+    netatom[NetSystemTrayOrientationHorz] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False);
     netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
     netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
     netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
@@ -1563,14 +1924,20 @@ setup(void)
     netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
     netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
     netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
+    xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
+    xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
+    xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
     /* init cursors */
     cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
+    cursor[CurHand] = drw_cur_create(drw, XC_hand2);
     cursor[CurResize] = drw_cur_create(drw, XC_sizing);
     cursor[CurMove] = drw_cur_create(drw, XC_fleur);
     /* init appearance */
     scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
     for (i = 0; i < LENGTH(colors); i++)
         scheme[i] = drw_scm_create(drw, colors[i], 3);
+    /* init system tray */
+    updatesystray();
     /* init bars */
     updatebars();
     updatestatus();
@@ -1638,10 +2005,42 @@ sigchld(int unused)
 }
 
 void
+sigdwmblocks(const Arg *arg)
+{
+        static int fd = -1;
+        struct flock fl;
+        union sigval sv;
+
+        if (!dwmblockssig)
+                return;
+        fl.l_type = F_WRLCK;
+        fl.l_whence = SEEK_SET;
+        fl.l_start = 0;
+        fl.l_len = 0;
+        if (fd != -1) {
+                if (fcntl(fd, F_GETLK, &fl) != -1 && fl.l_type == F_WRLCK)
+                        goto signal;
+                close(fd);
+                fl.l_type = F_WRLCK;
+        }
+        if ((fd = open(DWMBLOCKSLOCKFILE, O_RDONLY | O_CLOEXEC)) == -1)
+                return;
+        if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type != F_WRLCK) {
+                close(fd);
+                fd = -1;
+                return;
+        }
+signal:
+        sv.sival_int = (dwmblockssig << 8) | arg->i;
+        sigqueue(fl.l_pid, SIGRTMIN, sv);
+}
+
+void
 spawn(const Arg *arg)
 {
     if (arg->v == dmenucmd)
         dmenumon[0] = '0' + selmon->num;
+    selmon->tagset[selmon->seltags] &= ~scratchtag;
     if (fork() == 0) {
         if (dpy)
             close(ConnectionNumber(dpy));
@@ -1704,7 +2103,18 @@ togglebar(const Arg *arg)
 {
     selmon->showbar = !selmon->showbar;
     updatebarpos(selmon);
-    XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
+    resizebarwin(selmon);
+    if (showsystray) {
+        XWindowChanges wc;
+        if (!selmon->showbar)
+            wc.y = -bh;
+        else if (selmon->showbar) {
+            wc.y = 0;
+            if (!selmon->topbar)
+                wc.y = selmon->mh - bh;
+        }
+        XConfigureWindow(dpy, systray->win, CWY, &wc);
+    }
     arrange(selmon);
 }
 
@@ -1723,6 +2133,28 @@ togglefloating(const Arg *arg)
 }
 
 void
+togglescratch(const Arg *arg)
+{
+    Client *c;
+    unsigned int found = 0;
+
+    for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
+    if (found) {
+        unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
+        if (newtagset) {
+            selmon->tagset[selmon->seltags] = newtagset;
+            focus(NULL);
+            arrange(selmon);
+        }
+        if (ISVISIBLE(c)) {
+            focus(c);
+            restack(selmon);
+        }
+    } else
+        spawn(arg);
+}
+
+void
 toggletag(const Arg *arg)
 {
     unsigned int newtags;
@@ -1799,25 +2231,37 @@ unmapnotify(XEvent *e)
         else
             unmanage(c, 0);
     }
+    else if ((c = wintosystrayicon(ev->window))) {
+        /* KLUDGE! sometimes icons occasionally unmap their windows, but do
+         * _not_ destroy them. We map those windows back */
+        XMapRaised(dpy, c->win);
+        updatesystray();
+    }
 }
 
 void
 updatebars(void)
 {
+    unsigned int w;
     Monitor *m;
     XSetWindowAttributes wa = {
         .override_redirect = True,
         .background_pixmap = ParentRelative,
-        .event_mask = ButtonPressMask|ExposureMask
+        .event_mask = ButtonPressMask|ExposureMask|PointerMotionMask
     };
     XClassHint ch = {"dwm", "dwm"};
     for (m = mons; m; m = m->next) {
         if (m->barwin)
             continue;
-        m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
+        w = m->ww;
+        if (showsystray && m == systraytomon(m))
+            w -= getsystraywidth();
+        m->barwin = XCreateWindow(dpy, root, m->wx, m->by, w, bh, 0, DefaultDepth(dpy, screen),
                 CopyFromParent, DefaultVisual(dpy, screen),
                 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
         XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
+        if (showsystray && m == systraytomon(m))
+            XMapRaised(dpy, systray->win);
         XMapRaised(dpy, m->barwin);
         XSetClassHint(dpy, m->barwin, &ch);
     }
@@ -1850,6 +2294,41 @@ updateclientlist()
                 (unsigned char *) &(c->win), 1);
 }
 
+void
+updatedwmblockssig(int x)
+{
+        char *sts = stexts;
+        char *stp = stexts;
+        char tmp;
+
+        while (*sts != '\0') {
+                if ((unsigned char)*sts >= ' ') {
+                        sts++;
+                        continue;
+                }
+                tmp = *sts;
+                *sts = '\0';
+                x += TTEXTW(stp);
+                *sts = tmp;
+                if (x > 0) {
+                        if (tmp == DELIMITERENDCHAR)
+                                break;
+                        if (!selmon->statushandcursor) {
+                                selmon->statushandcursor = 1;
+                                XDefineCursor(dpy, selmon->barwin, cursor[CurHand]->cursor);
+                        }
+                        dwmblockssig = tmp;
+                        return;
+                }
+                stp = ++sts;
+        }
+        if (selmon->statushandcursor) {
+                selmon->statushandcursor = 0;
+                XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor);
+        }
+        dwmblockssig = 0;
+}
+
 int
 updategeom(void)
 {
@@ -1990,9 +2469,144 @@ updatesizehints(Client *c)
 void
 updatestatus(void)
 {
-    if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
-        strcpy(stext, "dwm-"VERSION);
-    drawbar(selmon);
+    char rawstext[STATUSLENGTH];
+
+    if (gettextprop(root, XA_WM_NAME, rawstext, sizeof rawstext)) {
+                char stextp[STATUSLENGTH];
+                char *stp = stextp, *stc = stextc, *sts = stexts;
+
+                for (char *rst = rawstext; *rst != '\0'; rst++)
+                        if ((unsigned char)*rst >= ' ')
+                                *(stp++) = *(stc++) = *(sts++) = *rst;
+                        else if ((unsigned char)*rst > DELIMITERENDCHAR)
+                                *(stc++) = *rst;
+                        else
+                                *(sts++) = *rst;
+                *stp = *stc = *sts = '\0';
+                wstext = TTEXTW(stextp) + LSPAD + RSPAD;
+        } else {
+                strcpy(stextc, "dwm-"VERSION);
+                strcpy(stexts, stextc);
+                wstext = TTEXTW(stextc) + LSPAD + RSPAD;
+        }
+        drawbar(selmon);
+}
+
+void
+updatesystrayicongeom(Client *i, int w, int h)
+{
+    if (i) {
+        i->h = bh;
+        if (w == h)
+            i->w = bh;
+        else if (h == bh)
+            i->w = w;
+        else
+            i->w = (int) ((float)bh * ((float)w / (float)h));
+        applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
+        /* force icons into the systray dimensions if they don't want to */
+        if (i->h > bh) {
+            if (i->w == i->h)
+                i->w = bh;
+            else
+                i->w = (int) ((float)bh * ((float)i->w / (float)i->h));
+            i->h = bh;
+        }
+    }
+}
+
+void
+updatesystrayiconstate(Client *i, XPropertyEvent *ev)
+{
+    long flags;
+    int code = 0;
+
+    if (!showsystray || !i || ev->atom != xatom[XembedInfo] ||
+            !(flags = getatomprop(i, xatom[XembedInfo])))
+        return;
+
+    if (flags & XEMBED_MAPPED && !i->tags) {
+        i->tags = 1;
+        code = XEMBED_WINDOW_ACTIVATE;
+        XMapRaised(dpy, i->win);
+        setclientstate(i, NormalState);
+    }
+    else if (!(flags & XEMBED_MAPPED) && i->tags) {
+        i->tags = 0;
+        code = XEMBED_WINDOW_DEACTIVATE;
+        XUnmapWindow(dpy, i->win);
+        setclientstate(i, WithdrawnState);
+    }
+    else
+        return;
+    sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
+            systray->win, XEMBED_EMBEDDED_VERSION);
+}
+
+void
+updatesystray(void)
+{
+    XSetWindowAttributes wa;
+    XWindowChanges wc;
+    Client *i;
+    Monitor *m = systraytomon(NULL);
+    unsigned int x = m->mx + m->mw;
+    /* unsigned int sw = TEXTW(stext) - lrpad + systrayspacing; */
+    unsigned int w = 1;
+
+    if (!showsystray)
+        return;
+    if (systrayonleft)
+        x -= sw + lrpad / 2;
+    if (!systray) {
+        /* init systray */
+        if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
+            die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
+        systray->win = XCreateSimpleWindow(dpy, root, x, m->by, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel);
+        wa.event_mask        = ButtonPressMask | ExposureMask;
+        wa.override_redirect = True;
+        wa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
+        XSelectInput(dpy, systray->win, SubstructureNotifyMask);
+        XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
+                PropModeReplace, (unsigned char *)&netatom[NetSystemTrayOrientationHorz], 1);
+        XChangeWindowAttributes(dpy, systray->win, CWEventMask|CWOverrideRedirect|CWBackPixel, &wa);
+        XMapRaised(dpy, systray->win);
+        XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime);
+        if (XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) {
+            sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime, netatom[NetSystemTray], systray->win, 0, 0);
+            XSync(dpy, False);
+        }
+        else {
+            fprintf(stderr, "dwm: unable to obtain system tray.\n");
+            free(systray);
+            systray = NULL;
+            return;
+        }
+    }
+    for (w = 0, i = systray->icons; i; i = i->next) {
+        /* make sure the background color stays the same */
+        wa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
+        XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
+        XMapRaised(dpy, i->win);
+        w += systrayspacing;
+        i->x = w;
+        XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
+        w += i->w;
+        if (i->mon != m)
+            i->mon = m;
+    }
+    w = w ? w + systrayspacing : 1;
+    x -= w;
+    XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh);
+    wc.x = x; wc.y = m->by; wc.width = w; wc.height = bh;
+    wc.stack_mode = Above; wc.sibling = m->barwin;
+    XConfigureWindow(dpy, systray->win, CWX|CWY|CWWidth|CWHeight|CWSibling|CWStackMode, &wc);
+    XMapWindow(dpy, systray->win);
+    XMapSubwindows(dpy, systray->win);
+    /* redraw background */
+    XSetForeground(dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel);
+    XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh);
+    XSync(dpy, False);
 }
 
 void
@@ -2060,6 +2674,16 @@ wintoclient(Window w)
     return NULL;
 }
 
+Client *
+wintosystrayicon(Window w) {
+    Client *i = NULL;
+
+    if (!showsystray || !w)
+        return i;
+    for (i = systray->icons; i && i->win != w; i = i->next) ;
+    return i;
+}
+
 Monitor *
 wintomon(Window w)
 {
@@ -2113,6 +2737,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
     return -1;
 }
 
+Monitor *
+systraytomon(Monitor *m) {
+    Monitor *t;
+    int i, n;
+    if(!systraypinning) {
+        if(!m)
+            return selmon;
+        return m == selmon ? m : NULL;
+    }
+    for(n = 1, t = mons; t && t->next; n++, t = t->next) ;
+    for(i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next) ;
+    if(systraypinningfailfirst && n < systraypinning)
+        return mons;
+    return t;
+}
+
 void
 zoom(const Arg *arg)
 {
@@ -2145,6 +2785,7 @@ main(int argc, char *argv[])
         die("pledge");
 #endif /* __OpenBSD__ */
     scan();
+    runautostart();
     run();
     cleanup();
     XCloseDisplay(dpy);
diff --git a/patches/dwm-alwayscenter-20200625-f04cac6.diff b/patches/dwm-alwayscenter-20200625-f04cac6.diff
@@ -0,0 +1,12 @@
+diff -up dwm/dwm.c dwmmod/dwm.c
+--- dwm/dwm.c    2020-06-25 00:21:30.383692180 -0300
++++ dwmmod/dwm.c    2020-06-25 00:20:35.643692330 -0300
+@@ -1057,6 +1057,8 @@ manage(Window w, XWindowAttributes *wa)
+     updatewindowtype(c);
+     updatesizehints(c);
+     updatewmhints(c);
++    c->x = c->mon->mx + (c->mon->mw - WIDTH(c)) / 2;
++    c->y = c->mon->my + (c->mon->mh - HEIGHT(c)) / 2;
+     XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
+     grabbuttons(c, 0);
+     if (!c->isfloating)
diff --git a/patches/dwm-autostart-20210120-cb3f58a.diff b/patches/dwm-autostart-20210120-cb3f58a.diff
@@ -0,0 +1,179 @@
+From 37e970479dc5d40e57fc0cbfeaa5e39941483237 Mon Sep 17 00:00:00 2001
+From: Gan Ainm <gan.ainm.riomhphost@gmail.com>
+Date: Wed, 10 Jun 2020 10:59:02 +0000
+Subject: [PATCH] dwm-xdgautostart-6.2.diff
+
+===================================================================
+---
+ dwm.1 | 23 +++++++++++++++++
+ dwm.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 105 insertions(+)
+
+diff --git a/dwm.1 b/dwm.1
+index 13b3729..9533aa6 100644
+--- a/dwm.1
++++ b/dwm.1
+@@ -30,6 +30,14 @@ top left corner.  The tags which are applied to one or more windows are
+ indicated with an empty square in the top left corner.
+ .P
+ dwm draws a small border around windows to indicate the focus state.
++.P
++On start, dwm can start additional programs that may be specified in two special
++shell scripts (see the FILES section below), autostart_blocking.sh and
++autostart.sh.  The former is executed first and dwm will wait for its
++termination before starting.  The latter is executed in the background before
++dwm enters its handler loop.
++.P
++Either of these files may be omitted.
+ .SH OPTIONS
+ .TP
+ .B \-v
+@@ -152,6 +160,21 @@ Toggles focused window between floating and tiled state.
+ .TP
+ .B Mod1\-Button3
+ Resize focused window while dragging. Tiled windows will be toggled to the floating state.
++.SH FILES
++The files containing programs to be started along with dwm are searched for in
++the following directories:
++.IP "1. $XDG_DATA_HOME/dwm"
++.IP "2. $HOME/.local/share/dwm"
++.IP "3. $HOME/.dwm"
++.P
++The first existing directory is scanned for any of the autostart files below.
++.TP 15
++autostart.sh
++This file is started as a shell background process before dwm enters its handler
++loop.
++.TP 15
++autostart_blocking.sh
++This file is started before any autostart.sh; dwm waits for its termination.
+ .SH CUSTOMIZATION
+ dwm is customized by creating a custom config.h and (re)compiling the source
+ code. This keeps it fast, secure and simple.
+diff --git a/dwm.c b/dwm.c
+index 4465af1..2156b49 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -29,6 +29,7 @@
+ #include <string.h>
+ #include <unistd.h>
+ #include <sys/types.h>
++#include <sys/stat.h>
+ #include <sys/wait.h>
+ #include <X11/cursorfont.h>
+ #include <X11/keysym.h>
+@@ -193,6 +194,7 @@ 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);
++static void runautostart(void);
+ static void scan(void);
+ static int sendevent(Client *c, Atom proto);
+ static void sendmon(Client *c, Monitor *m);
+@@ -235,7 +237,11 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
+ static void zoom(const Arg *arg);
+ 
+ /* variables */
++static const char autostartblocksh[] = "autostart_blocking.sh";
++static const char autostartsh[] = "autostart.sh";
+ static const char broken[] = "broken";
++static const char dwmdir[] = "dwm";
++static const char localshare[] = ".local/share";
+ static char stext[256];
+ static int screen;
+ static int sw, sh;           /* X display screen geometry width, height */
+@@ -1380,6 +1386,83 @@ run(void)
+             handler[ev.type](&ev); /* call handler */
+ }
+ 
++void
++runautostart(void)
++{
++    char *pathpfx;
++    char *path;
++    char *xdgdatahome;
++    char *home;
++    struct stat sb;
++
++    if ((home = getenv("HOME")) == NULL)
++        /* this is almost impossible */
++        return;
++
++    /* if $XDG_DATA_HOME is set and not empty, use $XDG_DATA_HOME/dwm,
++     * otherwise use ~/.local/share/dwm as autostart script directory
++     */
++    xdgdatahome = getenv("XDG_DATA_HOME");
++    if (xdgdatahome != NULL && *xdgdatahome != '\0') {
++        /* space for path segments, separators and nul */
++        pathpfx = ecalloc(1, strlen(xdgdatahome) + strlen(dwmdir) + 2);
++
++        if (sprintf(pathpfx, "%s/%s", xdgdatahome, dwmdir) <= 0) {
++            free(pathpfx);
++            return;
++        }
++    } else {
++        /* space for path segments, separators and nul */
++        pathpfx = ecalloc(1, strlen(home) + strlen(localshare)
++                             + strlen(dwmdir) + 3);
++
++        if (sprintf(pathpfx, "%s/%s/%s", home, localshare, dwmdir) < 0) {
++            free(pathpfx);
++            return;
++        }
++    }
++
++    /* check if the autostart script directory exists */
++    if (! (stat(pathpfx, &sb) == 0 && S_ISDIR(sb.st_mode))) {
++        /* the XDG conformant path does not exist or is no directory
++         * so we try ~/.dwm instead
++         */
++        char *pathpfx_new = realloc(pathpfx, strlen(home) + strlen(dwmdir) + 3);
++        if(pathpfx_new == NULL) {
++            free(pathpfx);
++            return;
++        }
++        pathpfx = pathpfx_new;
++
++        if (sprintf(pathpfx, "%s/.%s", home, dwmdir) <= 0) {
++            free(pathpfx);
++            return;
++        }
++    }
++
++    /* try the blocking script first */
++    path = ecalloc(1, strlen(pathpfx) + strlen(autostartblocksh) + 2);
++    if (sprintf(path, "%s/%s", pathpfx, autostartblocksh) <= 0) {
++        free(path);
++        free(pathpfx);
++    }
++
++    if (access(path, X_OK) == 0)
++        system(path);
++
++    /* now the non-blocking script */
++    if (sprintf(path, "%s/%s", pathpfx, autostartsh) <= 0) {
++        free(path);
++        free(pathpfx);
++    }
++
++    if (access(path, X_OK) == 0)
++        system(strcat(path, " &"));
++
++    free(pathpfx);
++    free(path);
++}
++
+ void
+ scan(void)
+ {
+@@ -2142,6 +2223,7 @@ main(int argc, char *argv[])
+         die("pledge");
+ #endif /* __OpenBSD__ */
+     scan();
++    runautostart();
+     run();
+     cleanup();
+     XCloseDisplay(dpy);
+-- 
+2.27.0
+
diff --git a/patches/dwm-floatrules-6.2.diff b/patches/dwm-floatrules-6.2.diff
@@ -0,0 +1,64 @@
+diff -u dwm/config.def.h dwmnew/config.def.h
+--- dwm/config.def.h    2020-03-01 19:10:06.676821764 +1300
++++ dwmnew/config.def.h    2020-03-01 19:29:26.276901430 +1300
+@@ -26,9 +26,9 @@
+      *    WM_CLASS(STRING) = instance, class
+      *    WM_NAME(STRING) = title
+      */
+-    /* class      instance    title       tags mask     isfloating   monitor */
+-    { "Gimp",     NULL,       NULL,       0,            1,           -1 },
+-    { "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
++    /* class      instance    title       tags mask     isfloating   monitor    float x,y,w,h         floatborderpx*/
++    { "Gimp",     NULL,       NULL,       0,            1,           -1,        50,50,500,500,        5 },
++    { "Firefox",  NULL,       NULL,       1 << 8,       0,           -1,        50,50,500,500,        5 },
+ };
+ 
+ /* layout(s) */
+Only in dwmnew: config.h
+Only in dwmnew: drw.o
+diff -u dwm/dwm.c dwmnew/dwm.c
+--- dwm/dwm.c    2020-03-01 19:10:06.680155097 +1300
++++ dwmnew/dwm.c    2020-03-01 19:28:26.793564016 +1300
+@@ -93,6 +93,7 @@
+     int bw, oldbw;
+     unsigned int tags;
+     int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
++    int floatborderpx;
+     Client *next;
+     Client *snext;
+     Monitor *mon;
+@@ -139,6 +140,8 @@
+     unsigned int tags;
+     int isfloating;
+     int monitor;
++    int floatx, floaty, floatw, floath;
++    int floatborderpx;
+ } Rule;
+ 
+ /* function declarations */
+@@ -299,6 +302,13 @@
+         {
+             c->isfloating = r->isfloating;
+             c->tags |= r->tags;
++            c->floatborderpx = r->floatborderpx;
++            if (r->isfloating) {
++                c->x = r->floatx;
++                c->y = r->floaty;
++                c->w = r->floatw;
++                c->h = r->floath;
++            }
+             for (m = mons; m && m->num != r->monitor; m = m->next);
+             if (m)
+                 c->mon = m;
+@@ -1281,7 +1291,10 @@
+     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;
++    if (c->isfloating)
++        wc.border_width = c->floatborderpx;
++    else
++        wc.border_width = c->bw;
+     XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
+     configure(c);
+     XSync(dpy, False);
diff --git a/patches/dwm-noborderfloatingfix-6.2.diff b/patches/dwm-noborderfloatingfix-6.2.diff
@@ -0,0 +1,31 @@
+From 700b0bdea872f4c00182b2bd925b41fe03f8d222 Mon Sep 17 00:00:00 2001
+From: Aidan Hall <aidan.hall@outlook.com>
+Date: Tue, 2 Jun 2020 14:41:53 +0000
+Subject: [PATCH] Prevents hiding the border if layout is floating.
+
+---
+ dwm.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/dwm.c b/dwm.c
+index 4465af1..2dd959d 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -1282,6 +1282,14 @@ resizeclient(Client *c, int x, int y, int w, int h)
+     c->oldw = c->w; c->w = wc.width = w;
+     c->oldh = c->h; c->h = wc.height = h;
+     wc.border_width = c->bw;
++    if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
++        || &monocle == c->mon->lt[c->mon->sellt]->arrange)
++        && !c->isfullscreen && !c->isfloating
++        && NULL != c->mon->lt[c->mon->sellt]->arrange) {
++        c->w = wc.width += c->bw * 2;
++        c->h = wc.height += c->bw * 2;
++        wc.border_width = 0;
++    }
+     XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
+     configure(c);
+     XSync(dpy, False);
+-- 
+2.26.2
+
diff --git a/patches/dwm-pertag-20200914-61bb8b2.diff b/patches/dwm-pertag-20200914-61bb8b2.diff
@@ -0,0 +1,177 @@
+diff --git a/dwm.c b/dwm.c
+index 664c527..ac8e4ec 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -111,6 +111,7 @@ typedef struct {
+     void (*arrange)(Monitor *);
+ } Layout;
+ 
++typedef struct Pertag Pertag;
+ struct Monitor {
+     char ltsymbol[16];
+     float mfact;
+@@ -130,6 +131,7 @@ struct Monitor {
+     Monitor *next;
+     Window barwin;
+     const Layout *lt[2];
++    Pertag *pertag;
+ };
+ 
+ typedef struct {
+@@ -272,6 +274,15 @@ static Window root, wmcheckwin;
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+ 
++struct Pertag {
++    unsigned int curtag, prevtag; /* current and previous tag */
++    int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
++    float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
++    unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
++    const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
++    int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
++};
++
+ /* compile-time check if all tags fit into an unsigned int bit array. */
+ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+ 
+@@ -632,6 +643,7 @@ Monitor *
+ createmon(void)
+ {
+     Monitor *m;
++    unsigned int i;
+ 
+     m = ecalloc(1, sizeof(Monitor));
+     m->tagset[0] = m->tagset[1] = 1;
+@@ -642,6 +654,20 @@ createmon(void)
+     m->lt[0] = &layouts[0];
+     m->lt[1] = &layouts[1 % LENGTH(layouts)];
+     strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
++    m->pertag = ecalloc(1, sizeof(Pertag));
++    m->pertag->curtag = m->pertag->prevtag = 1;
++
++    for (i = 0; i <= LENGTH(tags); i++) {
++        m->pertag->nmasters[i] = m->nmaster;
++        m->pertag->mfacts[i] = m->mfact;
++
++        m->pertag->ltidxs[i][0] = m->lt[0];
++        m->pertag->ltidxs[i][1] = m->lt[1];
++        m->pertag->sellts[i] = m->sellt;
++
++        m->pertag->showbars[i] = m->showbar;
++    }
++
+     return m;
+ }
+ 
+@@ -967,7 +993,7 @@ grabkeys(void)
+ void
+ incnmaster(const Arg *arg)
+ {
+-    selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
++    selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
+     arrange(selmon);
+ }
+ 
+@@ -1502,9 +1528,9 @@ void
+ setlayout(const Arg *arg)
+ {
+     if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
+-        selmon->sellt ^= 1;
++        selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
+     if (arg && arg->v)
+-        selmon->lt[selmon->sellt] = (Layout *)arg->v;
++        selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
+     strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+     if (selmon->sel)
+         arrange(selmon);
+@@ -1523,7 +1549,7 @@ setmfact(const Arg *arg)
+     f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
+     if (f < 0.05 || f > 0.95)
+         return;
+-    selmon->mfact = f;
++    selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
+     arrange(selmon);
+ }
+ 
+@@ -1702,7 +1728,7 @@ tile(Monitor *m)
+ void
+ togglebar(const Arg *arg)
+ {
+-    selmon->showbar = !selmon->showbar;
++    selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
+     updatebarpos(selmon);
+     XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
+     arrange(selmon);
+@@ -1741,9 +1767,33 @@ void
+ toggleview(const Arg *arg)
+ {
+     unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
++    int i;
+ 
+     if (newtagset) {
+         selmon->tagset[selmon->seltags] = newtagset;
++
++        if (newtagset == ~0) {
++            selmon->pertag->prevtag = selmon->pertag->curtag;
++            selmon->pertag->curtag = 0;
++        }
++
++        /* test if the user did not select the same tag */
++        if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
++            selmon->pertag->prevtag = selmon->pertag->curtag;
++            for (i = 0; !(newtagset & 1 << i); i++) ;
++            selmon->pertag->curtag = i + 1;
++        }
++
++        /* apply settings for this view */
++        selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
++        selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
++        selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
++        selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
++        selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
++
++        if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
++            togglebar(NULL);
++
+         focus(NULL);
+         arrange(selmon);
+     }
+@@ -2038,11 +2088,37 @@ updatewmhints(Client *c)
+ void
+ view(const Arg *arg)
+ {
++    int i;
++    unsigned int tmptag;
++
+     if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+         return;
+     selmon->seltags ^= 1; /* toggle sel tagset */
+-    if (arg->ui & TAGMASK)
++    if (arg->ui & TAGMASK) {
+         selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
++        selmon->pertag->prevtag = selmon->pertag->curtag;
++
++        if (arg->ui == ~0)
++            selmon->pertag->curtag = 0;
++        else {
++            for (i = 0; !(arg->ui & 1 << i); i++) ;
++            selmon->pertag->curtag = i + 1;
++        }
++    } else {
++        tmptag = selmon->pertag->prevtag;
++        selmon->pertag->prevtag = selmon->pertag->curtag;
++        selmon->pertag->curtag = tmptag;
++    }
++
++    selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
++    selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
++    selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
++    selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
++    selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
++
++    if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
++        togglebar(NULL);
++
+     focus(NULL);
+     arrange(selmon);
+ }
diff --git a/patches/dwm-scratchpad-6.2.diff b/patches/dwm-scratchpad-6.2.diff
@@ -0,0 +1,90 @@
+diff -up a/config.def.h b/config.def.h
+--- a/config.def.h    2019-06-06 21:23:27.006661784 +0200
++++ b/config.def.h    2019-06-20 15:05:59.083102462 +0200
+@@ -58,11 +58,14 @@ static const Layout layouts[] = {
+ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
+ 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 *termcmd[]  = { "st", NULL };
++static const char scratchpadname[] = "scratchpad";
++static const char *scratchpadcmd[] = { "st", "-t", scratchpadname, "-g", "120x34", NULL };
+ 
+ static Key keys[] = {
+     /* modifier                     key        function        argument */
+     { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
+     { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
++    { MODKEY,                       XK_grave,  togglescratch,  {.v = scratchpadcmd } },
+     { MODKEY,                       XK_b,      togglebar,      {0} },
+     { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
+     { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
+diff -up a/dwm.c b/dwm.c
+--- a/dwm.c    2019-06-06 21:23:27.023328450 +0200
++++ b/dwm.c    2019-06-20 15:07:01.089767947 +0200
+@@ -213,6 +213,7 @@ static void tagmon(const Arg *arg);
+ static void tile(Monitor *);
+ static void togglebar(const Arg *arg);
+ static void togglefloating(const Arg *arg);
++static void togglescratch(const Arg *arg);
+ static void toggletag(const Arg *arg);
+ static void toggleview(const Arg *arg);
+ static void unfocus(Client *c, int setfocus);
+@@ -273,6 +274,8 @@ static Window root, wmcheckwin;
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+ 
++static unsigned int scratchtag = 1 << LENGTH(tags);
++
+ /* compile-time check if all tags fit into an unsigned int bit array. */
+ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+ 
+@@ -1052,6 +1055,14 @@ manage(Window w, XWindowAttributes *wa)
+         && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
+     c->bw = borderpx;
+ 
++    selmon->tagset[selmon->seltags] &= ~scratchtag;
++    if (!strcmp(c->name, scratchpadname)) {
++        c->mon->tagset[c->mon->seltags] |= c->tags = scratchtag;
++        c->isfloating = True;
++        c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2);
++        c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2);
++    }
++
+     wc.border_width = c->bw;
+     XConfigureWindow(dpy, w, CWBorderWidth, &wc);
+     XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
+@@ -1661,6 +1672,7 @@ spawn(const Arg *arg)
+ {
+     if (arg->v == dmenucmd)
+         dmenumon[0] = '0' + selmon->num;
++    selmon->tagset[selmon->seltags] &= ~scratchtag;
+     if (fork() == 0) {
+         if (dpy)
+             close(ConnectionNumber(dpy));
+@@ -1748,6 +1760,28 @@ togglefloating(const Arg *arg)
+ }
+ 
+ void
++togglescratch(const Arg *arg)
++{
++    Client *c;
++    unsigned int found = 0;
++
++    for (c = selmon->clients; c && !(found = c->tags & scratchtag); c = c->next);
++    if (found) {
++        unsigned int newtagset = selmon->tagset[selmon->seltags] ^ scratchtag;
++        if (newtagset) {
++            selmon->tagset[selmon->seltags] = newtagset;
++            focus(NULL);
++            arrange(selmon);
++        }
++        if (ISVISIBLE(c)) {
++            focus(c);
++            restack(selmon);
++        }
++    } else
++        spawn(arg);
++}
++
++void
+ toggletag(const Arg *arg)
+ {
+     unsigned int newtags;
diff --git a/patches/dwm-smartborders-6.2.diff b/patches/dwm-smartborders-6.2.diff
@@ -0,0 +1,225 @@
+diff --git a/dwm.c b/dwm.c
+index 4465af1..3c94e4b 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -143,7 +143,7 @@ typedef struct {
+ 
+ /* function declarations */
+ static void applyrules(Client *c);
+-static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
++static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw, int interact);
+ static void arrange(Monitor *m);
+ static void arrangemon(Monitor *m);
+ static void attach(Client *c);
+@@ -188,8 +188,8 @@ static void pop(Client *);
+ static void propertynotify(XEvent *e);
+ static void quit(const Arg *arg);
+ static Monitor *recttomon(int x, int y, int w, int h);
+-static void resize(Client *c, int x, int y, int w, int h, int interact);
+-static void resizeclient(Client *c, int x, int y, int w, int h);
++static void resize(Client *c, int x, int y, int w, int h, int bw, int interact);
++static void resizeclient(Client *c, int x, int y, int w, int h, int bw);
+ static void resizemouse(const Arg *arg);
+ static void restack(Monitor *m);
+ static void run(void);
+@@ -312,7 +312,7 @@ applyrules(Client *c)
+ }
+ 
+ int
+-applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
++applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw, int interact)
+ {
+     int baseismin;
+     Monitor *m = c->mon;
+@@ -325,18 +325,18 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
+             *x = sw - WIDTH(c);
+         if (*y > sh)
+             *y = sh - HEIGHT(c);
+-        if (*x + *w + 2 * c->bw < 0)
++        if (*x + *w + 2 * *bw < 0)
+             *x = 0;
+-        if (*y + *h + 2 * c->bw < 0)
++        if (*y + *h + 2 * *bw < 0)
+             *y = 0;
+     } else {
+         if (*x >= m->wx + m->ww)
+             *x = m->wx + m->ww - WIDTH(c);
+         if (*y >= m->wy + m->wh)
+             *y = m->wy + m->wh - HEIGHT(c);
+-        if (*x + *w + 2 * c->bw <= m->wx)
++        if (*x + *w + 2 * *bw <= m->wx)
+             *x = m->wx;
+-        if (*y + *h + 2 * c->bw <= m->wy)
++        if (*y + *h + 2 * *bw <= m->wy)
+             *y = m->wy;
+     }
+     if (*h < bh)
+@@ -374,7 +374,7 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
+         if (c->maxh)
+             *h = MIN(*h, c->maxh);
+     }
+-    return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
++    return *x != c->x || *y != c->y || *w != c->w || *h != c->h || *bw != c->bw;
+ }
+ 
+ void
+@@ -394,9 +394,16 @@ arrange(Monitor *m)
+ void
+ arrangemon(Monitor *m)
+ {
++    Client *c;
++
+     strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
+     if (m->lt[m->sellt]->arrange)
+         m->lt[m->sellt]->arrange(m);
++    else
++        /* <>< case; rather than providing an arrange function and upsetting other logic that tests for its presence, simply add borders here */
++        for (c = selmon->clients; c; c = c->next)
++            if (ISVISIBLE(c) && c->bw == 0)
++                resize(c, c->x, c->y, c->w - 2*borderpx, c->h - 2*borderpx, borderpx, 0);
+ }
+ 
+ void
+@@ -566,7 +573,7 @@ configurenotify(XEvent *e)
+             for (m = mons; m; m = m->next) {
+                 for (c = m->clients; c; c = c->next)
+                     if (c->isfullscreen)
+-                        resizeclient(c, m->mx, m->my, m->mw, m->mh);
++                        resizeclient(c, m->mx, m->my, m->mw, m->mh, 0);
+                 XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
+             }
+             focus(NULL);
+@@ -1112,7 +1119,7 @@ monocle(Monitor *m)
+     if (n > 0) /* override layout symbol */
+         snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
+     for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
+-        resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
++        resize(c, m->wx, m->wy, m->ww, m->wh, 0, 0);
+ }
+ 
+ void
+@@ -1180,7 +1187,7 @@ movemouse(const Arg *arg)
+             && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
+                 togglefloating(NULL);
+             if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+-                resize(c, nx, ny, c->w, c->h, 1);
++                resize(c, nx, ny, c->w, c->h, c->bw, 1);
+             break;
+         }
+     } while (ev.type != ButtonRelease);
+@@ -1266,14 +1273,14 @@ recttomon(int x, int y, int w, int h)
+ }
+ 
+ void
+-resize(Client *c, int x, int y, int w, int h, int interact)
++resize(Client *c, int x, int y, int w, int h, int bw, int interact)
+ {
+-    if (applysizehints(c, &x, &y, &w, &h, interact))
+-        resizeclient(c, x, y, w, h);
++    if (applysizehints(c, &x, &y, &w, &h, &bw, interact))
++        resizeclient(c, x, y, w, h, bw);
+ }
+ 
+ void
+-resizeclient(Client *c, int x, int y, int w, int h)
++resizeclient(Client *c, int x, int y, int w, int h, int bw)
+ {
+     XWindowChanges wc;
+ 
+@@ -1281,7 +1288,7 @@ resizeclient(Client *c, int x, int y, int w, int h)
+     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;
++    c->oldbw = c->bw; c->bw = wc.border_width = bw;
+     XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
+     configure(c);
+     XSync(dpy, False);
+@@ -1330,7 +1337,7 @@ resizemouse(const Arg *arg)
+                     togglefloating(NULL);
+             }
+             if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+-                resize(c, c->x, c->y, nw, nh, 1);
++                resize(c, c->x, c->y, nw, nh, c->bw, 1);
+             break;
+         }
+     } while (ev.type != ButtonRelease);
+@@ -1477,22 +1484,20 @@ setfullscreen(Client *c, int fullscreen)
+             PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
+         c->isfullscreen = 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);
++        resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh, 0);
+         XRaiseWindow(dpy, c->win);
+     } else if (!fullscreen && c->isfullscreen){
+         XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
+             PropModeReplace, (unsigned char*)0, 0);
+         c->isfullscreen = 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);
++        c->bw = c->oldbw;
++        resizeclient(c, c->x, c->y, c->w, c->h, c->bw);
+         arrange(c->mon);
+     }
+ }
+@@ -1619,7 +1624,7 @@ showhide(Client *c)
+         /* show clients top down */
+         XMoveWindow(dpy, c->win, c->x, c->y);
+         if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
+-            resize(c, c->x, c->y, c->w, c->h, 0);
++            resize(c, c->x, c->y, c->w, c->h, c->bw, 0);
+         showhide(c->snext);
+     } else {
+         /* hide clients bottom up */
+@@ -1673,13 +1678,17 @@ tagmon(const Arg *arg)
+ void
+ tile(Monitor *m)
+ {
+-    unsigned int i, n, h, mw, my, ty;
++    unsigned int i, n, h, mw, my, ty, bw;
+     Client *c;
+ 
+     for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+     if (n == 0)
+         return;
+ 
++    if (n == 1)
++        bw = 0;
++    else
++        bw = borderpx;
+     if (n > m->nmaster)
+         mw = m->nmaster ? m->ww * m->mfact : 0;
+     else
+@@ -1687,11 +1696,11 @@ tile(Monitor *m)
+     for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+         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);
++            resize(c, m->wx, m->wy + my, mw - 2*bw, h - 2*bw, bw, 0);
+             my += HEIGHT(c);
+         } 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);
++            resize(c, m->wx + mw, m->wy + ty, m->ww - mw - 2*bw, h - 2*bw, bw, 0);
+             ty += HEIGHT(c);
+         }
+ }
+@@ -1715,7 +1724,9 @@ togglefloating(const Arg *arg)
+     selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
+     if (selmon->sel->isfloating)
+         resize(selmon->sel, selmon->sel->x, selmon->sel->y,
+-            selmon->sel->w, selmon->sel->h, 0);
++            selmon->sel->w - 2 * (borderpx - selmon->sel->bw),
++            selmon->sel->h - 2 * (borderpx - selmon->sel->bw),
++            borderpx, 0);
+     arrange(selmon);
+ }
+ 
diff --git a/patches/dwm-systray-20210418-67d76bd.diff b/patches/dwm-systray-20210418-67d76bd.diff
@@ -0,0 +1,754 @@
+From b9d4791ea3bdfcf3f750e133047345edebea0a70 Mon Sep 17 00:00:00 2001
+From: Hritik Vijay <hr1t1k@protonmail.com>
+Date: Wed, 17 Feb 2021 19:30:25 +0530
+Subject: [PATCH] System tray for dwm
+
+This patch adds an option for systray placement via `systrayleft`.
+
+Original author: Jan Christoph Ebersbach <jceb@e-jc.de>, inspired by http://code.google.com/p/dwm-plus
+URL: http://dwm.suckless.org/patches/systray
+dwm 6.2 port by Igor Gevka <igor.gevka@gmail.com>
+---
+ config.def.h |   6 +-
+ dwm.c        | 406 +++++++++++++++++++++++++++++++++++++++++++++++----
+ 2 files changed, 385 insertions(+), 27 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..9e74de2 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -3,6 +3,11 @@
+ /* appearance */
+ static const unsigned int borderpx  = 1;        /* border pixel of windows */
+ static const unsigned int snap      = 32;       /* snap pixel */
++static const unsigned int systraypinning = 0;   /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
++static const unsigned int systrayonleft = 0;       /* 0: systray in the right corner, >0: systray on left of status text */
++static const unsigned int systrayspacing = 2;   /* systray spacing */
++static const int systraypinningfailfirst = 1;   /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
++static const int showsystray        = 1;     /* 0 means no systray */
+ static const int showbar            = 1;        /* 0 means no bar */
+ static const int topbar             = 1;        /* 0 means bottom bar */
+ static const char *fonts[]          = { "monospace:size=10" };
+@@ -112,4 +117,3 @@ static Button buttons[] = {
+     { ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
+     { ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
+ };
+-
+diff --git a/dwm.c b/dwm.c
+index b0b3466..1e2a32d 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -57,12 +57,30 @@
+ #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
+ #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
+ 
++#define SYSTEM_TRAY_REQUEST_DOCK    0
++
++/* XEMBED messages */
++#define XEMBED_EMBEDDED_NOTIFY      0
++#define XEMBED_WINDOW_ACTIVATE      1
++#define XEMBED_FOCUS_IN             4
++#define XEMBED_MODALITY_ON         10
++
++#define XEMBED_MAPPED              (1 << 0)
++#define XEMBED_WINDOW_ACTIVATE      1
++#define XEMBED_WINDOW_DEACTIVATE    2
++
++#define VERSION_MAJOR               0
++#define VERSION_MINOR               0
++#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
++
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+ enum { SchemeNorm, SchemeSel }; /* color schemes */
+ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
++       NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
+        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
++enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */
+ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
+ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
+        ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
+@@ -141,6 +159,12 @@ typedef struct {
+     int monitor;
+ } Rule;
+ 
++typedef struct Systray   Systray;
++struct Systray {
++    Window win;
++    Client *icons;
++};
++
+ /* function declarations */
+ static void applyrules(Client *c);
+ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
+@@ -172,6 +196,7 @@ static void focusstack(const Arg *arg);
+ static Atom getatomprop(Client *c, Atom prop);
+ static int getrootptr(int *x, int *y);
+ static long getstate(Window w);
++static unsigned int getsystraywidth();
+ static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
+ static void grabbuttons(Client *c, int focused);
+ static void grabkeys(void);
+@@ -189,13 +214,16 @@ static void pop(Client *);
+ static void propertynotify(XEvent *e);
+ static void quit(const Arg *arg);
+ static Monitor *recttomon(int x, int y, int w, int h);
++static void removesystrayicon(Client *i);
+ static void resize(Client *c, int x, int y, int w, int h, int interact);
++static void resizebarwin(Monitor *m);
+ static void resizeclient(Client *c, int x, int y, int w, int h);
+ static void resizemouse(const Arg *arg);
++static void resizerequest(XEvent *e);
+ static void restack(Monitor *m);
+ static void run(void);
+ static void scan(void);
+-static int sendevent(Client *c, Atom proto);
++static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
+ static void sendmon(Client *c, Monitor *m);
+ static void setclientstate(Client *c, long state);
+ static void setfocus(Client *c);
+@@ -207,6 +235,7 @@ static void seturgent(Client *c, int urg);
+ static void showhide(Client *c);
+ static void sigchld(int unused);
+ static void spawn(const Arg *arg);
++static Monitor *systraytomon(Monitor *m);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *);
+@@ -224,18 +253,23 @@ static int updategeom(void);
+ static void updatenumlockmask(void);
+ static void updatesizehints(Client *c);
+ static void updatestatus(void);
++static void updatesystray(void);
++static void updatesystrayicongeom(Client *i, int w, int h);
++static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
+ static void updatetitle(Client *c);
+ static void updatewindowtype(Client *c);
+ static void updatewmhints(Client *c);
+ static void view(const Arg *arg);
+ static Client *wintoclient(Window w);
+ static Monitor *wintomon(Window w);
++static Client *wintosystrayicon(Window w);
+ static int xerror(Display *dpy, XErrorEvent *ee);
+ static int xerrordummy(Display *dpy, XErrorEvent *ee);
+ static int xerrorstart(Display *dpy, XErrorEvent *ee);
+ static void zoom(const Arg *arg);
+ 
+ /* variables */
++static Systray *systray =  NULL;
+ static const char broken[] = "broken";
+ static char stext[256];
+ static int screen;
+@@ -258,9 +292,10 @@ static void (*handler[LASTEvent]) (XEvent *) = {
+     [MapRequest] = maprequest,
+     [MotionNotify] = motionnotify,
+     [PropertyNotify] = propertynotify,
++    [ResizeRequest] = resizerequest,
+     [UnmapNotify] = unmapnotify
+ };
+-static Atom wmatom[WMLast], netatom[NetLast];
++static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
+ static int running = 1;
+ static Cur *cursor[CurLast];
+ static Clr **scheme;
+@@ -440,7 +475,7 @@ buttonpress(XEvent *e)
+             arg.ui = 1 << i;
+         } else if (ev->x < x + blw)
+             click = ClkLtSymbol;
+-        else if (ev->x > selmon->ww - (int)TEXTW(stext))
++        else if (ev->x > selmon->ww - (int)TEXTW(stext) - getsystraywidth())
+             click = ClkStatusText;
+         else
+             click = ClkWinTitle;
+@@ -483,6 +518,11 @@ cleanup(void)
+     XUngrabKey(dpy, AnyKey, AnyModifier, root);
+     while (mons)
+         cleanupmon(mons);
++    if (showsystray) {
++        XUnmapWindow(dpy, systray->win);
++        XDestroyWindow(dpy, systray->win);
++        free(systray);
++    }
+     for (i = 0; i < CurLast; i++)
+         drw_cur_free(drw, cursor[i]);
+     for (i = 0; i < LENGTH(colors); i++)
+@@ -513,9 +553,57 @@ cleanupmon(Monitor *mon)
+ void
+ clientmessage(XEvent *e)
+ {
++    XWindowAttributes wa;
++    XSetWindowAttributes swa;
+     XClientMessageEvent *cme = &e->xclient;
+     Client *c = wintoclient(cme->window);
+ 
++    if (showsystray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) {
++        /* add systray icons */
++        if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
++            if (!(c = (Client *)calloc(1, sizeof(Client))))
++                die("fatal: could not malloc() %u bytes\n", sizeof(Client));
++            if (!(c->win = cme->data.l[2])) {
++                free(c);
++                return;
++            }
++            c->mon = selmon;
++            c->next = systray->icons;
++            systray->icons = c;
++            if (!XGetWindowAttributes(dpy, c->win, &wa)) {
++                /* use sane defaults */
++                wa.width = bh;
++                wa.height = bh;
++                wa.border_width = 0;
++            }
++            c->x = c->oldx = c->y = c->oldy = 0;
++            c->w = c->oldw = wa.width;
++            c->h = c->oldh = wa.height;
++            c->oldbw = wa.border_width;
++            c->bw = 0;
++            c->isfloating = True;
++            /* reuse tags field as mapped status */
++            c->tags = 1;
++            updatesizehints(c);
++            updatesystrayicongeom(c, wa.width, wa.height);
++            XAddToSaveSet(dpy, c->win);
++            XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
++            XReparentWindow(dpy, c->win, systray->win, 0, 0);
++            /* use parents background color */
++            swa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
++            XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa);
++            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++            /* FIXME not sure if I have to send these events, too */
++            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
++            XSync(dpy, False);
++            resizebarwin(selmon);
++            updatesystray();
++            setclientstate(c, NormalState);
++        }
++        return;
++    }
+     if (!c)
+         return;
+     if (cme->message_type == netatom[NetWMState]) {
+@@ -568,7 +656,7 @@ configurenotify(XEvent *e)
+                 for (c = m->clients; c; c = c->next)
+                     if (c->isfullscreen)
+                         resizeclient(c, m->mx, m->my, m->mw, m->mh);
+-                XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
++                resizebarwin(m);
+             }
+             focus(NULL);
+             arrange(NULL);
+@@ -653,6 +741,11 @@ destroynotify(XEvent *e)
+ 
+     if ((c = wintoclient(ev->window)))
+         unmanage(c, 1);
++    else if ((c = wintosystrayicon(ev->window))) {
++        removesystrayicon(c);
++        resizebarwin(selmon);
++        updatesystray();
++    }
+ }
+ 
+ void
+@@ -696,19 +789,23 @@ dirtomon(int dir)
+ void
+ drawbar(Monitor *m)
+ {
+-    int x, w, tw = 0;
++    int x, w, tw = 0, stw = 0;
+     int boxs = drw->fonts->h / 9;
+     int boxw = drw->fonts->h / 6 + 2;
+     unsigned int i, occ = 0, urg = 0;
+     Client *c;
+ 
++    if(showsystray && m == systraytomon(m) && !systrayonleft)
++        stw = getsystraywidth();
++
+     /* draw status first so it can be overdrawn by tags later */
+     if (m == selmon) { /* status is only drawn on selected monitor */
+         drw_setscheme(drw, scheme[SchemeNorm]);
+-        tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+-        drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
++        tw = TEXTW(stext) - lrpad / 2 + 2; /* 2px extra right padding */
++        drw_text(drw, m->ww - tw - stw, 0, tw, bh, lrpad / 2 - 2, stext, 0);
+     }
+ 
++    resizebarwin(m);
+     for (c = m->clients; c; c = c->next) {
+         occ |= c->tags;
+         if (c->isurgent)
+@@ -729,7 +826,7 @@ drawbar(Monitor *m)
+     drw_setscheme(drw, scheme[SchemeNorm]);
+     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 - stw - x) > bh) {
+         if (m->sel) {
+             drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+             drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+@@ -740,7 +837,7 @@ drawbar(Monitor *m)
+             drw_rect(drw, x, 0, w, bh, 1, 1);
+         }
+     }
+-    drw_map(drw, m->barwin, 0, 0, m->ww, bh);
++    drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh);
+ }
+ 
+ void
+@@ -777,8 +874,11 @@ expose(XEvent *e)
+     Monitor *m;
+     XExposeEvent *ev = &e->xexpose;
+ 
+-    if (ev->count == 0 && (m = wintomon(ev->window)))
++    if (ev->count == 0 && (m = wintomon(ev->window))) {
+         drawbar(m);
++        if (m == selmon)
++            updatesystray();
++    }
+ }
+ 
+ void
+@@ -863,10 +963,17 @@ getatomprop(Client *c, Atom prop)
+     unsigned long dl;
+     unsigned char *p = NULL;
+     Atom da, atom = None;
++    /* FIXME getatomprop should return the number of items and a pointer to
++     * the stored data instead of this workaround */
++    Atom req = XA_ATOM;
++    if (prop == xatom[XembedInfo])
++        req = xatom[XembedInfo];
+ 
+-    if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
++    if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, req,
+         &da, &di, &dl, &dl, &p) == Success && p) {
+         atom = *(Atom *)p;
++        if (da == xatom[XembedInfo] && dl == 2)
++            atom = ((Atom *)p)[1];
+         XFree(p);
+     }
+     return atom;
+@@ -900,6 +1007,16 @@ getstate(Window w)
+     return result;
+ }
+ 
++unsigned int
++getsystraywidth()
++{
++    unsigned int w = 0;
++    Client *i;
++    if(showsystray)
++        for(i = systray->icons; i; w += i->w + systrayspacing, i = i->next) ;
++    return w ? w + systrayspacing : 1;
++}
++
+ int
+ gettextprop(Window w, Atom atom, char *text, unsigned int size)
+ {
+@@ -1004,7 +1121,7 @@ killclient(const Arg *arg)
+ {
+     if (!selmon->sel)
+         return;
+-    if (!sendevent(selmon->sel, wmatom[WMDelete])) {
++    if (!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0 , 0, 0)) {
+         XGrabServer(dpy);
+         XSetErrorHandler(xerrordummy);
+         XSetCloseDownMode(dpy, DestroyAll);
+@@ -1092,6 +1209,12 @@ maprequest(XEvent *e)
+ {
+     static XWindowAttributes wa;
+     XMapRequestEvent *ev = &e->xmaprequest;
++    Client *i;
++    if ((i = wintosystrayicon(ev->window))) {
++        sendevent(i->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, systray->win, XEMBED_EMBEDDED_VERSION);
++        resizebarwin(selmon);
++        updatesystray();
++    }
+ 
+     if (!XGetWindowAttributes(dpy, ev->window, &wa))
+         return;
+@@ -1216,6 +1339,16 @@ propertynotify(XEvent *e)
+     Window trans;
+     XPropertyEvent *ev = &e->xproperty;
+ 
++    if ((c = wintosystrayicon(ev->window))) {
++        if (ev->atom == XA_WM_NORMAL_HINTS) {
++            updatesizehints(c);
++            updatesystrayicongeom(c, c->w, c->h);
++        }
++        else
++            updatesystrayiconstate(c, ev);
++        resizebarwin(selmon);
++        updatesystray();
++    }
+     if ((ev->window == root) && (ev->atom == XA_WM_NAME))
+         updatestatus();
+     else if (ev->state == PropertyDelete)
+@@ -1266,6 +1399,20 @@ recttomon(int x, int y, int w, int h)
+     return r;
+ }
+ 
++void
++removesystrayicon(Client *i)
++{
++    Client **ii;
++
++    if (!showsystray || !i)
++        return;
++    for (ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next);
++    if (ii)
++        *ii = i->next;
++    free(i);
++}
++
++
+ void
+ resize(Client *c, int x, int y, int w, int h, int interact)
+ {
+@@ -1273,6 +1420,14 @@ resize(Client *c, int x, int y, int w, int h, int interact)
+         resizeclient(c, x, y, w, h);
+ }
+ 
++void
++resizebarwin(Monitor *m) {
++    unsigned int w = m->ww;
++    if (showsystray && m == systraytomon(m) && !systrayonleft)
++        w -= getsystraywidth();
++    XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh);
++}
++
+ void
+ resizeclient(Client *c, int x, int y, int w, int h)
+ {
+@@ -1345,6 +1500,19 @@ resizemouse(const Arg *arg)
+     }
+ }
+ 
++void
++resizerequest(XEvent *e)
++{
++    XResizeRequestEvent *ev = &e->xresizerequest;
++    Client *i;
++
++    if ((i = wintosystrayicon(ev->window))) {
++        updatesystrayicongeom(i, ev->width, ev->height);
++        resizebarwin(selmon);
++        updatesystray();
++    }
++}
++
+ void
+ restack(Monitor *m)
+ {
+@@ -1434,26 +1602,36 @@ setclientstate(Client *c, long state)
+ }
+ 
+ int
+-sendevent(Client *c, Atom proto)
++sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d3, long d4)
+ {
+     int n;
+-    Atom *protocols;
++    Atom *protocols, mt;
+     int exists = 0;
+     XEvent ev;
+ 
+-    if (XGetWMProtocols(dpy, c->win, &protocols, &n)) {
+-        while (!exists && n--)
+-            exists = protocols[n] == proto;
+-        XFree(protocols);
++    if (proto == wmatom[WMTakeFocus] || proto == wmatom[WMDelete]) {
++        mt = wmatom[WMProtocols];
++        if (XGetWMProtocols(dpy, w, &protocols, &n)) {
++            while (!exists && n--)
++                exists = protocols[n] == proto;
++            XFree(protocols);
++        }
++    }
++    else {
++        exists = True;
++        mt = proto;
+     }
+     if (exists) {
+         ev.type = ClientMessage;
+-        ev.xclient.window = c->win;
+-        ev.xclient.message_type = wmatom[WMProtocols];
++        ev.xclient.window = w;
++        ev.xclient.message_type = mt;
+         ev.xclient.format = 32;
+-        ev.xclient.data.l[0] = proto;
+-        ev.xclient.data.l[1] = CurrentTime;
+-        XSendEvent(dpy, c->win, False, NoEventMask, &ev);
++        ev.xclient.data.l[0] = d0;
++        ev.xclient.data.l[1] = d1;
++        ev.xclient.data.l[2] = d2;
++        ev.xclient.data.l[3] = d3;
++        ev.xclient.data.l[4] = d4;
++        XSendEvent(dpy, w, False, mask, &ev);
+     }
+     return exists;
+ }
+@@ -1467,7 +1645,7 @@ setfocus(Client *c)
+             XA_WINDOW, 32, PropModeReplace,
+             (unsigned char *) &(c->win), 1);
+     }
+-    sendevent(c, wmatom[WMTakeFocus]);
++    sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0);
+ }
+ 
+ void
+@@ -1556,6 +1734,10 @@ setup(void)
+     wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
+     netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
+     netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
++    netatom[NetSystemTray] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_S0", False);
++    netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
++    netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False);
++    netatom[NetSystemTrayOrientationHorz] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False);
+     netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
+     netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
+     netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
+@@ -1563,6 +1745,9 @@ setup(void)
+     netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
+     netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+     netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
++    xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
++    xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
++    xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
+     /* init cursors */
+     cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
+     cursor[CurResize] = drw_cur_create(drw, XC_sizing);
+@@ -1571,6 +1756,8 @@ setup(void)
+     scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
+     for (i = 0; i < LENGTH(colors); i++)
+         scheme[i] = drw_scm_create(drw, colors[i], 3);
++    /* init system tray */
++    updatesystray();
+     /* init bars */
+     updatebars();
+     updatestatus();
+@@ -1704,7 +1891,18 @@ togglebar(const Arg *arg)
+ {
+     selmon->showbar = !selmon->showbar;
+     updatebarpos(selmon);
+-    XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
++    resizebarwin(selmon);
++    if (showsystray) {
++        XWindowChanges wc;
++        if (!selmon->showbar)
++            wc.y = -bh;
++        else if (selmon->showbar) {
++            wc.y = 0;
++            if (!selmon->topbar)
++                wc.y = selmon->mh - bh;
++        }
++        XConfigureWindow(dpy, systray->win, CWY, &wc);
++    }
+     arrange(selmon);
+ }
+ 
+@@ -1799,11 +1997,18 @@ unmapnotify(XEvent *e)
+         else
+             unmanage(c, 0);
+     }
++    else if ((c = wintosystrayicon(ev->window))) {
++        /* KLUDGE! sometimes icons occasionally unmap their windows, but do
++         * _not_ destroy them. We map those windows back */
++        XMapRaised(dpy, c->win);
++        updatesystray();
++    }
+ }
+ 
+ void
+ updatebars(void)
+ {
++    unsigned int w;
+     Monitor *m;
+     XSetWindowAttributes wa = {
+         .override_redirect = True,
+@@ -1814,10 +2019,15 @@ updatebars(void)
+     for (m = mons; m; m = m->next) {
+         if (m->barwin)
+             continue;
+-        m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
++        w = m->ww;
++        if (showsystray && m == systraytomon(m))
++            w -= getsystraywidth();
++        m->barwin = XCreateWindow(dpy, root, m->wx, m->by, w, bh, 0, DefaultDepth(dpy, screen),
+                 CopyFromParent, DefaultVisual(dpy, screen),
+                 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+         XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
++        if (showsystray && m == systraytomon(m))
++            XMapRaised(dpy, systray->win);
+         XMapRaised(dpy, m->barwin);
+         XSetClassHint(dpy, m->barwin, &ch);
+     }
+@@ -1993,6 +2203,124 @@ updatestatus(void)
+     if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+         strcpy(stext, "dwm-"VERSION);
+     drawbar(selmon);
++    updatesystray();
++}
++
++void
++updatesystrayicongeom(Client *i, int w, int h)
++{
++    if (i) {
++        i->h = bh;
++        if (w == h)
++            i->w = bh;
++        else if (h == bh)
++            i->w = w;
++        else
++            i->w = (int) ((float)bh * ((float)w / (float)h));
++        applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
++        /* force icons into the systray dimensions if they don't want to */
++        if (i->h > bh) {
++            if (i->w == i->h)
++                i->w = bh;
++            else
++                i->w = (int) ((float)bh * ((float)i->w / (float)i->h));
++            i->h = bh;
++        }
++    }
++}
++
++void
++updatesystrayiconstate(Client *i, XPropertyEvent *ev)
++{
++    long flags;
++    int code = 0;
++
++    if (!showsystray || !i || ev->atom != xatom[XembedInfo] ||
++            !(flags = getatomprop(i, xatom[XembedInfo])))
++        return;
++
++    if (flags & XEMBED_MAPPED && !i->tags) {
++        i->tags = 1;
++        code = XEMBED_WINDOW_ACTIVATE;
++        XMapRaised(dpy, i->win);
++        setclientstate(i, NormalState);
++    }
++    else if (!(flags & XEMBED_MAPPED) && i->tags) {
++        i->tags = 0;
++        code = XEMBED_WINDOW_DEACTIVATE;
++        XUnmapWindow(dpy, i->win);
++        setclientstate(i, WithdrawnState);
++    }
++    else
++        return;
++    sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
++            systray->win, XEMBED_EMBEDDED_VERSION);
++}
++
++void
++updatesystray(void)
++{
++    XSetWindowAttributes wa;
++    XWindowChanges wc;
++    Client *i;
++    Monitor *m = systraytomon(NULL);
++    unsigned int x = m->mx + m->mw;
++    unsigned int sw = TEXTW(stext) - lrpad + systrayspacing;
++    unsigned int w = 1;
++
++    if (!showsystray)
++        return;
++    if (systrayonleft)
++        x -= sw + lrpad / 2;
++    if (!systray) {
++        /* init systray */
++        if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
++            die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
++        systray->win = XCreateSimpleWindow(dpy, root, x, m->by, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel);
++        wa.event_mask        = ButtonPressMask | ExposureMask;
++        wa.override_redirect = True;
++        wa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
++        XSelectInput(dpy, systray->win, SubstructureNotifyMask);
++        XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
++                PropModeReplace, (unsigned char *)&netatom[NetSystemTrayOrientationHorz], 1);
++        XChangeWindowAttributes(dpy, systray->win, CWEventMask|CWOverrideRedirect|CWBackPixel, &wa);
++        XMapRaised(dpy, systray->win);
++        XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime);
++        if (XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) {
++            sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime, netatom[NetSystemTray], systray->win, 0, 0);
++            XSync(dpy, False);
++        }
++        else {
++            fprintf(stderr, "dwm: unable to obtain system tray.\n");
++            free(systray);
++            systray = NULL;
++            return;
++        }
++    }
++    for (w = 0, i = systray->icons; i; i = i->next) {
++        /* make sure the background color stays the same */
++        wa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
++        XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
++        XMapRaised(dpy, i->win);
++        w += systrayspacing;
++        i->x = w;
++        XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
++        w += i->w;
++        if (i->mon != m)
++            i->mon = m;
++    }
++    w = w ? w + systrayspacing : 1;
++    x -= w;
++    XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh);
++    wc.x = x; wc.y = m->by; wc.width = w; wc.height = bh;
++    wc.stack_mode = Above; wc.sibling = m->barwin;
++    XConfigureWindow(dpy, systray->win, CWX|CWY|CWWidth|CWHeight|CWSibling|CWStackMode, &wc);
++    XMapWindow(dpy, systray->win);
++    XMapSubwindows(dpy, systray->win);
++    /* redraw background */
++    XSetForeground(dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel);
++    XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh);
++    XSync(dpy, False);
+ }
+ 
+ void
+@@ -2060,6 +2388,16 @@ wintoclient(Window w)
+     return NULL;
+ }
+ 
++Client *
++wintosystrayicon(Window w) {
++    Client *i = NULL;
++
++    if (!showsystray || !w)
++        return i;
++    for (i = systray->icons; i && i->win != w; i = i->next) ;
++    return i;
++}
++
+ Monitor *
+ wintomon(Window w)
+ {
+@@ -2113,6 +2451,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
+     return -1;
+ }
+ 
++Monitor *
++systraytomon(Monitor *m) {
++    Monitor *t;
++    int i, n;
++    if(!systraypinning) {
++        if(!m)
++            return selmon;
++        return m == selmon ? m : NULL;
++    }
++    for(n = 1, t = mons; t && t->next; n++, t = t->next) ;
++    for(i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next) ;
++    if(systraypinningfailfirst && n < systraypinning)
++        return mons;
++    return t;
++}
++
+ void
+ zoom(const Arg *arg)
+ {
+-- 
+2.31.0
+
diff --git a/patches/dwm-systray-dwmblocks-6.2.diff b/patches/dwm-systray-dwmblocks-6.2.diff
@@ -0,0 +1,439 @@
+diff -ruN dwm-6.2-ori/config.def.h dwm-6.2/config.def.h
+--- dwm-6.2-ori/config.def.h    2020-08-17 23:51:19.053910127 +0530
++++ dwm-6.2/config.def.h    2020-12-27 20:01:59.763790107 +0530
+@@ -16,10 +16,26 @@
+ static const char col_gray3[]       = "#bbbbbb";
+ static const char col_gray4[]       = "#eeeeee";
+ static const char col_cyan[]        = "#005577";
++static const char col1[]            = "#ffffff";
++static const char col2[]            = "#ffffff";
++static const char col3[]            = "#ffffff";
++static const char col4[]            = "#ffffff";
++static const char col5[]            = "#ffffff";
++static const char col6[]            = "#ffffff";
++
++enum { SchemeNorm, SchemeCol1, SchemeCol2, SchemeCol3, SchemeCol4,
++       SchemeCol5, SchemeCol6, SchemeSel }; /* color schemes */
++
+ static const char *colors[][3]      = {
+     /*               fg         bg         border   */
+-    [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+-    [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
++    [SchemeNorm]  = { col_gray3, col_gray1, col_gray2 },
++    [SchemeCol1]  = { col1,      col_gray1, col_gray2 },
++    [SchemeCol2]  = { col2,      col_gray1, col_gray2 },
++    [SchemeCol3]  = { col3,      col_gray1, col_gray2 },
++    [SchemeCol4]  = { col4,      col_gray1, col_gray2 },
++    [SchemeCol5]  = { col5,      col_gray1, col_gray2 },
++    [SchemeCol6]  = { col6,      col_gray1, col_gray2 },
++    [SchemeSel]   = { col_gray4, col_cyan,  col_cyan  },
+ };
+ 
+ /* tagging */
+@@ -107,7 +123,9 @@
+     { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
+     { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
+     { ClkWinTitle,          0,              Button2,        zoom,           {0} },
+-    { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
++    { ClkStatusText,        0,              Button1,        sigdwmblocks,   {.i = 1} },
++    { ClkStatusText,        0,              Button2,        sigdwmblocks,   {.i = 2} },
++    { ClkStatusText,        0,              Button3,        sigdwmblocks,   {.i = 3} },
+     { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
+     { ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
+     { ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
+diff -ruN dwm-6.2-ori/dwm.c dwm-6.2/dwm.c
+--- dwm-6.2-ori/dwm.c    2020-08-17 23:51:19.057243495 +0530
++++ dwm-6.2/dwm.c    2021-08-20 20:59:38.894111552 +0530
+@@ -40,6 +40,7 @@
+ #include <X11/extensions/Xinerama.h>
+ #endif /* XINERAMA */
+ #include <X11/Xft/Xft.h>
++#include <fcntl.h>
+ 
+ #include "drw.h"
+ #include "util.h"
+@@ -56,6 +57,13 @@
+ #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
+ #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
+ #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
++#define TTEXTW(X)               (drw_fontset_getwidth(drw, (X)))
++
++#define STATUSLENGTH            256
++#define DWMBLOCKSLOCKFILE       "/var/local/dwmblocks/dwmblocks.pid"
++#define DELIMITERENDCHAR        10
++#define LSPAD                   (lrpad / 2) /* padding on left side of status text */
++#define RSPAD                   (lrpad / 2) /* padding on right side of status text */
+ 
+ #define SYSTEM_TRAY_REQUEST_DOCK    0
+ 
+@@ -74,8 +82,7 @@
+ #define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
+ 
+ /* enums */
+-enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+-enum { SchemeNorm, SchemeSel }; /* color schemes */
++enum { CurNormal, CurHand, CurResize, CurMove, CurLast }; /* cursor */
+ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+        NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
+        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+@@ -142,6 +149,7 @@
+     unsigned int tagset[2];
+     int showbar;
+     int topbar;
++        int statushandcursor;
+     Client *clients;
+     Client *sel;
+     Client *stack;
+@@ -234,6 +242,7 @@
+ static void seturgent(Client *c, int urg);
+ static void showhide(Client *c);
+ static void sigchld(int unused);
++static void sigdwmblocks(const Arg *arg);
+ static void spawn(const Arg *arg);
+ static Monitor *systraytomon(Monitor *m);
+ static void tag(const Arg *arg);
+@@ -249,6 +258,7 @@
+ static void updatebarpos(Monitor *m);
+ static void updatebars(void);
+ static void updateclientlist(void);
++static void updatedwmblockssig(int x);
+ static int updategeom(void);
+ static void updatenumlockmask(void);
+ static void updatesizehints(Client *c);
+@@ -269,14 +279,17 @@
+ static void zoom(const Arg *arg);
+ 
+ /* variables */
+-static Systray *systray =  NULL;
+ static const char broken[] = "broken";
+-static char stext[256];
++static char stextc[STATUSLENGTH];
++static char stexts[STATUSLENGTH];
+ static int screen;
+ static int sw, sh;           /* X display screen geometry width, height */
+-static int bh, blw = 0;      /* bar geometry */
++static int bh, blw, ble;     /* bar geometry */
++static int wsbar;            /* width of selmon bar */
++static int wstext;           /* width of status text */
+ static int lrpad;            /* sum of left and right padding for text */
+ static int (*xerrorxlib)(Display *, XErrorEvent *);
++static unsigned int dwmblockssig;
+ static unsigned int numlockmask = 0;
+ static void (*handler[LASTEvent]) (XEvent *) = {
+     [ButtonPress] = buttonpress,
+@@ -303,6 +316,7 @@
+ static Drw *drw;
+ static Monitor *mons, *selmon;
+ static Window root, wmcheckwin;
++static Systray *systray =  NULL;
+ 
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+@@ -452,13 +466,13 @@
+ void
+ buttonpress(XEvent *e)
+ {
+-    unsigned int i, x, click;
++        int i, x;
++        unsigned int click;
+     Arg arg = {0};
+     Client *c;
+     Monitor *m;
+     XButtonPressedEvent *ev = &e->xbutton;
+ 
+-    click = ClkRootWin;
+     /* focus monitor if necessary */
+     if ((m = wintomon(ev->window)) && m != selmon) {
+         unfocus(selmon->sel, 1);
+@@ -466,25 +480,29 @@
+         focus(NULL);
+     }
+     if (ev->window == selmon->barwin) {
+-        i = x = 0;
+-        do
+-            x += TEXTW(tags[i]);
+-        while (ev->x >= x && ++i < LENGTH(tags));
+-        if (i < LENGTH(tags)) {
+-            click = ClkTagBar;
+-            arg.ui = 1 << i;
+-        } else if (ev->x < x + blw)
+-            click = ClkLtSymbol;
+-        else if (ev->x > selmon->ww - TEXTW(stext) - getsystraywidth())
+-            click = ClkStatusText;
+-        else
+-            click = ClkWinTitle;
++                if (ev->x < ble - blw) {
++                        i = -1, x = -ev->x;
++                        do
++                                x += TEXTW(tags[++i]);
++                        while (x <= 0);
++                        click = ClkTagBar;
++                        arg.ui = 1 << i;
++                } else if (ev->x < ble)
++                        click = ClkLtSymbol;
++                else if (ev->x < wsbar - wstext)
++                        click = ClkWinTitle;
++                else if ((x = wsbar - RSPAD - ev->x) > 0 && (x -= wstext - LSPAD - RSPAD) <= 0) {
++                        updatedwmblockssig(x);
++                        click = ClkStatusText;
++                } else
++                                return;
+     } else if ((c = wintoclient(ev->window))) {
+         focus(c);
+         restack(selmon);
+         XAllowEvents(dpy, ReplayPointer, CurrentTime);
+         click = ClkClientWin;
+-    }
++    } else
++                click = ClkRootWin;
+     for (i = 0; i < LENGTH(buttons); i++)
+         if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
+         && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
+@@ -789,23 +807,47 @@
+ void
+ drawbar(Monitor *m)
+ {
+-    int x, w, sw = 0, stw = 0;
++    int x, w;
++        int wbar = m->ww;
+     int boxs = drw->fonts->h / 9;
+     int boxw = drw->fonts->h / 6 + 2;
+     unsigned int i, occ = 0, urg = 0;
+     Client *c;
+ 
+-    if(showsystray && m == systraytomon(m))
+-        stw = getsystraywidth();
++        if (showsystray && m == systraytomon(m))
++                wbar -= getsystraywidth();
+ 
+     /* draw status first so it can be overdrawn by tags later */
+     if (m == selmon) { /* status is only drawn on selected monitor */
+-        drw_setscheme(drw, scheme[SchemeNorm]);
+-        sw = TEXTW(stext) - lrpad / 2 + 2; /* 2px right padding */
+-        drw_text(drw, m->ww - sw - stw, 0, sw, bh, lrpad / 2 - 2, stext, 0);
++                char *stc = stextc;
++                char *stp = stextc;
++                char tmp;
++
++                wsbar = wbar;
++                drw_setscheme(drw, scheme[SchemeNorm]);
++                x = wbar - wstext;
++                drw_rect(drw, x, 0, LSPAD, bh, 1, 1); x += LSPAD; /* to keep left padding clean */
++                for (;;) {
++                        if ((unsigned char)*stc >= ' ') {
++                                stc++;
++                                continue;
++                        }
++                        tmp = *stc;
++                        if (stp != stc) {
++                                *stc = '\0';
++                                x = drw_text(drw, x, 0, TTEXTW(stp), bh, 0, stp, 0);
++                        }
++                        if (tmp == '\0')
++                                break;
++                        if (tmp - DELIMITERENDCHAR - 1 < LENGTH(colors))
++                                drw_setscheme(drw, scheme[tmp - DELIMITERENDCHAR - 1]);
++                        *stc = tmp;
++                        stp = ++stc;
++                }
++                drw_setscheme(drw, scheme[SchemeNorm]);
++                drw_rect(drw, x, 0, wbar - x, bh, 1, 1); /* to keep right padding clean */
+     }
+ 
+-    resizebarwin(m);
+     for (c = m->clients; c; c = c->next) {
+         occ |= c->tags;
+         if (c->isurgent)
+@@ -822,11 +864,17 @@
+                 urg & 1 << i);
+         x += w;
+     }
+-    w = blw = TEXTW(m->ltsymbol);
++    w = TEXTW(m->ltsymbol);
+     drw_setscheme(drw, scheme[SchemeNorm]);
+     x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+ 
+-    if ((w = m->ww - sw - stw - x) > bh) {
++        if (m == selmon) {
++                blw = w, ble = x;
++                w = wbar - wstext - x;
++        } else
++                w = wbar - x;
++
++    if (w > bh) {
+         if (m->sel) {
+             drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+             drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+@@ -837,7 +885,9 @@
+             drw_rect(drw, x, 0, w, bh, 1, 1);
+         }
+     }
+-    drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh);
++
++        XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, wbar, bh);
++    drw_map(drw, m->barwin, 0, 0, wbar, bh);
+ }
+ 
+ void
+@@ -1243,17 +1293,24 @@
+ motionnotify(XEvent *e)
+ {
+     static Monitor *mon = NULL;
++        int x;
+     Monitor *m;
+     XMotionEvent *ev = &e->xmotion;
+ 
+-    if (ev->window != root)
+-        return;
+-    if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
+-        unfocus(selmon->sel, 1);
+-        selmon = m;
+-        focus(NULL);
+-    }
+-    mon = m;
++        if (ev->window == root) {
++                if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
++                        unfocus(selmon->sel, 1);
++                        selmon = m;
++                        focus(NULL);
++                }
++                mon = m;
++        } else if (ev->window == selmon->barwin && (x = wsbar - RSPAD - ev->x) > 0
++                                                && (x -= wstext - LSPAD - RSPAD) <= 0)
++                updatedwmblockssig(x);
++        else if (selmon->statushandcursor) {
++                selmon->statushandcursor = 0;
++                XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor);
++        }
+ }
+ 
+ void
+@@ -1750,6 +1807,7 @@
+     xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
+     /* init cursors */
+     cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
++        cursor[CurHand] = drw_cur_create(drw, XC_hand2);
+     cursor[CurResize] = drw_cur_create(drw, XC_sizing);
+     cursor[CurMove] = drw_cur_create(drw, XC_fleur);
+     /* init appearance */
+@@ -1825,6 +1883,37 @@
+ }
+ 
+ void
++sigdwmblocks(const Arg *arg)
++{
++        static int fd = -1;
++        struct flock fl;
++        union sigval sv;
++
++        if (!dwmblockssig)
++                return;
++        fl.l_type = F_WRLCK;
++        fl.l_whence = SEEK_SET;
++        fl.l_start = 0;
++        fl.l_len = 0;
++        if (fd != -1) {
++                if (fcntl(fd, F_GETLK, &fl) != -1 && fl.l_type == F_WRLCK)
++                        goto signal;
++                close(fd);
++                fl.l_type = F_WRLCK;
++        }
++        if ((fd = open(DWMBLOCKSLOCKFILE, O_RDONLY | O_CLOEXEC)) == -1)
++                return;
++        if (fcntl(fd, F_GETLK, &fl) == -1 || fl.l_type != F_WRLCK) {
++                close(fd);
++                fd = -1;
++                return;
++        }
++signal:
++        sv.sival_int = (dwmblockssig << 8) | arg->i;
++        sigqueue(fl.l_pid, SIGRTMIN, sv);
++}
++
++void
+ spawn(const Arg *arg)
+ {
+     if (arg->v == dmenucmd)
+@@ -2011,7 +2100,7 @@
+     XSetWindowAttributes wa = {
+         .override_redirect = True,
+         .background_pixmap = ParentRelative,
+-        .event_mask = ButtonPressMask|ExposureMask
++        .event_mask = ButtonPressMask|ExposureMask|PointerMotionMask
+     };
+     XClassHint ch = {"dwm", "dwm"};
+     for (m = mons; m; m = m->next) {
+@@ -2058,6 +2147,41 @@
+                 (unsigned char *) &(c->win), 1);
+ }
+ 
++void
++updatedwmblockssig(int x)
++{
++        char *sts = stexts;
++        char *stp = stexts;
++        char tmp;
++
++        while (*sts != '\0') {
++                if ((unsigned char)*sts >= ' ') {
++                        sts++;
++                        continue;
++                }
++                tmp = *sts;
++                *sts = '\0';
++                x += TTEXTW(stp);
++                *sts = tmp;
++                if (x > 0) {
++                        if (tmp == DELIMITERENDCHAR)
++                                break;
++                        if (!selmon->statushandcursor) {
++                                selmon->statushandcursor = 1;
++                                XDefineCursor(dpy, selmon->barwin, cursor[CurHand]->cursor);
++                        }
++                        dwmblockssig = tmp;
++                        return;
++                }
++                stp = ++sts;
++        }
++        if (selmon->statushandcursor) {
++                selmon->statushandcursor = 0;
++                XDefineCursor(dpy, selmon->barwin, cursor[CurNormal]->cursor);
++        }
++        dwmblockssig = 0;
++}
++
+ int
+ updategeom(void)
+ {
+@@ -2198,10 +2322,27 @@
+ void
+ updatestatus(void)
+ {
+-    if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+-        strcpy(stext, "dwm-"VERSION);
+-    drawbar(selmon);
+-    updatesystray();
++    char rawstext[STATUSLENGTH];
++
++    if (gettextprop(root, XA_WM_NAME, rawstext, sizeof rawstext)) {
++                char stextp[STATUSLENGTH];
++                char *stp = stextp, *stc = stextc, *sts = stexts;
++
++                for (char *rst = rawstext; *rst != '\0'; rst++)
++                        if ((unsigned char)*rst >= ' ')
++                                *(stp++) = *(stc++) = *(sts++) = *rst;
++                        else if ((unsigned char)*rst > DELIMITERENDCHAR)
++                                *(stc++) = *rst;
++                        else
++                                *(sts++) = *rst;
++                *stp = *stc = *sts = '\0';
++                wstext = TTEXTW(stextp) + LSPAD + RSPAD;
++        } else {
++                strcpy(stextc, "dwm-"VERSION);
++                strcpy(stexts, stextc);
++                wstext = TTEXTW(stextc) + LSPAD + RSPAD;
++        }
++        drawbar(selmon);
+ }
+ 
+ void
diff --git a/patches/dwm-titlecolor-20210815-ed3ab6b4.diff b/patches/dwm-titlecolor-20210815-ed3ab6b4.diff
@@ -0,0 +1,47 @@
+From 45a45a0e67f3841d8c4aed2c52b57c2a7ddf2a9a Mon Sep 17 00:00:00 2001
+From: Jack Bird <jack.bird@durham.ac.uk>
+Date: Sun, 15 Aug 2021 23:15:52 +0100
+Subject: [PATCH] Updated title color patch for 7162335
+
+---
+ config.def.h | 1 +
+ dwm.c        | 4 ++--
+ 2 files changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index a2ac963..5b9ae00 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -16,6 +16,7 @@ static const char *colors[][3]      = {
+     /*               fg         bg         border   */
+     [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+     [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
++    [SchemeTitle]  = { col_gray4, col_cyan,  col_cyan  },
+ };
+ 
+ /* tagging */
+diff --git a/dwm.c b/dwm.c
+index 5e4d494..73d335e 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -59,7 +59,7 @@
+ 
+ /* enums */
+ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+-enum { SchemeNorm, SchemeSel }; /* color schemes */
++enum { SchemeNorm, SchemeSel, SchemeTitle }; /* color schemes */
+ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+        NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+@@ -731,7 +731,7 @@ drawbar(Monitor *m)
+ 
+     if ((w = m->ww - tw - x) > bh) {
+         if (m->sel) {
+-            drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
++            drw_setscheme(drw, scheme[m == selmon ? SchemeTitle : SchemeNorm]);
+             drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+             if (m->sel->isfloating)
+                 drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
+-- 
+2.32.0
+