2020-09-11 15:00:39 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
########################################################################
|
|
|
|
# Usage
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# $ displays.pl [layout] [-w]
|
|
|
|
#
|
|
|
|
# layout Name of desired layout, as configured starting at line 100
|
|
|
|
# If missing, last known layout is used (logged to file $last)
|
|
|
|
# -w (Re)load waybar only. Skip display configuration. Only kill
|
|
|
|
# existing waybars and start new ones for desired layout
|
|
|
|
|
2020-09-11 15:00:39 +00:00
|
|
|
########################################################################
|
|
|
|
# Dependencies
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# Depends on JSON::XS and Proc::ProcessTable
|
|
|
|
#
|
|
|
|
# Debian:
|
|
|
|
# apt install libjson-xs-perl libproc-processtable-perl
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Directories and Files
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
# Template is a normal config with the following in place of values:
|
|
|
|
# "output": __OUTPUT__
|
|
|
|
# "position": __POSITION__
|
|
|
|
# "width": __WIDTH__ (optional)
|
2022-06-06 17:56:59 +00:00
|
|
|
my $waybar_template = "$ENV{'HOME'}/.dotfiles/waybar/config.template";
|
2020-09-11 15:00:39 +00:00
|
|
|
|
2022-06-06 17:56:59 +00:00
|
|
|
my $swaysock = $ENV{'SWAYSOCK'} || $ENV{'HOME'} . "/.spool/sway-ipc.sock";
|
2021-08-12 21:27:40 +00:00
|
|
|
|
2021-08-11 22:05:30 +00:00
|
|
|
# Path to actual config file generated from template
|
|
|
|
my $waybar_config = "$ENV{'HOME'}/.config/waybar/config";
|
2020-09-11 15:00:39 +00:00
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
# File to log and recover last used layout name
|
2022-06-06 17:56:59 +00:00
|
|
|
my $last = "$ENV{'HOME'}/.spool/last_display";
|
2020-11-16 04:47:18 +00:00
|
|
|
|
2021-01-18 02:51:31 +00:00
|
|
|
# File to log active outputs (used by swayidle, and to attempt to restore
|
2022-06-06 17:56:59 +00:00
|
|
|
my $active_outputs = "$ENV{'HOME'}/.spool/active_outputs";
|
2021-01-18 02:51:31 +00:00
|
|
|
|
2020-09-11 15:00:39 +00:00
|
|
|
########################################################################
|
|
|
|
# Display Serials and Names
|
|
|
|
########################################################################
|
|
|
|
|
2022-07-21 21:15:21 +00:00
|
|
|
# Hash to match display model name to internal name
|
|
|
|
# You can get the model from (quoted with *):
|
|
|
|
# $ swaymsg -t get_outputs --raw
|
2020-09-11 15:00:39 +00:00
|
|
|
my %outputs = (
|
2022-11-04 15:05:12 +00:00
|
|
|
'DENON-AVAMP' => 'TV',
|
2022-07-21 21:15:21 +00:00
|
|
|
'Paperlike253' => 'eInk',
|
|
|
|
'0x4140' => 'yoga'
|
2020-09-11 15:00:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Display Configurations
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
# First-level key of hash is the name of each configuration
|
|
|
|
# Second-level keys are the display friendly-names, above
|
|
|
|
# Third-level are the actual settings for that display
|
|
|
|
my %configs = (
|
2022-07-21 21:15:21 +00:00
|
|
|
'Both' => {
|
|
|
|
'yoga' => {
|
2022-04-19 04:25:29 +00:00
|
|
|
'on' => 0
|
|
|
|
},
|
2022-07-21 21:15:21 +00:00
|
|
|
'eInk' => {
|
|
|
|
'on' => 1,
|
|
|
|
'width' => 3200,
|
|
|
|
'height' => 1800,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
'rotate' => 90,
|
|
|
|
'scale' => 2,
|
|
|
|
'waybar' => 'top',
|
|
|
|
'fallback' => '#fefefe',
|
|
|
|
},
|
2022-04-19 04:25:29 +00:00
|
|
|
'TV' => {
|
|
|
|
'on' => 1,
|
|
|
|
'width' => 3840,
|
|
|
|
'height' => 2160,
|
2022-07-21 21:15:21 +00:00
|
|
|
'x' => 900,
|
2022-04-19 04:25:29 +00:00
|
|
|
'y' => 0,
|
|
|
|
'rotate' => 0,
|
2022-07-21 21:15:21 +00:00
|
|
|
'scale' => 1.33333,
|
2022-04-19 04:25:29 +00:00
|
|
|
'waybar' => 'top',
|
2022-07-21 21:15:21 +00:00
|
|
|
'fallback' => '#010101',
|
|
|
|
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
|
2022-04-19 04:25:29 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-23 09:35:26 +00:00
|
|
|
'detached' => {
|
2022-07-21 21:15:21 +00:00
|
|
|
'yoga' => {
|
2020-11-23 09:35:26 +00:00
|
|
|
'on' => 1,
|
2022-07-21 21:15:21 +00:00
|
|
|
'width' => 2560,
|
|
|
|
'height' => 1440,
|
2020-11-23 09:35:26 +00:00
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
'rotate' => 0,
|
2022-07-21 21:15:21 +00:00
|
|
|
'scale' => 1.33333,
|
2021-11-12 03:01:07 +00:00
|
|
|
'waybar' => 'bottom',
|
2022-07-21 21:15:21 +00:00
|
|
|
'fallback' => '#010101',
|
|
|
|
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
|
2021-11-12 03:01:07 +00:00
|
|
|
},
|
2022-07-21 21:15:21 +00:00
|
|
|
'eInk' => {
|
2021-11-12 03:01:07 +00:00
|
|
|
'on' => 0
|
|
|
|
},
|
2022-04-19 04:25:29 +00:00
|
|
|
'TV' => {
|
|
|
|
'on' => 0
|
2020-11-23 09:35:26 +00:00
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
},
|
2022-07-21 21:15:21 +00:00
|
|
|
'eInk' => {
|
|
|
|
'yoga' => {
|
|
|
|
'on' => 0
|
2020-11-23 09:35:26 +00:00
|
|
|
},
|
2022-07-21 21:15:21 +00:00
|
|
|
'eInk' => {
|
|
|
|
'on' => 1,
|
|
|
|
'width' => 3840,
|
|
|
|
'height' => 2160,
|
2021-01-18 02:51:31 +00:00
|
|
|
'x' => 0,
|
2022-07-21 21:15:21 +00:00
|
|
|
'y' => 0,
|
2020-11-23 09:35:26 +00:00
|
|
|
'rotate' => 0,
|
2022-07-21 21:15:21 +00:00
|
|
|
'scale' => 1.33333,
|
2021-12-31 16:57:58 +00:00
|
|
|
'waybar' => 'top',
|
2022-07-21 21:15:21 +00:00
|
|
|
'fallback' => '#010101',
|
|
|
|
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
|
|
|
|
},
|
2022-04-19 04:25:29 +00:00
|
|
|
'TV' => {
|
|
|
|
'on' => 0
|
|
|
|
},
|
2020-09-11 15:00:39 +00:00
|
|
|
},
|
2022-07-21 21:15:21 +00:00
|
|
|
'TV' => {
|
|
|
|
'yoga' => {
|
|
|
|
'on' => 0
|
2020-11-23 09:35:26 +00:00
|
|
|
},
|
2022-07-21 21:15:21 +00:00
|
|
|
'TV' => {
|
|
|
|
'on' => 1,
|
|
|
|
'width' => 3840,
|
|
|
|
'height' => 2160,
|
|
|
|
'x' => 0,
|
2020-11-23 09:35:26 +00:00
|
|
|
'y' => 0,
|
2022-07-21 21:15:21 +00:00
|
|
|
'rotate' => 0,
|
|
|
|
'scale' => 1.33333,
|
2021-12-31 16:57:58 +00:00
|
|
|
'waybar' => 'top',
|
2022-07-21 21:15:21 +00:00
|
|
|
'fallback' => '#010101',
|
|
|
|
'bg' => "$ENV{HOME}/wallpapers/wallpaper.png"
|
|
|
|
},
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# Program (do not edit below)
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
my $waybar_only = 0;
|
2021-01-18 02:51:31 +00:00
|
|
|
my $restore = 0; # Set if no config is provided. Requires validation.
|
2020-09-11 15:00:39 +00:00
|
|
|
my $config;
|
|
|
|
|
|
|
|
if (scalar(@ARGV)) {
|
2020-11-23 09:35:26 +00:00
|
|
|
while (@ARGV) {
|
|
|
|
my $arg = shift;
|
|
|
|
if ($arg eq "-w") {
|
|
|
|
$waybar_only = 1;
|
|
|
|
} else {
|
|
|
|
if (defined $config) {
|
|
|
|
die "Too many arguments.\n";
|
|
|
|
}
|
|
|
|
$config = $arg;
|
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
# Get previous config if one is not provided
|
2020-09-11 15:00:39 +00:00
|
|
|
unless (defined $config) {
|
2020-11-23 09:35:26 +00:00
|
|
|
open(my $fh, '<', $last) ||
|
|
|
|
die "Config name not provided and failed to open $last\n";
|
|
|
|
$config = <$fh>;
|
|
|
|
close($fh);
|
|
|
|
chomp $config;
|
2021-01-18 02:51:31 +00:00
|
|
|
$restore = 1;
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Bail if requested config doesn't exist
|
2021-01-18 02:51:31 +00:00
|
|
|
if (!defined($configs{$config})) {
|
|
|
|
if ($restore) {
|
|
|
|
# If restoration is attempted with invalid config, just enable eDP-1
|
|
|
|
$config = 'detached';
|
|
|
|
} else {
|
|
|
|
die "$config is not a defined configuration: "
|
|
|
|
. join(', ', keys %configs) . "\n";
|
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
# Write config that is to be used so that it can be recovered as default
|
2022-06-06 17:56:59 +00:00
|
|
|
if (open(my $fh, '>', $last)) {
|
|
|
|
print $fh $config;
|
|
|
|
close($fh);
|
|
|
|
} else {
|
|
|
|
print STDERR "Config name cannot be logged to: $last\n";
|
|
|
|
}
|
2021-01-18 02:51:31 +00:00
|
|
|
|
2020-09-11 15:00:39 +00:00
|
|
|
# Fetch connected displays
|
2020-11-16 04:47:18 +00:00
|
|
|
use JSON::XS;
|
|
|
|
my $json = JSON::XS->new();
|
2021-08-12 21:27:40 +00:00
|
|
|
my $displays_raw = `swaymsg -s $swaysock -t get_outputs --raw`;
|
2020-09-11 15:00:39 +00:00
|
|
|
my $displays = $json->decode($displays_raw);
|
|
|
|
|
|
|
|
# For each connected display, collect the desired settings for enabled
|
|
|
|
# displays and a list of displays to disable
|
|
|
|
my $on;
|
|
|
|
my @off;
|
|
|
|
for (my $i = 0; $i < scalar(@$displays); $i++) {
|
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
# If a display is found without any settings print error and turn it off
|
2022-07-21 21:15:21 +00:00
|
|
|
unless (defined $configs{$config}{$outputs{$displays->[$i]->{model}}}){
|
2020-11-23 09:35:26 +00:00
|
|
|
print STDERR "Output $displays->[$i]->{name} ("
|
2022-07-21 21:15:21 +00:00
|
|
|
. $displays->[$i]->{model}
|
2020-11-23 09:35:26 +00:00
|
|
|
. ") found without defined function. Disabling.\n";
|
|
|
|
push @off, $displays->[$i]->{name};
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# If display is enabled, copy all of the desired settings
|
2022-07-21 21:15:21 +00:00
|
|
|
if ($configs{$config}{$outputs{$displays->[$i]->{model}}}{on}) {
|
|
|
|
$on->{$outputs{$displays->[$i]->{model}}} =
|
|
|
|
$configs{$config}{$outputs{$displays->[$i]->{model}}};
|
|
|
|
$on->{$outputs{$displays->[$i]->{model}}}{output} =
|
2020-11-23 09:35:26 +00:00
|
|
|
$displays->[$i]->{name};
|
|
|
|
# Otherwise simply list it for disabling
|
|
|
|
} else {
|
|
|
|
push @off, $displays->[$i]->{name};
|
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-18 02:51:31 +00:00
|
|
|
# Verify that all requested displays are actually available
|
|
|
|
my @unavailable;
|
|
|
|
foreach my $output (keys %$on) {
|
|
|
|
my $found = 0;
|
|
|
|
foreach my $o (keys %outputs) {
|
|
|
|
if ($outputs{$o} eq $output) {
|
|
|
|
$found = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unless ($found) {
|
|
|
|
push @unavailable, $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scalar(@unavailable)) {
|
2021-08-12 21:27:40 +00:00
|
|
|
die "Config requires unavailable output(s) " . join(', ', @unavailable)
|
|
|
|
. "\n";
|
2021-01-18 02:51:31 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
# Skip enabling/disabling displays if only running waybar (re)start
|
2020-09-11 15:00:39 +00:00
|
|
|
unless ($waybar_only) {
|
2020-11-23 09:35:26 +00:00
|
|
|
# Number of simultaneous outputs is limited by gpu, so disabled displays
|
|
|
|
# first
|
|
|
|
foreach (@off) {
|
2020-09-11 15:00:39 +00:00
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
# Sway returns status as JSON
|
2021-08-12 21:27:40 +00:00
|
|
|
my $res_raw = `swaymsg -s $swaysock output $_ disable`;
|
2020-11-23 09:35:26 +00:00
|
|
|
my $res = $json->decode($res_raw)->[0];
|
2020-09-11 15:00:39 +00:00
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
# If failed, print to STDERR
|
|
|
|
unless ($res->{success}) {
|
2021-08-12 21:27:40 +00:00
|
|
|
print STDERR "Error ($res->{error}) in command 'swaymsg"
|
|
|
|
. " -s $swaysock output $_ disable'\n";
|
2020-11-23 09:35:26 +00:00
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Kill existing Waybars
|
|
|
|
require Proc::ProcessTable;
|
|
|
|
my $t = new Proc::ProcessTable;
|
|
|
|
foreach my $p ( @{ $t->table } ) {
|
2020-11-23 09:35:26 +00:00
|
|
|
my $cmndline = $p->{'cmndline'};
|
|
|
|
$cmndline =~ s/\s*$//g;
|
|
|
|
if ($cmndline =~ /^waybar.*/) {
|
|
|
|
# Never kill this process
|
|
|
|
if ($p->{'pid'} == $$) {
|
|
|
|
next;
|
|
|
|
} else {
|
|
|
|
$p->kill(9);
|
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
# Load in config template
|
|
|
|
my $template;
|
|
|
|
if (open (my $fh, '<', $waybar_template)) {
|
2020-11-23 09:35:26 +00:00
|
|
|
while (<$fh>) {
|
|
|
|
$template .= $_;
|
|
|
|
}
|
|
|
|
close $fh;
|
|
|
|
chomp $template;
|
2020-11-16 04:47:18 +00:00
|
|
|
} else {
|
2020-11-23 09:35:26 +00:00
|
|
|
print STDERR "Failed to load template $waybar_template\n";
|
2020-11-16 04:47:18 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
# If template is already set up as an array, remove the square brackets so that
|
|
|
|
# we can concatenate multiple displays
|
2020-11-16 04:47:18 +00:00
|
|
|
$template =~ s/^[^\[\{]*\[(.*)\]$/$1/s;
|
|
|
|
|
|
|
|
# Setup waybar config file
|
|
|
|
my $waybar = '';
|
|
|
|
|
2020-09-11 15:00:39 +00:00
|
|
|
# Configure each enabled display
|
2021-01-18 02:51:31 +00:00
|
|
|
my @active;
|
2020-09-11 15:00:39 +00:00
|
|
|
foreach my $out (keys %$on) {
|
|
|
|
|
2021-01-18 02:51:31 +00:00
|
|
|
push @active, $on->{$out}->{output};
|
|
|
|
unless ($waybar_only) {
|
2020-11-23 09:35:26 +00:00
|
|
|
# Build command, starting by enabling and powering on
|
2021-08-12 21:27:40 +00:00
|
|
|
my $cmd = "swaymsg -s $swaysock output $on->{$out}->{output}" .
|
|
|
|
" enable dpms on";
|
2020-11-23 09:35:26 +00:00
|
|
|
|
|
|
|
# If additional options are provided, add them to command
|
2021-11-12 03:01:07 +00:00
|
|
|
if (defined $on->{$out}->{scale}) {
|
|
|
|
$cmd .= " scale $on->{$out}->{scale}";
|
2021-12-31 16:57:58 +00:00
|
|
|
} else {
|
|
|
|
$cmd .= " scale 1";
|
|
|
|
}
|
2020-11-23 09:35:26 +00:00
|
|
|
if (defined $on->{$out}->{rotate}) {
|
|
|
|
$cmd .= " transform $on->{$out}->{rotate}";
|
2021-12-31 16:57:58 +00:00
|
|
|
} else {
|
|
|
|
$cmd .= " transform 0";
|
|
|
|
}
|
2020-11-23 09:35:26 +00:00
|
|
|
if (defined $on->{$out}->{x} && defined $on->{$out}->{y}) {
|
|
|
|
$cmd .= " position $on->{$out}->{x} $on->{$out}->{y}";
|
|
|
|
}
|
|
|
|
if (defined $on->{$out}->{width} &&
|
|
|
|
defined $on->{$out}->{height} )
|
|
|
|
{
|
2021-08-12 21:27:40 +00:00
|
|
|
$cmd .= " mode $on->{$out}->{width}x" .
|
|
|
|
"$on->{$out}->{height}";
|
2020-11-23 09:35:26 +00:00
|
|
|
}
|
2021-12-31 16:57:58 +00:00
|
|
|
if (defined $on->{$out}->{bg} &&
|
|
|
|
-f $on->{$out}->{bg})
|
|
|
|
{
|
|
|
|
$cmd .= " bg $on->{$out}->{bg} fit";
|
|
|
|
if (defined $on->{$out}->{fallback}) {
|
|
|
|
$cmd .= " $on->{$out}->{fallback}";
|
|
|
|
}
|
|
|
|
} elsif (defined $on->{$out}->{fallback}) {
|
|
|
|
$cmd .= " bg $on->{$out}->{fallback} solid_color";
|
|
|
|
}
|
2020-11-23 09:35:26 +00:00
|
|
|
|
|
|
|
# Sway returns status as JSON
|
|
|
|
my $res_raw = `$cmd`;
|
2022-06-06 17:56:59 +00:00
|
|
|
#print $res_raw . "\n";
|
2020-11-23 09:35:26 +00:00
|
|
|
my $res = $json->decode($res_raw)->[0];
|
|
|
|
|
|
|
|
# If failed, print to STDERR
|
|
|
|
unless ($res->{success}) {
|
2021-08-12 21:27:40 +00:00
|
|
|
print STDERR "Error ($res->{error}) in command " .
|
|
|
|
"'$cmd'\n";
|
2020-11-23 09:35:26 +00:00
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 09:35:26 +00:00
|
|
|
# Skip waybar setup if template failed to be loaded
|
|
|
|
if ( (defined $template) &&
|
|
|
|
(defined $on->{$out}->{waybar}) &&
|
|
|
|
($on->{$out}->{waybar} =~ m/(top|bottom|left|right)/) )
|
|
|
|
{
|
|
|
|
|
|
|
|
# If there's already a display set up, add a comma
|
|
|
|
unless ($waybar eq '') {
|
|
|
|
$waybar .= ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
$waybar .= $template;
|
|
|
|
|
|
|
|
# Replace basic preferences
|
2022-04-19 04:25:29 +00:00
|
|
|
$waybar =~ s/__OUTPUT__/"$on->{$out}->{output}"/gg;
|
|
|
|
$waybar =~ s/__POSITION__/"$on->{$out}->{waybar}"/gg;
|
2020-11-23 09:35:26 +00:00
|
|
|
if (defined $on->{$out}->{width}) {
|
2021-11-12 03:01:07 +00:00
|
|
|
my $x = $on->{$out}->{width};
|
|
|
|
if (defined $on->{$out}->{scale}) {
|
|
|
|
$x = sprintf("%.0d", $x / $on->{$out}->{scale});
|
|
|
|
}
|
2022-04-19 04:25:29 +00:00
|
|
|
$waybar =~ s/__WIDTH__/$x/gg;
|
2020-11-23 09:35:26 +00:00
|
|
|
# If width is not set, comment that line out to use default
|
|
|
|
} else {
|
|
|
|
$waybar =~ s/([^\s]*\s*)__WIDTH__/\/\/ $1__WIDTH__/gg;
|
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
}
|
2020-09-11 15:00:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 17:56:59 +00:00
|
|
|
# Log active outputs for recovery after crash/reboot
|
|
|
|
if (open(my $fh, '>', $active_outputs)) {
|
|
|
|
print $fh join(' ', @active);
|
|
|
|
close($fh);
|
|
|
|
} else {
|
|
|
|
print STDERR "Cannot write active outputs to: $active_outputs\n";
|
|
|
|
}
|
2021-01-18 02:51:31 +00:00
|
|
|
|
2020-11-16 04:47:18 +00:00
|
|
|
# Restore array formatting
|
|
|
|
$waybar = '[' . $waybar . ']';
|
|
|
|
|
|
|
|
# Start Waybar as fork
|
|
|
|
my $pid = fork;
|
|
|
|
unless ($pid) {
|
2020-11-23 09:35:26 +00:00
|
|
|
open STDIN, '/dev/null';
|
|
|
|
open STDOUT, '>>/dev/null';
|
|
|
|
open STDERR, '>>/dev/null';
|
|
|
|
# Write config to a temporary file
|
2022-06-06 17:56:59 +00:00
|
|
|
if (open (my $fh, '>', $waybar_config)) {
|
|
|
|
print $fh $waybar;
|
|
|
|
close $fh;
|
|
|
|
} else {
|
|
|
|
die "Failed to write configuration file: $waybar_config\n";
|
|
|
|
}
|
2021-11-12 03:01:07 +00:00
|
|
|
my $waydisplay = $ENV{'WAYLAND_DISPLAY'} || 'wayland-0';
|
2022-06-06 17:56:59 +00:00
|
|
|
`WAYLAND_DISPLAY=$waydisplay nohup waybar -b waybar0 --config=$waybar_config >> $ENV{'HOME'}/.waybar.log`;
|
2020-11-16 04:47:18 +00:00
|
|
|
}
|