summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2024-04-12 08:43:45 +0800
committerSean Whitton <spwhitton@spwhitton.name>2024-04-12 08:44:06 +0800
commiteecd0a0ed11df1878d588a25cf1b17838ed4705b (patch)
treeaacc103c888bf8d2680a2ba4c7275b913980bf1d
parentacad4445b81048140a7d658ac43f8a0a457750ad (diff)
downloaddotfiles-eecd0a0ed11df1878d588a25cf1b17838ed4705b.tar.gz
i3status-wrapper: tidying
-rwxr-xr-xscripts/desktop/i3status-wrapper46
1 files changed, 18 insertions, 28 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper
index 22b78bd0..7298fb2f 100755
--- a/scripts/desktop/i3status-wrapper
+++ b/scripts/desktop/i3status-wrapper
@@ -27,7 +27,6 @@ use AnyEvent;
use AnyEvent::I3 ":all";
use Sys::Hostname;
use POSIX "floor", "mkfifo";
-use Fcntl;
use File::Basename "basename", "dirname";
use File::Spec::Functions "catfile";
use List::Util qw(first min max zip);
@@ -36,17 +35,18 @@ $| = 1;
my $pipe = IO::Pipe->new;
-my $i3status = fork // die "couldn't fork()!";
+my $i3status = fork // die "couldn't fork: $!";
unless ($i3status) {
$pipe->writer;
open STDOUT, ">&=", $pipe->fileno
- or die "couldn't open child's STDOUT";
+ or die "couldn't re-open i3status's STDOUT: $!";
exec "i3status";
}
-my (%paper_ws, $focused_ws, %col_rows, $caffeinated_id, $caffeinated_name);
+my (%paper_ws, $focused_ws, %col_rows, $caffe_id, $caffe_name);
-my $wm_ipc_socket = $ENV{SWAYSOCK} || $ENV{I3SOCK};
+my $have_sway = !!$ENV{SWAYSOCK};
+my $wm_ipc_socket = $have_sway ? $ENV{SWAYSOCK} : $ENV{I3SOCK};
my $wmipc = AnyEvent::I3->new($wm_ipc_socket);
$wmipc->connect->recv or die "couldn't connect to WM IPC socket";
sub with_ignored_events (&) {
@@ -121,8 +121,7 @@ $wmipc->subscribe({
elsif ($e->{change} && $e->{change} eq "mark") {
if (grep $_ eq "caffeinated", $e->{container}{marks}->@*) {
register_caffeinated($e->{container});
- } elsif ($caffeinated_id
- && $caffeinated_id == $e->{container}{id}) {
+ } elsif ($caffe_id && $caffe_id == $e->{container}{id}) {
clear_caffeinated();
}
}
@@ -199,10 +198,9 @@ for_each_node {
$pipe->reader;
-my $hostname = hostname;
-my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid($<);
-my $hostinfo
- = { name => "hostinfo", full_text => $username . "@" . $hostname };
+my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid $<;
+my $hostinfo = { name => "hostinfo",
+ full_text => sprintf "%s@%s", $username, hostname };
# Skip the first line which contains the version header.
print scalar <$pipe>;
@@ -210,8 +208,6 @@ print scalar <$pipe>;
# The second line contains the start of the infinite array.
print scalar <$pipe>;
-wsbuttons("no");
-
# Basic idea here from Michael Stapelberg's sample i3status-wrapper.
my $i3status_wrapper = AnyEvent->io(
fh => $pipe, poll => "r", cb => sub {
@@ -231,8 +227,8 @@ my $i3status_wrapper = AnyEvent->io(
sprintf +($focused_ws == $key ? "<b>%s</b>" : "%s"),
ws_name($paper_ws{$key}{name})
}
- unshift @$blocks, { name => "ws", markup => "pango",
- full_text => join " ", @disp };
+ unshift @$blocks,
+ { name => "ws", markup => "pango", full_text => "@disp" };
}
if ($focused_ws && exists $paper_ws{$focused_ws}) {
@@ -252,10 +248,8 @@ my $i3status_wrapper = AnyEvent->io(
}
unshift @$blocks,
- {
- name => "caffeinated",
- full_text => "Caffeinated: " . $caffeinated_name }
- if $caffeinated_name;
+ { name => "caffeinated", full_text => "Caffeinated: $caffe_name" }
+ if $caffe_name;
unshift @$blocks, $hostinfo;
@@ -263,6 +257,7 @@ my $i3status_wrapper = AnyEvent->io(
});
# Start main loop.
+cmd("bar bar-0 workspace_buttons no") if $have_sway;
for (;;) {
$have_pending->recv;
$have_pending = AnyEvent::condvar;
@@ -282,20 +277,15 @@ for (;;) {
process_msg(shift @pending_msgs) while @pending_msgs;
}
-sub wsbuttons {
- return unless $ENV{XDG_CURRENT_DESKTOP} eq "sway";
- cmd("bar bar-0 workspace_buttons $_[0]");
-}
-
sub register_caffeinated {
- $caffeinated_id = $_[0]->{id};
- $caffeinated_name = $_[0]->{name};
+ $caffe_id = $_[0]->{id};
+ $caffe_name = $_[0]->{name};
kill USR1 => $i3status;
}
sub clear_caffeinated {
- undef $caffeinated_id;
- undef $caffeinated_name;
+ undef $caffe_id;
+ undef $caffe_name;
kill USR1 => $i3status;
}