On Mon, 17 Feb 2014 15:27:24 +0100, Holger Levsen wrote:

> attached are my first stabs for improved config file examples, showing how to 
> make use of events... I'm a bit unsure how to differate between the default 
> config as it's now and this theme, as for me it's the default. So maybe just 
> stick these two files into /usr/share/fdpowermon/examples/ - together with a 
> small README?
> 
> cc:ing Gregor, maybe he has some awesome idea on this :)

Not sure if I have awesome ideas :)
But I'm happy to share what I have.

I prefer to have my personal config in my $HOME, and to define a
separate theme:

% ls -1 ~/.config/fdpowermon 
theme.cfg
theme.pl

== theme.cfg ==

[gregoa]
steps = 11
dir = /usr/local/share/icons/gnome-colors-common/22x22/notifications
discharging = 
9:notification-battery-000.png,19:notification-battery-010.png,29:notification-battery-020.png,39:notification-battery-030.png,49:notification-battery-040.png,59:notification-battery-050.png,69:notification-battery-060.png,79:notification-battery-070.png,89:notification-battery-080.png,99:notification-battery-090.png,100:notification-battery-100.png
charging = 
9:notification-battery-000-plugged.png,19:notification-battery-010-plugged.png,29:notification-battery-020-plugged.png,39:notification-battery-030-plugged.png,49:notification-battery-040-plugged.png,59:notification-battery-050-plugged.png,69:notification-battery-060-plugged.png,79:notification-battery-070-plugged.png,89:notification-battery-080-plugged.png,99:notification-battery-090-plugged.png,100:notification-battery-100-plugged.png

== theme.pl ==

my $theme = fdpowermon::theme::get_theme("gregoa");

$theme->set_event( 0, \&action_discharging, 'd' );

sub action_discharging {
    my ( $percent, $state ) = @_;

    #print STDERR "percent: $percent, state: $state\n";

    return unless defined $state   && $state == 0;     # discharging
    return unless defined $percent && $percent <= 5;
    system("lock-hibernate");
}

1;

====

[`lock-hibernate' is a script that finally calls `sudo pm-hibernate']


> After having looked at the manpage again, maybe stick these two files as 
> _complete_ examples in the manpage? (incl. the comments...)

I'd rather put the example files as examples into
/usr/share/doc/fdpowermon/examples/ instead of into the manpage.
Copying files is simpler than copying text out of formatted *roff :)

I guess, without having tested it now, that a simple
/usr/share/doc/fdpowermon/examples/theme.pl like that should be
/enough:

===

# Copy this file to ~/.config/fdpowermon/theme.pl.
#
# If you don't like the 'default' theme, define a new one by copying
# /etc/fdpowermon/theme.cfg to ~/.config/fdpowermon/theme.cfg and
# renaming/adjusting the 'default' theme there to something new.
# Don't forget to replace "default" below with your new theme name.

# define a suspend action
sub suspend {
    system("sudo pm-suspend");
}

# initialize our theme, from /etc/fdpowermon/theme.cfg or
# ~/.config/fdpowermon/theme.cfg
my $theme = fdpowermon::theme::get_theme("default");

# on the first discharge event (0 = first in the index, "d" for
# discharge), call the "suspend" sub defined above
$theme->set_event( 0, \&suspend, 'd' );

===                                       


Reading through the manpage again it seems accurate; but I guess
that's easier to say after having found out how to write the .cfg and
.pl files :)
(And I remember that I needed some tries initially. But I think that
was before Wouter spelt out the necessary steps.)
 

Cheers,
gregor



-- 
 .''`.  Homepage: http://info.comodo.priv.at/ - OpenPGP key 0xBB3A68018649AA06
 : :' : Debian GNU/Linux user, admin, and developer  -  http://www.debian.org/
 `. `'  Member of VIBE!AT & SPI, fellow of the Free Software Foundation Europe
   `-   NP: Supertramp: Aubade And I Am Not Like Other

Attachment: signature.asc
Description: Digital signature

Reply via email to