Compare commits
5 Commits
da77896e0f
...
4af7235289
Author | SHA1 | Date |
---|---|---|
John Mertz | 4af7235289 | |
John Mertz | 978a6aef4b | |
John Mertz | 41ebb871d6 | |
John Mertz | 35ee85f260 | |
John Mertz | 668c3269d9 |
|
@ -12,7 +12,7 @@ fi
|
|||
if [[ $WM == 'i3' ]]; then
|
||||
res=$(printf "🔒 Lock|↩ Logout|↻ Reload i3|↹ Restart i3|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -columns 1 -rows 7 -width 32 -l 1 -hide-scrollbar -eh 1 -location 0 -padding 12 -opacity 100 -auto-select -no-fullscreen)
|
||||
else
|
||||
res=$(echo "🔒 Lock|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen)
|
||||
res=$(echo "🔒 Lock|🖵 Toggle Displays|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen)
|
||||
fi
|
||||
|
||||
if [ "$res" == "🔒 Lock" ]; then
|
||||
|
@ -21,6 +21,8 @@ elif [ "$res" == "↩ Logout" ]; then
|
|||
# Prevent auto-login
|
||||
rm /home/jpm/.config/last_login_gui
|
||||
${WM} exit
|
||||
elif [ "$res" == "🖵 Toggle Displays" ]; then
|
||||
/home/jpm/scripts/sway/toggle_outputs.sh
|
||||
elif [ "$res" == "↻ Reload i3" ]; then
|
||||
i3 reload
|
||||
elif [ "$res" == "↹ Restart i3" ]; then
|
||||
|
|
|
@ -36,6 +36,9 @@ my $waybar_temporary = '/tmp';
|
|||
# File to log and recover last used layout name
|
||||
my $last = "$ENV{'HOME'}/.config/last_display";
|
||||
|
||||
# File to log active outputs (used by swayidle, and to attempt to restore
|
||||
my $active_outputs = "$ENV{'HOME'}/.config/active_outputs";
|
||||
|
||||
########################################################################
|
||||
# Display Serials and Names
|
||||
########################################################################
|
||||
|
@ -45,9 +48,12 @@ my $last = "$ENV{'HOME'}/.config/last_display";
|
|||
# $ swaymsg -t get_outputs
|
||||
# Output eDP-1 'Unknown 0x057D *0x00000000*'
|
||||
my %outputs = (
|
||||
'0x00000101' => 'Sam',
|
||||
#'0x00000101' => 'Sam',
|
||||
'HTNCB00059' => 'Sam',
|
||||
#'3CQ3310Q1Q' => 'Sam',
|
||||
'3CQ4342S6W' => 'HP-1',
|
||||
'3CQ3310Q1Q' => 'HP-2',
|
||||
'0x00000101' => 'HP-2',
|
||||
#'3CQ3310Q1Q' => 'HP-2',
|
||||
'0x00000000' => 'LVDS'
|
||||
);
|
||||
|
||||
|
@ -93,7 +99,7 @@ my %configs = (
|
|||
'on' => 1,
|
||||
'width' => 1920,
|
||||
'height' => 1080,
|
||||
'x' => 0,
|
||||
'x' => 1920,
|
||||
'y' => 1200,
|
||||
'rotate' => 0,
|
||||
'waybar' => 'top'
|
||||
|
@ -102,7 +108,7 @@ my %configs = (
|
|||
'on' => 1,
|
||||
'width' => 1920,
|
||||
'height' => 1080,
|
||||
'x' => 1920,
|
||||
'x' => 0,
|
||||
'y' => 1200,
|
||||
'rotate' => 0,
|
||||
'waybar' => 'top'
|
||||
|
@ -153,6 +159,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
my $waybar_only = 0;
|
||||
my $restore = 0; # Set if no config is provided. Requires validation.
|
||||
my $config;
|
||||
|
||||
if (scalar(@ARGV)) {
|
||||
|
@ -176,12 +183,18 @@ unless (defined $config) {
|
|||
$config = <$fh>;
|
||||
close($fh);
|
||||
chomp $config;
|
||||
$restore = 1;
|
||||
}
|
||||
|
||||
# Bail if requested config doesn't exist
|
||||
unless (defined $configs{$config}) {
|
||||
die "$config is not a defined configuration: "
|
||||
. join(', ', keys %configs) . "\n";
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
# Write config that is to be used so that it can be recovered as default
|
||||
|
@ -190,6 +203,7 @@ open(my $fh, '>', $last) ||
|
|||
print $fh $config;
|
||||
close($fh);
|
||||
|
||||
|
||||
# Fetch connected displays
|
||||
use JSON::XS;
|
||||
my $json = JSON::XS->new();
|
||||
|
@ -224,6 +238,24 @@ for (my $i = 0; $i < scalar(@$displays); $i++) {
|
|||
|
||||
}
|
||||
|
||||
# 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)) {
|
||||
die "Config requires unavailable output(s) " . join(', ', @unavailable) . "\n";
|
||||
}
|
||||
|
||||
# Skip enabling/disabling displays if only running waybar (re)start
|
||||
unless ($waybar_only) {
|
||||
# Number of simultaneous outputs is limited by gpu, so disabled displays
|
||||
|
@ -279,9 +311,11 @@ $template =~ s/^[^\[\{]*\[(.*)\]$/$1/s;
|
|||
my $waybar = '';
|
||||
|
||||
# Configure each enabled display
|
||||
my @active;
|
||||
foreach my $out (keys %$on) {
|
||||
|
||||
unless ($waybar_only) {
|
||||
push @active, $on->{$out}->{output};
|
||||
unless ($waybar_only) {
|
||||
# Build command, starting by enabling and powering on
|
||||
my $cmd = "sway output $on->{$out}->{output} enable dpms on";
|
||||
|
||||
|
@ -334,6 +368,11 @@ foreach my $out (keys %$on) {
|
|||
}
|
||||
}
|
||||
|
||||
open($fh, '>', $active_outputs);
|
||||
print $fh join(' ', @active);
|
||||
close($fh);
|
||||
|
||||
|
||||
# Restore array formatting
|
||||
$waybar = '[' . $waybar . ']';
|
||||
|
||||
|
@ -348,7 +387,7 @@ unless ($pid) {
|
|||
open ($fh, '>', $tmp);
|
||||
print $fh $waybar;
|
||||
close $fh;
|
||||
`nohup waybar --config=$tmp`;
|
||||
`nohup waybar --config=$tmp >> waybar.log`;
|
||||
|
||||
# Remove config
|
||||
unlink $tmp;
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#!/bin/bash
|
||||
|
||||
BLFILE="/home/jpm/.config/blc.last"
|
||||
OPFILE="/home/jpm/.config/active_outputs"
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "Missing argument: run, warn, sleep or" \
|
||||
" wake"
|
||||
elif [ $1 == "start" ]; then
|
||||
swayidle -w timeout 270 "/home/jpm/scripts/sway/idle.sh warn" \
|
||||
resume "/home/jpm/scripts/sway/idle.sh resume" \
|
||||
timeout 300 "/home/jpm/scripts/sway/idle.sh sleep" \
|
||||
resume "/home/jpm/scripts/sway/idle.sh wake" \
|
||||
before-sleep "/usr/bin/swaylock -c 323232"
|
||||
elif [ $1 == "warn" ]; then
|
||||
# Store current brightness
|
||||
echo $(/home/jpm/scripts/thinkpad/blc.pl %) > $BLFILE
|
||||
# Dim display
|
||||
/home/jpm/scripts/thinkpad/blc.pl = 1
|
||||
# Warning notifications
|
||||
/home/jpm/scripts/sway/idlecountdown.sh
|
||||
elif [ $1 == "sleep" ]; then
|
||||
# Change nick to AFK
|
||||
ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
|
||||
'screen -S irssi -X stuff "/nick jpmAFK^M"'
|
||||
# Turn off monitor
|
||||
for i in `cat $OPFILE`; do swaymsg "output $i dpms off"; done
|
||||
elif [ $1 == "wake" ]; then
|
||||
# Kill additional counters that might have been started
|
||||
/home/jpm/scripts/sway/idle.sh resume
|
||||
# Restore output(s)
|
||||
/home/jpm/scripts/sway/displays.pl
|
||||
#for i in `cat $OPFILE`; do swaymsg "output $i dpms on"; done
|
||||
# Lock screen
|
||||
swaylock -c 323232
|
||||
# Restore brightness level
|
||||
/home/jpm/scripts/thinkpad/blc.pl = $(cat $BLFILE)
|
||||
elif [ $1 == "resume" ]; then
|
||||
# Kill warning
|
||||
for i in `pgrep idlecountdown`; do kill $i; done
|
||||
else
|
||||
echo "Invalid argument: run, sleep or wake"
|
||||
fi
|
|
@ -1,36 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
BLFILE="/tmp/blc"
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "Missing argument: swayidlerun, swayidlewarn, swayidlesleep or" \
|
||||
" swayidlewake"
|
||||
elif [ $1 == "swayidlerun" ]; then
|
||||
swayidle timeout 270 "/home/jpm/scripts/swayidle.sh swayidlewarn" \
|
||||
before-sleep "/home/jpm/scripts/swayidle.sh swayidlesleep" \
|
||||
resume "/home/jpm/scripts/swayidle.sh swayidlewake"
|
||||
elif [ $1 == "swayidlewarn" ]; then
|
||||
# Store current brightness
|
||||
echo $(/home/jpm/bin/blc.pl %) > $BLFILE
|
||||
# Dim display
|
||||
/home/jpm/bin/blc.pl = 1
|
||||
# Warning notifications
|
||||
/home/jpm/scripts/swayidlecountdown.sh
|
||||
elif [ $1 == "swayidlesleep" ]; then
|
||||
# Change nick to AFK
|
||||
ssh jpm@john.me.tz -i /home/jpm/.ssh/no_pass -t \
|
||||
'screen -S irssi -X stuff "/nick jpmAFK^M"'
|
||||
# Turn off monitor
|
||||
swaymsg 'swaymsg "output * dpms off"'
|
||||
# Lock screen
|
||||
swaylock -c 323232
|
||||
elif [ $1 == "swayidlewake" ]; then
|
||||
# Kill sleep if running
|
||||
# Turn on monitor
|
||||
swaymsg 'swaymsg "output * dpms on"'
|
||||
# Restore brightness level
|
||||
kill `pgrep swayidlecountdo`
|
||||
/home/jpm/bin/blc.pl = $(cat /tmp/blc)
|
||||
else
|
||||
echo "Invalid argument: run, sleep or wake"
|
||||
fi
|
|
@ -7,3 +7,5 @@ if [ "$CURRENT" == "detached" ]; then
|
|||
else
|
||||
/home/jpm/scripts/sway/displays.pl detached
|
||||
fi
|
||||
pkill mako
|
||||
mako &
|
||||
|
|
Loading…
Reference in New Issue