Skip to content

Commit

Permalink
Use I3SOCK environment variable for path in AnyEvent::I3
Browse files Browse the repository at this point in the history
Commit 3ae5f31 introduced the I3SOCK environment variable. This
prevents us from having to call `i3 --get-socketpath'. In case the
variable doesn't exist, fall back to the old ways.

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
  • Loading branch information
waterkip committed Apr 9, 2024
1 parent d91597b commit 39e1792
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AnyEvent-I3/lib/AnyEvent/I3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ instance on the current DISPLAY which is almost always what you want.
sub new {
my ($class, $path) = @_;

# We have I3SOCK now
$path ||= $ENV{I3SOCK};

# This is to untaint the path
if ($path && $path =~ /^([[:word:]\/\.]]+)$/) {
$path = $1;
}

$path = _call_i3('--get-socketpath') unless $path;

# This is the old default path (v3.*). This fallback line can be removed in
Expand All @@ -197,6 +205,10 @@ sub new {
$path =~ s/~/$home/g;
}

if(!-S $path) {
die "$path is not a socket", $/;
}

bless { path => $path } => $class;
}

Expand Down

0 comments on commit 39e1792

Please sign in to comment.