mirror of
https://github.com/dcarrillo/dotfiles.git
synced 2024-12-22 13:58:00 +00:00
[polybar] Add polywins and remove task_manager
This commit is contained in:
parent
8e109bef56
commit
cd25d92ac2
@ -66,8 +66,7 @@ font-3 = NotoSans-Regular:size=18:weight=bold:antialias=true;2
|
||||
font-4 = NotoSans-Regular:size=28:weight=bold:antialias=true;-12
|
||||
font-5 = "FontAwesome:size=21:antialias=true;4"
|
||||
|
||||
modules-left-dynamic =
|
||||
include-file = ~/.config/polybar/modules-left.ini
|
||||
modules-left = polywins
|
||||
modules-center = custom_date
|
||||
modules-right = updates cpu_bar memory_bar vpn network_usage alsa_bar
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
export TERMINAL_CMD=${TERMINAL_CMD:-"tilix --profile orange --new-process -e"}
|
||||
export WM_CONTROL=${WM_CONTROL:-"~/.config/polybar/scripts/switch_window_state"}
|
||||
export TASKMANAGER_MAX_TASKS=${TASKMANAGER_MAX_TASKS:-20}
|
||||
export ROFI_THEME=${ROFI_THEME:-orange}
|
||||
|
||||
function wait_for_polybar
|
||||
@ -22,7 +21,6 @@ function wait_for_polybar
|
||||
function kill_polybar
|
||||
{
|
||||
pkill polybar
|
||||
pkill -f "task_manager --daemon"
|
||||
wait_for_polybar stopped
|
||||
}
|
||||
|
||||
@ -36,6 +34,4 @@ function launch_polybar
|
||||
}
|
||||
|
||||
kill_polybar
|
||||
~/.config/polybar/scripts/task_manager --generate-config "$TASKMANAGER_MAX_TASKS"
|
||||
launch_polybar
|
||||
~/.config/polybar/scripts/task_manager --daemon &
|
||||
|
@ -154,8 +154,13 @@ tail = true
|
||||
interval = 5
|
||||
click-left = $TERMINAL_CMD "yay -Suy" &
|
||||
|
||||
; task_manager module
|
||||
include-file = ~/.config/polybar/task_manager.ini
|
||||
[module/polywins]
|
||||
type = custom/script
|
||||
exec = ~/.config/polybar/scripts/polywins 2>/dev/null
|
||||
format = <label>
|
||||
label = "%output%"
|
||||
label-padding = 0
|
||||
tail = true
|
||||
|
||||
[module/battery]
|
||||
type = internal/battery
|
||||
|
286
.config/polybar/scripts/polywins
Executable file
286
.config/polybar/scripts/polywins
Executable file
@ -0,0 +1,286 @@
|
||||
#!/bin/sh
|
||||
# POLYWINS
|
||||
|
||||
# Forked from: https://github.com/tam-carre/polywins
|
||||
|
||||
# SETTINGS {{{ ---
|
||||
|
||||
active_text_color="#F5A70A"
|
||||
active_bg="#000000"
|
||||
active_underline="#ECB3B2"
|
||||
|
||||
inactive_text_color="#ffffff"
|
||||
inactive_bg=
|
||||
inactive_underline=
|
||||
|
||||
separator=" "
|
||||
show="icon" # options: window_title, window_classname, icon
|
||||
forbidden_names="Polybar Conky Gmrun"
|
||||
empty_desktop_message=""
|
||||
|
||||
char_limit=20
|
||||
max_windows=15
|
||||
char_case="normal" # normal, upper, lower
|
||||
add_spaces="true"
|
||||
resize_increment=16
|
||||
wm_border_width=1 # setting this might be required for accurate resize position
|
||||
|
||||
# --- }}}
|
||||
|
||||
|
||||
main() {
|
||||
# If no argument passed...
|
||||
if [ -z "$2" ]; then
|
||||
# ...print new window list every time
|
||||
# the active window changes or
|
||||
# a window is opened or closed
|
||||
xprop -root -spy _NET_CLIENT_LIST _NET_ACTIVE_WINDOW |
|
||||
while IFS= read -r _; do
|
||||
generate_window_list
|
||||
done
|
||||
|
||||
# If arguments are passed, run requested on-click function
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
get_icon_by_name()
|
||||
{
|
||||
name=$(echo "$1" | tr '[:upper:]' '[:lower:]')
|
||||
declare -A ICON_MAP=(
|
||||
[tilix]=
|
||||
[code]=
|
||||
[brave-browser]=
|
||||
[firefox]=
|
||||
[chromium]=
|
||||
[tor]=
|
||||
[nextcloud]=
|
||||
[gnome-calculator]=
|
||||
[gnome-calendar]=
|
||||
[gnome-control-center]=
|
||||
[gnome-terminal]=
|
||||
[gpaste-ui]=
|
||||
[eog]=
|
||||
[evince]=
|
||||
[10]=
|
||||
[nautilus]=
|
||||
[file-roller]=
|
||||
[mailspring]=
|
||||
[keepassxc]=
|
||||
[steam]=
|
||||
[skype]=
|
||||
[slack]=
|
||||
[spotify]=
|
||||
[telegramdesktop]=
|
||||
[xterm]=
|
||||
)
|
||||
|
||||
if [ ${ICON_MAP[$name]+_} ]; then
|
||||
echo "${ICON_MAP[$name]}"
|
||||
else
|
||||
echo "$name" | cut -c 1 | tr '[:lower:]' '[:upper:]'
|
||||
fi
|
||||
}
|
||||
|
||||
# ON-CLICK FUNCTIONS {{{ ---
|
||||
|
||||
raise_or_minimize() {
|
||||
if [ "$(get_active_wid)" = "$1" ]; then
|
||||
# wmctrl -ir "$1" -b toggle,hidden
|
||||
xdotool windowminimize "$(xdotool getactivewindow)"
|
||||
echo "minimize" >> /dev/shm/log
|
||||
else
|
||||
echo "positos" >> /dev/shm/log
|
||||
wmctrl -ia "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
close() {
|
||||
wmctrl -ic "$1"
|
||||
}
|
||||
|
||||
slop_resize() {
|
||||
wmctrl -ia "$1"
|
||||
wmctrl -ir "$1" -e "$(slop -f 0,%x,%y,%w,%h)"
|
||||
}
|
||||
|
||||
increment_size() {
|
||||
while IFS="[ .]" read -r wid ws wx wy ww wh _; do
|
||||
test "$wid" != "$1" && continue
|
||||
x=$(( wx - wm_border_width * 2 - resize_increment / 2 ))
|
||||
y=$(( wy - wm_border_width * 2 - resize_increment / 2 ))
|
||||
w=$(( ww + resize_increment ))
|
||||
h=$(( wh + resize_increment ))
|
||||
done <<-EOF
|
||||
$(wmctrl -lG)
|
||||
EOF
|
||||
|
||||
wmctrl -ir "$1" -e "0,$x,$y,$w,$h"
|
||||
}
|
||||
|
||||
decrement_size() {
|
||||
while IFS="[ .]" read -r wid ws wx wy ww wh _; do
|
||||
test "$wid" != "$1" && continue
|
||||
x=$(( wx - wm_border_width * 2 + resize_increment / 2 ))
|
||||
y=$(( wy - wm_border_width * 2 + resize_increment / 2 ))
|
||||
w=$(( ww - resize_increment ))
|
||||
h=$(( wh - resize_increment ))
|
||||
done <<-EOF
|
||||
$(wmctrl -lG)
|
||||
EOF
|
||||
|
||||
wmctrl -ir "$1" -e "0,$x,$y,$w,$h"
|
||||
}
|
||||
|
||||
# --- }}}
|
||||
|
||||
|
||||
|
||||
# WINDOW LIST SETUP {{{ ---
|
||||
|
||||
active_left="%{F$active_text_color}"
|
||||
active_right="%{F-}"
|
||||
inactive_left="%{F$inactive_text_color}"
|
||||
inactive_right="%{F-}"
|
||||
separator="%{F$inactive_text_color}$separator%{F-}"
|
||||
|
||||
if [ -n "$active_underline" ]; then
|
||||
active_left="${active_left}%{+u}%{u$active_underline}"
|
||||
active_right="%{-u}${active_right}"
|
||||
fi
|
||||
|
||||
if [ -n "$active_bg" ]; then
|
||||
active_left="${active_left}%{B$active_bg}"
|
||||
active_right="%{B-}${active_right}"
|
||||
fi
|
||||
|
||||
if [ -n "$inactive_underline" ]; then
|
||||
inactive_left="${inactive_left}%{+u}%{u$inactive_underline}"
|
||||
inactive_right="%{-u}${inactive_right}"
|
||||
fi
|
||||
|
||||
if [ -n "$inactive_bg" ]; then
|
||||
inactive_left="${inactive_left}%{B$inactive_bg}"
|
||||
inactive_right="%{B-}${inactive_right}"
|
||||
fi
|
||||
|
||||
get_active_wid() {
|
||||
active_wid=$(xprop -root _NET_ACTIVE_WINDOW)
|
||||
active_wid="${active_wid#*\# }"
|
||||
active_wid="${active_wid%,*}" # Necessary for XFCE
|
||||
while [ ${#active_wid} -lt 10 ]; do
|
||||
active_wid="0x0${active_wid#*x}"
|
||||
done
|
||||
echo "$active_wid"
|
||||
}
|
||||
|
||||
get_active_workspace() {
|
||||
wmctrl -d |
|
||||
while IFS="[ .]" read -r number active_status _; do
|
||||
test "$active_status" = "*" && echo "$number" && break
|
||||
done
|
||||
}
|
||||
|
||||
generate_window_list() {
|
||||
active_workspace=$(get_active_workspace)
|
||||
active_wid=$(get_active_wid)
|
||||
window_count=0
|
||||
on_click="$0"
|
||||
|
||||
# Format each window name one by one
|
||||
# Space and . are both used as IFS,
|
||||
# because classname and class are separated by '.'
|
||||
while IFS=" " read -r wid ws cname host title; do
|
||||
cname=${cname##*.}
|
||||
# Don't show the window if on another workspace (-1 = sticky)
|
||||
if [ "$ws" != "$active_workspace" ] && [ "$ws" != "-1" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Don't show the window if its class is forbidden
|
||||
case "$forbidden_names" in
|
||||
*$cname*) continue ;;
|
||||
esac
|
||||
|
||||
# If max number of windows reached, just increment
|
||||
# the windows counter
|
||||
if [ "$window_count" -ge "$max_windows" ]; then
|
||||
window_count=$(( window_count + 1 ))
|
||||
continue
|
||||
fi
|
||||
|
||||
# Show the user-selected window property
|
||||
case "$show" in
|
||||
"window_classname") w_name="$cname" ;;
|
||||
"window_title") w_name="$title" ;;
|
||||
"icon") w_name=$(get_icon_by_name "$cname")
|
||||
esac
|
||||
|
||||
# Use user-selected character case
|
||||
case "$char_case" in
|
||||
"lower") w_name=$(
|
||||
echo "$w_name" | tr '[:upper:]' '[:lower:]'
|
||||
) ;;
|
||||
"upper") w_name=$(
|
||||
echo "$w_name" | tr '[:lower:]' '[:upper:]'
|
||||
) ;;
|
||||
esac
|
||||
|
||||
# Truncate displayed name to user-selected limit
|
||||
if [ "${#w_name}" -gt "$char_limit" ]; then
|
||||
w_name="$(echo "$w_name" | cut -c1-$((char_limit-1)))…"
|
||||
fi
|
||||
|
||||
# Apply add-spaces setting
|
||||
if [ "$add_spaces" = "true" ]; then
|
||||
w_name=" $w_name "
|
||||
fi
|
||||
|
||||
# Add left and right formatting to displayed name
|
||||
if [ "$wid" = "$active_wid" ]; then
|
||||
w_name="${active_left}${w_name}${active_right}"
|
||||
else
|
||||
w_name="${inactive_left}${w_name}${inactive_right}"
|
||||
fi
|
||||
|
||||
if [ "$window_count" = 0 ]; then
|
||||
printf "%s" "%{T4}Tasks: %{T-}"
|
||||
fi
|
||||
|
||||
# Add separator unless the window is first in list
|
||||
if [ "$window_count" != 0 ]; then
|
||||
printf "%s" "$separator"
|
||||
fi
|
||||
|
||||
# Add on-click action Polybar formatting
|
||||
printf "%s" "%{A1:$on_click raise_or_minimize $wid:}"
|
||||
printf "%s" "%{A2:$on_click close $wid:}"
|
||||
printf "%s" "%{A3:$on_click slop_resize $wid:}"
|
||||
printf "%s" "%{A4:$on_click increment_size $wid:}"
|
||||
printf "%s" "%{A5:$on_click decrement_size $wid:}"
|
||||
# Print the final window name
|
||||
printf "%s" "%{T6}$w_name%{T-}"
|
||||
printf "%s" "%{A}%{A}%{A}%{A}%{A}"
|
||||
|
||||
window_count=$(( window_count + 1 ))
|
||||
done <<-EOF
|
||||
$(wmctrl -lx)
|
||||
EOF
|
||||
|
||||
# After printing all the windows,
|
||||
# print number of hidden windows
|
||||
if [ "$window_count" -gt "$max_windows" ]; then
|
||||
printf "%s" "+$(( window_count - max_windows ))"
|
||||
# Print empty desktop message if no windows are open
|
||||
elif [ "$window_count" = 0 ]; then
|
||||
printf "%s" "$empty_desktop_message"
|
||||
fi
|
||||
|
||||
# Print newline
|
||||
echo ""
|
||||
}
|
||||
|
||||
# --- }}}
|
||||
|
||||
main "$@"
|
@ -1,222 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
STATUS_FILE=/dev/shm/polybar_task_manager
|
||||
BAR_CONFIG_FILE=~/.config/polybar/bar.ini
|
||||
MODULES_LEFT_FILE=~/.config/polybar/modules-left.ini
|
||||
REFRESH=1
|
||||
TASK_MENU=" Open a new one # Close"
|
||||
|
||||
update_bar_config()
|
||||
{
|
||||
base_config=$(grep -e "^modules-left-dynamic *= *" $BAR_CONFIG_FILE | cut -f 3- -d " " )
|
||||
new_config="taskslabel"
|
||||
|
||||
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-or-minimize-window $task
|
||||
hook-3 = ~/.config/polybar/scripts/task_manager --close-window $task
|
||||
hook-4 = ~/.config/polybar/scripts/task_manager --show-menu $task
|
||||
click-left = polybar-msg -p %pid% hook taskbar$task 3
|
||||
click-middle = polybar-msg -p %pid% hook taskbar$task 4
|
||||
click-right = polybar-msg -p %pid% hook taskbar$task 5
|
||||
|
||||
MODULE_TEMPLATE
|
||||
|
||||
new_config="$new_config taskbar$task"
|
||||
done
|
||||
|
||||
echo "modules-left = $base_config $new_config" > $MODULES_LEFT_FILE
|
||||
}
|
||||
|
||||
create_module_tasklabel()
|
||||
{
|
||||
cat <<TASKLABEL_TEMPLATE
|
||||
[module/taskslabel]
|
||||
type = custom/ipc
|
||||
hook-0 = echo "%{T4}Tasks:%{T-}"
|
||||
hook-1 = echo ""
|
||||
; click-left = rofi -modi window -show window -theme $ROFI_THEME -show-icons -location 1 -yoffset +45 -xoffset +20
|
||||
click-left = dbus-send --session --type=method_call \
|
||||
--dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'Main.overview.show();'
|
||||
TASKLABEL_TEMPLATE
|
||||
}
|
||||
|
||||
get_icon_by_name()
|
||||
{
|
||||
name=$(echo "$1" | tr '[:upper:]' '[:lower:]')
|
||||
declare -A ICON_MAP=(
|
||||
[tilix]=
|
||||
[code]=
|
||||
[brave-browser]=
|
||||
[firefox]=
|
||||
[chromium]=
|
||||
[tor]=
|
||||
[nextcloud]=
|
||||
[gnome-calculator]=
|
||||
[gnome-calendar]=
|
||||
[gnome-control-center]=
|
||||
[gnome-terminal]=
|
||||
[gpaste-ui]=
|
||||
[eog]=
|
||||
[evince]=
|
||||
[gimp-210]=
|
||||
[nautilus]=
|
||||
[file-roller]=
|
||||
[mailspring]=
|
||||
[keepassxc]=
|
||||
[steam]=
|
||||
[skype]=
|
||||
[slack]=
|
||||
[spotify]=
|
||||
[telegramdesktop]=
|
||||
[xterm]=
|
||||
)
|
||||
|
||||
if [ ${ICON_MAP[$name]+_} ]; then
|
||||
echo "${ICON_MAP[$name]}"
|
||||
else
|
||||
echo "$name" | cut -c 1 | tr '[:lower:]' '[:upper:]'
|
||||
fi
|
||||
}
|
||||
|
||||
show_tasks()
|
||||
{
|
||||
max_tasks=$(grep -cE "^\[module/taskbar[0-9]+]" ~/.config/polybar/task_manager.ini)
|
||||
wmctrl -lxp | awk '{if ($2 > -1) print $4,$1,$3}' \
|
||||
| sed -r 's/([0-9])\.([0-9])/\1\2/g' \
|
||||
| awk -F'.' '{ print $NF }' \
|
||||
| tail -"$max_tasks" | sort > $STATUS_FILE.current
|
||||
|
||||
if [ -f $STATUS_FILE.active ]; then
|
||||
if [ "$(get_task_id "$(cat $STATUS_FILE.active)")" = "$(get_active_window)" ]; then
|
||||
diff -q $STATUS_FILE $STATUS_FILE.current > /dev/null 2>&1
|
||||
if [ $? -ne 1 ]; then
|
||||
rm -rf $STATUS_FILE.current
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
mv $STATUS_FILE.current $STATUS_FILE
|
||||
|
||||
num_windows=$(wc -l $STATUS_FILE | cut -f 1 -d " ")
|
||||
|
||||
if [ "$num_windows" -eq 0 ]; then
|
||||
polybar-msg hook taskslabel 2 > /dev/null
|
||||
else
|
||||
polybar-msg hook taskslabel 1 > /dev/null
|
||||
fi
|
||||
|
||||
for counter in $(seq 1 "$max_tasks"); do
|
||||
if [ "$counter" -le "$num_windows" ]; then
|
||||
polybar-msg hook taskbar"$counter" 2 > /dev/null
|
||||
else
|
||||
polybar-msg hook taskbar"$counter" 1 > /dev/null
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
print_task_icon()
|
||||
{
|
||||
name=$(sed "${1}q;d" $STATUS_FILE | cut -f 1 -d " " | tr '[:upper:]' '[:lower:]')
|
||||
icon=$(get_icon_by_name "$name")
|
||||
|
||||
if [ "$(get_task_id "$1")" = "$(get_active_window)" ]; then
|
||||
echo '%{T6}%{F#F5A70A}'"$icon"'%{F-}%{T-}'
|
||||
if [ -f $STATUS_FILE.active ]; then
|
||||
polybar-msg hook "taskbar$(cat $STATUS_FILE.active)" 2 > /dev/null
|
||||
fi
|
||||
echo "$1" > $STATUS_FILE.active
|
||||
else
|
||||
echo '%{T6}'"$icon"'%{T-}'
|
||||
fi
|
||||
}
|
||||
|
||||
show_task_menu()
|
||||
{
|
||||
pid=$(get_task_pid "$1")
|
||||
cmd=$(ps --no-headers -o cmd "$pid" \
|
||||
| sed 's/--gapplication-service//g' \
|
||||
| tr -d '\n')
|
||||
offset=$(( ($1 * 65) ))
|
||||
ROFI="rofi -dmenu -sep # -theme $ROFI_THEME
|
||||
-location 1 -width 8
|
||||
-yoffset +45 -xoffset +${offset}"
|
||||
choice=$(echo "$TASK_MENU" | $ROFI -theme-str 'inputbar { children: [];}' \
|
||||
| sed 's/^[[:space:]]*//' | cut -f 1 -d " ")
|
||||
|
||||
case "$choice" in
|
||||
Open)
|
||||
$cmd &>/dev/null &
|
||||
;;
|
||||
Close)
|
||||
id=$(get_task_id "$1")
|
||||
wmctrl -ic "$id"
|
||||
;;
|
||||
esac
|
||||
|
||||
print_task_icon "$1"
|
||||
}
|
||||
|
||||
get_active_window()
|
||||
{
|
||||
echo 0x0"$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2 | cut -f 2 -d 'x')"
|
||||
}
|
||||
|
||||
get_task_id()
|
||||
{
|
||||
sed "${1}q;d" $STATUS_FILE | cut -f 2 -d " "
|
||||
}
|
||||
|
||||
get_task_pid()
|
||||
{
|
||||
sed "${1}q;d" $STATUS_FILE | cut -f 3 -d " "
|
||||
}
|
||||
|
||||
daemon()
|
||||
{
|
||||
while true; do
|
||||
show_tasks
|
||||
sleep $REFRESH
|
||||
done
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
--daemon)
|
||||
> /dev/shm/polybar_task_manager
|
||||
daemon
|
||||
;;
|
||||
--generate-config)
|
||||
create_module_tasklabel > ~/.config/polybar/task_manager.ini
|
||||
update_bar_config "$2" >> ~/.config/polybar/task_manager.ini
|
||||
;;
|
||||
--set-task)
|
||||
print_task_icon "$2"
|
||||
;;
|
||||
--show-menu)
|
||||
show_task_menu "$2"
|
||||
;;
|
||||
--show-or-minimize-window)
|
||||
id=$(get_task_id "$2")
|
||||
|
||||
if [ "$id" = "$(get_active_window)" ]; then
|
||||
xdotool getactivewindow windowminimize
|
||||
else
|
||||
wmctrl -ia "$id"
|
||||
fi
|
||||
print_task_icon "$2"
|
||||
;;
|
||||
--close-window)
|
||||
id=$(get_task_id "$2")
|
||||
wmctrl -ic "$id"
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user