Zenity
대화상자가 포커스를 잃었는지 감지하는 방법이 있나요 ?
사용자가 누르지 않는 한 대화 상자를 전경에 유지하고 싶습니다 ESC.
에 추가하려고 해요이 스크립트:
#!/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
답변1
#!/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")
원천:
답변2
이를 cron 작업으로 실행하면 문제가 발생할 수 있습니다. Cron의 환경은 X 디스플레이, dbus 또는 데스크탑에 대한 지식이 없으며 zenity 상자를 표시하거나 맨 위에 두지 않습니다. 앞에 DISPLAY=:0을 추가하세요.둘 다wmctrl과 zenity가 문제를 해결했습니다.
(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")
답변3
이 솔루션은 기본적으로 @Jan의 솔루션과 동일하지만 창 제목 대신 PID를 사용하여 창을 식별하고 Bourne Shell과 추가로 호환됩니다(-> bash 필요 없음).
#!/bin/sh
# This will wait 200ms, steal focus and set the Zenity dialog box
# to "always-on-top".
modify_win_by_pid() {
pid=$1
sleep 0.2
win_id=`wmctrl -l -p | grep ${pid} | awk '{print $1}'`
wmctrl -i - ${win_id} -b add,above
}
zenity --info --title="I am on top" --text="I received focus and will stay on top" &
modify_win_by_pid $!