Compare commits
5 Commits
2a33b7a4f3
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a8316992a | ||
|
|
5977c933a7 | ||
|
|
d0f7426003 | ||
|
|
d9719b1ddd | ||
|
|
2a588e5ae9 |
@@ -20,10 +20,10 @@ use warnings;
|
|||||||
use utf8;
|
use utf8;
|
||||||
use open qw (:std :utf8);
|
use open qw (:std :utf8);
|
||||||
use Fcntl qw (:seek);
|
use Fcntl qw (:seek);
|
||||||
use AnyEvent;
|
use AnyEvent ();
|
||||||
use AnyEvent::I3;
|
use AnyEvent::I3 qw (i3);
|
||||||
use JSON::XS;
|
use JSON::XS qw (encode_json decode_json);
|
||||||
use Encode;
|
use Encode qw (decode);
|
||||||
use IO::Socket qw (AF_INET SOCK_STREAM SHUT_WR);
|
use IO::Socket qw (AF_INET SOCK_STREAM SHUT_WR);
|
||||||
use POSIX qw (setsid);
|
use POSIX qw (setsid);
|
||||||
|
|
||||||
@@ -126,6 +126,9 @@ my $i3_subscription->{window} = sub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
# we just don't care about other events now
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
active_win_borders ();
|
active_win_borders ();
|
||||||
@@ -165,50 +168,21 @@ sub add_events () {
|
|||||||
if ($UPDATE) {
|
if ($UPDATE) {
|
||||||
my $jsonobj;
|
my $jsonobj;
|
||||||
|
|
||||||
if ($CONF->{app_buttons}) {
|
@{$jsonobj} = @{$O->{apps}} if $CONF->{app_buttons};
|
||||||
@{$jsonobj} = @{$O->{apps}};
|
push @{$jsonobj}, $O->{capslock} if $CONF->{capslock}->{enabled};
|
||||||
}
|
push @{$jsonobj}, $O->{cputemp} if $CONF->{cpu_temp}->{enabled};
|
||||||
|
push @{$jsonobj}, $O->{mem} if $CONF->{mem};
|
||||||
if ($CONF->{capslock}->{enabled}) {
|
push @{$jsonobj}, $O->{la} if $CONF->{la};
|
||||||
push @{$jsonobj}, $O->{capslock};
|
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};
|
||||||
if ($CONF->{cpu_temp}->{enabled}) {
|
push @{$jsonobj}, $O->{'simple-volume-pa'} if $CONF->{'simple-volume-pa'};
|
||||||
push @{$jsonobj}, $O->{cputemp};
|
push @{$jsonobj}, $O->{wallclock} if $CONF->{clock}->{enabled};
|
||||||
}
|
|
||||||
|
|
||||||
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};
|
|
||||||
}
|
|
||||||
|
|
||||||
my $output_string = eval { encode_json $jsonobj };
|
my $output_string = eval { encode_json $jsonobj };
|
||||||
|
|
||||||
if (defined $output_string) {
|
if (defined $output_string) {
|
||||||
print {*STDOUT} decode ('UTF-8', $output_string) . ",\n";
|
print {*STDOUT} decode ('UTF-8', $output_string) . ",\n";
|
||||||
} else {
|
} else {
|
||||||
warn $EVAL_ERROR;
|
warn $EVAL_ERROR;
|
||||||
}
|
}
|
||||||
@@ -233,8 +207,8 @@ sub add_events () {
|
|||||||
|
|
||||||
if ($msg) {
|
if ($msg) {
|
||||||
# drop leading ',' if present
|
# drop leading ',' if present
|
||||||
if (substr ($msg, 0, 1) eq ',') {
|
if (substr ($msg, 0, length (',')) eq ',') {
|
||||||
$msg = substr $msg, 1;
|
$msg = substr $msg, length (',');
|
||||||
}
|
}
|
||||||
|
|
||||||
my $j = eval { decode_json $msg };
|
my $j = eval { decode_json $msg };
|
||||||
@@ -405,19 +379,19 @@ sub add_events () {
|
|||||||
my $minutes = 0;
|
my $minutes = 0;
|
||||||
|
|
||||||
while ($str = pop (@up)) {
|
while ($str = pop (@up)) {
|
||||||
if (substr ($str, 4, 10) eq 'percentage') {
|
if (substr ($str, 4, length ('percentage')) eq 'percentage') {
|
||||||
$percentage = substr $str, 25, -1; # chop % symbol ath the end of the string
|
$percentage = substr $str, 25, 0 - length ('%'); # chop % symbol at the end of the string
|
||||||
} elsif (substr ($str, 4, 5) eq 'state') {
|
} elsif (substr ($str, 4, length ('state')) eq 'state') {
|
||||||
if (substr ($str, 25, 11) eq 'discharging') {
|
if (substr ($str, 25, length ('discharging')) eq 'discharging') {
|
||||||
$state = '▼';
|
$state = '▼';
|
||||||
} elsif (substr ($str, 25, 8) eq 'charging') {
|
} elsif (substr ($str, 25, length ('charging')) eq 'charging') {
|
||||||
$state = '▲';
|
$state = '▲';
|
||||||
} else {
|
} else {
|
||||||
$state = '•';
|
$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;
|
$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;
|
$time_to = substr $str, 25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -441,12 +415,12 @@ sub add_events () {
|
|||||||
if (defined $time_to) {
|
if (defined $time_to) {
|
||||||
chomp $time_to;
|
chomp $time_to;
|
||||||
|
|
||||||
if (substr ($time_to, -7) eq 'minutes') {
|
if (substr ($time_to, 0 - length ('minutes')) eq 'minutes') {
|
||||||
$minutes = substr $time_to, 0, -8;
|
$minutes = substr $time_to, 0, 0 - length (' minutes');
|
||||||
$minutes =~ tr/\,/./;
|
$minutes =~ tr/\,/./;
|
||||||
$minutes = int $minutes;
|
$minutes = int $minutes;
|
||||||
} elsif (substr ($time_to, -5) eq 'hours') {
|
} elsif (substr ($time_to, 0 - length ('hours')) eq 'hours') {
|
||||||
$hours = substr $time_to, 0, -6;
|
$hours = substr $time_to, 0, 0 - length (' hours');
|
||||||
$hours =~ tr/\,/./;
|
$hours =~ tr/\,/./;
|
||||||
$minutes = int (60 * ($hours - int ($hours)));
|
$minutes = int (60 * ($hours - int ($hours)));
|
||||||
}
|
}
|
||||||
@@ -590,13 +564,13 @@ sub add_events () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
close $MEMINFOHANDLE;
|
close $MEMINFOHANDLE;
|
||||||
@mem = map { substr $_, 0, -4 } @mem;
|
@mem = map { substr $_, 0, 0 - length (" kB\n") } @mem;
|
||||||
my $memtotal = (split /\s+/xms, $mem[0])[1];
|
my $memtotal = (split /\s+/xms, $mem[0])[1];
|
||||||
my $memavail = (split /\s+/xms, $mem[2])[1];
|
my $memavail = (split /\s+/xms, $mem[2])[1];
|
||||||
my $swaptotal = (split /\s+/xms, $mem[14])[1];
|
my $swaptotal = (split /\s+/xms, $mem[14])[1];
|
||||||
my $swapfree = (split /\s+/xms, $mem[15])[1];
|
my $swapfree = (split /\s+/xms, $mem[15])[1];
|
||||||
my $shmem = (split /\s+/xms, $mem[20])[1];
|
my $shmem = (split /\s+/xms, $mem[20])[1];
|
||||||
my $memused = int (($memtotal - $memavail) / ($memtotal / 100));
|
my $memused = int (($memtotal - $memavail) / ($memtotal / 100));
|
||||||
|
|
||||||
my $mem = sprintf (
|
my $mem = sprintf (
|
||||||
'M:%d%% SHM:%dM SW:%dM',
|
'M:%d%% SHM:%dM SW:%dM',
|
||||||
@@ -607,7 +581,7 @@ sub add_events () {
|
|||||||
|
|
||||||
if (! defined $O->{mem}->{'full_text'}) {
|
if (! defined $O->{mem}->{'full_text'}) {
|
||||||
$O->{mem}->{'full_text'} = $mem;
|
$O->{mem}->{'full_text'} = $mem;
|
||||||
$O->{mem}->{'color'} = '#3e78fd';
|
$O->{mem}->{'color'} = '#3e78fd';
|
||||||
$UPDATE = 1;
|
$UPDATE = 1;
|
||||||
} elsif ($O->{mem}->{'full_text'} ne $mem) {
|
} elsif ($O->{mem}->{'full_text'} ne $mem) {
|
||||||
$O->{mem}->{'full_text'} = $mem;
|
$O->{mem}->{'full_text'} = $mem;
|
||||||
@@ -638,7 +612,7 @@ sub add_events () {
|
|||||||
|
|
||||||
if (! defined $O->{cputemp}->{'full_text'}) {
|
if (! defined $O->{cputemp}->{'full_text'}) {
|
||||||
$O->{cputemp}->{'full_text'} = $cputemp;
|
$O->{cputemp}->{'full_text'} = $cputemp;
|
||||||
$O->{cputemp}->{'color'} = '#3e78fd';
|
$O->{cputemp}->{'color'} = '#3e78fd';
|
||||||
$UPDATE = 1;
|
$UPDATE = 1;
|
||||||
} elsif ($O->{cputemp}->{'full_text'} ne $cputemp) {
|
} elsif ($O->{cputemp}->{'full_text'} ne $cputemp) {
|
||||||
$O->{cputemp}->{'full_text'} = $cputemp;
|
$O->{cputemp}->{'full_text'} = $cputemp;
|
||||||
@@ -694,9 +668,9 @@ sub add_events () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! defined $O->{vpn}->{'full_text'}) {
|
if (! defined $O->{vpn}->{'full_text'}) {
|
||||||
$O->{vpn}->{'markup'} = 'pango';
|
$O->{vpn}->{'markup'} = 'pango';
|
||||||
$O->{vpn}->{'full_text'} = $vpnstr;
|
$O->{vpn}->{'full_text'} = $vpnstr;
|
||||||
$O->{vpn}->{'color'} = '#3e78fd';
|
$O->{vpn}->{'color'} = '#3e78fd';
|
||||||
$UPDATE = 1;
|
$UPDATE = 1;
|
||||||
} elsif ($O->{vpn}->{'full_text'} ne $vpnstr) {
|
} elsif ($O->{vpn}->{'full_text'} ne $vpnstr) {
|
||||||
$O->{vpn}->{'full_text'} = $vpnstr;
|
$O->{vpn}->{'full_text'} = $vpnstr;
|
||||||
@@ -725,8 +699,8 @@ sub add_events () {
|
|||||||
|
|
||||||
if (! defined $O->{'simple-volume-pa'}->{'full_text'}) {
|
if (! defined $O->{'simple-volume-pa'}->{'full_text'}) {
|
||||||
$O->{'simple-volume-pa'}->{'full_text'} = $volumestr;
|
$O->{'simple-volume-pa'}->{'full_text'} = $volumestr;
|
||||||
$O->{'simple-volume-pa'}->{'color'} = '#3e78fd';
|
$O->{'simple-volume-pa'}->{'color'} = '#3e78fd';
|
||||||
$O->{'simple-volume-pa'}->{'markup'} = 'pango';
|
$O->{'simple-volume-pa'}->{'markup'} = 'pango';
|
||||||
$UPDATE = 1;
|
$UPDATE = 1;
|
||||||
} elsif ($O->{'simple-volume-pa'}->{'full_text'} ne $volumestr) {
|
} elsif ($O->{'simple-volume-pa'}->{'full_text'} ne $volumestr) {
|
||||||
$O->{'simple-volume-pa'}->{'full_text'} = $volumestr;
|
$O->{'simple-volume-pa'}->{'full_text'} = $volumestr;
|
||||||
@@ -768,9 +742,9 @@ sub add_events () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! defined $O->{interfaces}->{full_text}) {
|
if (! defined $O->{interfaces}->{full_text}) {
|
||||||
$O->{interfaces}->{color} = $CONF->{color};
|
$O->{interfaces}->{color} = $CONF->{color};
|
||||||
$O->{interfaces}->{full_text} = $interfaces;
|
$O->{interfaces}->{full_text} = $interfaces;
|
||||||
$O->{interfaces}->{markup} = 'pango';
|
$O->{interfaces}->{markup} = 'pango';
|
||||||
$UPDATE = 1;
|
$UPDATE = 1;
|
||||||
} elsif ($O->{interfaces}->{full_text} ne $interfaces) {
|
} elsif ($O->{interfaces}->{full_text} ne $interfaces) {
|
||||||
$O->{interfaces}->{full_text} = $interfaces;
|
$O->{interfaces}->{full_text} = $interfaces;
|
||||||
@@ -838,8 +812,10 @@ sub spawn (@) {
|
|||||||
|
|
||||||
if (@args > 0) {
|
if (@args > 0) {
|
||||||
exec $prg, @args;
|
exec $prg, @args;
|
||||||
|
exit 0;
|
||||||
} else {
|
} else {
|
||||||
exec $prg;
|
exec $prg;
|
||||||
|
exit 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# else - we just unable to fork, so silently ignore event
|
# else - we just unable to fork, so silently ignore event
|
||||||
|
|||||||
Reference in New Issue
Block a user