summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2020-10-08 04:20:59 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2020-10-08 04:20:59 -0400
commit6ce9e00e4eb9f3cf22b0b9fcc1fa2d84c7a10f98 (patch)
tree3411a295b9c62ddf7f1fbb015dc1b92a7b43fbe0 /dwm.c
parent4cc2f25553037554a77024fd172c6b1e4bdec1b0 (diff)
Massive overhaul to fix the faulty statusbar
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c162
1 files changed, 139 insertions, 23 deletions
diff --git a/dwm.c b/dwm.c
index 3624ff4..d353e23 100644
--- a/dwm.c
+++ b/dwm.c
@@ -59,6 +59,8 @@
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define OPAQUE 0xffU
+
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel, SchemeInactive }; /* color schemes */
@@ -94,7 +96,7 @@ struct Client {
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
unsigned int tags;
- int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, iscentered, noswallow;
+ int isfixed, iscentered, isurgent, neverfocus, oldstate, isfullscreen, isfloating, isterminal, noswallow;
pid_t pid;
Client *next;
Client *snext;
@@ -169,6 +171,7 @@ static void clientmessage(XEvent *e);
static void configure(Client *c);
static void configurenotify(XEvent *e);
static void configurerequest(XEvent *e);
+static void copyvalidchars(char *text, char *rawtext);
static Monitor *createmon(void);
static void destroynotify(XEvent *e);
static void detach(Client *c);
@@ -185,6 +188,7 @@ static void focus(Client *c);
static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
+static int getdwmblockspid();
static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y);
static long getstate(Window w);
@@ -203,7 +207,7 @@ static void motionnotify(XEvent *e);
static void movemouse(const Arg *arg);
static Monitor *numtomon(const unsigned int num);
static Client *nexttiled(Client *c);
-static void pop(Client *);
+/* 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);
@@ -227,6 +231,7 @@ 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 void swapmon(const Arg *arg);
static void tag(const Arg *arg);
@@ -255,6 +260,7 @@ static Monitor *wintomon(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 xinitvisual();
static void zoom(const Arg *arg);
static void centeredmaster(Monitor *m);
static void centeredfloatingmaster(Monitor *m);
@@ -269,6 +275,9 @@ static pid_t winpid(Window w);
static Client *prevzoom = NULL;
static const char broken[] = "broken";
static char stext[256];
+static char rawstext[256];
+static int dwmblockssig;
+pid_t dwmblockspid = 0;
static int scanner;
static int screen;
static int sw, sh; /* X display screen geometry width, height */
@@ -303,6 +312,11 @@ static Window root, wmcheckwin;
static Layout *last_layout;
+static int useargb = 0;
+static Visual *visual;
+static int depth;
+static Colormap cmap;
+
static xcb_connection_t *xcon;
/* configuration, allows nested code to access above variables */
@@ -551,9 +565,26 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
click = ClkLtSymbol;
- else if (ev->x > selmon->ww - (int)TEXTW(stext))
+ else if (ev->x > (x = selmon->ww - (int)TEXTW(stext) + lrpad)) {
click = ClkStatusText;
- else
+
+ char *text = rawstext;
+ int i = -1;
+ char ch;
+ dwmblockssig = 0;
+ while (text[++i]) {
+ if ((unsigned char)text[i] < ' ') {
+ ch = text[i];
+ text[i] = '\0';
+ x += (int)TEXTW(text) - lrpad;
+ text[i] = ch;
+ text += i+1;
+ i = -1;
+ if (x >= ev->x) break;
+ dwmblockssig = ch;
+ }
+ }
+ } else
click = ClkWinTitle;
} else if ((c = wintoclient(ev->window))) {
focus(c);
@@ -746,6 +777,19 @@ configurerequest(XEvent *e)
XSync(dpy, False);
}
+void
+copyvalidchars(char *text, char *rawtext)
+{
+ int i = -1, j = 0;
+
+ while(rawtext[++i]) {
+ if ((unsigned char)rawtext[i] >= ' ') {
+ text[j++] = rawtext[i];
+ }
+ }
+ text[j] = '\0';
+}
+
Monitor *
createmon(void)
{
@@ -825,10 +869,9 @@ drawbar(Monitor *m)
/* 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[SchemeSel]);
- /* drw_setscheme(drw, scheme[SchemeNorm]); HERE */
+ drw_setscheme(drw, scheme[SchemeNorm]);
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
- drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);
+ drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
}
for (c = m->clients; c; c = c->next) {
@@ -1050,6 +1093,18 @@ getatomprop(Client *c, Atom prop)
}
int
+getdwmblockspid()
+{
+ char buf[16];
+ FILE *fp = popen("pidof -s dwmblocks", "r");
+ fgets(buf, sizeof(buf), fp);
+ pid_t pid = strtoul(buf, NULL, 10);
+ pclose(fp);
+ dwmblockspid = pid;
+ return pid != 0 ? 0 : -1;
+}
+
+int
getrootptr(int *x, int *y)
{
int di;
@@ -1518,14 +1573,14 @@ Monitor
return m;
}
-void
-pop(Client *c)
-{
- detach(c);
- attach(c);
- focus(c);
- arrange(c->mon);
-}
+/* void */
+/* pop(Client *c) */
+/* { */
+/* detach(c); */
+/* attach(c); */
+/* focus(c); */
+/* arrange(c->mon); */
+/* } */
void
propertynotify(XEvent *e)
@@ -1943,7 +1998,8 @@ setup(void)
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
root = RootWindow(dpy, screen);
- drw = drw_create(dpy, screen, root, sw, sh);
+ xinitvisual();
+ drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap);
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
@@ -1971,7 +2027,7 @@ setup(void)
/* init appearance */
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
for (i = 0; i < LENGTH(colors); i++)
- scheme[i] = drw_scm_create(drw, colors[i], 3);
+ scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3);
/* init bars */
updatebars();
updatestatus();
@@ -2039,8 +2095,27 @@ sigchld(int unused)
}
void
+sigdwmblocks(const Arg *arg)
+{
+ union sigval sv;
+ sv.sival_int = (dwmblockssig << 8) | arg->i;
+ if (!dwmblockspid)
+ if (getdwmblockspid() == -1)
+ return;
+
+ if (sigqueue(dwmblockspid, SIGUSR1, sv) == -1) {
+ if (errno == ESRCH) {
+ if (!getdwmblockspid())
+ sigqueue(dwmblockspid, SIGUSR1, sv);
+ }
+ }
+}
+
+void
spawn(const Arg *arg)
{
+ if (arg->v == dmenucmd)
+ dmenumon[0] = '0' + selmon->num;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
@@ -2190,7 +2265,7 @@ tile(Monitor *m)
mw = m->ww;
ns = 1;
}
- for (i = 0, my = ty = gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ for(i = 0, my = ty = gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < m->nmaster) {
h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gappx;
resize(c, m->wx + gappx, m->wy + my, mw - (2*c->bw) - gappx*(5-ns)/2, h - (2*c->bw), False);
@@ -2333,16 +2408,18 @@ updatebars(void)
Monitor *m;
XSetWindowAttributes wa = {
.override_redirect = True,
- .background_pixmap = ParentRelative,
+ .background_pixel = 0,
+ .border_pixel = 0,
+ .colormap = cmap,
.event_mask = ButtonPressMask|ExposureMask
};
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),
- CopyFromParent, DefaultVisual(dpy, screen),
- CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
+ m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
+ InputOutput, visual,
+ CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa);
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
XMapRaised(dpy, m->barwin);
XSetClassHint(dpy, m->barwin, &ch);
@@ -2517,8 +2594,10 @@ updatesizehints(Client *c)
void
updatestatus(void)
{
- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+ if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)))
strcpy(stext, "dwm-"VERSION);
+ else
+ copyvalidchars(stext, rawstext);
drawbar(selmon);
}
@@ -2747,6 +2826,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
}
void
+xinitvisual()
+{
+ XVisualInfo *infos;
+ XRenderPictFormat *fmt;
+ int nitems;
+ int i;
+
+ XVisualInfo tpl = {
+ .screen = screen,
+ .depth = 32,
+ .class = TrueColor
+ };
+ long masks = VisualScreenMask | VisualDepthMask | VisualClassMask;
+
+ infos = XGetVisualInfo(dpy, masks, &tpl, &nitems);
+ visual = NULL;
+ for(i = 0; i < nitems; i ++) {
+ fmt = XRenderFindVisualFormat(dpy, infos[i].visual);
+ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
+ visual = infos[i].visual;
+ depth = infos[i].depth;
+ cmap = XCreateColormap(dpy, root, visual, AllocNone);
+ useargb = 1;
+ break;
+ }
+ }
+
+ XFree(infos);
+
+ if (! visual) {
+ visual = DefaultVisual(dpy, screen);
+ depth = DefaultDepth(dpy, screen);
+ cmap = DefaultColormap(dpy, screen);
+ }
+}
+
+void
zoom(const Arg *arg)
{
Client *c = selmon->sel;