Compare commits

...

9 Commits

Author SHA1 Message Date
John Mertz b8bf5eb197 Wifi Menu
Slightly modified from https://github.com/fourstepper/wofi-wifi-menu
2022-09-17 16:26:39 -04:00
John Mertz 5c7f22bec7 Emoji picker
Slightly modified from https://github.com/dln/wofi-emoji in order to
always use wl-clip and use custom wofi style.css
2022-09-17 16:05:40 -04:00
John Mertz 1658999ba1 Track backlight brightness better to allow reverting (by screensaver, etc.) 2022-09-17 15:22:18 -04:00
John Mertz b403d8987c Whitespace 2022-09-17 15:21:13 -04:00
John Mertz d8ae0c1c48 Track PID 2022-09-17 15:17:28 -04:00
John Mertz 2559d13d38 Prevent fork. Limits to one PID 2022-09-17 15:17:02 -04:00
John Mertz 3c059af401 Increase delay to give more time before deletion 2022-09-17 15:16:05 -04:00
John Mertz 586ce31d0d Inverted logic for log level validationd 2022-09-02 23:05:44 -06:00
John Mertz 3a3bfcd6a6 Enhance kdb_backlight with sleep/restore function 2022-09-02 22:47:44 -06:00
6 changed files with 2108 additions and 105 deletions

View File

@ -13,11 +13,18 @@ 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';
`gammastep -l $lat_lon -b 0.7:0.3`;
exec "exec 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(1);
sleep(2);
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 $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
{
my $value = shift;
$value = int($value/get_max()*100);
return $value . '%';
return int($value/get_max()*100);
}
sub get_offset
@ -106,9 +106,28 @@ 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;
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
@ -120,9 +139,6 @@ sub increment
if ($target > $max) {
$target = $max;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
return $target;
}
}
@ -136,9 +152,7 @@ sub decrement
if ($target < $min) {
$target = $min;
}
open(my $c,'>',"$cur_file");
print $c $target;
close $c;
set($target);
return $target;
}
}
@ -147,18 +161,15 @@ sub set
{
my $value = shift;
if (writable()) {
$current = get_current();
my $current = get_current();
logger($current,$value);
if ($value > $current) {
for (my $i=$current;$i<=$value;$i++) {
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
writef($i);
}
} else {
for (my $i=$current;$i>=$value;$i--) {
open(my $c,'>',"$cur_file");
print $c $i;
close $c;
writef($i);
}
}
return $value;
@ -241,9 +252,9 @@ my (@output, $target, $silent, $notify);
my $operation_found = 0;
if (scalar @ARGV) {
while ($arg = shift) {
while ($arg = shift) {
if ($arg eq '%') {
push @output,int(get_current()/get_max()*100);
push @output,to_percent(get_current);
} elsif ($arg eq '^') {
push @output,get_max();
} elsif ($arg eq '==') {
@ -266,52 +277,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()) {
@ -326,7 +337,7 @@ if (scalar @ARGV) {
@output = to_percent($target);
$operation_found = 1;
} else {
push(@output,$arg);
push(@output,$arg);
}
}
} else {
@ -336,16 +347,11 @@ 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) {
@ -354,26 +360,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,35 +3,71 @@
use strict;
use warnings;
my $maxfile = "/sys/class/leds/tpacpi\:\:kbd_backlight/max_brightness";
my $current = "/sys/class/leds/tpacpi\:\:kbd_backlight/brightness";
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 ($max, $now, $new);
if (open(my $m, '<', $maxfile)) {
$max = readline($m);
chomp $max;
close($m);
} else {
print "Failed to read $maxfile\n";
exit;
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;
}
if (open(my $c, '<', $current)) {
$now = readline($c);
chomp $now;
close($c);
} else {
print "Failed to read $current\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 $fh, '>', $current)) {
$new = (($now+1) % ($max+1));
chomp $new;
print $fh $new;
close($fh);
} else {
print "Failed to write $current\n";
exit;
sub sleepFile
{
my $now = readFile($current);
writeFile($sleepfile,$now);
writeFile($current,0);
}
#print STDERR "$new\n";
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();

1853
wofi/wofi-emoji Executable file

File diff suppressed because it is too large Load Diff

101
wofi/wofi-wifi-menu.sh Executable file
View File

@ -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