aboutsummaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authordavidpkj <davidpenkow1@gmail.com>2023-03-16 13:52:08 +0100
committerdavidpkj <davidpenkow1@gmail.com>2023-03-16 13:52:20 +0100
commite1ab9d282197410c0d283d738b7b2bacc957dea9 (patch)
tree7c22e290ba838c28b077bca7996a88fe450919c3 /dwm.c
parente3edd704fb85474bc35478b23ffab048bc1564a7 (diff)
Patch: xrdb-6.4 + status2d-6.3
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c186
1 files changed, 178 insertions, 8 deletions
diff --git a/dwm.c b/dwm.c
index 9bfd150..ae71522 100644
--- a/dwm.c
+++ b/dwm.c
@@ -35,6 +35,7 @@
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
+#include <X11/Xresource.h>
#include <X11/Xutil.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
@@ -62,6 +63,21 @@
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \
+ if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \
+ int i = 1; \
+ for (; i <= 6; i++) { \
+ if (value.addr[i] < 48) break; \
+ if (value.addr[i] > 57 && value.addr[i] < 65) break; \
+ if (value.addr[i] > 70 && value.addr[i] < 97) break; \
+ if (value.addr[i] > 102) break; \
+ } \
+ if (i == 7) { \
+ strncpy(V, value.addr, 7); \
+ V[7] = '\0'; \
+ } \
+ } \
+ }
#define GAP_TOGGLE 100
#define GAP_RESET 0
@@ -193,6 +209,7 @@ static void detachstack(Client *c);
static Monitor *dirtomon(int dir);
static void drawbar(Monitor *m);
static void drawbars(void);
+static int drawstatusbar(Monitor *m, int bh, char* text);
static void drawtab(Monitor *m);
static void drawtabs(void);
static void enternotify(XEvent *e);
@@ -212,6 +229,7 @@ static void grabkeys(void);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
+static void loadxrdb(void);
static void manage(Window w, XWindowAttributes *wa);
static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
@@ -274,6 +292,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 xrdb(const Arg *arg);
static void zoom(const Arg *arg);
static pid_t getparentprocess(pid_t p);
@@ -284,7 +303,7 @@ static pid_t winpid(Window w);
/* variables */
static const char broken[] = "broken";
-static char stext[256];
+static char stext[1024];
static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh; /* bar height */
@@ -618,7 +637,7 @@ cleanup(void)
cleanupmon(mons);
for (i = 0; i < CurLast; i++)
drw_cur_free(drw, cursor[i]);
- for (i = 0; i < LENGTH(colors); i++)
+ for (i = 0; i < LENGTH(colors) + 1; i++)
free(scheme[i]);
free(scheme);
XDestroyWindow(dpy, wmcheckwin);
@@ -861,6 +880,114 @@ dirtomon(int dir)
return m;
}
+int
+drawstatusbar(Monitor *m, int bh, char* stext) {
+ int ret, i, w, x, len;
+ short isCode = 0;
+ char *text;
+ char *p;
+
+ len = strlen(stext) + 1 ;
+ if (!(text = (char*) malloc(sizeof(char)*len)))
+ die("malloc");
+ p = text;
+ memcpy(text, stext, len);
+
+ /* compute width of the status text */
+ w = 0;
+ i = -1;
+ while (text[++i]) {
+ if (text[i] == '^') {
+ if (!isCode) {
+ isCode = 1;
+ text[i] = '\0';
+ w += TEXTW(text) - lrpad;
+ text[i] = '^';
+ if (text[++i] == 'f')
+ w += atoi(text + ++i);
+ } else {
+ isCode = 0;
+ text = text + i + 1;
+ i = -1;
+ }
+ }
+ }
+ if (!isCode)
+ w += TEXTW(text) - lrpad;
+ else
+ isCode = 0;
+ text = p;
+
+ w += horizpadbar;
+ ret = x = m->ww - m->gap->gappx * 2 - w;
+
+ drw_setscheme(drw, scheme[LENGTH(colors)]);
+ drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
+ drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
+ drw_rect(drw, x, 0, w, bh, 1, 1);
+ x += horizpadbar / 2;
+
+ /* process status text */
+ i = -1;
+ while (text[++i]) {
+ if (text[i] == '^' && !isCode) {
+ isCode = 1;
+
+ text[i] = '\0';
+ w = TEXTW(text) - lrpad;
+ drw_text(drw, x, vertpadbar / 2, w, bh - vertpadbar, 0, text, 0);
+
+ x += w;
+
+ /* process code */
+ while (text[++i] != '^') {
+ if (text[i] == 'c') {
+ char buf[8];
+ memcpy(buf, (char*)text+i+1, 7);
+ buf[7] = '\0';
+ drw_clr_create(drw, &drw->scheme[ColFg], buf);
+ i += 7;
+ } else if (text[i] == 'b') {
+ char buf[8];
+ memcpy(buf, (char*)text+i+1, 7);
+ buf[7] = '\0';
+ drw_clr_create(drw, &drw->scheme[ColBg], buf);
+ i += 7;
+ } else if (text[i] == 'd') {
+ drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
+ drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
+ } else if (text[i] == 'r') {
+ int rx = atoi(text + ++i);
+ while (text[++i] != ',');
+ int ry = atoi(text + ++i);
+ while (text[++i] != ',');
+ int rw = atoi(text + ++i);
+ while (text[++i] != ',');
+ int rh = atoi(text + ++i);
+
+ drw_rect(drw, rx + x, ry + vertpadbar / 2, rw, rh, 1, 0);
+ } else if (text[i] == 'f') {
+ x += atoi(text + ++i);
+ }
+ }
+
+ text = text + i + 1;
+ i=-1;
+ isCode = 0;
+ }
+ }
+
+ if (!isCode) {
+ w = TEXTW(text) - lrpad;
+ drw_text(drw, x, vertpadbar / 2, w, bh - vertpadbar, 0, text, 0);
+ }
+
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ free(p);
+
+ return ret;
+}
+
void
drawbar(Monitor *m)
{
@@ -876,9 +1003,7 @@ 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[SchemeNorm]);
- tw = TEXTW(stext);
- drw_text(drw, m->ww - tw - 2 * sp, 0, tw, bh, 0, stext, 0);
+ tw = m->ww - drawstatusbar(m, bh, stext);
}
for (c = m->clients; c; c = c->next) {
@@ -901,9 +1026,9 @@ 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 + m->gap->gappx * 2 - tw - x) > bh) {
if (m->sel) {
- drw_setscheme(drw, scheme[m == selmon ? SchemeNorm : SchemeNorm]);
+ drw_setscheme(drw, SchemeNorm);
tlpad = MAX((m->ww - ((int)TEXTW(m->sel->name) - lrpad)) / 2 - x, lrpad / 2);
drw_text(drw, x, 0, w - 2 * sp, bh, tlpad, m->sel->name, 0);
if (m->sel->isfloating) {
@@ -1314,6 +1439,37 @@ killclient(const Arg *arg)
}
void
+loadxrdb()
+{
+ Display *display;
+ char * resm;
+ XrmDatabase xrdb;
+ char *type;
+ XrmValue value;
+
+ display = XOpenDisplay(NULL);
+
+ if (display != NULL) {
+ resm = XResourceManagerString(display);
+
+ if (resm != NULL) {
+ xrdb = XrmGetStringDatabase(resm);
+
+ if (xrdb != NULL) {
+ XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor);
+ XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor);
+ XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor);
+ XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor);
+ XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor);
+ XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor);
+ }
+ }
+ }
+
+ XCloseDisplay(display);
+}
+
+void
manage(Window w, XWindowAttributes *wa)
{
Client *c, *t = NULL, *term = NULL;
@@ -1983,7 +2139,8 @@ setup(void)
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
/* init appearance */
- scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
+ scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *));
+ scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3);
for (i = 0; i < LENGTH(colors); i++)
scheme[i] = drw_scm_create(drw, colors[i], 3);
/* init bars */
@@ -2783,6 +2940,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
}
void
+xrdb(const Arg *arg)
+{
+ loadxrdb();
+ int i;
+ for (i = 0; i < LENGTH(colors); i++)
+ scheme[i] = drw_scm_create(drw, colors[i], 3);
+ focus(NULL);
+ arrange(NULL);
+}
+
+void
zoom(const Arg *arg)
{
Client *c = selmon->sel;
@@ -2808,6 +2976,8 @@ main(int argc, char *argv[])
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
checkotherwm();
+ XrmInitialize();
+ loadxrdb();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec ps", NULL) == -1)