Dwm bar on only one monitor

As most of you know I run two screens. Does anyone know if it is possible to have the dwm bar display only on one monitor and if so how do I define that monitor?

Not possible with the defaults but it’d be pretty easy to edit the source to be only show on monitor X. If it’s something you actually want I can post a patch/breakdown to do it.

2 Likes

Please Mr @natemaia

That would be great.

1 Like

You’ll need to change/add a few things.

First define which monitor to use in the config

unsigned int barmon = 0;

Now update drawbars to only draw the bar for the monitor we want

void drawbars(void)
{
	uint i;
	Monitor *m;

	for (i = 0, m = mons; m; m = m->next, i++)
		if (i == barmon)
			drawbar(m);
}

Lastly edit drawbar and make the status always drawn regardless of whether the monitor is active or not

void drawbar(Monitor *m)
{
	int x, w, sw = 0;
	int boxs = drw->fonts->h / 9;
	int boxw = drw->fonts->h / 6 + 2;
	unsigned int i, occ = 0, urg = 0;
	Client *c;

	/* draw status first so it can be overdrawn by tags later */
	/* status is always drawn on bar regardless if monitor is active or not */
	drw_setscheme(drw, scheme[SchemeNorm]);
	sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
	drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0);

	for (c = m->clients; c; c = c->next) {
		occ |= c->tags;
		if (c->isurgent)
			urg |= c->tags;
	}
	x = 0;
	for (i = 0; i < LENGTH(tags); i++) {
		w = TEXTW(tags[i]);
		drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
		drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
		if (occ & 1 << i)
			drw_rect(drw, x + boxs, boxs, boxw, boxw,
				m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
				urg & 1 << i);
		x += w;
	}
	w = blw = TEXTW(m->ltsymbol);
	drw_setscheme(drw, scheme[SchemeNorm]);
	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);

	if ((w = m->ww - sw - x) > bh) {
		if (m->sel) {
			drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
			drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
			if (m->sel->isfloating)
				drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
		} else {
			drw_setscheme(drw, scheme[SchemeNorm]);
			drw_rect(drw, x, 0, w, bh, 1, 1);
		}
	}
	drw_map(drw, m->barwin, 0, 0, m->ww, bh
}

That should really be enough I believe, this is all untested so lemme know if it causes any issues.

2 Likes

Awesome, will give this a shot over the weekend.