[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

View File

@@ -493,19 +493,34 @@ static void handle_module_cmd(struct module *m, char *data, int data_len)
case MCMD_UPDATE_BATTERY:
{
struct mcmd_update_battery *batt;
extern char battery_status[];
if (data == NULL) {
reply_module(m, NULL, -1);
break;
}
if (data_len != sizeof(struct mcmd_update_battery)) {
reply_module(m, NULL, -1);
break;
}
batt = (void *) data;
#if 0
fprintf(stderr, "%s: called, BATTERY, pct=%d, time=%d, ac=%d\n",
__func__,
batt->battery_pct,
batt->battery_time,
batt->battery_ac);
#endif
/* XXX TODO: update the battery menu thingy here */
/*
* XXX TODO: for now we're just populating a string here.
* Later on we should just store the current battery state
* somewhere (a key/value table would be nice!) and then
* the widget code can pull out its needed state to render.
*/
snprintf(battery_status, 128, "%d pct%s", batt->battery_pct,
batt->battery_ac == 1 ? " A" : " -");
reply_module(m, NULL, 0);
break;