Move global bar fields to the bar structure

This commit is contained in:
Alex Kotov 2021-11-20 16:11:27 +05:00
parent 2d4fe700f5
commit 4d52a3211c
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
3 changed files with 20 additions and 20 deletions

View File

@ -128,6 +128,7 @@ typedef struct Bar {
int by;
int topbar;
Window barwin;
int bh;
} *Bar;
struct Monitor {
@ -265,7 +266,6 @@ static Unit global_unit = NULL;
static const char broken[] = "broken";
static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh, blw = 0; /* bar geometry */
static int lrpad; /* sum of left and right padding for text */
static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0;
@ -419,10 +419,10 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int bw, int interact)
if (*y + *h + 2 * bw <= m->wy)
*y = m->wy;
}
if (*h < bh)
*h = bh;
if (*w < bh)
*w = bh;
if (*h < m->bar->bh)
*h = m->bar->bh;
if (*w < m->bar->bh)
*w = m->bar->bh;
if (
c->isfloating
||
@ -648,6 +648,7 @@ createmon(void)
}
memset(m->bar, 0, sizeof(struct Bar));
m->bar->bh = drw->fonts->h + 2;
m->tagset[0] = m->tagset[1] = 1;
m->nmaster = settings_get_default_clients_in_master();
@ -1031,7 +1032,7 @@ manage(Window w, XWindowAttributes *wa)
(c->x + (c->w / 2) >= c->mon->wx) &&
(c->x + (c->w / 2) < c->mon->wx + c->mon->ww)
)
? bh
? c->mon->bar->bh
: c->mon->my
);
@ -1612,7 +1613,6 @@ setup(void)
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
bh = drw->fonts->h + 2;
updategeom();
/* init atoms */
atoms = atoms_create(dpy);

View File

@ -20,7 +20,7 @@ createbars(void)
m->wx,
m->bar->by,
m->ww,
bh,
m->bar->bh,
0,
DefaultDepth(dpy, screen),
CopyFromParent,
@ -55,19 +55,19 @@ drawbar(Monitor *m)
w = TEXTW(tags_get(i)->name.cstr);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, tags_get(i)->name.cstr, urg & 1 << i);
drw_text(drw, x, 0, w, m->bar->bh, lrpad / 2, tags_get(i)->name.cstr, 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);
x = drw_text(drw, x, 0, w, m->bar->bh, lrpad / 2, m->ltsymbol, 0);
if ((w = m->ww - tw - x) > bh) {
if ((w = m->ww - tw - x) > m->bar->bh) {
drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1);
drw_rect(drw, x, 0, w, m->bar->bh, 1, 1);
}
drw_map(drw, m->bar->barwin, 0, 0, m->ww, bh);
drw_map(drw, m->bar->barwin, 0, 0, m->ww, m->bar->bh);
}
void
@ -92,7 +92,7 @@ updatebar(Monitor *m)
m->show_bar = unit_get_show_bar(m->pertag->units[m->pertag->curtag]);
updatebarpos(m);
XMoveResizeWindow(dpy, selmon->bar->barwin, selmon->wx, selmon->bar->by, selmon->ww, bh);
XMoveResizeWindow(dpy, selmon->bar->barwin, selmon->wx, selmon->bar->by, selmon->ww, m->bar->bh);
arrange(m);
}
@ -110,11 +110,11 @@ updatebarpos(Monitor *m)
m->wy = m->my;
m->wh = m->mh;
if (m->show_bar) {
m->wh -= bh;
m->wh -= m->bar->bh;
m->bar->by = m->bar->topbar ? m->wy : m->wy + m->wh;
m->wy = m->bar->topbar ? m->wy + bh : m->wy;
m->wy = m->bar->topbar ? m->wy + m->bar->bh : m->wy;
} else
m->bar->by = -bh;
m->bar->by = -m->bar->bh;
}
#endif // _DWM_BAR_C

View File

@ -131,10 +131,10 @@ on_configure_notify(XEvent *e)
sw = ev->width;
sh = ev->height;
if (updategeom() || dirty) {
drw_resize(drw, sw, bh);
createbars();
for (m = mons; m; m = m->next) {
XMoveResizeWindow(dpy, m->bar->barwin, m->wx, m->bar->by, m->ww, bh);
drw_resize(drw, sw, m->bar->bh);
XMoveResizeWindow(dpy, m->bar->barwin, m->wx, m->bar->by, m->ww, m->bar->bh);
}
focus(NULL);
arrange(NULL);