Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 04-30-2009, 09:15 AM   #1
Registered: Aug 2003
Location: Minnesota, U.S.A.
Distribution: Debian, openSUSE
Posts: 400

Rep: Reputation: 30
Question How to write a daemon that polls X DPMS settings?

I'm fed up with gnome-power-manager, and I've resorted to using xset to make sure my LCD turns off after a specified amount of time.

I disable gnome-screensaver and set gnome-power-manager to blank the screen after 11 minutes. I then use xset to set DPMS Suspend and PowerOff times to 12 and 14 minutes, respectively. I do this because on my laptop Gnome 2.26 (and any previous version I've run in the past five years) rarely if ever actually turns off my LCD backlight.

This works great, the problem is that sometimes Gnome resets my DPMS Standby, Suspend, and PowerOff times to 0, 0, 0. I have a launcher on my panel now that runs `xset dpms 0 720 840` which I click before I leave my system so that I know the LCD will blank, but it isn't the most elegant solution.

Now I'm fairly handy with Perl and shell scripting, but I have no idea how to write a daemon-type utility to do any polling.

Basically I want to have a (user-run) daemon that starts with Gnome. That part I know how to do. What I don't know how to do is poll for current DPMS times. I can probably make it work by either having it poll every few minutes for what the current DPMS times are, or else having it poll for DPMS time changes. Whenever the times get reset or changed from 0, 720, 840, I want to run xset again.

So basically, how do I poll for X DPMS time values? Is there a better way than using regular expressions to parse the output of `xset q`?
Old 04-30-2009, 11:48 AM   #2
Registered: Aug 2003
Location: Minnesota, U.S.A.
Distribution: Debian, openSUSE
Posts: 400

Original Poster
Rep: Reputation: 30
It isn't pretty, but here's what I built during my lunch break:

use strict;

my $standbyTime = 0;
my $suspendTime = 720;
my $pwroffTime = 840;
my $pollTime = 300;
my $xsetOutput;

if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help") {
    print "\n";
    print " is a script that makes sure that X DPMS settings\n";
    print "do not get reset.\n";
    print "\n";
    print " will check DPMS settings once, unless it is given\n";
    print "the -d command line argument, which causes it to run as a daemon.\n";
    print "\n";
    print " options can be set by editing the variables at the\n";
    print "top of the script.\n";
    print "\n";

do {
    $xsetOutput = `xset q`;
    if ( $xsetOutput =~ m/.*DPMS.*\n\s*Standby:\s+(\d+)\s*Suspend:\s+(\d+)\s*Off:\s+(\d+)/g ) {
        # $1 is DPMS Standby time in seconds
        # $2 is DPMS Suspend time in seconds
        # $3 is DPMS Off time in seconds
        if ( $1 != $standbyTime || $2 != $suspendTime || $3 != $pwroffTime ) {
            system("xset dpms $standbyTime $suspendTime $pwroffTime");
    if ($ARGV[0] eq "-d") {
} while ($ARGV[0] eq "-d")


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Settings daemon problem Draiocht Slackware 2 09-14-2005 08:00 PM
gnome-settings-daemon quits slackwarefan Slackware 2 03-21-2005 07:07 PM
Gnome-settings-daemon failed slackwarefan Slackware 3 03-09-2005 06:30 AM
gnome settings daemon b0uncer Linux - Software 1 10-05-2003 04:33 AM
Daemon Settings Failed At Startup!!!!!!!! kDwosk Linux - Newbie 2 08-22-2003 05:46 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration