Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.windows.x > #625
| From | Anton Antimo <anton@safunu.org> |
|---|---|
| Newsgroups | comp.windows.x |
| Subject | Re: a battery monitor |
| Date | 2026-09-02 12:22 -0300 |
| Organization | A noiseless patient Spider |
| Message-ID | <874ig7oezo.fsf@safunu.org> (permalink) |
| References | <87v78oop87.fsf@safunu.org> <877bl48g2v.fsf@debian> |
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.
> 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 haven’t tested the code, but I assume
> you’re posting a working version, and the code looks fine at a glance,
> so I'm sure it’s fine.)
It's a working version.
Yeah---it's surprising how much code we end up writing for such a
hello-world, but we know it's code that must be written. I suppose
that's why people write higher-level graphical toolkits, but they
wouldn't teach me as much as Xlib does.
Back to comp.windows.x | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-01 14:28 -0300
Re: a battery monitor Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-02 00:52 -0300
Re: a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-02 12:22 -0300
Re: a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-11 16:58 -0300
Re: a battery monitor Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-02 21:45 +0000
Re: a battery monitor Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-03 12:34 +0800
Re: a battery monitor Eli the Bearded <*@eli.users.panix.com> - 2026-09-03 05:30 +0000
Re: a battery monitor Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-03 21:24 +0000
Re: a battery monitor Eli the Bearded <*@eli.users.panix.com> - 2026-09-04 02:51 +0000
Re: a battery monitor David Brown <david.brown@hesbynett.no> - 2026-09-03 09:28 +0200
Re: a battery monitor boltar@caprica.universe - 2026-09-03 15:55 +0000
Re: a battery monitor David Brown <david.brown@hesbynett.no> - 2026-09-04 09:07 +0200
Re: a battery monitor Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-04 15:14 +0800
Re: a battery monitor Lane W <cactus_DAC@yahoo.com> - 2026-09-04 05:32 -0600
Re: a battery monitor scott@slp53.sl.home (Scott Lurndal) - 2026-09-04 14:29 +0000
Re: a battery monitor Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-04 23:17 +0800
Re: a battery monitor boltar@caprica.universe - 2026-09-05 09:39 +0000
Re: a battery monitor gazelle@shell.xmission.com (Kenny McCormack) - 2026-09-04 12:05 +0000
Re: a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-02 18:48 -0300
csiph-web