From eb5a55e82d694626f22ef6a3c66f396e9ba36593 Mon Sep 17 00:00:00 2001 From: dcarrillo Date: Sun, 5 Apr 2020 11:43:56 +0200 Subject: [PATCH] [polybar] Add a MVP task_manager module --- .config/polybar/bar.ini | 3 +- .config/polybar/launch.sh | 15 +++++--- .config/polybar/modules.ini | 42 +++++++++++++++++++++++ .config/polybar/scripts/task_manager | 51 ++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100755 .config/polybar/scripts/task_manager diff --git a/.config/polybar/bar.ini b/.config/polybar/bar.ini index 0e1461d..2b8c2ea 100644 --- a/.config/polybar/bar.ini +++ b/.config/polybar/bar.ini @@ -32,6 +32,7 @@ radius-bottom = 0.0 border-bottom-size = 3 border-color = ${colors.primary} +padding-left = 2 padding-right = 2 module-margin-left = 1 @@ -65,7 +66,7 @@ font-2 = "Material Icons:size=16;1" font-3 = NotoSans-Regular:size=18:weight=bold;2 font-4 = NotoSans-Regular:size=18:weight=bold;-7 -modules-left = spotify +modules-left = taskbar1 taskbar2 taskbar3 taskbar4 taskbar5 taskbar6 taskbar7 taskbar8 taskbar9 taskbar10 spotify modules-center = custom_date modules-right = updates cpu_bar memory_bar vpn network_usage alsa_bar diff --git a/.config/polybar/launch.sh b/.config/polybar/launch.sh index e7f27d3..0a4a46d 100755 --- a/.config/polybar/launch.sh +++ b/.config/polybar/launch.sh @@ -1,14 +1,21 @@ #!/usr/bin/env bash -killall -q polybar -while pgrep -u "$(id -u)" -x polybar >/dev/null; do sleep 1; done +pkill polybar +pkill -f "task_manager --daemon" +while pgrep -u "$(id -u)" -x polybar >/dev/null; do + sleep 0.5; +done export TERMINAL_CMD="tilix --profile orange --new-process -e" -WM_CONTROL="$(dirname "$0")/scripts/switch_window_state" -export WM_CONTROL +export WM_CONTROL="$(dirname "$0")/scripts/switch_window_state" for monitor in $(polybar --list-monitors | cut -d":" -f1); do export MONITOR=$monitor polybar top -c ~/.config/polybar/bar.ini >/dev/null & done +until pgrep -u "$(id -u)" -x polybar >/dev/null; do + sleep 0.5 +done + +~/.config/polybar/scripts/task_manager --daemon & diff --git a/.config/polybar/modules.ini b/.config/polybar/modules.ini index 8165d57..7701e95 100644 --- a/.config/polybar/modules.ini +++ b/.config/polybar/modules.ini @@ -153,3 +153,45 @@ exec = ~/.config/polybar/scripts/check_updates tail = true interval = 5 click-left = $TERMINAL_CMD "yay -Suy" & + + +[module/taskbar1] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 1 +hook-1 = echo "" +[module/taskbar2] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 2 +hook-1 = echo "" +[module/taskbar3] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 3 +hook-1 = echo "" +[module/taskbar4] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 4 +hook-1 = echo "" +[module/taskbar5] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 5 +hook-1 = echo "" +[module/taskbar6] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 6 +hook-1 = echo "" +[module/taskbar7] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 7 +hook-1 = echo "" +[module/taskbar8] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 8 +hook-1 = echo "" +[module/taskbar9] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 9 +hook-1 = echo "" +[module/taskbar10] +type = custom/ipc +hook-0 = ~/.config/polybar/scripts/task_manager --window 10 +hook-1 = echo "" diff --git a/.config/polybar/scripts/task_manager b/.config/polybar/scripts/task_manager new file mode 100755 index 0000000..acd28ea --- /dev/null +++ b/.config/polybar/scripts/task_manager @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +STATUS_FILE=/dev/shm/polybar_task_manager +REFRESH=2 +MAX_TASKS=10 + +show_tasks() +{ + wmctrl -lx | awk '{if ($2 > -1) print $3}' \ + | awk -F'.' '{ print $NF }' \ + | tail -$MAX_TASKS | sort > $STATUS_FILE.current + + diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1 + if [ $? -ne 1 ]; then + return 0 + fi + + mv $STATUS_FILE.current $STATUS_FILE + + counter=1 + num_windows=$(wc -l $STATUS_FILE | cut -f 1 -d " ") + while [ $counter -le "$MAX_TASKS" ]; do + if [ $counter -le "$num_windows" ]; then + polybar-msg hook taskbar$counter 1 > /dev/null + else + polybar-msg hook taskbar"$counter" 2 > /dev/null + fi + + sleep 0.1 + counter=$((counter+1)) + done +} + +daemon() +{ + while true; do + show_tasks + sleep $REFRESH + done +} + +if [ "$1" = "--daemon" ]; then + > /dev/shm/polybar_task_manager + daemon +fi + +if [ "$1" = "--window" ]; then + sed "${2}q;d" $STATUS_FILE +fi + +exit 1