You are not logged in.

#1 2023-03-19 03:48:26

lukem93
Member
Registered: 2023-03-19
Posts: 1

Alternative to cbatticon that displays live percentage in, not an icon

I am running JWM as my window manager on Arch.

I am looking for as lightweight of a battery monitor I can get that shows the battery percentage live in the system tray.

The common recommendation is to use cbatticon as a lightweight battery monitor, but I don't want an icon. I just want "42%" etc. I know cbatticon does this when you hover over it, but I would like it displayed in the tray at all times.

I am also aware of batti, but it gives a segmentation fault when I try to run it.

Can cbatticon be made to do this (relatively easily without knowing C and editting the source)?

If not, is there a lightweight battery monitory for the tray that does this? Alternatively, is there a program that will display bash output as text in the tray? Then I could just read from /sys/class/power_supply/BAT0/capacity at intervals of 10 seconds and display the output.

Are there any packages on Arch that will do this?

Offline

#2 2023-03-19 16:51:55

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: Alternative to cbatticon that displays live percentage in, not an icon

What does --list-icon-types report for cbatticon? If "notification" is available, then running it with --icon-type notification should show different icons for 20, 40, 60, 80 or 100%, if I interpret the code correctly:

static gchar* get_icon_name (gint state, gint percentage)
{
...
        if (configuration.icon_type == BATTERY_ICON_NOTIFICATION) {
                 if (percentage <= 20)  g_strlcat (icon_name, "-020", STR_LTH);
            else if (percentage <= 40)  g_strlcat (icon_name, "-040", STR_LTH);
            else if (percentage <= 60)  g_strlcat (icon_name, "-060", STR_LTH);
            else if (percentage <= 80)  g_strlcat (icon_name, "-080", STR_LTH);
            else                        g_strlcat (icon_name, "-100", STR_LTH);

                 if (state == CHARGING) g_strlcat (icon_name, "-plugged", STR_LTH);
            else if (state == CHARGED)  g_strlcat (icon_name, "-plugged", STR_LTH);
        } else {
                 if (percentage <= 20)  g_strlcat (icon_name, "-caution", STR_LTH);
            else if (percentage <= 40)  g_strlcat (icon_name, "-low", STR_LTH);
            else if (percentage <= 80)  g_strlcat (icon_name, "-good", STR_LTH);
            else                        g_strlcat (icon_name, "-full", STR_LTH);

                 if (state == CHARGING) g_strlcat (icon_name, "-charging", STR_LTH);
            else if (state == CHARGED)  g_strlcat (icon_name, "-charged", STR_LTH);
        }

Offline

#3 2023-03-19 17:07:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,741
Website

Re: Alternative to cbatticon that displays live percentage in, not an icon

An X11 system tray does not show text, it only shows icon images.  In theory a tray client could generate an image from input text and set this as a tray icon.  But in practice this may be pretty inefficient as you'd have to decide when / how often to regenerate images.  If your battery monitor sends a number to the tray client every second, should it generate a new image for that input every second?  Most of the time the value will not have changed, so this is wasteful.  And what if it drops from 100% to 99% but then goes back to 100%?  Should the 100% image be cached, or regenerated every time that input comes again?  If cached, how many images should be cached and for how long?

All of these are answerable questions for any specific use-case, but they're so varied that I doubt you will find any existing tool that does this.  Instead, tray clients that display "numbers" would bin the numbers into useful categories (e.g., "0-10%", "10-20%", etc) and have a pre-made image for each of these categories.  As the post above suggests, this is what cbatticon does, but instead of images of numbers, it uses representative icons.

Now setting all this aside, it sounds like you'd be much better suited to using a status bar display rather than a tray item as most status bar displays can take / display plain text.  I'm not familiar with jwm, but quite a few WMs that have trays have the tray itself as part of a broader bar which can have text displays.  Your best bet is to look for options outside of the tray.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2023-03-19 18:17:33

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: Alternative to cbatticon that displays live percentage in, not an icon

Take a look at jwmtools (in the AUR). I have not used this, but the github page says it has a battery status tray applet that shows percentage, and a trayscript applet that shows the output of a bash scipt in the tray.

https://github.com/kostelnik/jwmtools

Offline

Board footer

Powered by FluxBB