mirror of
https://github.com/dcarrillo/dotfiles.git
synced 2024-12-22 22:07:59 +00:00
[polybar] Add icons and close/show handling to task_manager
This commit is contained in:
parent
eb5a55e82d
commit
5ab17fe438
@ -66,7 +66,7 @@ font-2 = "Material Icons:size=16;1"
|
|||||||
font-3 = NotoSans-Regular:size=18:weight=bold;2
|
font-3 = NotoSans-Regular:size=18:weight=bold;2
|
||||||
font-4 = NotoSans-Regular:size=18:weight=bold;-7
|
font-4 = NotoSans-Regular:size=18:weight=bold;-7
|
||||||
|
|
||||||
modules-left = taskbar1 taskbar2 taskbar3 taskbar4 taskbar5 taskbar6 taskbar7 taskbar8 taskbar9 taskbar10 spotify
|
modules-left = taskslabel taskbar1 taskbar2 taskbar3 taskbar4 taskbar5 taskbar6 taskbar7 taskbar8 taskbar9 taskbar10 spotify
|
||||||
modules-center = custom_date
|
modules-center = custom_date
|
||||||
modules-right = updates cpu_bar memory_bar vpn network_usage alsa_bar
|
modules-right = updates cpu_bar memory_bar vpn network_usage alsa_bar
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ label-song-maxlen = 30
|
|||||||
label-song-ellipsis = true
|
label-song-ellipsis = true
|
||||||
|
|
||||||
[module/cpu_bar]
|
[module/cpu_bar]
|
||||||
|
|
||||||
type = custom/script
|
type = custom/script
|
||||||
exec = ~/.config/polybar/scripts/cpu_usage.py
|
exec = ~/.config/polybar/scripts/cpu_usage.py
|
||||||
format-prefix = "%{A1:$TERMINAL_CMD 'top -o %CPU' &:}CPU %{A-}"
|
format-prefix = "%{A1:$TERMINAL_CMD 'top -o %CPU' &:}CPU %{A-}"
|
||||||
@ -154,44 +153,88 @@ tail = true
|
|||||||
interval = 5
|
interval = 5
|
||||||
click-left = $TERMINAL_CMD "yay -Suy" &
|
click-left = $TERMINAL_CMD "yay -Suy" &
|
||||||
|
|
||||||
|
[module/taskslabel]
|
||||||
|
type = custom/text
|
||||||
|
content = "%{T4}Tasks:%{T-}"
|
||||||
|
click-left = rofi -modi window -show window -theme orange -show-icons -location 1 -yoffset +45 -xoffset +20
|
||||||
|
|
||||||
[module/taskbar1]
|
[module/taskbar1]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 1
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 1
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 1
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 1
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar1 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar1 4
|
||||||
[module/taskbar2]
|
[module/taskbar2]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 2
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 2
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 2
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 2
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar2 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar2 4
|
||||||
[module/taskbar3]
|
[module/taskbar3]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 3
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 3
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 3
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 3
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar3 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar3 4
|
||||||
[module/taskbar4]
|
[module/taskbar4]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 4
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 4
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 4
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 4
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar4 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar4 4
|
||||||
[module/taskbar5]
|
[module/taskbar5]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 5
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 5
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 5
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 5
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar5 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar5 4
|
||||||
[module/taskbar6]
|
[module/taskbar6]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 6
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 6
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 6
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 6
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar6 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar6 4
|
||||||
[module/taskbar7]
|
[module/taskbar7]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 7
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 7
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 7
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 7
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar7 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar7 4
|
||||||
[module/taskbar8]
|
[module/taskbar8]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 8
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 8
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 8
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 8
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar8 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar8 4
|
||||||
[module/taskbar9]
|
[module/taskbar9]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 9
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 9
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --show-window 9
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --close-window 9
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar9 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar9 4
|
||||||
[module/taskbar10]
|
[module/taskbar10]
|
||||||
type = custom/ipc
|
type = custom/ipc
|
||||||
hook-0 = ~/.config/polybar/scripts/task_manager --window 10
|
hook-0 = echo ""
|
||||||
hook-1 = echo ""
|
hook-1 = ~/.config/polybar/scripts/task_manager --set-task 10
|
||||||
|
hook-2 = ~/.config/polybar/scripts/task_manager --sshow-window10
|
||||||
|
hook-3 = ~/.config/polybar/scripts/task_manager --sclosetwindow10
|
||||||
|
click-left = polybar-msg -p %pid% hook taskbar10 3
|
||||||
|
click-middle = polybar-msg -p %pid% hook taskbar10 4
|
||||||
|
@ -4,14 +4,32 @@ STATUS_FILE=/dev/shm/polybar_task_manager
|
|||||||
REFRESH=2
|
REFRESH=2
|
||||||
MAX_TASKS=10
|
MAX_TASKS=10
|
||||||
|
|
||||||
|
get_icon_by_name()
|
||||||
|
{
|
||||||
|
name=$(echo "$1" | tr '[:upper:]' '[:lower:]')
|
||||||
|
declare -A ICON_MAP=(
|
||||||
|
[firefox]=
|
||||||
|
[code]=
|
||||||
|
[tilix]=
|
||||||
|
[nautilus]=
|
||||||
|
[gnome-calculator]=
|
||||||
|
[gnome-calendar]=
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ ${ICON_MAP[$name]+_} ]; then
|
||||||
|
echo "${ICON_MAP[$name]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
show_tasks()
|
show_tasks()
|
||||||
{
|
{
|
||||||
wmctrl -lx | awk '{if ($2 > -1) print $3}' \
|
wmctrl -lx | awk '{if ($2 > -1) print $3,$1}' \
|
||||||
| awk -F'.' '{ print $NF }' \
|
| awk -F'.' '{ print $NF }' \
|
||||||
| tail -$MAX_TASKS | sort > $STATUS_FILE.current
|
| tail -$MAX_TASKS | sort > $STATUS_FILE.current
|
||||||
|
|
||||||
diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1
|
diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1
|
||||||
if [ $? -ne 1 ]; then
|
if [ $? -ne 1 ]; then
|
||||||
|
rm -rf $STATUS_FILE.current
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -21,9 +39,9 @@ show_tasks()
|
|||||||
num_windows=$(wc -l $STATUS_FILE | cut -f 1 -d " ")
|
num_windows=$(wc -l $STATUS_FILE | cut -f 1 -d " ")
|
||||||
while [ $counter -le "$MAX_TASKS" ]; do
|
while [ $counter -le "$MAX_TASKS" ]; do
|
||||||
if [ $counter -le "$num_windows" ]; then
|
if [ $counter -le "$num_windows" ]; then
|
||||||
polybar-msg hook taskbar$counter 1 > /dev/null
|
polybar-msg hook taskbar$counter 2 > /dev/null
|
||||||
else
|
else
|
||||||
polybar-msg hook taskbar"$counter" 2 > /dev/null
|
polybar-msg hook taskbar"$counter" 1 > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
@ -31,6 +49,23 @@ show_tasks()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_task_name()
|
||||||
|
{
|
||||||
|
name=$(sed "${1}q;d" $STATUS_FILE | cut -f 1 -d " ")
|
||||||
|
icon=$(get_icon_by_name "$name")
|
||||||
|
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
name="$name "
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s%s" "$name" "$icon"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_task_id()
|
||||||
|
{
|
||||||
|
sed "${1}q;d" $STATUS_FILE | cut -f 2 -d " "
|
||||||
|
}
|
||||||
|
|
||||||
daemon()
|
daemon()
|
||||||
{
|
{
|
||||||
while true; do
|
while true; do
|
||||||
@ -39,13 +74,23 @@ daemon()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$1" = "--daemon" ]; then
|
case "$1" in
|
||||||
> /dev/shm/polybar_task_manager
|
--daemon)
|
||||||
daemon
|
> /dev/shm/polybar_task_manager
|
||||||
fi
|
daemon
|
||||||
|
;;
|
||||||
|
--set-task)
|
||||||
|
print_task_name "$2"
|
||||||
|
;;
|
||||||
|
--show-window)
|
||||||
|
id=$(get_task_id "$2")
|
||||||
|
wmctrl -ia "$id"
|
||||||
|
print_task_name "$2"
|
||||||
|
;;
|
||||||
|
--close-window)
|
||||||
|
id=$(get_task_id "$2")
|
||||||
|
wmctrl -ic "$id"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [ "$1" = "--window" ]; then
|
exit 0
|
||||||
sed "${2}q;d" $STATUS_FILE
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 1
|
|
||||||
|
Loading…
Reference in New Issue
Block a user