Compare commits

..

No commits in common. "4af723528921e69c6b8ee9ee6e3047990e1d5052" and "da77896e0fca478d0c7e6f7f09966181f18ef0fc" have entirely different histories.

6 changed files with 46 additions and 96 deletions

View File

@ -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|🖵 Toggle Displays|↩ Logout|↻ Reload Sway|↻ Reload Waybar|↯ Hibernate|🡙 Reboot|⏻ Shutdown" | rofi -sep "|" -dmenu -i -p 'Power: ' "" -no-lazy-grab -auto-select -no-fullscreen)
res=$(echo "🔒 Lock|↩ 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,8 +21,6 @@ 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

View File

@ -36,9 +36,6 @@ 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
########################################################################
@ -48,12 +45,9 @@ my $active_outputs = "$ENV{'HOME'}/.config/active_outputs";
# $ swaymsg -t get_outputs
# Output eDP-1 'Unknown 0x057D *0x00000000*'
my %outputs = (
#'0x00000101' => 'Sam',
'HTNCB00059' => 'Sam',
#'3CQ3310Q1Q' => 'Sam',
'0x00000101' => 'Sam',
'3CQ4342S6W' => 'HP-1',
'0x00000101' => 'HP-2',
#'3CQ3310Q1Q' => 'HP-2',
'3CQ3310Q1Q' => 'HP-2',
'0x00000000' => 'LVDS'
);
@ -99,7 +93,7 @@ my %configs = (
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 1920,
'x' => 0,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
@ -108,7 +102,7 @@ my %configs = (
'on' => 1,
'width' => 1920,
'height' => 1080,
'x' => 0,
'x' => 1920,
'y' => 1200,
'rotate' => 0,
'waybar' => 'top'
@ -159,7 +153,6 @@ use strict;
use warnings;
my $waybar_only = 0;
my $restore = 0; # Set if no config is provided. Requires validation.
my $config;
if (scalar(@ARGV)) {
@ -183,18 +176,12 @@ unless (defined $config) {
$config = <$fh>;
close($fh);
chomp $config;
$restore = 1;
}
# Bail if requested config doesn't exist
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";
}
unless (defined $configs{$config}) {
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
@ -203,7 +190,6 @@ open(my $fh, '>', $last) ||
print $fh $config;
close($fh);
# Fetch connected displays
use JSON::XS;
my $json = JSON::XS->new();
@ -238,24 +224,6 @@ 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
@ -311,11 +279,9 @@ $template =~ s/^[^\[\{]*\[(.*)\]$/$1/s;
my $waybar = '';
# Configure each enabled display
my @active;
foreach my $out (keys %$on) {
push @active, $on->{$out}->{output};
unless ($waybar_only) {
unless ($waybar_only) {
# Build command, starting by enabling and powering on
my $cmd = "sway output $on->{$out}->{output} enable dpms on";
@ -368,11 +334,6 @@ foreach my $out (keys %$on) {
}
}
open($fh, '>', $active_outputs);
print $fh join(' ', @active);
close($fh);
# Restore array formatting
$waybar = '[' . $waybar . ']';
@ -387,7 +348,7 @@ unless ($pid) {
open ($fh, '>', $tmp);
print $fh $waybar;
close $fh;
`nohup waybar --config=$tmp >> waybar.log`;
`nohup waybar --config=$tmp`;
# Remove config
unlink $tmp;

View File

@ -1,43 +0,0 @@
#!/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

36
sway/swayidle.sh Executable file
View File

@ -0,0 +1,36 @@
#!/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

View File

@ -7,5 +7,3 @@ if [ "$CURRENT" == "detached" ]; then
else
/home/jpm/scripts/sway/displays.pl detached
fi
pkill mako
mako &