ref: 0574a2b65135d7ae63cd9910f8fed6f1d0838289
parent: f637e7de9dc3c1bb8e90590ab2956fe9d86a2d02
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Dec 4 07:11:04 EST 2020
horizontally centered too (thanks jmi2k)
--- a/README.md
+++ b/README.md
@@ -4,6 +4,7 @@
the screen. Bar can be forced into background with `-b` option.
Corner can be chosen by specifying it with `-p` option, the value is
first letters of top/bottom and left/right, ie `lt` would place it in
-the left top of the screen.
+the left top of the screen. Bar is centered horizontally if no "top"
+or "bottom" specified for its position.
![screenshot](scr.png)
--- a/bar.c
+++ b/bar.c
@@ -79,9 +79,12 @@
if(pos[0] == 'l' || pos[1] == 'l'){
minx = 0;
maxx = MAX(100, Borderwidth+Off+width+Off+Borderwidth);
- }else{
+ }else if(pos[0] == 'r' || pos[1] == 'r'){
minx = MAX(100, w-(Borderwidth+Off+width+Off+Borderwidth));
maxx = w;
+ }else{
+ minx = (w-MAX(100, Borderwidth+Off+width+Off+Borderwidth))/2;
+ maxx = (w+MAX(100, Borderwidth+Off+width+Off+Borderwidth))/2;
}
snprint(t, sizeof(t), "resize -r %d %d %d %d", minx, miny, maxx, maxy);
if(fprint(wctl, "%s", t) < 0)
@@ -117,9 +120,12 @@
if(pos[0] == 'l' || pos[1] == 'l'){
snprint(s, sizeof(s), "%τ%s", tf, bats);
p.x = r.min.x + Off;
- }else{
+ }else if(pos[0] == 'r' || pos[1] == 'r'){
snprint(s, sizeof(s), "%s%τ", bats, tf);
p.x = r.max.x - (stringwidth(f, s) + Off);
+ }else{
+ snprint(s, sizeof(s), "%s%τ", bats, tf);
+ p.x = r.min.x + Off;
}
p.y = (pos[0] == 't' || pos[1] == 't') ? r.max.y - (f->height + Off) : r.min.y + Off;
string(screen, p, ctext, ZP, f, s);
@@ -155,7 +161,7 @@
static void
usage(void)
{
- fprint(2, "usage: %s [-b] [-p lt|rt|lb|rb]\n", argv0);
+ fprint(2, "usage: %s [-b] [-p lt|t|rt|lb|b|rb]\n", argv0);
threadexitsall("usage");
}