貌似Lose系統下看在線視頻的時候不會超時自動關閉屏幕,但是我在Arch下就一直晃鼠標、按鍵盤來著,這嚴重違反了DRY原則。於是昨天終於寫了這個腳本,當全屏播放視頻的時候,關閉屏保和顯示器的節能特性,否則則激活它們。由於是在X的級別實現,理論上應當適合所有桌面環境。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# Baby-sitter of the monitor's DPMS
idle_period=60
ss_switch_off=0
ss_is_off=0
while true; do
# Read DPMS state
xset -q|grep "DPMS is Disabled" > /dev/null && ss_is_off=1 || ss_is_off=0
# Get pid of the current window
active_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
decimal_id=`xprop -id $active_window_id | grep PID | cut -d" " -f3`
# Traverse all libflashplayer.so
for pid in `ps -ef|grep -v grep|grep libflashplayer.so|awk '{print $2}'`; do
# If the current window is libflashplayer.so
if [ "$pid" -eq "$decimal_id" ]; then
ss_switch_off=1
break
else
ss_switch_off=0
fi
done
if [ $ss_switch_off -eq 1 ]; then
# Turn off DPMS
echo Turn off DPMS
if [ $ss_is_off -eq 0 ]; then
echo Action
xset s off
xset -dpms
fi
else
# Turn on DPMS
echo Turn on DPMS
if [ $ss_is_off -eq 1 ]; then
echo Action
xset +dpms
xset s on
fi
fi
sleep $idle_period
done

似乎對非全屏播放的情況沒有什麼好方法。

Posted via UltraBlog.vim.