Hack to support waybar autohide

Small C program to send hide signal to bar. Coordination script which
expects the C program to be compiled at scripts/waybar/toggle
This commit is contained in:
John Mertz 2021-12-31 10:47:35 -05:00 committed by John Mertz
parent 93125c95ee
commit 2ef12fe5de
Signed by: jpm
GPG Key ID: E9C5EA2D867501AB
2 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <ctype.h>
int main(int argc, char*argv[])
{
int pid;
if (argc <= 1) {
printf("No PID given\n");
return(1);
} else if (argc > 2) {
printf("Too many arguments\n");
return(1);
} else {
long val;
char *next;
val = strtol(argv[1], &next, 10);
if ((next == argv[1]) || (*next != '\0')) {
printf("Argument '%s' is not a number\n", argv[1]);
return(1);
} else {
pid = val;
}
}
kill(pid, SIGUSR1);
return(0);
}

32
waybar/toggle.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
ARG=$1
if [[ $ARG == '' ]]; then
ARG="toggle"
fi
if [[ $ARG == 'toggle' ]]; then
if [[ -e '/home/jpm/.config/waybar/.hidden' ]]; then
rm '/home/jpm/.config/waybar/.hidden';
else
touch '/home/jpm/.config/waybar/.hidden';
fi
elif [[ $ARG == 'hide' ]]; then
if [[ ! -e '/home/jpm/.config/waybar/.hidden' ]]; then
touch '/home/jpm/.config/waybar/.hidden';
else
echo 'Already hidden. You may need to use the "invert" option if action is reversed';
exit;
fi
elif [[ $ARG == 'show' ]]; then
if [[ -e '/home/jpm/.config/waybar/.hidden' ]]; then
rm '/home/jpm/.config/waybar/.hidden';
else
echo 'Already shown. You may need to use the "invert" option if action is reversed';
exit;
fi
elif [[ $ARG != 'invert' ]]; then
echo "Invalid argument";
fi
/home/jpm/scripts/waybar/toggle `pgrep waybar`