Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ sysinfo_update()

/* get swap status */
sysinfo.swap_used = sysinfo.swap_total = 0;
if ((nswaps = swapctl(SWAP_NSWAP, 0, 0)) == 0) {
if ((nswaps = swapctl(SWAP_NSWAP, 0, 0)) != 0) {
if ((swapdev = calloc(nswaps, sizeof(*swapdev))) == NULL)
err(1, "sysinfo update: swapdev calloc failed (%d)", nswaps);
if (swapctl(SWAP_STATS, swapdev, nswaps) == -1)
Expand Down Expand Up @@ -512,7 +512,7 @@ sysinfo_close()
}

int
cpu_draw(int cpu, XColor color, int x, int y)
cpu_draw_one(int cpu, XColor color, int x, int y)
{
static char str[1000];
static char *cpuStateNames[] = { "u", "n", "s", "i", "I" };
Expand Down Expand Up @@ -587,6 +587,23 @@ cpu_draw(int cpu, XColor color, int x, int y)
return x - startx;
}

int
cpu_draw(XColor color, int x, int y)
{
int cpu, startx;
int nw, spacing = 10;
static int width = 0;

startx = x;
for (cpu = 0; cpu < sysinfo.ncpu; cpu++) {
nw = cpu_draw_one(cpu, COLOR_WHITE, x, y) + spacing;
width = nw > width ? nw : width;
x += width;
}
x -= spacing; /* trailing spacing */
return x - startx;
}

int
mem_draw(XColor color, int x, int y)
{
Expand Down Expand Up @@ -696,7 +713,18 @@ time_draw(XColor color, int x, int y)
strftime(timestr, sizeof(timestr), time_fmt, localtime(&now));

/* XXX hack to right-align it - rethink a more general way for this */
width = XTextWidth(XINFO.font, timestr, strlen(timestr));
width = XTextWidth(XINFO.font, timestr, strlen(timestr)) + 2;
return render_text(color, XINFO.width - width, y, timestr);
}

int
border_draw(XColor color, int x, int y)
{
int bw = XINFO.border;
if (!bw)
return 0;
XSetForeground(XINFO.disp, XINFO.gc, color.pixel);
XSetLineAttributes(XINFO.disp, XINFO.gc, bw, LineSolid, CapNotLast, JoinMiter);
XDrawRectangle(XINFO.disp, XINFO.buf, XINFO.gc, bw/2, bw/2, XINFO.width-bw, XINFO.height-bw);
return 0;
}
3 changes: 2 additions & 1 deletion stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ void sysinfo_close();

int volume_draw(XColor c, int x, int y);
int power_draw(XColor c, int x, int y);
int cpu_draw(int cpu, XColor c, int x, int y);
int cpu_draw(XColor c, int x, int y);
int mem_draw(XColor c, int x, int y);
int procs_draw(XColor c, int x, int y);
int time_draw(XColor c, int x, int y);
int border_draw(XColor c, int x, int y);

#endif
4 changes: 4 additions & 0 deletions xstatbar.1
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ edit the source.
.Pp
The following options are supported:
.Bl -tag -width Fl
.It Fl b Ar width
Inner border width, in pixels.
.Pp
The default is 0.
.It Fl x Ar offset
The x coordinate, in pixels, of the upper-left corner of the window.
.Pp
Expand Down
Loading