views:

59

answers:

3

Hi,

is there a way to check programmatically (via ioctl(), etc.) or by reading a file in /sys, /proc or /dev) whether the screen has been blanked by the Linux console screensaver?

Thanks and best regards,

Günter

A: 

I haven't done any desktop development in ages, but memory tells me that most linux screensavers were being executed by xscreensaver - maybe checking whether the process is running, or going through its source-code to see for any system-state being set, or asking on the project maillist would yield some results. Of course KDE and Gnome might have separate screensaver implementations by now - there is very little uniformity when it comes to linux GUIs, unfortunately...

vstoyanov
+1  A: 

You can parse the output of xset q with DISPLAY set, but it's not pretty.

$ xset q
Keyboard Control:
  auto repeat:  on    key click percent:  0    LED mask:  00000000
  XKB indicators:
    00: Caps Lock:   off    01: Num Lock:    off    02: Scroll Lock: off
    03: Compose:     off    04: Kana:        off    05: Sleep:       off
    06: Suspend:     off    07: Mute:        off    08: Misc:        off
    09: Mail:        off    10: Charging:    off    11: Shift Lock:  off
    12: Group 2:     off    13: Mouse Keys:  off
  auto repeat delay:  250    repeat rate:  30
  auto repeating keys:  00ffffffdffffbbf
                        fadfffefffedffff
                        9fffffffffffffff
                        fff7ffffffffffff
  bell percent:  50    bell pitch:  400    bell duration:  100
Pointer Control:
  acceleration:  20/10    threshold:  4
Screen Saver:
  prefer blanking:  yes    allow exposures:  yes
  timeout:  0    cycle:  600
Colors:
  default colormap:  0x20    BlackPixel:  0    WhitePixel:  16777215
Font Path:
  /usr/share/fonts/misc,/usr/share/fonts/100dpi:unscaled,/usr/share/fonts/75dpi:unscaled,/usr/share/fonts/TTF,/usr/share/fonts/Type1,/usr/share/fonts/misc/,/usr/share/fonts/TTF/,/usr/share/fonts/Type1/,/usr/share/fonts/100dpi/,/usr/share/fonts/75dpi/,built-ins
DPMS (Energy Star):
  Standby: 1200    Suspend: 1800    Off: 0
  DPMS is Enabled
  Monitor is On
Font cache:
  Server does not have the FontCache Extension
Daenyth
Thanks, this does the trick. Not the most elegant solution, but checking the output for "Monitor is on|off" works.
obiltschnig
This is fine, but it relies on an X server being available. If you just have a console (which is rare these days, admittedly), it won't work.
Gabe
In my case it's fine. I'm running a fullscreen Gtk-WebKit browser which leaks memory like a sieve, so after the screen has been turned off for a while I can safely kill and restart the browser ;-) Of course it would be nice not to have those leaks in the first place...
obiltschnig
@obiltschnig: Look into valgrind.
Daenyth
I would but I don't have the time and resources to fix WebKitGTK+... For now, dirty tricks will have to do.
obiltschnig
+2  A: 

Okay, checked the xset source code. The relevant code parts are

#include <X11/extensions/dpms.h>
...
Display* dpy = XOpenDisplay(NULL);
...
int dummy;
CARD16 standby, suspend, off;
BOOL onoff;
CARD16 state;

printf("DPMS (Energy Star):\n");
if (DPMSQueryExtension(dpy, &dummy, &dummy)) 
{
    if (DPMSCapable(dpy)) 
    {
        DPMSGetTimeouts(dpy, &standby, &suspend, &off);
        printf ("  Standby: %d    Suspend: %d    Off: %d\n",
                standby, suspend, off);
        DPMSInfo(dpy, &state, &onoff);
        if (onoff) 
        {
            printf("  DPMS is Enabled\n");
            switch (state) 
            {
            case DPMSModeOn:
                printf("  Monitor is On\n");
                break;
            case DPMSModeStandby:
                printf("  Monitor is in Standby\n");
                break;
            case DPMSModeSuspend:
                printf("  Monitor is in Suspend\n");
                break;
            case DPMSModeOff:
                printf("  Monitor is Off\n");
                break;
            default:
                printf("  Unrecognized response from server\n");
            }
        }
    }
}

Just in case anyone else needs this ;-)

obiltschnig