HOWTO disable screensaver and powermanager while mplayer or other apps are running

来源:互联网 发布:mac 删除 ds store 编辑:程序博客网 时间:2024/05/20 20:46

http://ubuntuforums.org/showthread.php?t=284804

 

HOWTO disable screensaver and powermanager while mplayer or other apps are running

Ihave written a small python daemon to disable gnome-screensaver andgnome-powermanager while certain specified apps are running.
It works quite well on Ubuntu Edgy. It requires dbus (>= 0.93),python-dbus, and obviously gnome-screensaver and gnome-powermanager (ongnome 2.16).
The idea is simple: I have seen how Totem is working, and I emulate its behavior with a small python daemon.
To install it just copy "disablegss.py" in /usr/local/bin, fix itsexecute permissions and create a simple config file in your homedir"~/.disablegss". In this config file add every application name thatcould stop gnome-screensaver, one for each line. Example:

Code:
mplayer
gmplayer
vlc
wxvlc
xine
gxine
Please notice you must insert the name of the app how you can seeit on 'ps aux': for example if you want to add firefox, you must writea line with "/usr/lib/firefox/firefox-bin".
Now just launch disablegss.py on a terminal or simply add it on your session!
You can change the config file on fly (I check if someone modify it), adding or removing apps without restarting it.


HOW IT WORKS
Unfortunately the dbus and gnome development documentation are a bitoutdated, so I have read totem sources to view which methods are calledto stop gnome-screensaver and gnome-powermanager. The idea is if youcall the Inhibit method of gnome-screensaver, you disable the screensaver AND the powermanager. To enable them again you must call the UnInhibitmethod. There is a small terminal app, dbus-send, to comunicate withdbus but it doesn't work well with these methods, so I decide to usethe python dbus interface. This is my first program in python so pleasetell me if something is wrong or not well coded!
Every 60 secs the daemon check if there are apps running that are alsopresent in the config file. If it's true, the screensaver is disabled.If someone change the config file, the daemon read it again.
I don't think that this small daemon could run on Dapper: the dbus andgnome API change on every release. But you can modify it to fix things.There are only two lines that could be problematic:

Line 38: cookie = dev.Inhibit(myprogram, 'Disabled by DisableGSS Daemon')
Line 49: dev.UnInhibit(cookie)

These two methos are different on gnome 2.14 on Dapper. Also dbus hasradically changed. If you want to use disablegss.py on Dapper, find theright methods (try to see dapper totem sources) and feel free to changewhat you want!
To do debug, I suggest you to launch disablegss.py on a terminal anddbus-monitor on another one (you can see all messages from and to dbusdaemon). Also change the sleep time value in seconds (line 121) todebug it faster.
Happy coding!
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 联排别墅装修效果图 80平方的房子装修图 90平方房屋设计图 小平米装修效果图 新房子装修效果图 室内简单装修效果图大全 儿童卧室装修效果图小户型 小户型装修效果图大全2015图片 楼中楼装修效果图小户型 三室两厅装修效果图现代简约 现代装修风格效果图客厅 简约客厅装修实景图大全 90平方米简约装修效果图 190平方房子装修效果图 8平米卫生间装修效果图 100平方房屋装修效果图 四室两厅两卫装修效果图 130平米三室两厅装修效果图 八十平米小户型设计效果图 三室一厅一厨一卫装修效果图 七十平米小户型装修效果图 200平方米的房子设计图 75平方两室一厅装修效果图 113平方三室两厅装修效果图2015 85平米两室一厅装修效果图 四十平米小户型装修效果图 三房两厅两卫装修效果图 现代简约客厅装修效果图 3平方米卫生间装修效果图 主人房卫生间装修效果图 110平米三室两厅装修效果图 30平米单身公寓装修效果图 现代简约风格装修效果图 65平米小户型装修效果图大全 家装评选 装修帮登陆 家装帮 东易日盛全屋定制家装 东易日盛家装怎么样 柠檬树家装 柠檬树家装公司