bash: display simple sinusoid animation in active window title

77 Views Asked by At

I’m using Xubuntu 18.04.2 LTS with the base Greybird theme. My file manager is Nemo (3.8.6) and the window decoration manager is xfwm4.

Thanks to this bash script1 (code below and source here https://forum.ubuntu-fr.org/viewtopic.php?pid=22123363#p22123363), I can display a simple sinusoid on the console window. This animation also adapts automatically upon resizing the window:

[script1]

#!/bin/bash

motif="⠁⠂⠄⡀⢀⠠⠐⠈ "
tempo=0.04

recalcule() {
    columns=$( tput cols )
    repet=$(( columns / longMotif ))
    reste=$(( columns % longMotif ))
}

affPointApoint() {
    longChaine=${#1}
    for (( i=0; i<$longChaine; i++ )); do
        printf "${1:$i:1}"
        trap 'recalcule' SIGWINCH
    sleep $tempo
    done
}

longMotif="${#motif}"

while :; do
    recalcule
    tput clear   
    for (( x=0; x<$repet; x++ )); do
        affPointApoint "$motif"
    done
    affPointApoint "${motif:0:$reste}"
done

I would now like to display this simple sinusoid on a window other than the console one. Is it even possible to do this in the decoration of the active window, for example next to the window title?

My first idea is to make use of wmctrl with the script2 below but I didn't manage to do it. Do you think you could help? Thank you!

[script2]

#!/bin/bash
while true
do
  wmctrl -r :ACTIVE: -N "$(awk -F' \\|\\|' '{print $1}' <<<  $(xdotool  getwindowfocus getwindowname)) || $(sinusoid variable here)"
    sleep .1
done

Thanks for your time and help!

1

There are 1 best solutions below

1
On BEST ANSWER

The following actually works (start in a terminal, hover over other windows); I hope this is what you were thinking of:

#!/bin/bash

motif="⠁⠂⠄⡀⢀⠠⠐⠈ "
tempo=0.04
len=${#motif}

i=0
while true
do
    left=${motif:0:i}
    right=${motif:i:len}

    wmctrl -r :ACTIVE: -N "${right}${left}"

    i=$((i+1))
    [ $i -eq $len ] && i=0

    sleep 0.1
done