Mantenha uma caixa de diálogo Zenity sempre em primeiro plano em primeiro plano

8

Existe uma maneira de detectar que uma caixa de diálogo Zenity perdeu o foco?

Eu gostaria de manter a caixa de diálogo em primeiro plano, a menos que o usuário pressione ESC .

Eu estou tentando adicioná-lo a este script :

#!/bin/bash

# requires these packages from ubuntu repository:
# wmctrl, zenity, x11-utils 
# and the script mouse-speed

# This procect on git:        https://github.com/rubo77/mouse-speed


######## configuration ##########
# seconds between micro breaks
microbreak_time=$(( 10 * 60 ))
# micro break duration in seconds
microbreak_duration=15
# seconds between long breaks
longbreak_time=$(( 120 * 60 ))

# message to display 
message="Try focussing a far object outside the window with the eye to relax!"
longbreak_message="Change your seating or continue work in a standing/sitting position"
#postpone label
postpone="Postpone"

window_title="typebreak"

# global zoom of your window manager:
ZOOM=2
# height in px of the top system-bar:
TOPMARGIN=57
# sum in px of all horizontal borders:
HORIZONTALMARGIN=40
# get width of screen and height of screen
SCREEN_WIDTH=$(xwininfo -root | awk '$1=="Width:" {print $2}')
SCREEN_HEIGHT=$(xwininfo -root | awk '$1=="Height:" {print $2}')
# width and height
W=$(( $SCREEN_WIDTH / $ZOOM - 2 * $HORIZONTALMARGIN ))
H=$(( $SCREEN_HEIGHT / $ZOOM - 2 * $TOPMARGIN ))

function slow_down(){
    #zenity --warning --text "slow down mouse";
    mouse-speed -d 30
}

while true; do
    # short loop every few minutes to look around
    sleep $microbreak_time
    (
    echo "99"
    sleep $(( $microbreak_duration - 2 ))
    echo "# Mouse speed reset to 100%"
    sleep 2
    echo "100"
    ) | if ( sleep 1 && wmctrl -F -a "$window_title" -b add,maximized_vert,maximized_horz && sleep 3 &&  wmctrl -F -a "$window_title" -b add,above ) & ( zenity --progress --text "$message" --percentage=0 --auto-close  --height=$H --width=$W --pulsate --title="$window_title" --cancel-label="$postpone" ); then
        #zenity --info --text "Maus normal speed!"
        mouse-speed -r
    else 
        slow_down
    fi
done &
while true; do
    # second long loop to change seat position
    sleep $longbreak_time
    zenity --warning --text "$longbreak_message" --title="$window_title - long break"
done
    
por rubo77 26.08.2014 / 21:13

2 respostas

10
#!/bin/bash
# This will wait one second and then steal focus and make the Zenity dialog box always-on-top (aka. 'above').

(sleep 1 && wmctrl -F -a "I am on top" -b add,above) &
(zenity --info --title="I am on top" --text="How to help Zenity to get focus and be always on top")

Fonte:

por 26.08.2014 / 21:32
0

Você pode ter problemas se você executar isso como uma tarefa cron. O ambiente do Cron não está ciente do seu display X, dbus ou desktop e não exibirá a caixa zenity ou a manterá no topo. Adicionando DISPLAY =: 0 antes de both wmctrl e zenity resolve o problema:

(sleep 1 && DISPLAY=:0 wmctrl -F -a "I am on top" -b add,above) & (DISPLAY=:0 zenity --info --title="I am on top" --text="How to help Zenity to get focus and be always on top")

    
por 10.03.2015 / 14:06

Tags