1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2024-12-22 08:08:00 +00:00

[polybar] Create task_manager modules dynamically

This commit is contained in:
Daniel Carrillo 2020-04-07 18:24:25 +02:00
parent 15f87b9cbd
commit 07f564f956
4 changed files with 41 additions and 91 deletions

View File

@ -18,4 +18,4 @@ until pgrep -u "$(id -u)" -x polybar >/dev/null; do
sleep 0.5
done
~/.config/polybar/scripts/task_manager --daemon &
~/.config/polybar/scripts/task_manager --daemon 10 &

View File

@ -153,88 +153,5 @@ tail = true
interval = 5
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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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]
type = custom/ipc
hook-0 = 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
; task_manager module
include-file = ~/.config/polybar/task_manager.ini

View File

@ -2,7 +2,36 @@
STATUS_FILE=/dev/shm/polybar_task_manager
REFRESH=2
MAX_TASKS=10
create_module_tasklabel()
{
cat <<TASKLABEL_TEMPLATE
[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
TASKLABEL_TEMPLATE
}
create_module_sections()
{
for task in $(seq 1 "$1"); do
cat <<MODULE_TEMPLATE
[module/taskbar$task]
type = custom/ipc
hook-0 = echo ""
hook-1 = ~/.config/polybar/scripts/task_manager --set-task $task
hook-2 = ~/.config/polybar/scripts/task_manager --show-window $task
hook-3 = ~/.config/polybar/scripts/task_manager --close-window $task
click-left = polybar-msg -p %pid% hook taskbar$task 3
click-middle = polybar-msg -p %pid% hook taskbar$task 4
MODULE_TEMPLATE
done
}
get_icon_by_name()
{
@ -26,9 +55,10 @@ get_icon_by_name()
show_tasks()
{
max_tasks=$(grep -cE "^\[module/taskbar[0-9]+]" ~/.config/polybar/task_manager.ini)
wmctrl -lx | awk '{if ($2 > -1) print $3,$1}' \
| 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
if [ $? -ne 1 ]; then
@ -40,7 +70,7 @@ show_tasks()
counter=1
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
polybar-msg hook taskbar$counter 2 > /dev/null
else
@ -76,6 +106,9 @@ get_task_id()
daemon()
{
create_module_tasklabel > ~/.config/polybar/task_manager.ini
create_module_sections "$1" >> ~/.config/polybar/task_manager.ini
while true; do
show_tasks
sleep $REFRESH
@ -85,7 +118,7 @@ daemon()
case "$1" in
--daemon)
> /dev/shm/polybar_task_manager
daemon
daemon "$2"
;;
--set-task)
print_task_name "$2"

2
.gitignore vendored
View File

@ -1 +1 @@
.vscode/
.config/polybar/task_manager.ini