Showing posts with label screensaver. Show all posts
Showing posts with label screensaver. Show all posts

Sunday, October 16, 2011

shutdown x screen saver 关闭x的屏幕保护

这几天看house医生,本子老是自动关闭显示器,比较麻烦

本来现在使用的是awesome,根本没有打开screen saver的类似程序,只有google了

原来X 默认包含省电和屏保的设置,找到一个 xset 来关闭x screen saver 的做法,具体参数察看man xset .

查看xset的手册后发现屏幕保护是由X的两个部分控制的, 一个是BlankTime(较新的X中放在ScreenSaver选项中), 一个是DPMS. BlankTime设置的是黑屏, 也就是说只黑屏而不关显示器电源, 对于液晶显示器来说就是不关背灯. DPMS设置的是电源, 三个子选项Standby, Suspend和Off对于CRT显示器是一个逐步关闭电源的过程, 对于液晶显示器应该是一样的.

使用 xset q 可以看到如下2个内容

       Screen Saver:
          prefer blanking:  yes    allow exposures:  yes
          timeout:  600    cycle:  600

       DPMS (Energy Star):
  Standby: 600    Suspend: 600   Off: 600
  DPMS is Enabled
  Monitor is On
正因为X的屏幕保护由两部分控制, 单纯的关闭DPMS或者BlankTime都不行, 必须都关掉. 所以我在.xinitrc中加入了下面的命令, 具体解释和其它xset命令参数见Manual.
  
       xset s off
       xset dpms 0 0 0

但是暴力关闭显示器电源不怎么划算,比如通宵下载可以选择把DPMS和BlankTime的超时时间设置得久一点,或者加一条alias用来手动关闭显示器电源(笔记本没显示器开关).

alias soff='sleep 5 && xset dpms force off'

之所以sleep 5是为了防止命令执行以后因为手抖或者合上笔记本的盖子而唤醒显示器. 同时这也解释了我为什么在上一步不用xset -dpms, 因为关显示器的时候会再次启用DPMS模块, 屏保又开始生效了, 而置0只是关屏保而不关DPMS, 留着这个模块用来关显示器. 还有一个原因在于有的桌面环境会不停得去检测并启用DPMS模块, 无法简单地关闭DPMS模块.


参考 :http://socol.iteye.com/blog/1039725
    http://www.adam8157.info/blog/2010/06/turn-off-x-screensaver/

Tuesday, October 4, 2011

flash全屏的时候停止gnome屏幕保护disable screen saver when looking at flash videos(youtube, vimeo, youku,etc)

~/dis.sh.html
# gnome环境当开启flash全屏播放的时候禁用屏幕保护 

#!/bin/bash 


# cleanup any bad state we left behind if the user exited while flash was running
gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true

turn_it_off=0
sleepcomputer0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_ac`
sleepdisplay0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_display_ac`

# run loop forever
while true; do
  # interval between checks
  sleep 30
  SS_off=0
  # make id variable of window in focus
  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
  # make pid array of every command with libflashplayer in full(-f) command
  for pid in `pgrep -f libflashplayer` ; do
    # check if window in focus is our libflashplayer
    if [ $pid == `xprop -id $current_window_id | grep PID | cut -d" " -f3` ]
      then SS_off=1
    fi
  done

# check to see if xine is being used
#  if pgrep xine > /dev/null; then
#    SS_off=1
#  fi
#
# check to see if current application is fullscreen
#  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
#  if xprop -id $current_window_id | grep "_NET_WM_STATE_FULLSCREEN" > /dev/null; then
#    SS_off=1
#  fi

  # read current state of screensaver
  ss_on=`gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled`

  # change state of screensaver as necessary
  if [ "$SS_off" = "1" ] && [ "$ss_on" = "true" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int 0
    turn_it_off=1
  elif [ "$SS_off" = "0" ] && [ "$ss_on" = "false" ] && [ "$turn_it_off" = "1" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $sleepcomputer0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int $sleepdisplay0
    turn_it_off=0
  fi
done



#Reference: http://ubuntuforums.org/showthread.php?p=10832670#post10832670