|
|
|
|
@@ -2,12 +2,14 @@
|
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
use English qw ( -no_match_vars );
|
|
|
|
|
|
|
|
|
|
# we need to disable hash shuffling in order to make as less prints to stdout as possible
|
|
|
|
|
BEGIN {
|
|
|
|
|
unless (defined $ENV{PERL_PERTURB_KEYS}) {
|
|
|
|
|
$ENV{PERL_PERTURB_KEYS} = 0;
|
|
|
|
|
exec ( $^X, $0, @ARGV );
|
|
|
|
|
$ENV{PERL_ANYEVENT_MODEL} = 'EV';
|
|
|
|
|
exec ( $EXECUTABLE_NAME, $PROGRAM_NAME, @ARGV );
|
|
|
|
|
exit 0; # we actually never get here
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -18,15 +20,14 @@ use warnings;
|
|
|
|
|
use utf8;
|
|
|
|
|
use open qw (:std :utf8);
|
|
|
|
|
use Fcntl qw (:seek);
|
|
|
|
|
use AnyEvent;
|
|
|
|
|
use AnyEvent::Timer::Cron;
|
|
|
|
|
use AnyEvent::I3;
|
|
|
|
|
use JSON::XS;
|
|
|
|
|
use Encode;
|
|
|
|
|
use AnyEvent ();
|
|
|
|
|
use AnyEvent::I3 qw (i3);
|
|
|
|
|
use JSON::XS qw (encode_json decode_json);
|
|
|
|
|
use Encode qw (decode);
|
|
|
|
|
use IO::Socket qw (AF_INET SOCK_STREAM SHUT_WR);
|
|
|
|
|
use POSIX qw (setsid);
|
|
|
|
|
|
|
|
|
|
local $| = 1;
|
|
|
|
|
local $OUTPUT_AUTOFLUSH = 1;
|
|
|
|
|
|
|
|
|
|
sub add_events ();
|
|
|
|
|
sub spawn (@);
|
|
|
|
|
@@ -36,10 +37,19 @@ sub readconf ();
|
|
|
|
|
sub active_win_borders ();
|
|
|
|
|
|
|
|
|
|
my $CONF = readconf ();
|
|
|
|
|
|
|
|
|
|
# load AnyEvent::Timer::Cron only if cron enabled in config
|
|
|
|
|
if ($CONF->{'cron'}->{enabled}) {
|
|
|
|
|
require AnyEvent::Timer::Cron;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $i3 = i3 ();
|
|
|
|
|
my $done = AnyEvent->condvar;
|
|
|
|
|
$i3->connect->recv or die 'Unable to connect to i3';
|
|
|
|
|
|
|
|
|
|
# Local Time Counter
|
|
|
|
|
my $TC = time();
|
|
|
|
|
|
|
|
|
|
# event pool
|
|
|
|
|
my @EP;
|
|
|
|
|
|
|
|
|
|
@@ -81,6 +91,8 @@ unless (-f $BATTERY_CHARGE_FULL_FILE) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $CAPS_LED_PATH = find_caps_led ();
|
|
|
|
|
my $CAPS_LED_SKIPS = 0;
|
|
|
|
|
my $CAPS_LED_SKIPS_MAX = 180;
|
|
|
|
|
|
|
|
|
|
# opened windows info storage ref
|
|
|
|
|
my $win;
|
|
|
|
|
@@ -114,6 +126,9 @@ my $i3_subscription->{window} = sub {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
# we just don't care about other events now
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
active_win_borders ();
|
|
|
|
|
@@ -143,13 +158,6 @@ sub add_events () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Register callbacks/event handlers
|
|
|
|
|
push @EP, AnyEvent->timer (
|
|
|
|
|
after => 1,
|
|
|
|
|
interval => 120,
|
|
|
|
|
cb => sub {
|
|
|
|
|
AnyEvent->now_update;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
# Actually print messages there
|
|
|
|
|
push @EP, AnyEvent->timer (
|
|
|
|
|
@@ -160,52 +168,23 @@ sub add_events () {
|
|
|
|
|
if ($UPDATE) {
|
|
|
|
|
my $jsonobj;
|
|
|
|
|
|
|
|
|
|
if ($CONF->{app_buttons}) {
|
|
|
|
|
@{$jsonobj} = @{$O->{apps}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{capslock}->{enabled}) {
|
|
|
|
|
push @{$jsonobj}, $O->{capslock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{cpu_temp}->{enabled}) {
|
|
|
|
|
push @{$jsonobj}, $O->{cputemp};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{mem}) {
|
|
|
|
|
push @{$jsonobj}, $O->{mem};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{la}) {
|
|
|
|
|
push @{$jsonobj}, $O->{la};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{vpn}->{enabled}) {
|
|
|
|
|
push @{$jsonobj}, $O->{vpn};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{'net-if'}->{enabled}) {
|
|
|
|
|
push @{$jsonobj}, $O->{interfaces};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{battery}->{enabled}) {
|
|
|
|
|
push @{$jsonobj}, $O->{battery};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{'simple-volume-pa'}) {
|
|
|
|
|
push @{$jsonobj}, $O->{'simple-volume-pa'};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CONF->{clock}->{enabled}) {
|
|
|
|
|
push @{$jsonobj}, $O->{wallclock};
|
|
|
|
|
}
|
|
|
|
|
@{$jsonobj} = @{$O->{apps}} if $CONF->{app_buttons};
|
|
|
|
|
push @{$jsonobj}, $O->{capslock} if $CONF->{capslock}->{enabled};
|
|
|
|
|
push @{$jsonobj}, $O->{cputemp} if $CONF->{cpu_temp}->{enabled};
|
|
|
|
|
push @{$jsonobj}, $O->{mem} if $CONF->{mem};
|
|
|
|
|
push @{$jsonobj}, $O->{la} if $CONF->{la};
|
|
|
|
|
push @{$jsonobj}, $O->{vpn} if $CONF->{vpn}->{enabled};
|
|
|
|
|
push @{$jsonobj}, $O->{interfaces} if $CONF->{'net-if'}->{enabled};
|
|
|
|
|
push @{$jsonobj}, $O->{battery} if $CONF->{battery}->{enabled};
|
|
|
|
|
push @{$jsonobj}, $O->{'simple-volume-pa'} if $CONF->{'simple-volume-pa'};
|
|
|
|
|
push @{$jsonobj}, $O->{wallclock} if $CONF->{clock}->{enabled};
|
|
|
|
|
|
|
|
|
|
my $output_string = eval { encode_json $jsonobj };
|
|
|
|
|
|
|
|
|
|
if (defined $output_string) {
|
|
|
|
|
print {*STDOUT} decode ('UTF-8', $output_string) . ",\n";
|
|
|
|
|
print {*STDOUT} decode ('UTF-8', $output_string) . ",\n";
|
|
|
|
|
} else {
|
|
|
|
|
warn $@;
|
|
|
|
|
warn $EVAL_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$UPDATE = 0;
|
|
|
|
|
@@ -228,8 +207,8 @@ sub add_events () {
|
|
|
|
|
|
|
|
|
|
if ($msg) {
|
|
|
|
|
# drop leading ',' if present
|
|
|
|
|
if (substr ($msg, 0, 1) eq ',') {
|
|
|
|
|
$msg = substr $msg, 1;
|
|
|
|
|
if (substr ($msg, 0, length (',')) eq ',') {
|
|
|
|
|
$msg = substr $msg, length (',');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $j = eval { decode_json $msg };
|
|
|
|
|
@@ -277,6 +256,7 @@ sub add_events () {
|
|
|
|
|
cb => sub { # the callback to invoke
|
|
|
|
|
my $caps_state = 0;
|
|
|
|
|
my $CAPSHANDLE;
|
|
|
|
|
my $xsetflag = 0;
|
|
|
|
|
|
|
|
|
|
if (defined $CAPS_LED_PATH) {
|
|
|
|
|
unless (open $CAPSHANDLE, '<', $CAPS_LED_PATH) {
|
|
|
|
|
@@ -284,13 +264,39 @@ sub add_events () {
|
|
|
|
|
$caps_state = 2
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$caps_state = 2;
|
|
|
|
|
# we can use "$ xset q | grep Caps" as fallback, but it is notably more expensive check
|
|
|
|
|
my $xset = `xset q`;
|
|
|
|
|
$xsetflag = 1;
|
|
|
|
|
|
|
|
|
|
if ($CHILD_ERROR) {
|
|
|
|
|
# some kind of error, so we assume that we cannot update caps lock status
|
|
|
|
|
$caps_state = 2;
|
|
|
|
|
} else {
|
|
|
|
|
$xset =~ /Caps Lock\:\s+(o[n|f]f?)\s+/;
|
|
|
|
|
|
|
|
|
|
if ($1 eq 'off') {
|
|
|
|
|
$caps_state = 0;
|
|
|
|
|
} elsif ($1 eq 'on') {
|
|
|
|
|
$caps_state = 1;
|
|
|
|
|
} else {
|
|
|
|
|
$caps_state = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($CAPS_LED_SKIPS == $CAPS_LED_SKIPS_MAX) {
|
|
|
|
|
$CAPS_LED_SKIPS = 0;
|
|
|
|
|
$CAPS_LED_PATH = find_caps_led ();
|
|
|
|
|
} else {
|
|
|
|
|
$CAPS_LED_SKIPS++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($caps_state ne '2') {
|
|
|
|
|
$caps_state = readline $CAPSHANDLE;
|
|
|
|
|
close $CAPSHANDLE;
|
|
|
|
|
chomp $caps_state;
|
|
|
|
|
unless ($xsetflag) {
|
|
|
|
|
$caps_state = readline $CAPSHANDLE;
|
|
|
|
|
close $CAPSHANDLE;
|
|
|
|
|
chomp $caps_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{capslock}->{state}) {
|
|
|
|
|
$O->{capslock}->{border} = $CONF->{capslock}->{background};
|
|
|
|
|
@@ -361,7 +367,7 @@ sub add_events () {
|
|
|
|
|
my @up;
|
|
|
|
|
my $str = `upower -i $CONF->{battery}->{upower_device}`;
|
|
|
|
|
|
|
|
|
|
if ($?) {
|
|
|
|
|
if ($CHILD_ERROR) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -373,20 +379,19 @@ sub add_events () {
|
|
|
|
|
my $minutes = 0;
|
|
|
|
|
|
|
|
|
|
while ($str = pop (@up)) {
|
|
|
|
|
if (substr ($str, 4, 10) eq 'percentage') {
|
|
|
|
|
$percentage = substr $str, 25;
|
|
|
|
|
chomp $percentage;
|
|
|
|
|
} elsif (substr ($str, 4, 5) eq 'state') {
|
|
|
|
|
if (substr ($str, 25, 11) eq 'discharging') {
|
|
|
|
|
if (substr ($str, 4, length ('percentage')) eq 'percentage') {
|
|
|
|
|
$percentage = substr $str, 25, 0 - length ('%'); # chop % symbol at the end of the string
|
|
|
|
|
} elsif (substr ($str, 4, length ('state')) eq 'state') {
|
|
|
|
|
if (substr ($str, 25, length ('discharging')) eq 'discharging') {
|
|
|
|
|
$state = '▼';
|
|
|
|
|
} elsif (substr ($str, 25, 8) eq 'charging') {
|
|
|
|
|
} elsif (substr ($str, 25, length ('charging')) eq 'charging') {
|
|
|
|
|
$state = '▲';
|
|
|
|
|
} else {
|
|
|
|
|
$state = '•';
|
|
|
|
|
}
|
|
|
|
|
} elsif (substr ($str, 4, 13) eq 'time to empty') {
|
|
|
|
|
} elsif (substr ($str, 4, length ('time to empty')) eq 'time to empty') {
|
|
|
|
|
$time_to = substr $str, 25;
|
|
|
|
|
} elsif (substr ($str, 4, 12) eq 'time to full') {
|
|
|
|
|
} elsif (substr ($str, 4, length ('time to full')) eq 'time to full') {
|
|
|
|
|
$time_to = substr $str, 25;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -395,15 +400,27 @@ sub add_events () {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $color = '<span foreground="Blue">';
|
|
|
|
|
|
|
|
|
|
if ($percentage > 85) {
|
|
|
|
|
$color = '<span foreground="LimeGreen">';
|
|
|
|
|
} elsif ($percentage < 25 && $percentage > 15) {
|
|
|
|
|
$color = '<span foreground="Goldenrod">';
|
|
|
|
|
} elsif ($percentage <= 15 && $percentage > 11) {
|
|
|
|
|
$color = '<span foreground="DarkOrange">';
|
|
|
|
|
} elsif ($percentage <= 11) {
|
|
|
|
|
$color = '<span foreground="Red">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (defined $time_to) {
|
|
|
|
|
chomp $time_to;
|
|
|
|
|
|
|
|
|
|
if (substr ($time_to, -7) eq 'minutes') {
|
|
|
|
|
$minutes = substr $time_to, 0, -8;
|
|
|
|
|
if (substr ($time_to, 0 - length ('minutes')) eq 'minutes') {
|
|
|
|
|
$minutes = substr $time_to, 0, 0 - length (' minutes');
|
|
|
|
|
$minutes =~ tr/\,/./;
|
|
|
|
|
$minutes = int $minutes;
|
|
|
|
|
} elsif (substr ($time_to, -5) eq 'hours') {
|
|
|
|
|
$hours = substr $time_to, 0, -6;
|
|
|
|
|
} elsif (substr ($time_to, 0 - length ('hours')) eq 'hours') {
|
|
|
|
|
$hours = substr $time_to, 0, 0 - length (' hours');
|
|
|
|
|
$hours =~ tr/\,/./;
|
|
|
|
|
$minutes = int (60 * ($hours - int ($hours)));
|
|
|
|
|
}
|
|
|
|
|
@@ -413,7 +430,7 @@ sub add_events () {
|
|
|
|
|
$time_to = '00:00';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $charge = sprintf '<big>⚡</big> %s %s %s', $percentage, $state, $time_to;
|
|
|
|
|
my $charge = sprintf '<b><big><span foreground="Goldenrod">⚡</span></big></b> %s%s%%</span> %s %s', $color, $percentage, $state, $time_to;
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{battery}->{'full_text'}) {
|
|
|
|
|
$O->{battery}->{'full_text'} = $charge;
|
|
|
|
|
@@ -491,19 +508,19 @@ sub add_events () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $capacity = int (100 * ($current_charge / $charge_max));
|
|
|
|
|
my $color = '<span foreground="blue">';
|
|
|
|
|
my $color = '<span foreground="Blue">';
|
|
|
|
|
|
|
|
|
|
if ($capacity > 85) {
|
|
|
|
|
$color = '<span foreground="green">';
|
|
|
|
|
$color = '<span foreground="LimeGreen">';
|
|
|
|
|
} elsif ($capacity < 25 && $capacity > 15) {
|
|
|
|
|
$color = '<span foreground="yellow">';
|
|
|
|
|
$color = '<span foreground="Goldenrod">';
|
|
|
|
|
} elsif ($capacity <= 15 && $capacity > 11) {
|
|
|
|
|
$color = '<span foreground="orange">';
|
|
|
|
|
$color = '<span foreground="DarkOrange">';
|
|
|
|
|
} elsif ($capacity <= 11) {
|
|
|
|
|
$color = '<span foreground="red">';
|
|
|
|
|
$color = '<span foreground="Red">';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $charge = sprintf '<b><big><span foreground="yellow">⚡</span></big></b> %s%s%%</span> %s', $color, $capacity, $state;
|
|
|
|
|
my $charge = sprintf '<b><big><span foreground="Goldenrod">⚡</span></big></b> %s%s%%</span> %s', $color, $capacity, $state;
|
|
|
|
|
|
|
|
|
|
if ($O->{battery}->{'full_text'} ne $charge) {
|
|
|
|
|
$O->{battery}->{'full_text'} = $charge;
|
|
|
|
|
@@ -547,13 +564,13 @@ sub add_events () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close $MEMINFOHANDLE;
|
|
|
|
|
@mem = map { substr $_, 0, -4 } @mem;
|
|
|
|
|
my $memtotal = (split /\s+/xms, $mem[0])[1];
|
|
|
|
|
@mem = map { substr $_, 0, 0 - length (" kB\n") } @mem;
|
|
|
|
|
my $memtotal = (split /\s+/xms, $mem[0])[1];
|
|
|
|
|
my $memavail = (split /\s+/xms, $mem[2])[1];
|
|
|
|
|
my $swaptotal = (split /\s+/xms, $mem[14])[1];
|
|
|
|
|
my $swapfree = (split /\s+/xms, $mem[15])[1];
|
|
|
|
|
my $shmem = (split /\s+/xms, $mem[20])[1];
|
|
|
|
|
my $memused = int (($memtotal - $memavail) / ($memtotal / 100));
|
|
|
|
|
my $shmem = (split /\s+/xms, $mem[20])[1];
|
|
|
|
|
my $memused = int (($memtotal - $memavail) / ($memtotal / 100));
|
|
|
|
|
|
|
|
|
|
my $mem = sprintf (
|
|
|
|
|
'M:%d%% SHM:%dM SW:%dM',
|
|
|
|
|
@@ -564,7 +581,7 @@ sub add_events () {
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{mem}->{'full_text'}) {
|
|
|
|
|
$O->{mem}->{'full_text'} = $mem;
|
|
|
|
|
$O->{mem}->{'color'} = '#3e78fd';
|
|
|
|
|
$O->{mem}->{'color'} = '#3e78fd';
|
|
|
|
|
$UPDATE = 1;
|
|
|
|
|
} elsif ($O->{mem}->{'full_text'} ne $mem) {
|
|
|
|
|
$O->{mem}->{'full_text'} = $mem;
|
|
|
|
|
@@ -595,7 +612,7 @@ sub add_events () {
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{cputemp}->{'full_text'}) {
|
|
|
|
|
$O->{cputemp}->{'full_text'} = $cputemp;
|
|
|
|
|
$O->{cputemp}->{'color'} = '#3e78fd';
|
|
|
|
|
$O->{cputemp}->{'color'} = '#3e78fd';
|
|
|
|
|
$UPDATE = 1;
|
|
|
|
|
} elsif ($O->{cputemp}->{'full_text'} ne $cputemp) {
|
|
|
|
|
$O->{cputemp}->{'full_text'} = $cputemp;
|
|
|
|
|
@@ -617,15 +634,15 @@ sub add_events () {
|
|
|
|
|
|
|
|
|
|
if (defined $mtime) {
|
|
|
|
|
if ((time () - $mtime) < $CONF->{vpn}->{mtime_threshold}) {
|
|
|
|
|
$vpnstr .= '⍋';
|
|
|
|
|
$vpnstr .= sprintf '<span foreground="%s">⍋</span>', $CONF->{vpn}->{up_color};
|
|
|
|
|
} else {
|
|
|
|
|
$vpnstr .= '⍒';
|
|
|
|
|
$vpnstr .= sprintf '<span foreground="%s">⍒</span>', $CONF->{vpn}->{down_color};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$file_check_mtime = $mtime;
|
|
|
|
|
} else {
|
|
|
|
|
$mtime = 0;
|
|
|
|
|
$vpnstr .= '⍒';
|
|
|
|
|
$vpnstr .= sprintf '<span foreground="%s">⍒</span>', $CONF->{vpn}->{down_color};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Try to tcp connect to server in vpn network
|
|
|
|
|
@@ -644,15 +661,16 @@ sub add_events () {
|
|
|
|
|
) {
|
|
|
|
|
$sock->shutdown (SHUT_WR);
|
|
|
|
|
$sock->close ();
|
|
|
|
|
$vpnstr .= '✔';
|
|
|
|
|
$vpnstr .= sprintf '<span foreground="%s">✔</span>', $CONF->{vpn}->{up_color};
|
|
|
|
|
} else {
|
|
|
|
|
$vpnstr .= '✘';
|
|
|
|
|
$vpnstr .= sprintf '<span foreground="%s">✘</span>', $CONF->{vpn}->{down_color};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{vpn}->{'full_text'}) {
|
|
|
|
|
$O->{vpn}->{'markup'} = 'pango';
|
|
|
|
|
$O->{vpn}->{'full_text'} = $vpnstr;
|
|
|
|
|
$O->{vpn}->{'color'} = '#3e78fd';
|
|
|
|
|
$O->{vpn}->{'color'} = '#3e78fd';
|
|
|
|
|
$UPDATE = 1;
|
|
|
|
|
} elsif ($O->{vpn}->{'full_text'} ne $vpnstr) {
|
|
|
|
|
$O->{vpn}->{'full_text'} = $vpnstr;
|
|
|
|
|
@@ -663,26 +681,29 @@ sub add_events () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# poll pulseaudio volume on first sink in list
|
|
|
|
|
if ($CONF->{'simple-volume-pa'}) {
|
|
|
|
|
if ($CONF->{'simple-volume-pa'}->{enabled}) {
|
|
|
|
|
push @EP, AnyEvent->timer (
|
|
|
|
|
after => 0, # first invoke ASAP
|
|
|
|
|
interval => 1, # then invoke every 1 second
|
|
|
|
|
cb => sub { # the callback to invoke
|
|
|
|
|
my $pactl = `LC_ALL=C pactl list sinks`;
|
|
|
|
|
|
|
|
|
|
if ($?) {
|
|
|
|
|
if ($CHILD_ERROR) {
|
|
|
|
|
# we've some error here, so quit further processing
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach my $str (split /\n/, $pactl) {
|
|
|
|
|
if ($str =~ /^\s+Volume\:\s+[a-z|A-Z\\-]+\:\s+\d+\s+\/\s+(\d+)% /xms ) {
|
|
|
|
|
my $volumestr = sprintf '<big>%s</big> %s%%', $CONF->{'simple-volume-pa'}->{symbol}, $1;
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{'simple-volume-pa'}->{'full_text'}) {
|
|
|
|
|
$O->{'simple-volume-pa'}->{'full_text'} = $1;
|
|
|
|
|
$O->{'simple-volume-pa'}->{'color'} = '#3e78fd';
|
|
|
|
|
$O->{'simple-volume-pa'}->{'full_text'} = $volumestr;
|
|
|
|
|
$O->{'simple-volume-pa'}->{'color'} = '#3e78fd';
|
|
|
|
|
$O->{'simple-volume-pa'}->{'markup'} = 'pango';
|
|
|
|
|
$UPDATE = 1;
|
|
|
|
|
} elsif ($O->{'simple-volume-pa'}->{'full_text'} ne $1) {
|
|
|
|
|
$O->{'simple-volume-pa'}->{'full_text'} = $1;
|
|
|
|
|
} elsif ($O->{'simple-volume-pa'}->{'full_text'} ne $volumestr) {
|
|
|
|
|
$O->{'simple-volume-pa'}->{'full_text'} = $volumestr;
|
|
|
|
|
$UPDATE = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -721,9 +742,9 @@ sub add_events () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! defined $O->{interfaces}->{full_text}) {
|
|
|
|
|
$O->{interfaces}->{color} = $CONF->{color};
|
|
|
|
|
$O->{interfaces}->{color} = $CONF->{color};
|
|
|
|
|
$O->{interfaces}->{full_text} = $interfaces;
|
|
|
|
|
$O->{interfaces}->{markup} = 'pango';
|
|
|
|
|
$O->{interfaces}->{markup} = 'pango';
|
|
|
|
|
$UPDATE = 1;
|
|
|
|
|
} elsif ($O->{interfaces}->{full_text} ne $interfaces) {
|
|
|
|
|
$O->{interfaces}->{full_text} = $interfaces;
|
|
|
|
|
@@ -746,6 +767,20 @@ sub add_events () {
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# also we need workaround for timers after sleep or hibernate
|
|
|
|
|
push @EP, AnyEvent->timer (
|
|
|
|
|
after => 60, # first invoke after 1 minute
|
|
|
|
|
interval => 60, # then invoke every 1 second
|
|
|
|
|
cb => sub { # the callback to invoke
|
|
|
|
|
$TC = $TC + 60;
|
|
|
|
|
my $timeskew = $TC - time ();
|
|
|
|
|
|
|
|
|
|
if (($timeskew > 60) || ($timeskew < -60)) {
|
|
|
|
|
kill 'HUP', $PROCESS_ID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
@@ -760,7 +795,7 @@ sub spawn (@) {
|
|
|
|
|
return;
|
|
|
|
|
} elsif ($pid == 0) { # Child
|
|
|
|
|
setsid ();
|
|
|
|
|
# it seems that at least vscode creashes if we close stdio handles
|
|
|
|
|
# it seems that at least vscode crashes if we close stdio handles
|
|
|
|
|
open STDOUT, '>', '/dev/null'; ## no critic (InputOutput::RequireCheckedOpen)
|
|
|
|
|
open STDERR, '>', '/dev/null'; ## no critic (InputOutput::RequireCheckedOpen)
|
|
|
|
|
open STDIN, '<', '/dev/null'; ## no critic (InputOutput::RequireCheckedOpen)
|
|
|
|
|
@@ -777,8 +812,10 @@ sub spawn (@) {
|
|
|
|
|
|
|
|
|
|
if (@args > 0) {
|
|
|
|
|
exec $prg, @args;
|
|
|
|
|
exit 0;
|
|
|
|
|
} else {
|
|
|
|
|
exec $prg;
|
|
|
|
|
exit 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
# else - we just unable to fork, so silently ignore event
|
|
|
|
|
@@ -835,7 +872,7 @@ sub readconf () {
|
|
|
|
|
my $FH;
|
|
|
|
|
|
|
|
|
|
unless (open $FH, '<', $file) {
|
|
|
|
|
die "Unable to open $file: $!\n";
|
|
|
|
|
die "Unable to open $file: $OS_ERROR\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $len = (stat $file)[7];
|
|
|
|
|
@@ -846,7 +883,7 @@ sub readconf () {
|
|
|
|
|
close $FH;
|
|
|
|
|
|
|
|
|
|
unless (defined $readlen) {
|
|
|
|
|
die "Unable to read $file: $!\n";
|
|
|
|
|
die "Unable to read $file: $OS_ERROR\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($readlen != $len) {
|
|
|
|
|
@@ -856,7 +893,7 @@ sub readconf () {
|
|
|
|
|
my $config = eval { JSON::XS->new->utf8->relaxed->decode ($data) };
|
|
|
|
|
|
|
|
|
|
unless ($config) {
|
|
|
|
|
die "Unable to decode $file: $@\n";
|
|
|
|
|
die "Unable to decode $file: $EVAL_ERROR\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $config;
|
|
|
|
|
|