[amiwm] Add the basic battery info printing bits

* add a batteryinfo config option to enable whether or not to display
  the current battery info string

* populate that battery info string whenever we receive a battery
  update from the module

* document it all

This is very specific to a battery thing rather than a generic menu
widget thing, but I think I'll go and twiddle with this stuff a bit
more first and then work on a more generic "menu widget" thing later.

It'd be nice to have "menu bar things" like battery and the date/time
field on a linked list of "things".

There's also some bugs - notably, rendering artifacts when the
string length shrinks, and it only updating on the 'current' menu bar
(when you have multiple desktops visible at once.)  Those also
should be fixed for completeness. :-)
This commit is contained in:
Adrian Chadd
2022-05-15 19:36:03 -07:00
parent fc23b3e054
commit 2a9bd912a1
6 changed files with 33 additions and 5 deletions

11
menu.c
View File

@@ -37,6 +37,8 @@ extern struct Library *XLibBase;
#define CHECKED 2
#define DISABLED 4
char battery_status[128];
extern Display *dpy;
extern Cursor wm_curs;
extern XContext screen_context, client_context;
@@ -303,7 +305,7 @@ void redraw_item(struct Item *i, Window w)
XSetForeground(dpy, scr->menubargc, scr->dri.dri_Pens[BARDETAILPEN]);
XSetBackground(dpy, scr->menubargc, scr->dri.dri_Pens[BARBLOCKPEN]);
}
if(i->text)
if(i->text) {
#ifdef USE_FONTSETS
XmbDrawImageString(dpy, w, scr->dri.dri_FontSet,
scr->menubargc, (i->flags&CHECKIT)?1+scr->checkmarkspace:1,
@@ -312,8 +314,9 @@ void redraw_item(struct Item *i, Window w)
XDrawImageString(dpy, w, scr->menubargc, (i->flags&CHECKIT)?1+scr->checkmarkspace:1,
scr->dri.dri_Ascent+1, i->text, i->textlen);
#endif
else
} else {
XFillRectangle(dpy, w, scr->menubargc, 2, 2, m->width-10, 2);
}
if(i->sub) {
int x=m->width-6-scr->hotkeyspace-1+8;
#ifdef USE_FONTSETS
@@ -547,11 +550,11 @@ void redrawmenubar(Window w)
/*
* Update the battery indicator if it's enabled.
*/
if (1) {
if (prefs.battery_info) {
char battery_buf[512];
int l;
sprintf(battery_buf, "| Battery |");
sprintf(battery_buf, "| %s |", battery_status);
#ifdef USE_FONTSETS
l = XmbTextEscapement(scr->dri.dri_FontSet, battery_buf, strlen(battery_buf));
XmbDrawImageString(dpy, w, scr->dri.dri_FontSet, scr->menubargc,