Re: [dev] How to monitor battery status

2011-07-04 Thread Ethan Grammatikidis
On Mon, 20 Jun 2011 06:47:35 -0400
Kurt H Maier  wrote:

> On Mon, Jun 20, 2011 at 5:59 AM, ilf  wrote:
> > I have done this the /proc/acpi/battery/BAT0/state | shell way for years and
> > found it to be way more resource intense then calling acpi -b.
> >
> > Let's face it, the Shell/Perl/Python/whatever scripting is relatively easy,
> > but very inefficient.
> 
> I update my status bar every 50 seconds.  I sacrifice, for this,
> approximately thirty seconds of battery life on a battery that lasts
> on the order of seven hours to a charge.  I'm not particularly
> concerned by this 'inefficiency,' to be honest.

Heh, thanks for that, the talk of inefficiency had me worried for a minute. I 
should know better, I've observed most usage of the word "inefficiency" is 
worthless talk anyway, particularly in a computing context.

My offering; I made this to run in 9vx when I run it full-screen for long 
periods. NOTE: has some issues with a kfs-root due to the fid bug in 9vx.

#!/bin/rc

# battery monitor for recent Linux machines
# if running under p9p, remove all '#Z'
# if 9vx, canopenpath must be unset

fn cd

cd '#Z'/sys/class/power_supply/BAT0

bat = `{hoc -e `{cat charge_now } ^ / ^ `{cat charge_full} ^ '*100' | sed 
's/\..*//'}

charging=''
cd '#Z'/sys/class/power_supply/AC0

if(~ `{cat online} 1) {
if(~ $bat 100)
charging = ' charged'
if not
charging = ' charging'
}

echo $"bat ^ % ^ $charging



Re: [dev] How to monitor battery status

2011-06-21 Thread Stefan Mark
On 20.06.2011 12:17, Stefan Mark wrote:
> Just two Days ago i found a nice and relatively complete one in this
> Mailinglist. Since then, im tinkering around with it, with the intention
> to make it more or less a replacement for my old perl project. It has
> some monitors and libnotify support. If there is interest, i could make
> a svn.
> 
If anyone is interested, here is the svn:
https://svn.0mark.unserver.de/dwmbarthingy/



Re: [dev] How to monitor battery status

2011-06-20 Thread Hiltjo Posthuma
On Mon, Jun 20, 2011 at 7:15 PM, Connor Lane Smith  wrote:
>
> My point was that this is unnecessary: is your screen able to display
> more than, say, 8192 characters (a common value for BUFSIZ) on a
> single line? And even if so, why are you piping an essay into your
> status bar anyway?
>

Hah, then I fully agree with you (I kinda missed the context here, sorry) :)



Re: [dev] How to monitor battery status

2011-06-20 Thread Rafa Garcia Gallego
A while back I put together a crappy C monitor, which I still use to the day.

Find the .c attached, compile with -lX11 as normal, peruse at will.

Cheers,
Rafa.
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define BATTERY "BAT1"
#define BATT_INFO_PATH  "/proc/acpi/battery/"BATTERY"/info"
#define BATT_STATE_PATH "/proc/acpi/battery/"BATTERY"/state"
#define BATT_FULL_REGEX "^last full capacity:[ ]+([0-9]*) .*$"
#define BATT_CUR_REGEX  "^remaining capacity:[ ]+([0-9]*) .*$"
#define DATE_FORMAT "%H:%M (%Z) - %a %d.%m.%Y"
#define BUFFER_SIZE 4096
#define STATUS_SIZE 256

static char *buf;
static regex_t *batt_full_re, *batt_cur_re;
static Display *dpy;
static Window root;
static XTextProperty name;

void update_status(char *c) {
	name.value=(unsigned char*)c;
	name.nitems=strlen(c);
	XSetWMName(dpy, root, &name);
	XSync(dpy, False);
}

void cleanup(void) {
	regfree(batt_full_re);
	regfree(batt_cur_re);
	free(buf);
}

void die(int unused) {
	update_status("dwmrc died!");
	exit(EXIT_FAILURE);
}

int read_batt(const char *batt_path, const regex_t *batt_re) {
	FILE *f;
	int batt_total = -1;
	regmatch_t result_re[2];

	f = fopen(batt_path, "r");
	fread(buf, 1, BUFFER_SIZE, f);
	regexec(batt_re, buf, 2, result_re, 0);
	if(result_re[1].rm_so != -1 && result_re[1].rm_eo != -1) {
		buf[result_re[1].rm_eo]='\0';
		batt_total = atoi(buf+result_re[1].rm_so);
	}
	fclose(f);
	return batt_total;
}

int main(int argc, char **argv) {
	time_t cur_t;
	struct tm *cur_lt;
	char *status;
	int batt_full, batt_cur;
	int n;

	if( !(dpy = XOpenDisplay(NULL)) ||
		!(buf = calloc(1, sizeof(char)*BUFFER_SIZE)) ||
		!(status = calloc(1, sizeof(char)*STATUS_SIZE)) ||
		!(batt_full_re = calloc(1, sizeof(regex_t))) ||
		!(batt_cur_re = calloc(1, sizeof(regex_t))) ) die(0);

	regcomp(batt_full_re, BATT_FULL_REGEX, REG_EXTENDED|REG_NEWLINE);
	regcomp(batt_cur_re,  BATT_CUR_REGEX, REG_EXTENDED|REG_NEWLINE);

	root = RootWindow(dpy, DefaultScreen(dpy));
	name.encoding=XA_STRING;
	name.format=8;

	signal(SIGINT, die);
	signal(SIGILL, die);
	signal(SIGTERM, die);

	while(1) {
		batt_full=read_batt(BATT_INFO_PATH, batt_full_re);
		batt_cur =read_batt(BATT_STATE_PATH, batt_cur_re);

		if(batt_full > 0 && batt_cur >= 0) n=snprintf(status, STATUS_SIZE, "%3d%% -- ", (100*batt_cur/batt_full));
		else n=snprintf(status, STATUS_SIZE, " NAN -- ");

		cur_t = time(NULL);
		cur_lt = localtime(&cur_t);
		strftime(&status[n], STATUS_SIZE-n, DATE_FORMAT, cur_lt);
		update_status(status);

		sleep(10);
	}

	return EXIT_SUCCESS;
}



Re: [dev] How to monitor battery status

2011-06-20 Thread Christoph Lohmann

Good evening,

ilf wrote:

On 06-20 10:43, Stefan Mark wrote:

But i think think this is a better solution:
http://dwm.suckless.org/dwmstatus/


Unfortunately, this promise is not kept:


This page will give you a barebone dwmstatus project and show examples on
how to extend it to your needs.


actually, dwmstatus was intended to be such a unification or an
example, how it could be done. The example source, that is hosted
there includes all the needs I had for my statusbar, so I lost
interest in developing the wiki site a bit further.

Dwmstatus is currently using a rather expensive implementation,
that is using malloc() for all parts of the status string and then
prints them together. I found this to be the most modular way for
such a code. Of course a static buffer could be used.

The wiki page should rather read »This is an example for a status
bar C application. It shows a barebone, how to construct it. For
stopping the doubling of work, to find out how to gather various
system information in the statusbar, please add your code right on
this wiki page. See [wiki] for how to edit this wiki.«

So you are free to change the wiki page or add further simple
examples to collect system information in C.


Sincerely,

Christoph Lohmann



Re: [dev] How to monitor battery status

2011-06-20 Thread Connor Lane Smith
On 20 June 2011 18:05, Hiltjo Posthuma  wrote:
> getline / getdelim (re)allocates buffers though. But yes a custom
> function with fgets would be more compatible.

My point was that this is unnecessary: is your screen able to display
more than, say, 8192 characters (a common value for BUFSIZ) on a
single line? And even if so, why are you piping an essay into your
status bar anyway?

cls



Re: [dev] How to monitor battery status

2011-06-20 Thread Hiltjo Posthuma
On Mon, Jun 20, 2011 at 6:06 PM, Connor Lane Smith  wrote:
>
> Please don't encourage things like this. getline() is available in
> POSIX 2008; though I suspect the far more portable fgets() would
> suffice.
>

getline / getdelim (re)allocates buffers though. But yes a custom
function with fgets would be more compatible.



Re: [dev] How to monitor battery status

2011-06-20 Thread Connor Lane Smith
Hey,

On 20 June 2011 12:25, Kurt Van Dijck  wrote:
> #ifndef _GNU_SOURCE
> #define _GNU_SOURCE
> #endif

Please don't encourage things like this. getline() is available in
POSIX 2008; though I suspect the far more portable fgets() would
suffice.

Thanks,
cls



Re: [dev] How to monitor battery status

2011-06-20 Thread Kurt Van Dijck
On Mon, Jun 20, 2011 at 09:24:25AM -0400, Andrew Hills wrote:
> On Mon, Jun 20, 2011 at 8:40 AM, Kurt Van Dijck  wrote:
> > I missed (and still do not see)
> > how to make xsetroot(1) read from stdin, line by line.
> 
> xsetroot -name "`my_commands_that_write_to_stdout`"
> 
> > That's why (I thought) that scripts spawn xsetroot(1) each time.
> 
> They wouldn't need to run your C program each time?

it would do
$ while true; do my_commands_that_write_to_stdout; done | stdin2xroot
as a replacement,

and when my_commands_that_write_to_stdout would be a single program
that emits a line every now & then, you would not spawn processes at all.

That indeed is the only advantage of my program :-)
> 
> --Andrew Hills
> 



Re: [dev] How to monitor battery status

2011-06-20 Thread Bartosz Nitkiewicz
Thx to all for hints. I put acpi -b |tr -d ','|awk '{print $4}' onto my old
script and everythig works fine.
Maby i'll be usefull for somebody

git://github.com/dziq/configs.git

2011/6/20 Kurt Van Dijck 

> On Mon, Jun 20, 2011 at 01:59:57PM +0200, ilf wrote:
> > On 06-20 13:25, Kurt Van Dijck wrote:
> > >This program allows me to put 'whatever I can create on stdout' to the
> statusbar
> >
> > Euh yeah, that's what we use xsetroot(1) for.
>
> I missed (and still do not see)
> how to make xsetroot(1) read from stdin, line by line.
> That's why (I thought) that scripts spawn xsetroot(1) each time.
> >
>
>


-- 
Bartosz Nitkiewicz


Re: [dev] How to monitor battery status

2011-06-20 Thread Andrew Hills
On Mon, Jun 20, 2011 at 8:40 AM, Kurt Van Dijck  wrote:
> I missed (and still do not see)
> how to make xsetroot(1) read from stdin, line by line.

xsetroot -name "`my_commands_that_write_to_stdout`"

> That's why (I thought) that scripts spawn xsetroot(1) each time.

They wouldn't need to run your C program each time?

--Andrew Hills



Re: [dev] How to monitor battery status

2011-06-20 Thread Kurt Van Dijck
On Mon, Jun 20, 2011 at 01:59:57PM +0200, ilf wrote:
> On 06-20 13:25, Kurt Van Dijck wrote:
> >This program allows me to put 'whatever I can create on stdout' to the 
> >statusbar
> 
> Euh yeah, that's what we use xsetroot(1) for.

I missed (and still do not see)
how to make xsetroot(1) read from stdin, line by line.
That's why (I thought) that scripts spawn xsetroot(1) each time.
> 



Re: [dev] How to monitor battery status

2011-06-20 Thread ilf

On 06-20 13:25, Kurt Van Dijck wrote:

This program allows me to put 'whatever I can create on stdout' to the statusbar


Euh yeah, that's what we use xsetroot(1) for.

The problem is the scripting before that setp, aquiring the "whatever I 
can create on stdout".


--
ilf

Über 80 Millionen Deutsche benutzen keine Konsole. Klick dich nicht weg!
-- Eine Initiative des Bundesamtes für Tastaturbenutzung


signature.asc
Description: Digital signature


Re: [dev] How to monitor battery status

2011-06-20 Thread Kurt Van Dijck
On Mon, Jun 20, 2011 at 12:17:58PM +0200, Stefan Mark wrote:
> On 20.06.2011 11:59, ilf wrote:
> > On 06-19 22:55, Erik Hahn wrote:
> >> http://dwm.suckless.org/scripts/simple_monitors
> > 
> > I have done this the /proc/acpi/battery/BAT0/state | shell way for years
> > and found it to be way more resource intense then calling acpi -b.
> > 
> > Let's face it, the Shell/Perl/Python/whatever scripting is relatively
> > easy, but very inefficient.
> > 

This program allows me to put 'whatever I can create on stdout' to the statusbar

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include 
#include 

#include 

int main (int argc, char *argv[]) {
int ret;
Display *dpy;
Window root;
const char *display;
char *line = 0;
size_t size = 0;


/* open display */
display = getenv("DISPLAY") ?: ":0";
dpy = XOpenDisplay(display);
if (!dpy) {
fprintf(stderr, "Unable to open display '%s'\n", display);
exit(1);
}
root = RootWindow(dpy, DefaultScreen(dpy));

while (1) {
ret = getline(&line, &size, stdin);
if (ret < 0)
break;
XStoreName(dpy, root, line);
XSync(dpy, False);
}
return 0;
}




Re: [dev] How to monitor battery status

2011-06-20 Thread Stefan Mark
On 20.06.2011 12:47, Kurt H Maier wrote:
> On Mon, Jun 20, 2011 at 5:59 AM, ilf  wrote:
>> I have done this the /proc/acpi/battery/BAT0/state | shell way for years and
>> found it to be way more resource intense then calling acpi -b.
>>
>> Let's face it, the Shell/Perl/Python/whatever scripting is relatively easy,
>> but very inefficient.
> 
> I update my status bar every 50 seconds.  I sacrifice, for this,
> approximately thirty seconds of battery life on a battery that lasts
> on the order of seven hours to a charge.  I'm not particularly
> concerned by this 'inefficiency,' to be honest.
> 
On one of my system im really concerned about the ram usage.
But mostly its because i dont like to waste resources. It just nags me
having a perl script running that uses twice the memory as the window
manager just to display some status information. And it adds up. 2 for
the status, 6 for a python based notifier, maybe a wallpaper changer or
a udev daemon...



Re: [dev] How to monitor battery status

2011-06-20 Thread Kurt H Maier
On Mon, Jun 20, 2011 at 5:59 AM, ilf  wrote:
> I have done this the /proc/acpi/battery/BAT0/state | shell way for years and
> found it to be way more resource intense then calling acpi -b.
>
> Let's face it, the Shell/Perl/Python/whatever scripting is relatively easy,
> but very inefficient.

I update my status bar every 50 seconds.  I sacrifice, for this,
approximately thirty seconds of battery life on a battery that lasts
on the order of seven hours to a charge.  I'm not particularly
concerned by this 'inefficiency,' to be honest.

-- 
# Kurt H Maier



Re: [dev] How to monitor battery status

2011-06-20 Thread Jukka Ruohonen
On Sun, Jun 19, 2011 at 10:51:46PM +0200, Bartosz Nitkiewicz wrote:
> I'm looking for a best way to monitor battery status in dwm. Any hints?

xbattbar,

http://iplab.naist.jp/member/suguru/xbattbar.html

But no idea whether it is suckless (i.e. haven't looked beyond the surface,
which I like).

- Jukka.



Re: [dev] How to monitor battery status

2011-06-20 Thread Stefan Mark
On 20.06.2011 11:59, ilf wrote:
> On 06-19 22:55, Erik Hahn wrote:
>> http://dwm.suckless.org/scripts/simple_monitors
> 
> I have done this the /proc/acpi/battery/BAT0/state | shell way for years
> and found it to be way more resource intense then calling acpi -b.
> 
> Let's face it, the Shell/Perl/Python/whatever scripting is relatively
> easy, but very inefficient.
> 
Indeed

> That's why I really like this approach:
> 
> On 06-20 10:43, Stefan Mark wrote:
>> But i think think this is a better solution:
>> http://dwm.suckless.org/dwmstatus/
> 
> Unfortunately, this promise is not kept:
> 
>> This page will give you a barebone dwmstatus project and show examples
>> on how to extend it to your needs.
> 
> It'd be cool to have a configurable C program to do what we're currently
> all scripting ourselves.
> 
Just two Days ago i found a nice and relatively complete one in this
Mailinglist. Since then, im tinkering around with it, with the intention
to make it more or less a replacement for my old perl project. It has
some monitors and libnotify support. If there is interest, i could make
a svn.



Re: [dev] How to monitor battery status

2011-06-20 Thread ilf

On 06-19 22:55, Erik Hahn wrote:

http://dwm.suckless.org/scripts/simple_monitors


I have done this the /proc/acpi/battery/BAT0/state | shell way for years 
and found it to be way more resource intense then calling acpi -b.


Let's face it, the Shell/Perl/Python/whatever scripting is relatively 
easy, but very inefficient.


That's why I really like this approach:

On 06-20 10:43, Stefan Mark wrote:

But i think think this is a better solution:
http://dwm.suckless.org/dwmstatus/


Unfortunately, this promise is not kept:

This page will give you a barebone dwmstatus project and show examples 
on how to extend it to your needs.


It'd be cool to have a configurable C program to do what we're currently 
all scripting ourselves.


FWIW, my relevant part from .xinitrc: http://pastebin.com/ShQYQri1

--
ilf

Über 80 Millionen Deutsche benutzen keine Konsole. Klick dich nicht weg!
-- Eine Initiative des Bundesamtes für Tastaturbenutzung


signature.asc
Description: Digital signature


Re: [dev] How to monitor battery status

2011-06-20 Thread Hadrian Węgrzynowski
On Mon, 20 Jun 2011 11:27:10 +0200
pancake  wrote:

>On 06/20/11 10:24, Hadrian Węgrzynowski wrote:
>> It's maybe not the best way, but I written small utility that uses
>> Linux /proc and /sys to take stats. Original source outputs cpu
>> usage, cpu freq, cpu temp, mem usage, battery status and gpu temp
>> for my thinkpad.
>> https://gitorious.org/stater
>> To configure it you must change source ;) You can remove wmfs
>> formatters.
>> I am not proficient in C and Makefile could be better and don't know
>> is it suckless enough.
>>
>this is thinkpad specific.
>

This is not true. As I said:
>> To configure it you must change source ;) You can remove wmfs
>> formatters.
But of course it needs few more changes than simply changing paths.

I use modified version of this on old Athlon XP 2600+ machine and my
Pentium Dual Core desktop.

You can rip off all but battery status checks and set proper paths.
Probably battery status will not need any changes on newer kernels with
ACPI_BATTERY, ACPI_SYSFS_POWER and SYSFS
(/sys/class/power_supply/BAT0/). 



Re: [dev] How to monitor battery status

2011-06-20 Thread pancake

On 06/20/11 10:24, Hadrian Węgrzynowski wrote:

On Sun, 19 Jun 2011 22:51:46 +0200
Bartosz Nitkiewicz  wrote:


Hello,
I'm looking for a best way to monitor battery status in dwm. Any hints?


It's maybe not the best way, but I written small utility that uses
Linux /proc and /sys to take stats. Original source outputs cpu usage,
cpu freq, cpu temp, mem usage, battery status and gpu temp for my
thinkpad.
https://gitorious.org/stater
To configure it you must change source ;) You can remove wmfs
formatters.
I am not proficient in C and Makefile could be better and don't know
is it suckless enough.


this is thinkpad specific.



Re: [dev] How to monitor battery status

2011-06-20 Thread Stefan Mark
On 19.06.2011 22:51, Bartosz Nitkiewicz wrote:
> Hello, 
> I'm looking for a best way to monitor battery status in dwm. Any hints?
> 
I use a extensible perl script
(https://svn.0mark.unserver.de/dwmd/branches/experimental/). Not
perfect, but easy to maintain and extend. The script features Monitors
for temp (acpi and lm-sensors), cpu clock, battery, wireless signal
strength, mpd and date. It also provied wallpaper changer and autostart.
Lacks documentation.

But i think think this is a better solution:
http://dwm.suckless.org/dwmstatus/



Re: [dev] How to monitor battery status

2011-06-20 Thread Hadrian Węgrzynowski
On Sun, 19 Jun 2011 22:51:46 +0200
Bartosz Nitkiewicz  wrote:

>Hello,
>I'm looking for a best way to monitor battery status in dwm. Any hints?
>

It's maybe not the best way, but I written small utility that uses
Linux /proc and /sys to take stats. Original source outputs cpu usage,
cpu freq, cpu temp, mem usage, battery status and gpu temp for my
thinkpad.
https://gitorious.org/stater
To configure it you must change source ;) You can remove wmfs
formatters.
I am not proficient in C and Makefile could be better and don't know
is it suckless enough.



Re: [dev] How to monitor battery status

2011-06-19 Thread Kurt H Maier
you can also do this by hand if you don't have acpi userspace installed

http://git.remotehost.co/web?p=USER/kurt/xorgstuff.git;a=blob;f=scripts/status.sh

-- 
# Kurt H Maier



Re: [dev] How to monitor battery status

2011-06-19 Thread Erik Hahn

On 19.06.2011 22:51, Bartosz Nitkiewicz wrote:

Hello,
I'm looking for a best way to monitor battery status in dwm. Any hints?

--
Bartosz Nitkiewicz

http://dwm.suckless.org/scripts/simple_monitors



Re: [dev] How to monitor battery status

2011-06-19 Thread J Thigpen (cdarwin)
On Sun, Jun 19, 2011 at 4:51 PM, Bartosz Nitkiewicz
 wrote:
> Hello,
> I'm looking for a best way to monitor battery status in dwm. Any hints?
>
> --
> Bartosz Nitkiewicz
>

xsetroot -name "`acpi -b |tr -d ','|awk '{print $4}'`"

I have something like this is a while loop in my .xinitrc