diff --git a/README.md b/README.md index d80bd03..3bde332 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,29 @@ # polybar-dynamic-centered-tray -A bunch of scripts able to create a "dynamic traybar" experience for Polybar, making it behave kinda like a module. +Apenas alguns scripts capazes de criar a experiência de uma "traybar dinâmica" para a Polybar, fazendo-a com que se comporte *tipo* um módulo. + +## Requisitos +1. Versão recente da [Polybar](https://github.com/polybar/polybar/); +2. i3wm (preferencialmente v.4.17+); +3. Instalar os scripts e o módulo corretamente. + +## Instalação +1. Baixe a release mais recente ou clone este repositório com ```git clone https://github.com/daltroaugusto/polybar-dynamic-centered-tray.git```, depois navegue para a pasta extraída; +2. Execute ```sudo ./install``` (script de instalação com privilégios de superusuário), ou copie os scripts para uma pasta em seu ```$PATH```; +3. Insira o módulo ```polybar_trayoffset``` na posição em que desejar, no arquivo de configuração da Polybar: + + + + + + + + +
+ ``` +[module/trayoffset] +type = custom/script +interval = 1.0 +exec = polybar_trayoffset echo +format =
\ No newline at end of file diff --git a/README_EN.md b/README_EN.md new file mode 100644 index 0000000..cee4c75 --- /dev/null +++ b/README_EN.md @@ -0,0 +1,2 @@ +# polybar-dynamic-centered-tray +A bunch of scripts able to create a "dynamic traybar" experience for Polybar, making it behave *kinda like* a module. \ No newline at end of file diff --git a/install b/install new file mode 100644 index 0000000..a3381f8 --- /dev/null +++ b/install @@ -0,0 +1,4 @@ +#!/bin/bash + +install "$PWD/polybar_trayoffset" "/usr/local/bin/" +install "$PWD/watchps_tray" "/usr/local/bin/" \ No newline at end of file diff --git a/polybar_trayoffset b/polybar_trayoffset new file mode 100644 index 0000000..6cbf472 --- /dev/null +++ b/polybar_trayoffset @@ -0,0 +1,48 @@ +#!/bin/bash + +# Script base que apenas insere e remove caracteres U+2000 (Unicode) no módulo, a fim de dar espaço para a traybar, que já pode ter um offset inicial configurado, a depender da intenção da rice/pessoa. +# EN: base script which just insert and remove U+2000 (Unicode) characters in the module, giving the needed offset for traybar, that may need some initial offset setted up, depending on ricing/people intentions. + +# Daltro Augusto. 2021-. LGPLv2. + +POLYBAR_TRAYOFFSET=$(<"${HOME}/.config/polybar/.trayoffset") +SYNTAX_TEXT="SYNTAX: [ \e[3madd [no. of spaces]\e[0m | \e[3mecho\e[0m | \e[3mremove\e[0m | \e[3mremove-all\e[0m ]" + +case $1 in + add) + result="${POLYBAR_TRAYOFFSET}      " + + if test -n "$2" -a "$2" -ge 1 2>/dev/null ; then + result="${POLYBAR_TRAYOFFSET}" + + for((i=0; i<$2; i++)); do + result+=" " + done + fi + + echo "$result" > "${HOME}/.config/polybar/.trayoffset" + ;; + + echo) + echo "${POLYBAR_TRAYOFFSET}" + ;; + + remove) + i=${POLYBAR_TRAYOFFSET} + offset=$((${#i} - 6)) + + if test -n "$2" -a "$2" -ge 1 2>/dev/null; then offset=$((${#i} - $2)); fi + + result=${i:0:$offset} + + echo "$result" > "${HOME}/.config/polybar/.trayoffset" + ;; + + remove-all) + echo "" > "${HOME}/.config/polybar/.trayoffset" + ;; + + *) + echo -e "$SYNTAX_TEXT" + ;; +esac diff --git a/watchps_tray b/watchps_tray new file mode 100644 index 0000000..743c9aa --- /dev/null +++ b/watchps_tray @@ -0,0 +1,18 @@ +#!/bin/bash +# Este script é para ser hookado no arquivo i3config, usando os seletores for_window do i3wm. +# EN: script to be hooked in i3config file, with for_window i3wm's selectors. + +# Daltro Augusto. 2021-. LGPLv2. + +PS=$1 +polybar_trayoffset add "$2" + +while true +do + if [ "$(pidof "${PS}" | wc -l)" -eq 0 ]; then + polybar_trayoffset remove "$2" + break + fi + + sleep 1 +done