ref: a256cd75fe9d07308b20d17ebf3558d85557360c
parent: 041131cb849af2044790e60839c491130aea52a3
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Feb 22 07:09:30 EST 2021
highlight clicked item
--- a/bar.c
+++ b/bar.c
@@ -13,7 +13,7 @@
Off = 3,
};
-static int wctl, owidth, width, twidth, bottom, bat, minheight, seplen, sepw;
+static int wctl, owidth, width, twidth, bottom, bat, minheight, seplen, sepw, hlitem;
static char sep[16], bats[16], *aux;
static char *pos = "rb", *dfmt = "YYYY/MM/DD WW hh:mm:ss", *items[64];
static int itemw[64], nitems;
@@ -127,6 +127,7 @@
Tmfmt tf;
Point p;
Tm tm;
+ int i;
r = screen->r;
@@ -142,6 +143,14 @@
}
draw(screen, r, cback, nil, ZP);
string(screen, p, ctext, ZP, f, s);
+ if(hlitem >= 0){
+ for(i = 0; i < hlitem; i++)
+ r.min.x += itemw[i];
+ r.max.x = r.min.x + itemw[i];
+ replclipr(screen, 0, r);
+ stringbg(screen, p, cback, ZP, f, s, ctext, ZP);
+ replclipr(screen, 0, screen->r);
+ }
split(s);
flushimage(display, 1);
@@ -209,10 +218,16 @@
{
int i, ix;
+ if(hlitem >= 0){
+ hlitem = -1;
+ return;
+ }
+
for(i = ix = 0; i < nitems; i++){
ix += itemw[i];
if(x <= ix){
fprint(1, "%d\t%s\n", buttons, items[i]);
+ hlitem = i;
break;
}
}
@@ -307,6 +322,7 @@
a[Eaux].c = chancreate(sizeof(s), 0);
a[Etimer].c = chancreate(sizeof(ulong), 0);
+ hlitem = -1;
aux = strdup("");
readbattery();
redraw();
@@ -326,8 +342,8 @@
}
break;
- case Emouse:
- if(m.buttons == 0 || m.buttons == oldbuttons)
+ case Emouse:
+ if(m.buttons == oldbuttons)
break;
clicked(m.xy.x-screen->r.min.x, m.buttons);
/* wet floor */