So in my desire to map some ACPI buttons on my thinkpad, I noticed this ‘battery’ button (Fn+F2). I thought it would be nice if I get this nice graph showing me my battery state.
Sadly osd_cat only does bars and text, and I wanted a nice pie or something. So I looked around for perl modules which could do more. In comes X11::Aosd.
X11::Aosd is a Cairo powered OSD interface which works quite nicely. As it’s an XS module it works fast and efficient, but as usual lacks in -proper- usage documenation.
The script I ended up writing (which called by another script that actually read the battery info) became as followed:
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use X11::Aosd ':all';
my $per = 100;
my $mx = 200;
my $my = 200;
my $text;
my $res = GetOptions("percentage=i" => \$per,
"xoffset=i" => \$mx,
"yoffset=i" => \$my,
"text=s" => \$text,
);
my $pi = 3.14159265358979;
my $rad = ((2*$pi) / 100) * $per;
my $aosd = X11::Aosd->new;
$aosd->set_transparency(TRANSPARENCY_COMPOSITE);
$aosd->set_position_with_offset(
COORDINATE_CENTER,
COORDINATE_CENTER,
200, 200, 0, 0
);
$aosd->set_renderer(sub {
my ($cr) = @_;
$cr->set_source_rgba (1, 0.6, 0, 1) if($per < 30);
$cr->set_source_rgba (1, 0, 0, 1) if($per < 10);
$cr->set_source_rgba (0, 1, 0, 1) if($per >= 30);
$cr->set_line_width(10);
$cr->set_line_cap('round');
$cr->arc(100, 75, 70, 0, $rad);
$cr->line_to(100,75);
$cr->line_to(170,75) if($per < 100);
$cr->stroke;
$cr->fill;
if($text) {
$cr->move_to(0, 175);
$cr->select_font_face("Sans", 'normal', 'bold');
$cr->set_font_size (23);
$cr->show_text($text);
$cr->fill;
}
});
$aosd->show;
$aosd->loop_once;
It’s a simple piece but it works. I kinda like X11:Aosd even though it’s less then perfect docs, toghether with the original cairo docs you get a nice idea. Maybe more examples later.
btw, Thinkpad F<n> acpi buttons(Fn+Function) are quite simple in their acpi mapping: 00000080 00001003 is F3, 00000080 00001002 is F2, etc