Compare commits
9 Commits
540dc56478
...
b8bf5eb197
Author | SHA1 | Date |
---|---|---|
John Mertz | b8bf5eb197 | |
John Mertz | 5c7f22bec7 | |
John Mertz | 1658999ba1 | |
John Mertz | b403d8987c | |
John Mertz | d8ae0c1c48 | |
John Mertz | 2559d13d38 | |
John Mertz | 3c059af401 | |
John Mertz | 586ce31d0d | |
John Mertz | 3a3bfcd6a6 |
|
@ -13,11 +13,18 @@ my $lat_lon = fetch_lat_lon($location);
|
||||||
|
|
||||||
my $pid = fork;
|
my $pid = fork;
|
||||||
unless ($pid) {
|
unless ($pid) {
|
||||||
|
open(my $fh, ">", $ENV{HOME}."/.spool/gammastep.pid");
|
||||||
|
print $fh $$;
|
||||||
|
close($fh);
|
||||||
|
open($fh, ">", $ENV{HOME}."/.spool/gammastep.status");
|
||||||
|
print $fh 1;
|
||||||
|
close($fh);
|
||||||
|
|
||||||
open STDIN, '/dev/null';
|
open STDIN, '/dev/null';
|
||||||
open STDOUT, '>>/dev/null';
|
open STDOUT, '>>/dev/null';
|
||||||
open STDERR, '>>/dev/null';
|
open STDERR, '>>/dev/null';
|
||||||
|
|
||||||
`gammastep -l $lat_lon -b 0.7:0.3`;
|
exec "exec gammastep -l $lat_lon -b 0.7:0.3";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fetch_lat_lon
|
sub fetch_lat_lon
|
||||||
|
|
|
@ -357,7 +357,7 @@ sub run
|
||||||
if ($self->{crop}) {
|
if ($self->{crop}) {
|
||||||
$self->do_log('LOG_DEBUG', "Deleting $cropped");
|
$self->do_log('LOG_DEBUG', "Deleting $cropped");
|
||||||
# Give swaybg a second, otherwise the file will be missing before it ends
|
# Give swaybg a second, otherwise the file will be missing before it ends
|
||||||
sleep(1);
|
sleep(2);
|
||||||
unlink($cropped) || $self->do_log("LOG_WARNING", "Failed to delete $cropped after setting: $!");
|
unlink($cropped) || $self->do_log("LOG_WARNING", "Failed to delete $cropped after setting: $!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -433,7 +433,7 @@ while (my $arg = shift(@ARGV)) {
|
||||||
$wp->do_log("LOG_DEBUG", "Validating arguments");
|
$wp->do_log("LOG_DEBUG", "Validating arguments");
|
||||||
die "Invalid rotation delay: $delay" if (defined($delay) && $delay !~ m/^\d+$/);
|
die "Invalid rotation delay: $delay" if (defined($delay) && $delay !~ m/^\d+$/);
|
||||||
die "Invalid wallpaper path '$path'. Not a directory." if (defined($path) && !-d $path);
|
die "Invalid wallpaper path '$path'. Not a directory." if (defined($path) && !-d $path);
|
||||||
die "Invalid verbosity level: '$verbose'\n" if (defined($verbose) && $verbose =~ m/^[1-8]$/);
|
die "Invalid verbosity level: '$verbose'\n" if (defined($verbose) && $verbose !~ m/^[1-8]$/);
|
||||||
|
|
||||||
$wp->do_log("LOG_DEBUG", "Configuring object");
|
$wp->do_log("LOG_DEBUG", "Configuring object");
|
||||||
$wp->{targets} = \@targets || undef;
|
$wp->{targets} = \@targets || undef;
|
||||||
|
|
|
@ -66,13 +66,13 @@
|
||||||
# Files containing current and max brightness values
|
# Files containing current and max brightness values
|
||||||
my $cur_file = "/sys/class/backlight/intel_backlight/brightness";
|
my $cur_file = "/sys/class/backlight/intel_backlight/brightness";
|
||||||
my $max_file = "/sys/class/backlight/intel_backlight/max_brightness";
|
my $max_file = "/sys/class/backlight/intel_backlight/max_brightness";
|
||||||
my $last_file = "/home/jpm/.config/blc.last";
|
my $cur_log = $ENV{HOME}."/.spool/blc.current";
|
||||||
|
my $last_log = $ENV{HOME}."/.spool/blc.last";
|
||||||
|
|
||||||
sub to_percent
|
sub to_percent
|
||||||
{
|
{
|
||||||
my $value = shift;
|
my $value = shift;
|
||||||
$value = int($value/get_max()*100);
|
return int($value/get_max()*100);
|
||||||
return $value . '%';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_offset
|
sub get_offset
|
||||||
|
@ -111,6 +111,25 @@ sub writable
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub logger
|
||||||
|
{
|
||||||
|
my ($current, $target) = @_;
|
||||||
|
open(my $fh,'>',$last_log);
|
||||||
|
print $fh to_percent($current);
|
||||||
|
close($fh);
|
||||||
|
open($fh,'>',$cur_log);
|
||||||
|
print $fh to_percent($target);
|
||||||
|
close($fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub writef
|
||||||
|
{
|
||||||
|
my $target = shift;
|
||||||
|
open(my $fh,'>',$cur_file);
|
||||||
|
print $fh $target;
|
||||||
|
close($fh);
|
||||||
|
}
|
||||||
|
|
||||||
sub increment
|
sub increment
|
||||||
{
|
{
|
||||||
if (writable()) {
|
if (writable()) {
|
||||||
|
@ -120,9 +139,6 @@ sub increment
|
||||||
if ($target > $max) {
|
if ($target > $max) {
|
||||||
$target = $max;
|
$target = $max;
|
||||||
}
|
}
|
||||||
open(my $c,'>',"$cur_file");
|
|
||||||
print $c $target;
|
|
||||||
close $c;
|
|
||||||
return $target;
|
return $target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,9 +152,7 @@ sub decrement
|
||||||
if ($target < $min) {
|
if ($target < $min) {
|
||||||
$target = $min;
|
$target = $min;
|
||||||
}
|
}
|
||||||
open(my $c,'>',"$cur_file");
|
set($target);
|
||||||
print $c $target;
|
|
||||||
close $c;
|
|
||||||
return $target;
|
return $target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,18 +161,15 @@ sub set
|
||||||
{
|
{
|
||||||
my $value = shift;
|
my $value = shift;
|
||||||
if (writable()) {
|
if (writable()) {
|
||||||
$current = get_current();
|
my $current = get_current();
|
||||||
|
logger($current,$value);
|
||||||
if ($value > $current) {
|
if ($value > $current) {
|
||||||
for (my $i=$current;$i<=$value;$i++) {
|
for (my $i=$current;$i<=$value;$i++) {
|
||||||
open(my $c,'>',"$cur_file");
|
writef($i);
|
||||||
print $c $i;
|
|
||||||
close $c;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (my $i=$current;$i>=$value;$i--) {
|
for (my $i=$current;$i>=$value;$i--) {
|
||||||
open(my $c,'>',"$cur_file");
|
writef($i);
|
||||||
print $c $i;
|
|
||||||
close $c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -243,7 +254,7 @@ my $operation_found = 0;
|
||||||
if (scalar @ARGV) {
|
if (scalar @ARGV) {
|
||||||
while ($arg = shift) {
|
while ($arg = shift) {
|
||||||
if ($arg eq '%') {
|
if ($arg eq '%') {
|
||||||
push @output,int(get_current()/get_max()*100);
|
push @output,to_percent(get_current);
|
||||||
} elsif ($arg eq '^') {
|
} elsif ($arg eq '^') {
|
||||||
push @output,get_max();
|
push @output,get_max();
|
||||||
} elsif ($arg eq '==') {
|
} elsif ($arg eq '==') {
|
||||||
|
@ -341,11 +352,6 @@ if (scalar @ARGV) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
open(my $fh,'>',$last_file);
|
|
||||||
print $fh get_current();
|
|
||||||
close($fh);
|
|
||||||
|
|
||||||
print $_."\n" foreach(@output);
|
|
||||||
if ($silent) {
|
if ($silent) {
|
||||||
exit();
|
exit();
|
||||||
} elsif ($notify) {
|
} elsif ($notify) {
|
||||||
|
|
|
@ -3,35 +3,71 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
my $maxfile = "/sys/class/leds/tpacpi\:\:kbd_backlight/max_brightness";
|
our $maxfile = "/sys/class/leds/tpacpi\:\:kbd_backlight/max_brightness";
|
||||||
my $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
|
our $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
|
||||||
|
our $sleepfile = "$ENV{HOME}/.spool/kbd_sleep";
|
||||||
|
|
||||||
my ($max, $now, $new);
|
sub readFile
|
||||||
if (open(my $m, '<', $maxfile)) {
|
{
|
||||||
$max = readline($m);
|
my $file = shift;
|
||||||
chomp $max;
|
my $ret;
|
||||||
close($m);
|
if (open(my $fh, '<', $file)) {
|
||||||
} else {
|
$ret = readline($fh);
|
||||||
print "Failed to read $maxfile\n";
|
chomp $ret;
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open(my $c, '<', $current)) {
|
|
||||||
$now = readline($c);
|
|
||||||
chomp $now;
|
|
||||||
close($c);
|
|
||||||
} else {
|
|
||||||
print "Failed to read $current\n";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (open(my $fh, '>', $current)) {
|
|
||||||
$new = (($now+1) % ($max+1));
|
|
||||||
chomp $new;
|
|
||||||
print $fh $new;
|
|
||||||
close($fh);
|
close($fh);
|
||||||
} else {
|
} else {
|
||||||
print "Failed to write $current\n";
|
die "Failed to read $file: $?\n";
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
#print STDERR "$new\n";
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub writeFile
|
||||||
|
{
|
||||||
|
my ($file, $value) = @_;
|
||||||
|
if (open(my $fh, '>', $file)) {
|
||||||
|
print $fh $value;
|
||||||
|
close($fh);
|
||||||
|
} else {
|
||||||
|
die "Failed to write $current\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub sleepFile
|
||||||
|
{
|
||||||
|
my $now = readFile($current);
|
||||||
|
writeFile($sleepfile,$now);
|
||||||
|
writeFile($current,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub restoreFile
|
||||||
|
{
|
||||||
|
unless (-e $sleepfile) {
|
||||||
|
die "Missing '$sleepfile'. Must not have slept prior to restore.\n"
|
||||||
|
}
|
||||||
|
my $value = readFile($sleepfile);
|
||||||
|
writeFile($current,$value);
|
||||||
|
unlink($sleepfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub rotateFile
|
||||||
|
{
|
||||||
|
my $max = readFile($maxfile);
|
||||||
|
my $now = readFile($current);
|
||||||
|
my $new = (($now+1) % ($max+1));
|
||||||
|
writeFile($current,$new);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defined($ARGV[0])) {
|
||||||
|
if ($ARGV[0] eq 'sleep') {
|
||||||
|
sleepFile();
|
||||||
|
exit(0);
|
||||||
|
} elsif ($ARGV[0] eq 'restore') {
|
||||||
|
restoreFile();
|
||||||
|
exit(0);
|
||||||
|
} elsif ($ARGV[0] ne 'rotate') {
|
||||||
|
die "Invalid mode '".$ARGV[0]."'. 'rotate', 'sleep', or 'restore'\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rotateFile();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,101 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Starts a scan of available broadcasting SSIDs
|
||||||
|
# nmcli dev wifi rescan
|
||||||
|
|
||||||
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
FIELDS=SSID,SECURITY
|
||||||
|
POSITION=0
|
||||||
|
YOFF=0
|
||||||
|
XOFF=0
|
||||||
|
|
||||||
|
if [ -r "$DIR/config" ]; then
|
||||||
|
source "$DIR/config"
|
||||||
|
elif [ -r "$HOME/.dotfiles/wofi/wifi" ]; then
|
||||||
|
source "$HOME/.dotfiles/wofi/wifi"
|
||||||
|
else
|
||||||
|
echo "WARNING: config file not found! Using default values."
|
||||||
|
fi
|
||||||
|
|
||||||
|
LIST=$(nmcli --fields "$FIELDS" device wifi list | sed '/^--/d')
|
||||||
|
# For some reason wofi always approximates character width 2 short... hmmm
|
||||||
|
RWIDTH=$(($(echo "$LIST" | head -n 1 | awk '{print length($0); }')*10))
|
||||||
|
# Dynamically change the height of the wofi menu
|
||||||
|
LINENUM=$(echo "$LIST" | wc -l)
|
||||||
|
# Gives a list of known connections so we can parse it later
|
||||||
|
KNOWNCON=$(nmcli connection show)
|
||||||
|
# Really janky way of telling if there is currently a connection
|
||||||
|
CONSTATE=$(nmcli -fields WIFI g)
|
||||||
|
|
||||||
|
CURRSSID=$(LANGUAGE=C nmcli -t -f active,ssid dev wifi | awk -F: '$1 ~ /^yes/ {print $2}')
|
||||||
|
|
||||||
|
if [[ ! -z $CURRSSID ]]; then
|
||||||
|
HIGHLINE=$(echo "$(echo "$LIST" | awk -F "[ ]{2,}" '{print $1}' | grep -Fxn -m 1 "$CURRSSID" | awk -F ":" '{print $1}') + 1" | bc )
|
||||||
|
fi
|
||||||
|
|
||||||
|
# HOPEFULLY you won't need this as often as I do
|
||||||
|
# If there are more than 8 SSIDs, the menu will still only have 8 lines
|
||||||
|
if [ "$LINENUM" -gt 8 ] && [[ "$CONSTATE" =~ "enabled" ]]; then
|
||||||
|
LINENUM=8
|
||||||
|
elif [[ "$CONSTATE" =~ "disabled" ]]; then
|
||||||
|
LINENUM=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ "$CONSTATE" =~ "enabled" ]]; then
|
||||||
|
TOGGLE="toggle off"
|
||||||
|
elif [[ "$CONSTATE" =~ "disabled" ]]; then
|
||||||
|
TOGGLE="toggle on"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
CHENTRY=$(echo -e "$TOGGLE\nmanual\n$LIST" | uniq -u | wofi -s $HOME/.dotfiles/wofi/style.css -i -d --prompt "Wi-Fi SSID: " --lines "$LINENUM" --location "$POSITION" --yoffset "$YOFF" --xoffset "$XOFF" --width $RWIDTH)
|
||||||
|
if [[ $CHENTRY == "" ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
#echo "$CHENTRY"
|
||||||
|
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $1}')
|
||||||
|
#echo "$CHSSID"
|
||||||
|
|
||||||
|
# If the user inputs "manual" as their SSID in the start window, it will bring them to this screen
|
||||||
|
if [ "$CHENTRY" = "manual" ] ; then
|
||||||
|
# Manual entry of the SSID and password (if appplicable)
|
||||||
|
MSSID=$(echo "enter the SSID of the network (SSID,password)" | wofi -s $HOME/.dotfiles/wofi/style.css -d "Manual Entry: " --lines 1)
|
||||||
|
# Separating the password from the entered string
|
||||||
|
MPASS=$(echo "$MSSID" | awk -F "," '{print $2}')
|
||||||
|
|
||||||
|
#echo "$MSSID"
|
||||||
|
#echo "$MPASS"
|
||||||
|
|
||||||
|
# If the user entered a manual password, then use the password nmcli command
|
||||||
|
if [ "$MPASS" = "" ]; then
|
||||||
|
nmcli dev wifi con "$MSSID"
|
||||||
|
else
|
||||||
|
nmcli dev wifi con "$MSSID" password "$MPASS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
elif [ "$CHENTRY" = "toggle on" ]; then
|
||||||
|
nmcli radio wifi on
|
||||||
|
|
||||||
|
elif [ "$CHENTRY" = "toggle off" ]; then
|
||||||
|
nmcli radio wifi off
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
# If the connection is already in use, then this will still be able to get the SSID
|
||||||
|
if [ "$CHSSID" = "*" ]; then
|
||||||
|
CHSSID=$(echo "$CHENTRY" | sed 's/\s\{2,\}/\|/g' | awk -F "|" '{print $3}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Parses the list of preconfigured connections to see if it already contains the chosen SSID. This speeds up the connection process
|
||||||
|
if [[ $(echo "$KNOWNCON" | grep "$CHSSID") = "$CHSSID" ]]; then
|
||||||
|
nmcli con up "$CHSSID"
|
||||||
|
else
|
||||||
|
if [[ "$CHENTRY" =~ "WPA2" ]] || [[ "$CHENTRY" =~ "WEP" ]]; then
|
||||||
|
WIFIPASS=$(echo "if connection is stored, hit enter" | wofi -s $HOME/.dotfiles/wofi/style.css -P -d --prompt "password" --lines 1 --location "$POSITION" --yoffset "$YOFF" --xoffset "$XOFF" --width $RWIDTH)
|
||||||
|
fi
|
||||||
|
nmcli dev wifi con "$CHSSID" password "$WIFIPASS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
Loading…
Reference in New Issue