Add sock and display id to allow non-attached execution
SWAYSOCK is now static so it can be referenced by all of the swaymsg commands. waybar now includes a static WAYLAND_DISPLAY declaration. This allows for recovery/configuration via SSH as well as groundwork for udev (un)docking rules.
This commit is contained in:
parent
567d271786
commit
24457ca338
|
@ -30,6 +30,8 @@
|
||||||
# "width": __WIDTH__ (optional)
|
# "width": __WIDTH__ (optional)
|
||||||
my $waybar_template = "$ENV{'HOME'}/.config/waybar/config.template";
|
my $waybar_template = "$ENV{'HOME'}/.config/waybar/config.template";
|
||||||
|
|
||||||
|
my $swaysock = "/home/jpm/.config/sway-ipc.sock";
|
||||||
|
|
||||||
# Path to actual config file generated from template
|
# Path to actual config file generated from template
|
||||||
my $waybar_config = "$ENV{'HOME'}/.config/waybar/config";
|
my $waybar_config = "$ENV{'HOME'}/.config/waybar/config";
|
||||||
|
|
||||||
|
@ -206,7 +208,7 @@ close($fh);
|
||||||
# Fetch connected displays
|
# Fetch connected displays
|
||||||
use JSON::XS;
|
use JSON::XS;
|
||||||
my $json = JSON::XS->new();
|
my $json = JSON::XS->new();
|
||||||
my $displays_raw = `swaymsg -t get_outputs --raw`;
|
my $displays_raw = `swaymsg -s $swaysock -t get_outputs --raw`;
|
||||||
my $displays = $json->decode($displays_raw);
|
my $displays = $json->decode($displays_raw);
|
||||||
|
|
||||||
# For each connected display, collect the desired settings for enabled
|
# For each connected display, collect the desired settings for enabled
|
||||||
|
@ -252,7 +254,8 @@ foreach my $output (keys %$on) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scalar(@unavailable)) {
|
if (scalar(@unavailable)) {
|
||||||
die "Config requires unavailable output(s) " . join(', ', @unavailable) . "\n";
|
die "Config requires unavailable output(s) " . join(', ', @unavailable)
|
||||||
|
. "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Skip enabling/disabling displays if only running waybar (re)start
|
# Skip enabling/disabling displays if only running waybar (re)start
|
||||||
|
@ -262,13 +265,13 @@ unless ($waybar_only) {
|
||||||
foreach (@off) {
|
foreach (@off) {
|
||||||
|
|
||||||
# Sway returns status as JSON
|
# Sway returns status as JSON
|
||||||
my $res_raw = `sway output $_ disable`;
|
my $res_raw = `swaymsg -s $swaysock output $_ disable`;
|
||||||
my $res = $json->decode($res_raw)->[0];
|
my $res = $json->decode($res_raw)->[0];
|
||||||
|
|
||||||
# If failed, print to STDERR
|
# If failed, print to STDERR
|
||||||
unless ($res->{success}) {
|
unless ($res->{success}) {
|
||||||
print STDERR "Error ($res->{error}) in command 'sway"
|
print STDERR "Error ($res->{error}) in command 'swaymsg"
|
||||||
. "output $_ disable'\n";
|
. " -s $swaysock output $_ disable'\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -316,7 +319,8 @@ foreach my $out (keys %$on) {
|
||||||
push @active, $on->{$out}->{output};
|
push @active, $on->{$out}->{output};
|
||||||
unless ($waybar_only) {
|
unless ($waybar_only) {
|
||||||
# Build command, starting by enabling and powering on
|
# Build command, starting by enabling and powering on
|
||||||
my $cmd = "sway output $on->{$out}->{output} enable dpms on";
|
my $cmd = "swaymsg -s $swaysock output $on->{$out}->{output}" .
|
||||||
|
" enable dpms on";
|
||||||
|
|
||||||
# If additional options are provided, add them to command
|
# If additional options are provided, add them to command
|
||||||
if (defined $on->{$out}->{rotate}) {
|
if (defined $on->{$out}->{rotate}) {
|
||||||
|
@ -328,7 +332,8 @@ foreach my $out (keys %$on) {
|
||||||
if (defined $on->{$out}->{width} &&
|
if (defined $on->{$out}->{width} &&
|
||||||
defined $on->{$out}->{height} )
|
defined $on->{$out}->{height} )
|
||||||
{
|
{
|
||||||
$cmd .= " mode $on->{$out}->{width}x$on->{$out}->{height}";
|
$cmd .= " mode $on->{$out}->{width}x" .
|
||||||
|
"$on->{$out}->{height}";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sway returns status as JSON
|
# Sway returns status as JSON
|
||||||
|
@ -337,7 +342,8 @@ foreach my $out (keys %$on) {
|
||||||
|
|
||||||
# If failed, print to STDERR
|
# If failed, print to STDERR
|
||||||
unless ($res->{success}) {
|
unless ($res->{success}) {
|
||||||
print STDERR "Error ($res->{error}) in command '$cmd'\n";
|
print STDERR "Error ($res->{error}) in command " .
|
||||||
|
"'$cmd'\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +377,6 @@ open($fh, '>', $active_outputs);
|
||||||
print $fh join(' ', @active);
|
print $fh join(' ', @active);
|
||||||
close($fh);
|
close($fh);
|
||||||
|
|
||||||
|
|
||||||
# Restore array formatting
|
# Restore array formatting
|
||||||
$waybar = '[' . $waybar . ']';
|
$waybar = '[' . $waybar . ']';
|
||||||
|
|
||||||
|
@ -385,5 +390,5 @@ unless ($pid) {
|
||||||
open ($fh, '>', $waybar_config);
|
open ($fh, '>', $waybar_config);
|
||||||
print $fh $waybar;
|
print $fh $waybar;
|
||||||
close $fh;
|
close $fh;
|
||||||
`nohup waybar --config=$waybar_config >> waybar.log`;
|
`WAYLAND_DISPLAY=wayland-1 nohup waybar --config=$waybar_config >> waybar.log`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue