Test split extrabar

This commit is contained in:
Linux User 2022-10-01 09:49:37 +00:00
parent 3f65bea116
commit d6b3d8419b
6 changed files with 143 additions and 15 deletions

View File

@ -7,7 +7,7 @@
static const unsigned int borderpx = 4; static const unsigned int borderpx = 4;
static const unsigned int gappx = 10; static const unsigned int gappx = 10;
static const unsigned int snap = 32; /* snap pixel */ static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 0; /* 0 means no bar */ static const int showbar = 1; /* 0 means no bar */
static const int showextrabar = 1; /* 0 means no bar */ static const int showextrabar = 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 statussep = ';';

BIN
drw.o

Binary file not shown.

BIN
dwm

Binary file not shown.

156
dwm.c
View File

@ -251,7 +251,7 @@ static void zoom(const Arg *arg);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
static char stext[1024]; static char stext[1024];
static char estext[1024]; static char estext[2048];
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, blw = 0; /* bar geometry */ static int bh, blw = 0; /* bar geometry */
@ -736,14 +736,35 @@ dirtomon(int dir)
int int
drawstatusbar(Monitor *m, int bh, int extra, char* stext) { drawstatusbar(Monitor *m, int bh, int extra, char* stext) {
int ret, i, w, x, len; int ret, i, w, w2, x, x2, len, len2;
short isCode = 0; short isCode = 0, isCode2 = 0;
char *text; char *text;
char *text2;
char *p; char *p;
char *p2;
char stext2[1024];
len = strlen(stext) + 1 ; if (extra) {
char *st = strchr(stext, statussep);
if (st) {
*st = '\0'; st++;
strncpy(stext2, st, sizeof(stext2) - 1);
} else {
stext2[0] = '\0';
}
len2 = strlen(stext2) + 1;
if (!(text2 = (char*) malloc(sizeof(char)*len2)))
die("malloc");
p2 = text2;
memcpy(text2, stext2, len2);
}
len = strlen(stext) + 1;
if (!(text = (char*) malloc(sizeof(char)*len))) if (!(text = (char*) malloc(sizeof(char)*len)))
die("malloc"); die("malloc");
p = text; p = text;
memcpy(text, stext, len); memcpy(text, stext, len);
@ -772,19 +793,44 @@ drawstatusbar(Monitor *m, int bh, int extra, char* stext) {
isCode = 0; isCode = 0;
text = p; text = p;
if (extra) {
w2 = 0;
i = -1;
while (text2[++i]) {
if (text2[i] == '^') {
if (!isCode2) {
isCode2 = 1;
text2[i] = '\0';
w2 += TEXTW(text2) - lrpad;
text2[i] = '^';
if (text2[++i] == 'f')
w2 += atoi(text2 + ++i);
} else {
isCode2 = 0;
text2 = text2 + i + 1;
i = -1;
}
}
}
if (!isCode2)
w2 += TEXTW(text2) - lrpad;
else
isCode2 = 0;
text2 = p2;
}
if (extra) { if (extra) {
w = m->ww; w = m->ww;
// w = m->ww - w - 2 * hpb; // w = m->ww - w - 2 * hpb;
ret = x = 1; ret = 1;
x = 0;
x2 = m->ww - 2 * hpb;
} else { } else {
// w += 2; /* 1px padding on both sides */ // w += 2; /* 1px padding on both sides */
// ret = x = m->ww - w; // ret = x = m->ww - w;
ret = x = m->ww - w - 2 * hpb; ret = x = m->ww - w - 2 * hpb;
} }
// ret = m->ww - w;
// x = m->ww - w - 2 * hpb;
drw_setscheme(drw, scheme[LENGTH(colors)]); drw_setscheme(drw, scheme[LENGTH(colors)]);
drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
@ -841,11 +887,73 @@ drawstatusbar(Monitor *m, int bh, int extra, char* stext) {
} }
} }
if (extra) {
drw_setscheme(drw, scheme[LENGTH(colors)]);
drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
drw_rect(drw, m->ww - w2, 0, w2, bh, 1, 1);
x2++;
i = -1;
while (text2[++i]) {
if (text2[i] == '^' && !isCode2) {
isCode2 = 1;
text2[i] = '\0';
w2 = TEXTW(text2) - lrpad;
drw_text(drw, m->ww - w2, vertpadstat, w2, bh - 2 * vertpadstat, 0, text2, 0);
x2 += w2;
/* process code */
while (text2[++i] != '^') {
if (text2[i] == 'c') {
char buf[8];
memcpy(buf, (char*)text2+i+1, 7);
buf[7] = '\0';
drw_clr_create(drw, &drw->scheme[ColFg], buf);
i += 7;
} else if (text2[i] == 'b') {
char buf[8];
memcpy(buf, (char*)text2+i+1, 7);
buf[7] = '\0';
drw_clr_create(drw, &drw->scheme[ColBg], buf);
i += 7;
} else if (text2[i] == 'd') {
drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
} else if (text2[i] == 'r') {
int rx = atoi(text2 + ++i);
while (text2[++i] != ',');
int ry = atoi(text2 + ++i);
while (text2[++i] != ',');
int rw = atoi(text2 + ++i);
while (text2[++i] != ',');
int rh = atoi(text2 + ++i);
drw_rect(drw, rx, ry, rw, rh, 1, 0);
} else if (text2[i] == 'f') {
x2 += atoi(text2 + ++i);
}
}
text2 = text2 + i + 1;
i=-1;
isCode2 = 0;
}
}
}
if (!isCode) { if (!isCode) {
w = TEXTW(text) - lrpad; w = TEXTW(text) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0); drw_text(drw, x, 0, w, bh, 0, text, 0);
} }
if (!isCode2) {
w2 = TEXTW(text2) - lrpad;
drw_text(drw, m->ww - w2 - hpb * 2, 0, w2, bh, 0, text2, 0);
}
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
free(p); free(p);
@ -1455,9 +1563,14 @@ void
resizemouse(const Arg *arg) resizemouse(const Arg *arg)
{ {
int ocx, ocy, nw, nh; int ocx, ocy, nw, nh;
int ocx2, ocy2, nx, ny;
Client *c; Client *c;
Monitor *m; Monitor *m;
XEvent ev; XEvent ev;
int horizcorner, vertcorner;
int di;
unsigned int dui;
Window dummy;
Time lasttime = 0; Time lasttime = 0;
if (!(c = selmon->sel)) if (!(c = selmon->sel))
@ -1467,10 +1580,18 @@ resizemouse(const Arg *arg)
restack(selmon); restack(selmon);
ocx = c->x; ocx = c->x;
ocy = c->y; ocy = c->y;
ocx2 = c->x + c->w;
ocy2 = c->y + c->h;
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess)
return; return;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui))
return;
horizcorner = nx < c->w / 2;
vertcorner = ny < c->h / 2;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
horizcorner ? (-c->bw) : (c->w + c->bw - 1),
vertcorner ? (-c->bw) : (c->h + c->bw - 1));
do { do {
XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
switch(ev.type) { switch(ev.type) {
@ -1484,8 +1605,11 @@ resizemouse(const Arg *arg)
continue; continue;
lasttime = ev.xmotion.time; lasttime = ev.xmotion.time;
nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nx = horizcorner ? ev.xmotion.x : c->x;
nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); ny = vertcorner ? ev.xmotion.y : c->y;
nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1);
nh = MAX(vertcorner ? (ocy2 - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1);
if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww
&& c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh)
{ {
@ -1494,11 +1618,13 @@ resizemouse(const Arg *arg)
togglefloating(NULL); togglefloating(NULL);
} }
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
resize(c, c->x, c->y, nw, nh, 1); resize(c, nx, ny, nw, nh, 1);
break; break;
} }
} while (ev.type != ButtonRelease); } while (ev.type != ButtonRelease);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
horizcorner ? (-c->bw) : (c->w + c->bw - 1),
vertcorner ? (-c->bw) : (c->h + c->bw - 1));
XUngrabPointer(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime);
while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
@ -2236,7 +2362,7 @@ updatesizehints(Client *c)
void void
updatestatus(void) updatestatus(void)
{ {
char text[2048]; char text[3072];
if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) {
strcpy(stext, "dwm-"VERSION); strcpy(stext, "dwm-"VERSION);
estext[0] = '\0'; estext[0] = '\0';
@ -2248,8 +2374,10 @@ updatestatus(void)
} else { } else {
estext[0] = '\0'; estext[0] = '\0';
} }
strncpy(stext, text, sizeof(stext) - 1); strncpy(stext, text, sizeof(stext) - 1);
} }
drawbar(selmon); drawbar(selmon);
} }

BIN
dwm.o

Binary file not shown.

BIN
util.o

Binary file not shown.