Compare commits

..

No commits in common. "b8bf5eb197f39bdf0e104d25fa05c7b5bd37365d" and "540dc564788d370294631b2bc69b9a967c8e1611" have entirely different histories.

6 changed files with 105 additions and 2108 deletions

View File

@ -13,18 +13,11 @@ my $lat_lon = fetch_lat_lon($location);
my $pid = fork;
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 STDOUT, '>>/dev/null';
open STDERR, '>>/dev/null';
exec "exec gammastep -l $lat_lon -b 0.7:0.3";
`gammastep -l $lat_lon -b 0.7:0.3`;
}
sub fetch_lat_lon

View File

@ -357,7 +357,7 @@ sub run
if ($self->{crop}) {
$self->do_log('LOG_DEBUG', "Deleting $cropped");
# Give swaybg a second, otherwise the file will be missing before it ends
sleep(2);
sleep(1);
unlink($cropped) || $self->do_log("LOG_WARNING", "Failed to delete $cropped after setting: $!");
}
} else {
@ -433,7 +433,7 @@ while (my $arg = shift(@ARGV)) {
$wp->do_log("LOG_DEBUG", "Validating arguments");
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 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->{targets} = \@targets || undef;

View File

@ -11,7 +11,7 @@
#
# to output like:
# 1000/10000 = 10%
#
#
# Create a new array of hashes to classify the ARGV elements, eg:
# $0 + "+%c" -= 10 +=4 =1 =100 "+%p"
# [
@ -66,13 +66,13 @@
# Files containing current and max brightness values
my $cur_file = "/sys/class/backlight/intel_backlight/brightness";
my $max_file = "/sys/class/backlight/intel_backlight/max_brightness";
my $cur_log = $ENV{HOME}."/.spool/blc.current";
my $last_log = $ENV{HOME}."/.spool/blc.last";
my $last_file = "/home/jpm/.config/blc.last";
sub to_percent
{
my $value = shift;
return int($value/get_max()*100);
$value = int($value/get_max()*100);
return $value . '%';
}
sub get_offset
@ -106,28 +106,9 @@ sub get_min
sub writable
{
if (! -w $cur_file) {
die "You don't have permission to write $cur_file\n";
die "You don't have permission to write $cur_file\n";
}
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);
return 1;
}
sub increment
@ -139,6 +120,9 @@ sub increment
if ($target > $max) {
$target = $max;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
}
}
@ -152,7 +136,9 @@ sub decrement
if ($target < $min) {
$target = $min;
}
set($target);
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
}
}
@ -161,15 +147,18 @@ sub set
{
my $value = shift;
if (writable()) {
my $current = get_current();
logger($current,$value);
$current = get_current();
if ($value > $current) {
for (my $i=$current;$i<=$value;$i++) {
writef($i);
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
}
} else {
for (my $i=$current;$i>=$value;$i--) {
writef($i);
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
}
}
return $value;
@ -252,9 +241,9 @@ my (@output, $target, $silent, $notify);
my $operation_found = 0;
if (scalar @ARGV) {
while ($arg = shift) {
while ($arg = shift) {
if ($arg eq '%') {
push @output,to_percent(get_current);
push @output,int(get_current()/get_max()*100);
} elsif ($arg eq '^') {
push @output,get_max();
} elsif ($arg eq '==') {
@ -277,52 +266,52 @@ if (scalar @ARGV) {
} else {
$duration = 1000;
}
} elsif ($arg eq '+') {
unshift(@ARGV,1);
unshift(@ARGV,'+=');
} elsif ($arg eq '+') {
unshift(@ARGV,1);
unshift(@ARGV,'+=');
} elsif ($arg =~ /^\+=/) {
my $offset;
if ($arg =~ m/^\+=(.+)$/) {
$offset = $1;
} else {
$offset = shift || die "+= without accompanying offset value\n";
}
unless ($offset =~ /^\d+$/) {
die "+= <value> is not a number ($offset)\n";
}
my $offset;
if ($arg =~ m/^\+=(.+)$/) {
$offset = $1;
} else {
$offset = shift || die "+= without accompanying offset value\n";
}
unless ($offset =~ /^\d+$/) {
die "+= <value> is not a number ($offset)\n";
}
for (my $j=0;$j<$offset;$j++) {
$target = increment();
@output = to_percent($target);
@output = to_percent($target);
}
$operation_found = 1;
} elsif ($arg eq '-') {
unshift(@ARGV,1);
unshift(@ARGV,'-=');
} elsif ($arg eq '-') {
unshift(@ARGV,1);
unshift(@ARGV,'-=');
} elsif ($arg =~ /^-=/) {
my $offset;
if ($arg =~ m/^-=(.+)$/) {
$offset = $1;
} else {
$offset = shift || die "-= without accompanying offset value\n";
}
unless ($offset =~ /^\d+$/) {
die "-= <value> is not a number ($offset)\n";
}
my $offset;
if ($arg =~ m/^-=(.+)$/) {
$offset = $1;
} else {
$offset = shift || die "-= without accompanying offset value\n";
}
unless ($offset =~ /^\d+$/) {
die "-= <value> is not a number ($offset)\n";
}
for (my $j=0;$j<$offset;$j++) {
$target = decrement();
@output = to_percent($target);
@output = to_percent($target);
}
$operation_found = 1;
} elsif ($arg =~ m/^=/) {
my $value;
if ($arg =~ m/^=(.+)$/) {
$target = $1;
} else {
$target = shift || die "= without accompanying absolute value\n";
}
unless ($target =~ /^\d+$/) {
die "= <value> is not a number ($target)\n";
}
my $value;
if ($arg =~ m/^=(.+)$/) {
$target = $1;
} else {
$target = shift || die "= without accompanying absolute value\n";
}
unless ($target =~ /^\d+$/) {
die "= <value> is not a number ($target)\n";
}
if ($target < 1) {
$target = set(get_min());
} elsif ($target > get_max()) {
@ -337,7 +326,7 @@ if (scalar @ARGV) {
@output = to_percent($target);
$operation_found = 1;
} else {
push(@output,$arg);
push(@output,$arg);
}
}
} else {
@ -347,11 +336,16 @@ if (scalar @ARGV) {
. '","Current":"'
. get_current()
. '","Percentage","'
. int(get_current()/get_max()*100)
. int(get_current()/get_max()*100)
. '%"}}'
);
}
open(my $fh,'>',$last_file);
print $fh get_current();
close($fh);
print $_."\n" foreach(@output);
if ($silent) {
exit();
} elsif ($notify) {
@ -360,26 +354,26 @@ if ($silent) {
$concat .= $_;
}
=pod
use Gtk2::Notify -init, "Backlight";
my $notification = Gtk2::Notify::new('Backlight', $concat, '', "notification-display-brightness");
use Gtk2::Notify -init, "Backlight";
my $notification = Gtk2::Notify::new('Backlight', $concat, '', "notification-display-brightness");
$notification->set_hint_string('x-canonical-private-synchronous','blc');
$notification->set_urgency('NOTIFY_URGENCY_LOW');
$notification->set_hint_int32('value',(split('%',$concat))[0]);
$notification->set_timeout($duration);
$notification->show();
exit;
$notification->set_hint_string('x-canonical-private-synchronous','blc');
$notification->set_urgency('NOTIFY_URGENCY_LOW');
$notification->set_hint_int32('value',(split('%',$concat))[0]);
$notification->set_timeout($duration);
$notification->show();
exit;
print "notify-send --urgency=normal"
. ' --icon="notification-display-brightness"'
. ' --hint=string:x-canonical-private-synchronous:blc'
. ' --hint=string:x-canonical-private-synchronous:blc'
. ' --expire-time=' . $duration
. ' "Backlight"'
. ' "Backlight"'
. ' "' . $concat . " '" . join("','", @output) . "'\"";
system "notify-send --urgency=normal"
. ' --icon="notification-display-brightness"'
. ' --hint=string:x-canonical-private-synchronous:blc'
. ' --hint=int:value:' . (split('%',$concat))[0]
. ' --expire-time=' . $duration
. ' --hint=string:x-canonical-private-synchronous:blc'
. ' --hint=int:value:' . (split('%',$concat))[0]
. ' --expire-time=' . $duration
. ' "' . $concat . "\"";
=cut

View File

@ -3,71 +3,35 @@
use strict;
use warnings;
our $maxfile = "/sys/class/leds/tpacpi\:\:kbd_backlight/max_brightness";
our $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
our $sleepfile = "$ENV{HOME}/.spool/kbd_sleep";
my $maxfile = "/sys/class/leds/tpacpi\:\:kbd_backlight/max_brightness";
my $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
sub readFile
{
my $file = shift;
my $ret;
if (open(my $fh, '<', $file)) {
$ret = readline($fh);
chomp $ret;
close($fh);
} else {
die "Failed to read $file: $?\n";
}
return $ret;
my ($max, $now, $new);
if (open(my $m, '<', $maxfile)) {
$max = readline($m);
chomp $max;
close($m);
} else {
print "Failed to read $maxfile\n";
exit;
}
sub writeFile
{
my ($file, $value) = @_;
if (open(my $fh, '>', $file)) {
print $fh $value;
close($fh);
} else {
die "Failed to write $current\n";
}
if (open(my $c, '<', $current)) {
$now = readline($c);
chomp $now;
close($c);
} else {
print "Failed to read $current\n";
exit;
}
sub sleepFile
{
my $now = readFile($current);
writeFile($sleepfile,$now);
writeFile($current,0);
if (open(my $fh, '>', $current)) {
$new = (($now+1) % ($max+1));
chomp $new;
print $fh $new;
close($fh);
} else {
print "Failed to write $current\n";
exit;
}
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();
#print STDERR "$new\n";

File diff suppressed because it is too large Load Diff

View File

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