2020-04-05 09:43:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
STATUS_FILE=/dev/shm/polybar_task_manager
|
|
|
|
REFRESH=2
|
2020-04-07 16:24:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2020-04-05 09:43:56 +00:00
|
|
|
|
2020-04-05 12:10:38 +00:00
|
|
|
get_icon_by_name()
|
|
|
|
{
|
|
|
|
name=$(echo "$1" | tr '[:upper:]' '[:lower:]')
|
|
|
|
declare -A ICON_MAP=(
|
|
|
|
[tilix]=
|
2020-04-05 12:28:30 +00:00
|
|
|
[code]=
|
2020-04-09 10:02:18 +00:00
|
|
|
[firefox]=
|
|
|
|
[chromium]=
|
2020-04-09 16:03:27 +00:00
|
|
|
[tor]=
|
2020-04-09 10:02:18 +00:00
|
|
|
[nextcloud]=
|
2020-04-05 12:10:38 +00:00
|
|
|
[gnome-calculator]=
|
|
|
|
[gnome-calendar]=
|
2020-04-09 10:02:18 +00:00
|
|
|
[gnome-control-center]=
|
2020-04-05 12:28:30 +00:00
|
|
|
[eog]=
|
2020-04-09 10:02:18 +00:00
|
|
|
[nautilus]=
|
2020-04-05 12:28:30 +00:00
|
|
|
[keepassxc]=
|
2020-04-09 10:02:18 +00:00
|
|
|
[steam]=
|
|
|
|
[skype]=
|
|
|
|
[slack]=
|
2020-04-05 12:10:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if [ ${ICON_MAP[$name]+_} ]; then
|
|
|
|
echo "${ICON_MAP[$name]}"
|
2020-04-09 10:02:18 +00:00
|
|
|
else
|
|
|
|
echo "$name" | cut -c 1 | tr '[:lower:]' '[:upper:]'
|
2020-04-05 12:10:38 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:43:56 +00:00
|
|
|
show_tasks()
|
|
|
|
{
|
2020-04-07 16:24:25 +00:00
|
|
|
max_tasks=$(grep -cE "^\[module/taskbar[0-9]+]" ~/.config/polybar/task_manager.ini)
|
2020-04-05 12:10:38 +00:00
|
|
|
wmctrl -lx | awk '{if ($2 > -1) print $3,$1}' \
|
2020-04-09 10:02:18 +00:00
|
|
|
| sed -r 's/([0-9])\.([0-9])/\1\2/g' \
|
2020-04-05 09:43:56 +00:00
|
|
|
| awk -F'.' '{ print $NF }' \
|
2020-04-07 16:24:25 +00:00
|
|
|
| tail -"$max_tasks" | sort > $STATUS_FILE.current
|
2020-04-05 09:43:56 +00:00
|
|
|
|
|
|
|
diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1
|
|
|
|
if [ $? -ne 1 ]; then
|
2020-04-05 12:10:38 +00:00
|
|
|
rm -rf $STATUS_FILE.current
|
2020-04-05 09:43:56 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
mv $STATUS_FILE.current $STATUS_FILE
|
|
|
|
|
|
|
|
num_windows=$(wc -l $STATUS_FILE | cut -f 1 -d " ")
|
2020-04-07 16:29:53 +00:00
|
|
|
for counter in $(seq 1 "$max_tasks"); do
|
|
|
|
if [ "$counter" -le "$num_windows" ]; then
|
|
|
|
polybar-msg hook taskbar"$counter" 2 > /dev/null
|
2020-04-05 09:43:56 +00:00
|
|
|
else
|
2020-04-05 12:10:38 +00:00
|
|
|
polybar-msg hook taskbar"$counter" 1 > /dev/null
|
2020-04-05 09:43:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-04-05 12:10:38 +00:00
|
|
|
print_task_name()
|
|
|
|
{
|
2020-04-05 12:28:30 +00:00
|
|
|
name=$(sed "${1}q;d" $STATUS_FILE | cut -f 1 -d " " | tr '[:upper:]' '[:lower:]')
|
2020-04-05 12:10:38 +00:00
|
|
|
icon=$(get_icon_by_name "$name")
|
|
|
|
|
|
|
|
if [ -n "$icon" ]; then
|
|
|
|
name="$name "
|
|
|
|
fi
|
|
|
|
|
2020-04-09 10:02:18 +00:00
|
|
|
#echo "${name^}${icon}"
|
|
|
|
echo '%{T6}'"$icon"'%{T-}'
|
2020-04-05 12:10:38 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 17:33:16 +00:00
|
|
|
get_active_window()
|
|
|
|
{
|
|
|
|
echo 0x0"$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2 | cut -f 2 -d 'x')"
|
|
|
|
}
|
|
|
|
|
2020-04-05 12:10:38 +00:00
|
|
|
get_task_id()
|
|
|
|
{
|
|
|
|
sed "${1}q;d" $STATUS_FILE | cut -f 2 -d " "
|
|
|
|
}
|
|
|
|
|
2020-04-05 09:43:56 +00:00
|
|
|
daemon()
|
|
|
|
{
|
2020-04-07 16:24:25 +00:00
|
|
|
create_module_tasklabel > ~/.config/polybar/task_manager.ini
|
|
|
|
create_module_sections "$1" >> ~/.config/polybar/task_manager.ini
|
|
|
|
|
2020-04-05 09:43:56 +00:00
|
|
|
while true; do
|
|
|
|
show_tasks
|
|
|
|
sleep $REFRESH
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-04-05 12:10:38 +00:00
|
|
|
case "$1" in
|
|
|
|
--daemon)
|
|
|
|
> /dev/shm/polybar_task_manager
|
2020-04-07 16:24:25 +00:00
|
|
|
daemon "$2"
|
2020-04-05 12:10:38 +00:00
|
|
|
;;
|
|
|
|
--set-task)
|
|
|
|
print_task_name "$2"
|
|
|
|
;;
|
|
|
|
--show-window)
|
|
|
|
id=$(get_task_id "$2")
|
2020-04-06 17:33:16 +00:00
|
|
|
|
|
|
|
if [ "$id" = "$(get_active_window)" ]; then
|
|
|
|
xdotool getactivewindow windowminimize
|
|
|
|
else
|
|
|
|
wmctrl -ia "$id"
|
|
|
|
fi
|
2020-04-05 12:10:38 +00:00
|
|
|
print_task_name "$2"
|
|
|
|
;;
|
|
|
|
--close-window)
|
|
|
|
id=$(get_task_id "$2")
|
|
|
|
wmctrl -ic "$id"
|
|
|
|
;;
|
|
|
|
esac
|
2020-04-05 09:43:56 +00:00
|
|
|
|
2020-04-05 12:10:38 +00:00
|
|
|
exit 0
|