1
0
mirror of https://gitlab.com/linuxstuff/dotfiles.git synced 2026-06-19 04:06:00 +02:00

polypopup cleanup

This commit is contained in:
Simon
2020-12-29 19:55:56 +01:00
parent d6fa6e467e
commit c05d789689
4 changed files with 103 additions and 54 deletions
+2 -2
View File
@@ -373,8 +373,8 @@ type = custom/script
interval = 0.5
format = <label>
label-maxlen = 5
exec = ~/.config/polybar/scripts/sysinfo.sh
click-left = ~/.config/polybar/scripts/sysinfo.sh --toggle
exec = ~/.config/polybar/scripts/polypopup.sh
click-left = ~/.config/polybar/scripts/polypopup.sh --toggle
content = 󰋼
[module/playerctl]
+7 -5
View File
@@ -453,11 +453,11 @@ function hide_window() {
xdotool windowactivate $WIN_ID > /dev/null 2>&1
else
# Hide
while [ -f "$STATUSFILE" ]; do
#while [ -f "$STATUSFILE" ]; do
# File exists
sleep 0.2
done
#bash ~/.config/polybar/scripts/sysinfo.sh --hide
# sleep 0.2
#done
bash ~/.config/polybar/scripts/polypopup.sh --hide
fi
# Generate the sequence used to move the window
@@ -612,7 +612,9 @@ function serve_xev() {
if [[ "$line" =~ ^EnterNotify.* ]]; then
hide_window 1
elif [[ "$line" =~ ^LeaveNotify.* ]]; then
hide_window 0
if [ -nf "$STATUSFILE" ]; then
hide_window 0
fi
fi
done
}
+94
View File
@@ -0,0 +1,94 @@
#!/bin/bash
###########
## Defaults
#
# Name of the bar in polybar (e.g. [bar/BARNAME]) which should be used as popup
POPUP_NAME="floating_sysinfo"
#
# Set labels to indicate whether the corresponding popup is shown. These will appear in your main polybar
POPUP_LABEL_ACTIVE="󰋽"
POPUP_LABEL_INACTIVE="󰋼"
#
# For each polypopup, a statusfile is created based on its name. You can set the path and prefix here
# Be careful, as clearing all statusfiles happens with 'rm -f "$STATUSFILE_PATH$STATUSFILE_PREFIX*" '
STATUSFILE_PATH="$HOME/.config/polybar/scripts/"
STATUSFILE_PREFIX=".polypopup."
#
###########
POPUP_PID=-1
STATUSFILE=$STATUSFILE_PATH$STATUSFILE_PREFIX
function removeLocks() {
# Clears all lock files
echo "$STATUSFILE_PATH$STATUSFILE_PREFIX*"
}
function mapPID() {
# Fetches the PID for the process with a name equal to 'POPUP_NAME' and stores it in 'POPUP_PID'
POPUP_PID=$(ps -ef | grep $POPUP_NAME | grep -v grep | awk '{print $2}')
}
function setVisibility() {
# Uses polybar-msg to hide or show the polybar with PID equal to 'POPUP_PID'.
# Also creates a status file as indicator, using the name stored in 'POPUP_NAME' and
# echos the specified active/inactive indicator label ('POPUP_LABEL_ACTIVE' / 'POPUP_LABEL_INACTIVE')
#
# Args:
# $1: visibility (0 = hide / 1 = show)
if [ "$POPUP_PID" -eq -1 ]; then
mapPID
fi
if [ "$1" -eq 0 ] ; then
# Hide
rm -f "$STATUSFILE$POPUP_NAME"
polybar-msg -p "$POPUP_PID" cmd hide
echo "$POPUP_LABEL_INACTIVE"
else
#Show
touch "$STATUSFILE$POPUP_NAME"
polybar-msg -p "$POPUP_PID" cmd show
echo "$POPUP_LABEL_ACTIVE"
fi
}
if [ "$1" == "--toggle" ]; then
if [ -f "$STATUSFILE$POPUP_NAME" ]; then
# File exists -> hide
setVisibility 0
else
# File does not exist -> show
setVisibility 1
fi
exit
fi
if [ "$1" == "--hide" ]; then
setVisibility 0
exit
fi
if [ "$1" == "--show" ]; then
setVisibility 1
exit
fi
if [ "$1" == "--remove-locks" ]; then
removeLocks
exit
fi
if [ -f "$STATUSFILE$POPUP_NAME" ]; then
echo "$POPUP_LABEL_ACTIVE"
else
echo "$POPUP_LABEL_INACTIVE"
fi
exit
-47
View File
@@ -1,47 +0,0 @@
#!/bin/bash
ICON_ACTIVE="󰋽"
ICON_INACTIVE="󰋼"
STATUSFILE="$HOME/.config/polybar/scripts/.sysinfo.active"
PID=$(ps -ef | grep floating_sysinfo | grep -v grep | awk '{print $2}')
function show() {
touch "$STATUSFILE"
polybar-msg -p "$PID" cmd show
echo "$ICON_ACTIVE"
}
function hide() {
rm "$STATUSFILE"
polybar-msg -p "$PID" cmd hide
echo "$ICON_INACTIVE"
}
if [ "$1" == "--toggle" ]; then
if [ -f "$STATUSFILE" ]; then
# File exists -> hide
hide
else
# File does not exist -> show
show
fi
exit
fi
if [ "$1" == "--show" ]; then
show
exit
fi
if [ "$1" == "--hide" ]; then
hide
exit
fi
if [ -f "$STATUSFILE" ]; then
echo "$ICON_ACTIVE"
else
echo "$ICON_INACTIVE"
fi
exit