I don't like those squares, but I still want some indication as to whether a
tag is occupied, so I wrote this patch. It removes the squares, and uses a
different font (specified as boldfont in config.h) for occupied tags.
This is just a quick hack, and bad things will happen if both fonts are not of
the same dimensions.
diff -r ce355cea9bb8 config.def.h
--- a/config.def.h Tue Jul 29 11:32:22 2008 +0100
+++ b/config.def.h Mon Aug 11 06:56:30 2008 +0200
@@ -2,6 +2,7 @@
/* appearance */
static const char font[] =
"-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*";
+static const char boldfont[] =
"-*-terminus-bold-r-normal-*-14-*-*-*-*-*-*-*";
static const char normbordercolor[] = "#cccccc";
static const char normbgcolor[] = "#cccccc";
static const char normfgcolor[] = "#000000";
diff -r ce355cea9bb8 dwm.1
--- a/dwm.1 Tue Jul 29 11:32:22 2008 +0100
+++ b/dwm.1 Mon Aug 11 06:56:30 2008 +0200
@@ -20,13 +20,7 @@
tags. Selecting certain tags displays all windows with these tags.
.P
dwm contains a small status bar which displays all available tags, the layout,
-the title of the focused window, and the text read from standard input. A
-floating window is indicated with an empty square and a maximised
-floating window is indicated with a filled square before the windows
-title. The selected tags are indicated with a different color. The tags of
-the focused window are indicated with a filled square in the top left
-corner. The tags which are applied to one or more windows are indicated
-with an empty square in the top left corner.
+the title of the focused window, and the text read from standard input.
.P
dwm draws a small border around windows to indicate the focus state.
.SH OPTIONS
diff -r ce355cea9bb8 dwm.c
--- a/dwm.c Tue Jul 29 11:32:22 2008 +0100
+++ b/dwm.c Mon Aug 11 06:56:30 2008 +0200
@@ -94,18 +94,21 @@
};
typedef struct {
+ int ascent;
+ int descent;
+ int height;
+ XFontSet set;
+ XFontStruct *xfont;
+} Fount;
+
+typedef struct {
int x, y, w, h;
unsigned long norm[ColLast];
unsigned long sel[ColLast];
Drawable drawable;
GC gc;
- struct {
- int ascent;
- int descent;
- int height;
- XFontSet set;
- XFontStruct *xfont;
- } font;
+ Fount font;
+ Fount boldfont;
} DC; /* draw context */
typedef struct {
@@ -145,8 +148,7 @@
static void detachstack(Client *c);
static void die(const char *errstr, ...);
static void drawbar(void);
-static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long
col[ColLast]);
-static void drawtext(const char *text, unsigned long col[ColLast], Bool
invert);
+static void drawtext(const char *text, unsigned long col[ColLast], Bool
invert, Bool occupied);
static void enternotify(XEvent *e);
static void expose(XEvent *e);
static void focus(Client *c);
@@ -158,7 +160,7 @@
static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, Bool focused);
static void grabkeys(void);
-static void initfont(const char *fontstr);
+static void initfont(Fount *fount, const char *fontstr);
static Bool isoccupied(unsigned int t);
static Bool isprotodel(Client *c);
static Bool isurgent(unsigned int t);
@@ -505,19 +507,15 @@
dc.x = 0;
for(i = 0; i < LENGTH(tags); i++) {
dc.w = TEXTW(tags[i]);
- if(tagset[seltags] & 1 << i) {
- drawtext(tags[i], dc.sel, isurgent(i));
- drawsquare(sel && sel->tags & 1 << i, isoccupied(i),
isurgent(i), dc.sel);
- }
- else {
- drawtext(tags[i], dc.norm, isurgent(i));
- drawsquare(sel && sel->tags & 1 << i, isoccupied(i),
isurgent(i), dc.norm);
- }
+ if(tagset[seltags] & 1 << i)
+ drawtext(tags[i], dc.sel, isurgent(i), isoccupied(i));
+ else
+ drawtext(tags[i], dc.norm, isurgent(i), isoccupied(i));
dc.x += dc.w;
}
if(blw > 0) {
dc.w = blw;
- drawtext(lt[sellt]->symbol, dc.norm, False);
+ drawtext(lt[sellt]->symbol, dc.norm, False, False);
x = dc.x + dc.w;
}
else
@@ -528,46 +526,24 @@
dc.x = x;
dc.w = ww - x;
}
- drawtext(stext, dc.norm, False);
+ drawtext(stext, dc.norm, False, False);
if((dc.w = dc.x - x) > bh) {
dc.x = x;
- if(sel) {
- drawtext(sel->name, dc.sel, False);
- drawsquare(sel->isfixed, sel->isfloating, False,
dc.sel);
- }
+ if(sel)
+ drawtext(sel->name, dc.sel, False, False);
else
- drawtext(NULL, dc.norm, False);
+ drawtext(NULL, dc.norm, False, False);
}
XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, ww, bh, 0, 0);
XSync(dpy, False);
}
void
-drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
- int x;
- XGCValues gcv;
- XRectangle r = { dc.x, dc.y, dc.w, dc.h };
-
- gcv.foreground = col[invert ? ColBG : ColFG];
- XChangeGC(dpy, dc.gc, GCForeground, &gcv);
- x = (dc.font.ascent + dc.font.descent + 2) / 4;
- r.x = dc.x + 1;
- r.y = dc.y + 1;
- if(filled) {
- r.width = r.height = x + 1;
- XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
- }
- else if(empty) {
- r.width = r.height = x;
- XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
- }
-}
-
-void
-drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
+drawtext(const char *text, unsigned long col[ColLast], Bool invert, Bool
occupied) {
int i, x, y, h, len, olen;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
char buf[256];
+ Fount *fount = occupied ? &dc.boldfont : &dc.font;
XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
@@ -586,10 +562,13 @@
if(len < olen)
for(i = len; i && i > len - 3; buf[--i] = '.');
XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
- if(dc.font.set)
- XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf,
len);
- else
+ if(fount->set)
+ XmbDrawString(dpy, dc.drawable, fount->set, dc.gc, x, y, buf,
len);
+ else {
+ XSetFont(dpy, dc.gc, fount->xfont->fid);
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
+ XSetFont(dpy, dc.gc, dc.font.xfont->fid);
+ }
}
void
@@ -776,43 +755,43 @@
}
void
-initfont(const char *fontstr) {
+initfont(Fount *fount, const char *fontstr) {
char *def, **missing;
int i, n;
missing = NULL;
- if(dc.font.set)
- XFreeFontSet(dpy, dc.font.set);
- dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
+ if(fount->set)
+ XFreeFontSet(dpy, fount->set);
+ fount->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
if(missing) {
while(n--)
fprintf(stderr, "dwm: missing fontset: %s\n",
missing[n]);
XFreeStringList(missing);
}
- if(dc.font.set) {
+ if(fount->set) {
XFontSetExtents *font_extents;
XFontStruct **xfonts;
char **font_names;
- dc.font.ascent = dc.font.descent = 0;
- font_extents = XExtentsOfFontSet(dc.font.set);
- n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
- for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++)
{
- dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
- dc.font.descent =
MAX(dc.font.descent,(*xfonts)->descent);
+ fount->ascent = fount->descent = 0;
+ font_extents = XExtentsOfFontSet(fount->set);
+ n = XFontsOfFontSet(fount->set, &xfonts, &font_names);
+ for(i = 0, fount->ascent = 0, fount->descent = 0; i < n; i++) {
+ fount->ascent = MAX(fount->ascent, (*xfonts)->ascent);
+ fount->descent = MAX(fount->descent,(*xfonts)->descent);
xfonts++;
}
}
else {
- if(dc.font.xfont)
- XFreeFont(dpy, dc.font.xfont);
- dc.font.xfont = NULL;
- if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
- && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
+ if(fount->xfont)
+ XFreeFont(dpy, fount->xfont);
+ fount->xfont = NULL;
+ if(!(fount->xfont = XLoadQueryFont(dpy, fontstr))
+ && !(fount->xfont = XLoadQueryFont(dpy, "fixed")))
die("error, cannot load font: '%s'\n", fontstr);
- dc.font.ascent = dc.font.xfont->ascent;
- dc.font.descent = dc.font.xfont->descent;
+ fount->ascent = fount->xfont->ascent;
+ fount->descent = fount->xfont->descent;
}
- dc.font.height = dc.font.ascent + dc.font.descent;
+ fount->height = fount->ascent + fount->descent;
}
Bool
@@ -1337,7 +1316,8 @@
/* init screen */
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
- initfont(font);
+ initfont(&dc.font, font);
+ initfont(&dc.boldfont, boldfont);
sx = 0;
sy = 0;
sw = DisplayWidth(dpy, screen);