So, yes, the program is more like a progress bar to be used by some kind
of shell program. Here's how I've been using it. My system has this
program called acpi, which gives me battery information:
%acpi -b
Battery 0: Charging, 91%, 00:18:43 until charged
I run CWM, the calm window manager. So from my ~/xinitrc, I run:
while true; \
do acpi -b | awk '{printf("%d\n",$4)}' | tr -d '%,' && sleep 60; \
done | xbattery 220x40-0-0 &
Anton Antimo <anton@safunu.org> writes:
So, yes, the program is more like a progress bar to be used by some kind
of shell program. Here's how I've been using it. My system has this
program called acpi, which gives me battery information:
%acpi -b
Battery 0: Charging, 91%, 00:18:43 until charged
I run CWM, the calm window manager. So from my ~/xinitrc, I run:
while true; \
do acpi -b | awk '{printf("%d\n",$4)}' | tr -d '%,' && sleep 60; \
done | xbattery 220x40-0-0 &
This is a good idea!
X-Windows makes it a lot more trouble to write than it really ought to
be. In theory, it ought to be doable in much less code, but X really
makes your life hard there. (I havenrCOt tested the code, but I assume yourCOre posting a working version, and the code looks fine at a glance,
so I'm sure itrCOs fine.)
So, yes, xbattery.c (source code below) is able to read the desired
window geometry from the command line (as it's typical of X
programs).
On Tue, 01 Sep 2026 14:28:40 -0300, Anton Antimo wrote:
So, yes, xbattery.c (source code below) is able to read the desired
window geometry from the command line (as it's typical of X
programs).
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
On 03/09/2026 5:45 AM, Lawrence D'Oliveiro wrote:
On Tue, 01 Sep 2026 14:28:40 -0300, Anton Antimo wrote:
So, yes, xbattery.c (source code below) is able to read the desired
window geometry from the command line (as it's typical of X
programs).
Instead of writing all that C code, why not using a preexistingDear Lawrence,
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
What kind of /moron/ are you? Can't you understand that Anton is writ-
ing his code for his own amusement and education?
On Tue, 01 Sep 2026 14:28:40 -0300, Anton Antimo wrote:
So, yes, xbattery.c (source code below) is able to read the desired
window geometry from the command line (as it's typical of X
programs).
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
I wrote a battery monitor. The program watches its stdin for lines containing numbers that tell what is the current percentage of the
battery. You can see a picture of it on the lower right of the image at
https://archive.org/details/x11-battery-monitor
If you compile it, then how you can see a demonstration of it running
(using bash):
for i in $(seq 100 -5 0); do echo $i && sleep 0.5 ; done | ./xbattery
So, yes, the program is more like a progress bar to be used by some kind
of shell program. Here's how I've been using it. My system has this
program called acpi, which gives me battery information:
%acpi -b
Battery 0: Charging, 91%, 00:18:43 until charged
I run CWM, the calm window manager. So from my ~/xinitrc, I run:
while true; \
do acpi -b | awk '{printf("%d\n",$4)}' | tr -d '%,' && sleep 60; \
done | xbattery 220x40-0-0 &
So, yes, xbattery.c (source code below) is able to read the desired
window geometry from the command line (as it's typical of X programs).
Be kind with criticism---that's my first one.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/select.h>
#include <errno.h>
void draw(Display *d, Window w, GC gc, int p,
unsigned int width, unsigned int height,
unsigned long green, unsigned long red) {
XClearWindow(d, w);
if (p < 0) p = 0;
if (p > 100) p = 100;
int howmuch;
if (p >= 100)
howmuch = width;
else
howmuch = (width * p) / 100;
if (howmuch > 0) {
if (p <= 10) XSetForeground(d, gc, red); else XSetForeground(d, gc, green);
XFillRectangle(d, w, gc, 0, 0, howmuch, width);
}
}
On 02/09/2026 23:45, Lawrence DrCOOliveiro wrote:
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
The OP wrote a cross-post that was devoid of any C relevant content or >question for comp.lang.c. But he helpfully set follow-ups to a group
that presumably /is/ relevant - comp.windows.x. We already suffer from
far too many rambling off-topic threads, and suffer even more from some
of the obnoxious trolls that have followed. (To be clear, I am /not/ >counting the OP here!) If you want to give the OP advice on writing gui >programs for X, that's great - but please do so in a group that is >appropriate, and which the OP clearly thought was appropriate.
(For those in the other groups listed who might be wondering -
comp.lang.c is about the C /language/ - the language and the standards.
Just because a program happens to be written in C, does not mean it is >relevant or topical in the group, any more than a random post written in
the English language is topical for linguistics.languages.english.
There are millions of lines of C code written every day, and they cannot
all be topical in a single group. But if anyone wants to discuss
details of the language itself, comp.lang.c is the place to be.)
Lawrence is the sort of guy who always wants to have a reply.
On Thu, 3 Sep 2026 05:30:37 -0000 (UTC), Eli the Bearded wrote:
Lawrence is the sort of guy who always wants to have a reply.Technology is a means to an end, not an end in itself.
On Thu, 3 Sep 2026 09:28:51 +0200
David Brown <david.brown@hesbynett.no> gabbled:
On 02/09/2026 23:45, Lawrence DrCOOliveiro wrote:
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
The OP wrote a cross-post that was devoid of any C relevant content or
question for comp.lang.c.-a But he helpfully set follow-ups to a group
that presumably /is/ relevant - comp.windows.x.-a We already suffer
from far too many rambling off-topic threads, and suffer even more
from some of the obnoxious trolls that have followed.-a (To be clear, I
am /not/ counting the OP here!)-a If you want to give the OP advice on
writing gui programs for X, that's great - but please do so in a group
that is appropriate, and which the OP clearly thought was appropriate.
(For those in the other groups listed who might be wondering -
comp.lang.c is about the C /language/ - the language and the
standards. Just because a program happens to be written in C, does not
mean it is relevant or topical in the group, any more than a random
post written in the English language is topical for
linguistics.languages.english. There are millions of lines of C code
written every day, and they cannot all be topical in a single group.
But if anyone wants to discuss details of the language itself,
comp.lang.c is the place to be.)
Right, because usenet these days is overflowing with posts and wouldn't
cope
with many more.
On 03/09/2026 17:55, boltar@caprica.universe wrote:
On Thu, 3 Sep 2026 09:28:51 +0200
David Brown <david.brown@hesbynett.no> gabbled:
On 02/09/2026 23:45, Lawrence DrCOOliveiro wrote:
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
The OP wrote a cross-post that was devoid of any C relevant content
or question for comp.lang.c.-a But he helpfully set follow-ups to a
group that presumably /is/ relevant - comp.windows.x.-a We already
suffer from far too many rambling off-topic threads, and suffer even
more from some of the obnoxious trolls that have followed.-a (To be
clear, I am /not/ counting the OP here!)-a If you want to give the OP
advice on writing gui programs for X, that's great - but please do so
in a group that is appropriate, and which the OP clearly thought was
appropriate.
(For those in the other groups listed who might be wondering -
comp.lang.c is about the C /language/ - the language and the
standards. Just because a program happens to be written in C, does
not mean it is relevant or topical in the group, any more than a
random post written in the English language is topical for
linguistics.languages.english. There are millions of lines of C code
written every day, and they cannot all be topical in a single group.
But if anyone wants to discuss details of the language itself,
comp.lang.c is the place to be.)
Right, because usenet these days is overflowing with posts and
wouldn't cope
with many more.
Many of us would rather have just a few interesting threads, than a few interesting threads hidden amongst piles of rubbish.
I'm okay with threads drifting a bit off-topic - and even with threads
that are a bit off-topic to start with.-a But they should at least have / some/ relation to C as a programming language.-a I'm not okay with AI
slop, endless discussions on wildly different languages, cross-posts to totally random groups, posts that are just curses and insults, or people
who jump into a community of regulars who have been there for decades
and start trying to tell them what they should and should not talk
about.-a (Note - that was not a reference to you.)-a That's just rude and anti-social.
1: a person who puts on a false appearance of virtue or religion
On 03/09/2026 17:55, boltar@caprica.universe wrote:
On Thu, 3 Sep 2026 09:28:51 +0200
David Brown <david.brown@hesbynett.no> gabbled:
On 02/09/2026 23:45, Lawrence DrCOOliveiro wrote:
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
The OP wrote a cross-post that was devoid of any C relevant content
or question for comp.lang.c.-a But he helpfully set follow-ups to a
group that presumably /is/ relevant - comp.windows.x.-a We already
suffer from far too many rambling off-topic threads, and suffer even
more from some of the obnoxious trolls that have followed.-a (To be
clear, I am /not/ counting the OP here!)-a If you want to give the OP
advice on writing gui programs for X, that's great - but please do so
in a group that is appropriate, and which the OP clearly thought was
appropriate.
(For those in the other groups listed who might be wondering -
comp.lang.c is about the C /language/ - the language and the
standards. Just because a program happens to be written in C, does
not mean it is relevant or topical in the group, any more than a
random post written in the English language is topical for
linguistics.languages.english. There are millions of lines of C code
written every day, and they cannot all be topical in a single group.
But if anyone wants to discuss details of the language itself,
comp.lang.c is the place to be.)
Right, because usenet these days is overflowing with posts and
wouldn't cope
with many more.
Many of us would rather have just a few interesting threads, than a few interesting threads hidden amongst piles of rubbish.
I'm okay with threads drifting a bit off-topic - and even with threads
that are a bit off-topic to start with.-a But they should at least have /some/ relation to C as a programming language.-a I'm not okay with AI
slop, endless discussions on wildly different languages, cross-posts to totally random groups, posts that are just curses and insults, or people
who jump into a community of regulars who have been there for decades
and start trying to tell them what they should and should not talk
about.-a (Note - that was not a reference to you.)-a That's just rude and anti-social.
Right, because usenet these days is overflowing with posts and wouldn't cope >with many more.
Newflash - threads drift, stop being so uptight about it.
*sigh*
On 03/09/2026 17:55, boltar@caprica.universe wrote:
On Thu, 3 Sep 2026 09:28:51 +0200
David Brown <david.brown@hesbynett.no> gabbled:
On 02/09/2026 23:45, Lawrence DrCOOliveiro wrote:
Instead of writing all that C code, why not using a preexisting
GUI utility that can display simple widgets like progress bars,
under the control of a shell script?
The OP wrote a cross-post that was devoid of any C relevant content or
question for comp.lang.c.-a But he helpfully set follow-ups to a group
that presumably /is/ relevant - comp.windows.x.-a We already suffer
from far too many rambling off-topic threads, and suffer even more
from some of the obnoxious trolls that have followed.-a (To be clear, I >>> am /not/ counting the OP here!)-a If you want to give the OP advice on
writing gui programs for X, that's great - but please do so in a group
that is appropriate, and which the OP clearly thought was appropriate.
(For those in the other groups listed who might be wondering -
comp.lang.c is about the C /language/ - the language and the
standards. Just because a program happens to be written in C, does not
mean it is relevant or topical in the group, any more than a random
post written in the English language is topical for
linguistics.languages.english. There are millions of lines of C code
written every day, and they cannot all be topical in a single group.
But if anyone wants to discuss details of the language itself,
comp.lang.c is the place to be.)
Right, because usenet these days is overflowing with posts and wouldn't
cope
with many more.
Many of us would rather have just a few interesting threads, than a few >interesting threads hidden amongst piles of rubbish.
David Brown <david.brown@hesbynett.no> writes:
On 03/09/2026 17:55, boltar@caprica.universe wrote:<snip>
On Thu, 3 Sep 2026 09:28:51 +0200
Many of us would rather have just a few interesting threads, than a few
interesting threads hidden amongst piles of rubbish.
Keep in mind that this thread is cross-posted to three different
groups.
It's the cross-posting idiots that start this; I've removed
the unnecessary groups (including comp.windows.x) from this reply.
one knows is the only proper windowing protocol in existence! Nobody
cares about Wayland anyway.
Kragen Javier Sitaker <kragen@canonical.org> writes:
Anton Antimo <anton@safunu.org> writes:
So, yes, the program is more like a progress bar to be used by some kind >>> of shell program. Here's how I've been using it. My system has this
program called acpi, which gives me battery information:
%acpi -b
Battery 0: Charging, 91%, 00:18:43 until charged
I run CWM, the calm window manager. So from my ~/xinitrc, I run:
while true; \
do acpi -b | awk '{printf("%d\n",$4)}' | tr -d '%,' && sleep 60; \
done | xbattery 220x40-0-0 &
This is a good idea!
But take notice of a bug in this script above. With the &&-conditional
above the script ends up consuming a lot of CPU if something goes wrong
in the previous pipeline. We want to sleep regardless of what happens before---or at least exit 1 if the pipeline fails.
Another bug is that the pipeline fails when you plug power in. The percentage is not always at field number 4, so the AWK script is
naive.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 02:20:14 |
| Calls: | 1,194 |
| Files: | 1,353 |
| D/L today: |
2 files (1,590K bytes) |
| Messages: | 291,157 |