From a2a365dfb2e566f235c24fbc10d38460ecf3ca7f Mon Sep 17 00:00:00 2001 From: John Mertz Date: Fri, 31 Dec 2021 10:47:35 -0500 Subject: [PATCH] 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 --- waybar/toggle-visibility.c | 30 ++++++++++++++++++++++++++++++ waybar/toggle.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 waybar/toggle-visibility.c create mode 100755 waybar/toggle.sh diff --git a/waybar/toggle-visibility.c b/waybar/toggle-visibility.c new file mode 100644 index 0000000..1b2485f --- /dev/null +++ b/waybar/toggle-visibility.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +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); +} + diff --git a/waybar/toggle.sh b/waybar/toggle.sh new file mode 100755 index 0000000..705b053 --- /dev/null +++ b/waybar/toggle.sh @@ -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`