Add status2d + extrabar patch

This commit is contained in:
BitHeaven 2024-05-31 17:00:25 +05:00
parent 976638aa52
commit 22da8d956f
6 changed files with 191 additions and 32 deletions

View File

@ -1,8 +1,7 @@
actualfullscreen actualfullscreen
quitprompt quitprompt
fullgaps fullgaps
status2d
extrabar
grid
gaplessgrid gaplessgrid
status2d + extrabar
anycorners

View File

@ -8,6 +8,7 @@ static const unsigned int gappx = 15; /* gaps between windows */
static const unsigned int snap = 32; /* snap pixel */ static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */ static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */ static const int topbar = 1; /* 0 means bottom bar */
static const char statussep = ';';
static const char *fonts[] = { "Ubuntu Mono:size=12" }; static const char *fonts[] = { "Ubuntu Mono:size=12" };
static const char dmenufont[] = "Ubuntu Mono:size=12"; static const char dmenufont[] = "Ubuntu Mono:size=12";
static const char col_gray1[] = "#222222"; static const char col_gray1[] = "#222222";
@ -120,11 +121,10 @@ static const Key keys[] = {
{ SUPERKEY, XK_l, setmfact, {.f = +0.05} }, { SUPERKEY, XK_l, setmfact, {.f = +0.05} },
{ SUPERKEY|ShiftMask, XK_Return, zoom, {0} }, { SUPERKEY|ShiftMask, XK_Return, zoom, {0} },
{ SUPERKEY, XK_q, killclient, {0} }, { SUPERKEY, XK_q, killclient, {0} },
{ SUPERKEY, XK_g, setlayout, {.v = &layouts[0]} },
{ SUPERKEY, XK_t, setlayout, {.v = &layouts[1]} }, { SUPERKEY, XK_t, setlayout, {.v = &layouts[1]} },
{ SUPERKEY, XK_f, setlayout, {.v = &layouts[2]} }, { SUPERKEY, XK_f, setlayout, {.v = &layouts[2]} },
{ SUPERKEY, XK_m, setlayout, {.v = &layouts[3]} }, { SUPERKEY, XK_m, setlayout, {.v = &layouts[3]} },
{ SUPERKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[4]} },
{ SUPERKEY, XK_g, setlayout, {.v = &layouts[0]} },
{ SUPERKEY|ShiftMask, XK_space, togglefloating, {0} }, { SUPERKEY|ShiftMask, XK_space, togglefloating, {0} },
// { SUPERKEY, XK_comma, focusmon, {.i = -1 } }, // { SUPERKEY, XK_comma, focusmon, {.i = -1 } },
// { SUPERKEY, XK_period, focusmon, {.i = +1 } }, // { SUPERKEY, XK_period, focusmon, {.i = +1 } },

View File

@ -8,6 +8,7 @@ static const unsigned int gappx = 15; /* gaps between windows */
static const unsigned int snap = 32; /* snap pixel */ static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */ static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */ static const int topbar = 1; /* 0 means bottom bar */
static const char statussep = ';';
static const char *fonts[] = { "Ubuntu Mono:size=12" }; static const char *fonts[] = { "Ubuntu Mono:size=12" };
static const char dmenufont[] = "Ubuntu Mono:size=12"; static const char dmenufont[] = "Ubuntu Mono:size=12";
static const char col_gray1[] = "#222222"; static const char col_gray1[] = "#222222";
@ -66,10 +67,11 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
#include "layouts.c" #include "layouts.c"
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol arrange function */ /* symbol arrange function */
{ "[]=", tile }, /* first entry is default */ { "###", gaplessgrid },
{ "><>", NULL }, /* no layout function means floating behavior */ { "[]=", tile },
{ "[M]", monocle }, { "><>", NULL },
{ "[M]", monocle },
}; };
/* key definitions */ /* key definitions */
@ -119,11 +121,10 @@ static const Key keys[] = {
{ SUPERKEY, XK_l, setmfact, {.f = +0.05} }, { SUPERKEY, XK_l, setmfact, {.f = +0.05} },
{ SUPERKEY|ShiftMask, XK_Return, zoom, {0} }, { SUPERKEY|ShiftMask, XK_Return, zoom, {0} },
{ SUPERKEY, XK_q, killclient, {0} }, { SUPERKEY, XK_q, killclient, {0} },
{ SUPERKEY, XK_g, setlayout, {.v = &layouts[0]} },
{ SUPERKEY, XK_t, setlayout, {.v = &layouts[1]} }, { SUPERKEY, XK_t, setlayout, {.v = &layouts[1]} },
{ SUPERKEY, XK_f, setlayout, {.v = &layouts[2]} }, { SUPERKEY, XK_f, setlayout, {.v = &layouts[2]} },
{ SUPERKEY, XK_m, setlayout, {.v = &layouts[3]} }, { SUPERKEY, XK_m, setlayout, {.v = &layouts[3]} },
{ SUPERKEY|ShiftMask, XK_g, setlayout, {.v = &layouts[4]} },
{ SUPERKEY, XK_g, setlayout, {.v = &layouts[0]} },
{ SUPERKEY|ShiftMask, XK_space, togglefloating, {0} }, { SUPERKEY|ShiftMask, XK_space, togglefloating, {0} },
// { SUPERKEY, XK_comma, focusmon, {.i = -1 } }, // { SUPERKEY, XK_comma, focusmon, {.i = -1 } },
// { SUPERKEY, XK_period, focusmon, {.i = +1 } }, // { SUPERKEY, XK_period, focusmon, {.i = +1 } },

BIN
dwm

Binary file not shown.

199
dwm.c
View File

@ -117,6 +117,7 @@ struct Monitor {
int nmaster; int nmaster;
int num; int num;
int by; /* bar geometry */ int by; /* bar geometry */
int eby; /* extra bar geometry */
int mx, my, mw, mh; /* screen size */ int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */ int wx, wy, ww, wh; /* window area */
int gappx; /* gaps between windows */ int gappx; /* gaps between windows */
@ -130,6 +131,7 @@ struct Monitor {
Client *stack; Client *stack;
Monitor *next; Monitor *next;
Window barwin; Window barwin;
Window extrabarwin;
const Layout *lt[2]; const Layout *lt[2];
}; };
@ -164,6 +166,7 @@ static void detachstack(Client *c);
static Monitor *dirtomon(int dir); static Monitor *dirtomon(int dir);
static void drawbar(Monitor *m); static void drawbar(Monitor *m);
static void drawbars(void); static void drawbars(void);
static int drawstatusbar(Monitor *m, int bh, int extra, char* text);
static void enternotify(XEvent *e); static void enternotify(XEvent *e);
static void expose(XEvent *e); static void expose(XEvent *e);
static void focus(Client *c); static void focus(Client *c);
@ -237,7 +240,8 @@ static void zoom(const Arg *arg);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
static char stext[256]; static char stext[1024];
static char estext[1024];
static int screen; static int screen;
static int sw, sh; /* X display screen geometry width, height */ static int sw, sh; /* X display screen geometry width, height */
static int bh; /* bar height */ static int bh; /* bar height */
@ -488,7 +492,7 @@ cleanup(void)
cleanupmon(mons); cleanupmon(mons);
for (i = 0; i < CurLast; i++) for (i = 0; i < CurLast; i++)
drw_cur_free(drw, cursor[i]); drw_cur_free(drw, cursor[i]);
for (i = 0; i < LENGTH(colors); i++) for (i = 0; i < LENGTH(colors) + 1; i++)
free(scheme[i]); free(scheme[i]);
free(scheme); free(scheme);
XDestroyWindow(dpy, wmcheckwin); XDestroyWindow(dpy, wmcheckwin);
@ -510,7 +514,9 @@ cleanupmon(Monitor *mon)
m->next = mon->next; m->next = mon->next;
} }
XUnmapWindow(dpy, mon->barwin); XUnmapWindow(dpy, mon->barwin);
XUnmapWindow(dpy, mon->extrabarwin);
XDestroyWindow(dpy, mon->barwin); XDestroyWindow(dpy, mon->barwin);
XDestroyWindow(dpy, mon->extrabarwin);
free(mon); free(mon);
} }
@ -573,6 +579,7 @@ configurenotify(XEvent *e)
if (c->isfullscreen) if (c->isfullscreen)
resizeclient(c, m->mx, m->my, m->mw, m->mh); resizeclient(c, m->mx, m->my, m->mw, m->mh);
XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
XMoveResizeWindow(dpy, m->extrabarwin, m->wx, m->eby, m->ww, bh);
} }
focus(NULL); focus(NULL);
arrange(NULL); arrange(NULL);
@ -698,6 +705,119 @@ dirtomon(int dir)
return m; return m;
} }
int
drawstatusbar(Monitor *m, int bh, int extra, 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;
if (extra) {
w = m->ww;
ret = x = 1;
} else {
w += 2; /* 1px padding on both sides */
ret = x = m->ww - 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++;
/* 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, 0, w, bh, 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, 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, 0, w, bh, 0, text, 0);
}
drw_setscheme(drw, scheme[SchemeNorm]);
free(p);
return ret;
}
void void
drawbar(Monitor *m) drawbar(Monitor *m)
{ {
@ -712,9 +832,10 @@ drawbar(Monitor *m)
/* draw status first so it can be overdrawn by tags later */ /* draw status first so it can be overdrawn by tags later */
if (m == selmon) { /* status is only drawn on selected monitor */ if (m == selmon) { /* status is only drawn on selected monitor */
drw_setscheme(drw, scheme[SchemeNorm]); // drw_setscheme(drw, scheme[SchemeNorm]);
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ // tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); // drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
tw = m->ww - drawstatusbar(m, bh, 0, stext);
} }
for (c = m->clients; c; c = c->next) { for (c = m->clients; c; c = c->next) {
@ -749,6 +870,11 @@ drawbar(Monitor *m)
} }
} }
drw_map(drw, m->barwin, 0, 0, m->ww, bh); drw_map(drw, m->barwin, 0, 0, m->ww, bh);
if (m == selmon) { /* extra status is only drawn on selected monitor */
sw = drawstatusbar(m, bh, 1, estext);
drw_map(drw, m->extrabarwin, 0, 0, m->ww, bh);
}
} }
void void
@ -1597,7 +1723,8 @@ setup(void)
cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur); cursor[CurMove] = drw_cur_create(drw, XC_fleur);
/* init appearance */ /* init appearance */
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++) for (i = 0; i < LENGTH(colors); i++)
scheme[i] = drw_scm_create(drw, colors[i], 3); scheme[i] = drw_scm_create(drw, colors[i], 3);
/* init bars */ /* init bars */
@ -1703,6 +1830,7 @@ togglebar(const Arg *arg)
selmon->showbar = !selmon->showbar; selmon->showbar = !selmon->showbar;
updatebarpos(selmon); updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
XMoveResizeWindow(dpy, selmon->extrabarwin, selmon->wx, selmon->eby, selmon->ww, bh);
arrange(selmon); arrange(selmon);
} }
@ -1818,14 +1946,30 @@ updatebars(void)
}; };
XClassHint ch = {"dwm", "dwm"}; XClassHint ch = {"dwm", "dwm"};
for (m = mons; m; m = m->next) { for (m = mons; m; m = m->next) {
if (m->barwin) if (!m->barwin) {
continue; m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); XMapRaised(dpy, m->barwin);
XMapRaised(dpy, m->barwin); XSetClassHint(dpy, m->barwin, &ch);
XSetClassHint(dpy, m->barwin, &ch); }
if (!m->extrabarwin) {
m->extrabarwin = XCreateWindow(dpy, root, m->wx, m->eby, m->ww, bh, 0, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
XDefineCursor(dpy, m->extrabarwin, cursor[CurNormal]->cursor);
XMapRaised(dpy, m->extrabarwin);
XSetClassHint(dpy, m->extrabarwin, &ch);
}
// 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);
// XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
// XMapRaised(dpy, m->barwin);
// XSetClassHint(dpy, m->barwin, &ch);
} }
} }
@ -1834,12 +1978,15 @@ updatebarpos(Monitor *m)
{ {
m->wy = m->my; m->wy = m->my;
m->wh = m->mh; m->wh = m->mh;
m->wh -= bh * m->showbar * 2;
m->wy = m->showbar ? m->wy + bh : m->wy;
if (m->showbar) { if (m->showbar) {
m->wh -= bh; m->by = m->topbar ? m->wy - bh : m->wy + m->wh;
m->by = m->topbar ? m->wy : m->wy + m->wh; m->eby = m->topbar ? m->wy + m->wh : m->wy - bh;
m->wy = m->topbar ? m->wy + bh : m->wy; } else {
} else
m->by = -bh; m->by = -bh;
m->eby = -bh;
}
} }
void void
@ -1997,8 +2144,20 @@ updatesizehints(Client *c)
void void
updatestatus(void) updatestatus(void)
{ {
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) char text[2048];
if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) {
strcpy(stext, "dwm-"VERSION); strcpy(stext, "dwm-"VERSION);
estext[0] = '\0';
} else {
char *e = strchr(text, statussep);
if (e) {
*e = '\0'; e++;
strncpy(estext, e, sizeof(estext) - 1);
} else {
estext[0] = '\0';
}
strncpy(stext, text, sizeof(stext) - 1);
}
drawbar(selmon); drawbar(selmon);
} }
@ -2077,7 +2236,7 @@ wintomon(Window w)
if (w == root && getrootptr(&x, &y)) if (w == root && getrootptr(&x, &y))
return recttomon(x, y, 1, 1); return recttomon(x, y, 1, 1);
for (m = mons; m; m = m->next) for (m = mons; m; m = m->next)
if (w == m->barwin) if (w == m->barwin || w == m->extrabarwin)
return m; return m;
if ((c = wintoclient(w))) if ((c = wintoclient(w)))
return c->mon; return c->mon;

BIN
dwm.o

Binary file not shown.