【问题标题】:Starting a custom screensaver on boot behaves differently than manually starting the screensaver在启动时启动自定义屏幕保护程序与手动启动屏幕保护程序的行为不同
【发布时间】:2016-07-22 15:13:49
【问题描述】:

我有一个运行网络服务器的触摸屏信息亭。如果屏幕在一定时间内没有被触摸,我想显示幻灯片。为此,我有下面的脚本。

#!/bin/sh

# Wanted trigger timeout in milliseconds.
IDLE_TIME=$((15*1000))

# Sequence to execute when timeout triggers.
trigger_cmd() {
DISPLAY=:0 feh -ZXYrzFD 10 /home/pi/screensaver/img --zoom fill &
    echo '"pkill -n feh; pkill -n xbindkeys"'>/home/pi/screensaver/xbindkeys.temp
    echo "b:1">>/home/pi/screensaver/xbindkeys.temp
    DISPLAY=:0 xbindkeys -n -f /home/pi/screensaver/xbindkeys.temp
    sudo rm /home/pi/screensaver/xbindkeys.temp
}

sleep_time=$IDLE_TIME
triggered=false

# ceil() instead of floor()
while sleep $(((sleep_time+999)/1000)); do
    idle=$(DISPLAY=:0 xprintidle)
    if [ $idle -gt $IDLE_TIME ]; then
        if ! $triggered; then
            trigger_cmd
            triggered=true
            sleep_time=$IDLE_TIME
        fi
    else
        triggered=false
        # Give 100 ms buffer to avoid frantic loops shortly before triggers.
        sleep_time=$((IDLE_TIME-idle+100))
    fi
done

我使用xprintidle 来检查屏幕空闲了多长时间。 xbindkeys 部分用于在触摸屏幕时杀死 feh。当我手动启动脚本时,我可以通过触摸屏幕一次来关闭幻灯片,它会在给定的空闲时间后重新打开。当我通过init.d 中的脚本启动脚本时,我必须触摸屏幕两次才能再次打开幻灯片,并且如果你只触摸一次屏幕就永远不会重新打开幻灯片。
init.d 中的脚本只是以用户 pi 的身份启动上面的脚本。

谁能帮我弄清楚为什么在启动时启动脚本显然会导致脚本需要点击两次而不是一次来启动空闲计时器?

【问题讨论】:

  • 有多少用户登录?
  • 只有pi用户登录

标签: linux screensaver init.d


【解决方案1】:

触摸屏脚本很可能在设置 DISPLAY 环境变量之前由 init.d 运行(即用户 pi 未登录)。

尝试从.bash_profile 运行它。这样一来,您的所有用户环境变量都将被设置,尤其是 $DISPLAY,并且脚本将在登录时运行一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 1970-01-01
    相关资源
    最近更新 更多