mabox-pipemenus/usr/bin/jgdesktops
2023-05-03 15:53:23 +02:00

228 lines
6.8 KiB
Bash
Executable File

#!/bin/bash
# jgdesktops
#
me="jgdesktops -s"
case $LANG in
pl*)
REMOVE="Usuń to menu z panelu"
ACTIVE="bieżący"
GOTO="Idź do..."
WINKILL="Zabijacz Okien"
CLOSEALL_GR="Z wdziękiem <b>zamknij wszystkie okna</b> na..."
CLOSEALL="Zamknij wszystkie okna na..."
DESKTOP="Pulpicie"
ALL_DESK="Wszystkich pulpitach"
MANAGE="Pulpity"
ADD="<b>Dodaj nowy</b>"
REMOVE_LAST="<b>Usuń ostatni</b>"
CONKY_TOGGLE="Włącz/Wyłącz Conky"
PICOM_TOGGLE="Włącz/Wyłącz Picom"
DESKMNGR="Menadżer sesji pulpitowych"
WALLCHANGER="Tapeta"
DESKGRID="Desktop Grid"
SCREEN_RES="Ustawienia ekranu"
ENABLE="Włącz"
DISABLE="Wyłącz"
DESK_SERVICES="Usługi pulpitu"
CONKY="Sesja <b>Conky</b>"
PICOM="<b>Picom</b> - kompozytor"
CORTILE="<b>Cortile</b> - tiling manager"
MCORNERS="<b>Krawędzie ekranu</b>"
RUNNING="(uruchomiona)"
STOPPED="(zatrzymana)"
;;
es*)
REMOVE="Eliminar este menú del panel"
ACTIVE="active"
GOTO="Go to..."
WINKILL="Windows Killer"
CLOSEALL_GR="Gracefully <b>close all windows</b> on..."
CLOSEALL="Close all windows on..."
DESKTOP="Desktop"
ALL_DESK="All Desktops"
MANAGE="Manage Desktops"
ADD="<b>Add new</b> desktop"
REMOVE_LAST="<b>Remove last</b> desktop"
CONKY_TOGGLE="Conky Toggle"
PICOM_TOGGLE="Picom Toggle"
DESKMNGR="Desktop session Manager"
WALLCHANGER="Wallpaper"
DESKGRID="Desktop Grid"
SCREEN_RES="Screen resolution"
ENABLE="Enable"
DISABLE="Disable"
DESK_SERVICES="Desktop services"
CONKY="<b>Conky</b> session"
PICOM="<b>Picom</b> - compositor"
CORTILE="<b>Cortile</b> - tiling manager"
MCORNERS="<b>Screen Edges</b> - hot corners"
RUNNING="(running)"
STOPPED="(stopped)"
;;
*)
REMOVE="Remove this menu from panel"
ACTIVE="active"
GOTO="Go to..."
WINKILL="Windows Killer"
CLOSEALL_GR="Gracefully <b>close all windows</b> on..."
CLOSEALL="Close all windows on..."
DESKTOP="Desktop"
ALL_DESK="All Desktops"
MANAGE="Manage Desktops"
ADD="<b>Add new</b> desktop"
REMOVE_LAST="<b>Remove last</b> desktop"
DESKMNGR="Desktop session Manager"
CONKY_TOGGLE="Conky Toggle"
PICOM_TOGGLE="Picom Toggle"
WALLCHANGER="Wallpaper"
DESKGRID="Desktop Grid"
SCREEN_RES="Screen settings"
ENABLE="Enable"
DISABLE="Disable"
DESK_SERVICES="Desktop services"
CONKY="<b>Conky</b> session"
PICOM="<b>Picom</b> - compositor"
CORTILE="<b>Cortile</b> - tiling manager"
MCORNERS="<b>Screen Edges</b> - hot corners"
RUNNING="(running)"
STOPPED="(stopped)"
;;
esac
CSVFILE="$HOME/.config/mabox/jgdesktops-bottom.csv"
# If config file not exist create one with defaults
if [ ! -f $CSVFILE ]; then
cat <<EOF > ${CSVFILE}
^sep(WALLPAPER)
<big>󰸉</big> $WALLCHANGER,^pipe(jgwallpaperchanger)
^sep(TOOLS)
<big>󱇙</big> $DESKGRID,^pipe(jgdeskgrid)
<big></big> $DESKMNGR,^pipe(jgdeskmngr)
^sep($SCREEN_RES)
ARandR,arandr
LXRandr,lxrandr
EOF
fi
currdesk=$(wmctrl -d | grep "*" | awk '{print $1}')
#out+=("^sep(Okna i pulpity)")
i=0
while IFS= read -r linia || [ -n "$linia" ];
do
name=""
read -r ID name< <(echo $linia)
#declare -g "arr$ID"=("$name, wmctrl -s $ID")
dname=$(wmctrl -d | grep ^${ID} | cut -d' ' -f13-)
if [[ "$ID" = "$currdesk" ]]; then
out+=("^sep(<i><small>${dname/&/&amp;} ($ACTIVE)</small></i>)")
else
out+=("^sep(<i><small>${dname/&/&amp;}</small></i>)" " <i>$GOTO</i>,wmctrl -s $ID")
fi
while IFS= read -r line
do
read -r id DESK host title< <(echo $line)
if [[ "$DESK" = "$ID" ]]; then
trimmed=${title:0:60}
out+=("\"\"\"[ ${trimmed/&/&amp;} ]\"\"\",wmctrl -i -a $id")
fi
done < <(wmctrl -l| grep -v " -1")
done < <(wmctrl -d|awk '{print $1" "$10" "$11}')
# Gracefully close windows on any desktop or all windows
if [ $(wmctrl -l | awk $2 '!/-1/ {print $2}' | uniq |wc -l) -gt 0 ];then
out+=("^sep($WINKILL)")
out+=("<big>󰚌</big> $CLOSEALL_GR,^checkout(killwin)")
out2+=("^tag(killwin)" "^sep($CLOSEALL)")
for i in $(wmctrl -l | awk $2 '!/-1/ {print $2}' |sort| uniq)
do
dname=$(wmctrl -d | grep ^${i} | cut -d' ' -f13-)
out2+=(" $DESKTOP ${dname/&/&amp;},killwindows $i")
done
out2+=("^sep()" "$ALL_DESK,killwindows all")
fi
out+=("^sep($MANAGE)")
desktops=$(wmctrl -d |wc -l)
out+=("$ADD,wmctrl -n $((desktops+1));$me")
out+=("$REMOVE_LAST,wmctrl -n $((desktops-1));$me")
out+=("^sep($DESK_SERVICES)")
if command -v mcorners &> /dev/null;then
if [[ -f /tmp/mcorners.lck ]]; then
out+=("<big>󰄲</big> $MCORNERS <i>$RUNNING</i>,mcorners --stop;$me")
else
out+=("<big>󰄱</big> $MCORNERS <i>$STOPPED</i>,mcorners -tl 'colorizer -s' -l 'mb-jgtools places' -t mabox-terminal -tr 'mb-music -s' -bl 'colorizer-menus -s' -b 'mb-fetch' -br 'skippy-xd-fix' -r 'mb-jgtools right' -iof;$me")
fi
fi
if pidof conky &>/dev/null; then
out+=("<big>󰄲</big> $CONKY <i>$RUNNING</i>,conky_toggle;$me")
else
out+=("<big>󰄱</big> $CONKY <i>$STOPPED</i>,conky_toggle;$me")
fi
if pidof picom &>/dev/null; then
out+=("<big>󰄲</big> $PICOM <i>$RUNNING</i>,compton_toggle;$me")
else
out+=("<big>󰄱</big> $PICOM <i>$STOPPED</i>,compton_toggle;$me")
fi
if command -v cortilectl &> /dev/null;then
if pidof cortile &>/dev/null; then
out+=("<big>󰄲</big> $CORTILE <i>$RUNNING</i>,cortilectl stop;$me")
else
out+=("<big>󰄱</big> $CORTILE <i>$STOPPED</i>,cortilectl start;$me")
fi
fi
out+=(". ~/.config/mabox/jgdesktops-bottom.csv")
### RUN
if [[ "$1" == "-s" || "$1" == "ipc" ]]; then
. /usr/share/mb-jgtools/pipemenu-standalone.cfg
. $HOME/.config/mabox/mabox.conf
if [[ $panels_heightpos == "top" ]]; then
MENU_VALIGN="top"
MENU_MARGIN_Y=${panels_topmargin:-0}
elif [[ $panels_heightpos == "bottom" ]]; then
MENU_VALIGN="bottom"
MENU_MARGIN_Y=${panels_topmargin:-0}
else
MENU_VALIGN="center"
fi
MENU_PADDING_TOP=${jgtools_padding:-0}
MENU_HALIGN="center"
if [[ "$1" == "ipc" ]]; then
POSITION_MODE="ipc"
else
POSITION_MODE="pointer"
fi
jgmenu_icon_size=0
[ $(pidof picom) ] && MENU_RADIUS=$jgtools_radius
[ -z $jgmenu_use_borders ] && menu_border=0
mkconfigfile
cat <<EOF > ${MENU_ITEMS}
$(printf '%s\n' "${out[@]}")
$(printf '%s\n' "${out2[@]}")
EOF
jgmenu --config-file=${CONFIG_FILE} --csv-file=${MENU_ITEMS} 2>/dev/null
exit 0
fi
printf '%s\n' "${out[@]}"
if [[ $1 == "-r" ]]; then
printf '%s\n' "^sep()"
printf '%s\n' "<i>$REMOVE</i>,mb-setvar places_jgdesktops=false;mb-jgtools places"
fi
printf '%s\n' "${out2[@]}"