fix picom handling

This commit is contained in:
Daniel Napora 2024-12-08 22:29:26 +01:00
parent 72fcf6e7ba
commit b3ab627166
2 changed files with 69 additions and 112 deletions

View File

@ -1,10 +1,12 @@
#!/bin/bash
# jgpicom-pipe - pipemenu to start, stop, restart Picom and manage Picom configs (WIP)
# Copyright (C) 2020 napcok <napcok@gmail.com>
# Copyright (C) 2020-2024 napcok <napcok@gmail.com>
. "$HOME/.config/mabox/mabox.conf"
backend=${picom_renderer:-glx}
CONFDIR="$HOME/.config/picom/configs"
CONFFILE="$HOME/.config/picom.conf"
RESTART_ATTEMPTS=20
mkdir -p "$CONFDIR"
@ -12,7 +14,6 @@ menu() {
case $LANG in
pl*)
ENABLE="Włącz Kompozytora"
GREYSCALE="Skala szarości"
RESTART="Restartuj Kompozytora"
DISABLE="Wyłącz Kompozytora"
CHOOSE="Wybierz plik konfiguracyjny"
@ -20,10 +21,12 @@ case $LANG in
EDIT_TITLE="Edytuj..."
EDIT="Edytuj plik ustawień Kompozytora"
OPENDIR="Otwórz katalog <i>~/.config/picom/configs</i>"
RENDERER="Rendering Backend"
GLX="<b>glx</b> <i>(zalecany)</i>"
XRENDER="<b>xrender</b> <i>(dla starszego sprzętu)</i>"
;;
es*)
ENABLE="Activar Compositor"
GREYSCALE="Greyscale"
RESTART="Reiniciar Compositor"
DISABLE="Desactivar Compositor"
CHOOSE="Elegir el archivo de configuración"
@ -31,31 +34,32 @@ case $LANG in
EDIT_TITLE="Editar..."
EDIT="Editar archivo de ajustes del Compositor"
OPENDIR="Abrir la carpeta <i>~/.config/picom/configs</i>"
RENDERER="Rendering Backend"
GLX="<b>glx</b> <i>(recommended)</i>"
XRENDER="<b>xrender</b> <i>(for older hardware)</i>"
;;
*)
ENABLE="Enable Compositor"
GREYSCALE="Greyscale"
ENABLE="Start Compositor"
RESTART="Restart Compositor"
DISABLE="Disable Compositor"
DISABLE="Stop Compositor"
CHOOSE="Choose config file"
DEVNULL="/dev/null <i>(none)</i>"
EDIT_TITLE="Edit..."
EDIT="Edit Compositor settings file"
OPENDIR="Open <i>~/.config/picom/configs</i> directory"
RENDERER="Rendering Backend"
GLX="<b>glx</b> <i>(recommended)</i>"
XRENDER="<b>xrender</b> <i>(for older hardware)</i>"
;;
esac
out+=("^sep(Picom)")
if ! pidof picom > /dev/null; then
out+=("$ENABLE,compton_toggle")
out+=("^sep()")
out+=("$GREYSCALE,greyscale")
out+=("$ENABLE,mabox-compositor --start")
else
out+=("$RESTART,compton_toggle;compton_toggle")
out+=("$DISABLE,compton_toggle")
out+=("^sep()")
out+=("$GREYSCALE,greyscale")
out+=("$RESTART,mabox-compositor --restart")
out+=("$DISABLE,mabox-compositor --stop")
fi
@ -64,7 +68,7 @@ out+=("^sep($CHOOSE)")
if [ "$(readlink $CONFFILE)" -ef "/dev/null" ];then
out+=("<u><b>$DEVNULL</b></u>")
else
out+=("$DEVNULL,ln -sf /dev/null $CONFFILE")
out+=("$DEVNULL,ln -sf /dev/null $CONFFILE;mabox-compositor --restart")
fi
for item in "$CONFDIR"/*.conf; do
@ -72,26 +76,29 @@ if [ -f "$item" ];then
if [ "$(readlink $CONFFILE)" -ef "$item" ];then
out+=("<u><b>${item##*/}</b></u>")
else
out+=("${item##*/},ln -sf $item $CONFFILE;compton_toggle;compton_toggle")
out+=("${item##*/},ln -sf $item $CONFFILE;mabox-compositor --restart")
fi
fi
done
out+=("^sep($EDIT_TITLE)")
if [ -f "$CONFFFILE" ];then
if [ -f "$CONFFILE" ];then
if [ ! "$(readlink $CONFFILE)" -ef "/dev/null" ];then
out+=("$EDIT,xdg-open $CONFFILE")
fi
fi
out+=("$OPENDIR,exo-open --launch FileManager $CONFDIR")
out+=("^sep($RENDERER)")
[[ "$backend" == "glx" ]] && out+=("<big>綠</big> $GLX" "<big>祿</big> $XRENDER,mb-setvar picom_renderer=xrender;mabox-compositor --restart") || out+=("<big>祿</big> $GLX,mb-setvar picom_renderer=glx;mabox-compositor --restart" "<big>綠</big> $XRENDER")
printf '%s\n' "${out[@]}"
}
case "$1" in
start) start;;
stop) stop;;
restart) restart;;
menu) menu "$2";;
start) start;;
stop) stop;;
restart) restart;;
menu) menu "$2";;
esac

View File

@ -1,100 +1,50 @@
#!/bin/bash
# mabox-compositor
# Openbox Pipe Menu for use with picom compositor
# Written for CrunchBang Linux <http://crunchbang.org/>
# by Philip Newborough <corenominal@corenominal.org>
# Ported to #!++ <https://crunchbangplusplus.org>
# by Ben Young <computermouth@crunchbangplusplus.org>
# Ported to Manjaro <https://manjaro.github.io/>
# mabox-compositor - script to start|stop|restart picom
# by Daniel Napora <napcok@gmail.com>
RESTART_ATTEMPTS=20
. "$HOME/.config/mabox/mabox.conf"
if ! . mabox-include.cfg 2> /dev/null; then
echo ' Failed to locate mabox-include.cfg in PATH' >&2
exit 1
backend=${picom_renderer:-glx}
start() {
CONFIGFILE="$HOME/.config/picom.conf"
if [ -f "$CONFIGFILE" ];then
picom --backend "$backend" --config "$CONFIGFILE" &
else
picom --backend "$backend" --config /usr/share/doc/picom/picom.conf.example &
fi
case $LANG in
pl*)
ENABLE="Włącz Kompozytora"
RESTART="Restartuj Kompozytora"
DISABLE="Wyłącz Kompozytora"
EDIT="Edytuj plik ustawień Kompozytora"
EDIT_GUI="Ustawienia Kompozytora (GUI)"
;;
es*)
ENABLE="Activar Compositor"
RESTART="Reiniciar Compositor"
DISABLE="Desactivar Compositor"
EDIT="Editar archivo de ajustes del Compositor"
EDIT_GUI="Ajustes gráfico (GUI)"
;;
*)
ENABLE="Enable Compositor"
RESTART="Restart Compositor"
DISABLE="Disable Compositor"
EDIT="Edit Compositor settings file"
EDIT_GUI="Settings (GUI)"
;;
esac
# ------------- Set xcompmgr command options -----------------------------------
EXECXCOMP='picom'
#if glxinfo | grep 'direct rendering: Yes'; then
# EXECXCOMP+=' --vsync opengl'
}
stop() {
if [ $(pgrep -u $USER picom) ]; then
killall -u $USER picom
fi
}
restart(){
stop
sleep 0.25
start
}
# OLD RESTART
#if [[ $1 = '--restart' ]]; then
# if pidof picom > /dev/null;then
# killall -q picom
# for (( i=0; i < RESTART_ATTEMPTS; i++ )); do
# pidof picom > /dev/null || # no process found! Safe to start again
# break
#
# (( i == RESTART_ATTEMPTS - 1 )) && # still didn't die? Probably hangs. Force it to die!
# killall -q -S KILL picom
#
# sleep 0.25
# done
# mabox-compositor --start
#fi
# Edit xcompmgr settings
if [[ $1 = '--edit' ]]; then
[[ ! -f $HOME/.config/picom.conf ]] &&
cp '/etc/xdg/picom.conf' "$HOME/.config/picom.conf"
if [[ -x /usr/bin/xdg-open ]]; then
xdg-open "$HOME/.config/picom.conf" &
else
terminator --command='nano "$HOME/.config/picom.conf"'
fi
elif [[ $1 = '--toggle' || $1 = '--start' ]]; then # Toggle compositing with picom.
[[ ! -f $HOME/.config/picom.conf ]] &&
ln -sf /dev/null "$HOME/.config/picom.conf"
# TODO why --toggle and --start act exactly the same?
if ! pidof picom > /dev/null; then
$EXECXCOMP &
else
killall picom
fi
elif [[ $1 = '--restart' ]]; then
if pidof picom > /dev/null;then
killall -q picom
for (( i=0; i < RESTART_ATTEMPTS; i++ )); do
pidof picom > /dev/null || # no process found! Safe to start again
break
(( i == RESTART_ATTEMPTS - 1 )) && # still didn't die? Probably hangs. Force it to die!
killall -q -S KILL picom
sleep 0.25
done
mabox-compositor --start
fi
elif [[ $1 = '--watch' ]]; then
while inotifywait -e modify "$HOME/.config/picom.conf"; do
mabox-compositor --restart
done
else
# Output Openbox menu
menuStart
menuSeparator "Picom"
if ! pidof picom > /dev/null; then
menuItem "$ENABLE" 'mabox-compositor --start'
else
menuItem "$RESTART" 'mabox-compositor --restart'
menuItem "$DISABLE" 'mabox-compositor --toggle'
fi
menuSeparator
menuItem "$EDIT" 'mabox-compositor --edit'
#menuItem "$EDIT_GUI" 'compton-conf'
menuEnd
fi
case "$1" in
--start) start;;
--stop) stop;;
--restart) restart;;
menu) menu "$2";;
esac
exit 0