~ft/bar

a256cd75fe9d07308b20d17ebf3558d85557360c — Sigrid Solveig Haflínudóttir 3 months ago 041131c
highlight clicked item
1 files changed, 19 insertions(+), 3 deletions(-)

M bar.c
M bar.c => bar.c +19 -3
@@ 13,7 13,7 @@ enum {
	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 @@ redraw(void)
	Tmfmt tf;
	Point p;
	Tm tm;
	int i;

	r = screen->r;



@@ 142,6 143,14 @@ redraw(void)
	}
	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 @@ clicked(int x, int buttons)
{
	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 @@ threadmain(int argc, char **argv)
	a[Eaux].c = chancreate(sizeof(s), 0);
	a[Etimer].c = chancreate(sizeof(ulong), 0);

	hlitem = -1;
	aux = strdup("");
	readbattery();
	redraw();


@@ 326,8 342,8 @@ threadmain(int argc, char **argv)
			}
			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 */