i3status-anyevent: Add simple net if state indicator
This commit is contained in:
@@ -68,7 +68,8 @@ my $charge = '';
|
|||||||
my $tcp_check = 0;
|
my $tcp_check = 0;
|
||||||
my $file_check = 0;
|
my $file_check = 0;
|
||||||
my $file_check_mtime = 0;
|
my $file_check_mtime = 0;
|
||||||
my $simple_volume_pa = '??';
|
my $simple_volume_pa = '<big>♪</big> ??%';
|
||||||
|
my $interfaces = '??';
|
||||||
my $output_string;
|
my $output_string;
|
||||||
my $old_output_string = '';
|
my $old_output_string = '';
|
||||||
my $STDIN_FIRST_LINE_DROPPED = 0;
|
my $STDIN_FIRST_LINE_DROPPED = 0;
|
||||||
@@ -215,6 +216,10 @@ sub add_events () {
|
|||||||
push @{$OUTPUT}, { color => $CONF->{color}, full_text => $vpn_str };
|
push @{$OUTPUT}, { color => $CONF->{color}, full_text => $vpn_str };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($CONF->{'net-if'}->{enabled}) {
|
||||||
|
push @{$OUTPUT}, { color => $CONF->{color}, full_text => $interfaces, markup => 'pango' };
|
||||||
|
}
|
||||||
|
|
||||||
if ($CONF->{battery}->{enabled}) {
|
if ($CONF->{battery}->{enabled}) {
|
||||||
push @{$OUTPUT}, { color => $CONF->{color}, full_text => $charge, markup => 'pango' };
|
push @{$OUTPUT}, { color => $CONF->{color}, full_text => $charge, markup => 'pango' };
|
||||||
}
|
}
|
||||||
@@ -618,6 +623,35 @@ sub add_events () {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# poll operstate for given net ifs
|
||||||
|
if ($CONF->{'net-if'}->{enabled}) {
|
||||||
|
push @EP, AnyEvent->timer (
|
||||||
|
after => 0, # first invoke ASAP
|
||||||
|
interval => 1, # then invoke every 1 second
|
||||||
|
cb => sub { # the callback to invoke
|
||||||
|
my @ifstate;
|
||||||
|
|
||||||
|
foreach my $if (@{$CONF->{'net-if'}->{if}}) {
|
||||||
|
if (open my $STATEFH, '<', "$if->{dir}/operstate") {
|
||||||
|
my $state = <$STATEFH>;
|
||||||
|
close $STATEFH;
|
||||||
|
chomp $state;
|
||||||
|
|
||||||
|
if ($state eq 'up') {
|
||||||
|
push @ifstate, sprintf '%s:<span foreground="%s">▲</span>', $if->{name}, $CONF->{'net-if'}->{up_color};
|
||||||
|
} else {
|
||||||
|
push @ifstate, sprintf '%s:<span foreground="%s">▼</span>', $if->{name}, $CONF->{'net-if'}->{down_color};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($#ifstate >=0 ) {
|
||||||
|
$interfaces = join ' ', @ifstate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
"tcp_check" : {
|
"tcp_check" : {
|
||||||
"enabled": 0,
|
"enabled": 0,
|
||||||
"host": "somehost.tld",
|
"host": "somehost.tld",
|
||||||
"port": "443",
|
"port": 443,
|
||||||
"timeout" : 3
|
"timeout" : 3
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -61,6 +61,23 @@
|
|||||||
# so it's not light on system resources as i'd like
|
# so it's not light on system resources as i'd like
|
||||||
"simple-volume-pa": 0,
|
"simple-volume-pa": 0,
|
||||||
|
|
||||||
|
"net-if" : {
|
||||||
|
"enabled" : 0,
|
||||||
|
# html (actually, pango) notation
|
||||||
|
"down_color" : "red",
|
||||||
|
"up_color" : "green",
|
||||||
|
"if" : [
|
||||||
|
{
|
||||||
|
"name" : "eth0",
|
||||||
|
"dir" : "/sys/class/net/eth0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "wlan0",
|
||||||
|
"dir" : "/sys/class/net/wlan0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
# Weather to display Application Buttons
|
# Weather to display Application Buttons
|
||||||
"app_buttons": 1,
|
"app_buttons": 1,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user