Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use Gtk2 '-init';
- sub get_current_status_image
- {
- `acpi` =~ /: (\w+)(, (\d+))?\%/;
- my $status = $1;
- my $percent = $3;
- my $result = '/usr/share/icons/oxygen/48x48/status/battery';
- if ($status eq "Charging")
- {
- $result .= '-charging';
- }
- if ($status eq "Full")
- {
- $result .= '-100';
- }
- if ($percent <= 20)
- {
- $result .= "-caution";
- }
- elsif ($percent <= 40)
- {
- $result .= "-low";
- }
- elsif ($percent <= 60)
- {
- $result .= "-040";
- }
- elsif ($percent <= 80)
- {
- $result .= "-060";
- }
- else
- {
- $result .= "-080";
- }
- #print "Status: $status, $percent percent, result $result.png\n";
- return $result . '.png';
- }
- my $tray = Gtk2::StatusIcon->new;
- $tray->set_from_file(get_current_status_image());
- $tray->set_visible(1);
- Glib::Timeout->add (10 * 1000, sub
- {
- $tray->set_from_file(get_current_status_image());
- return 1;
- });
- Gtk2->main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement