Wednesday, October 31, 2007

xcalib and Linux screen savers

I was asked how you can start xcalib when the Linux screen saver deactivates.

Let's first talk about what the reason for this question may have been: Probably the screen saver alters the LUTs and resets them to their default value. It could also be possible that a 3D screen saver does some weird things with the LUTs. In any case, it seems like some screen savers require to load the LUTs again after the screen saver is disabled.

Unfortunately, there's no single screen saver program on Linux. There is the good old xscreensaver and the rather new gnome-screensaver. The later one supports D-Bus, so we can monitor a certain signal and issue the xcalib command when the screen saver deactivates. For the first one unfortunately no D-Bus signals exist (there's only a hack which is not integrated in the current xscreensaver).

So let's try to modify the FAQ Perl scripts of both screensavers for running xcalib when the screensaver unblanks.

xscrensaver:
#!/usr/bin/perl
my $blanked = 0;
open (IN, "xscreensaver-command -watch |");
while () {
if (m/^(BLANK|LOCK)/) {
if (!$blanked) {
$blanked = 1;
}
} elsif (m/^UNBLANK/) {
system "xcalib myprofile.icm";
$blanked = 0;
}
}

gnome-screensaver:
#!/usr/bin/perl
my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";
open (IN, "$cmd |");
while () {
if (m/^\s+boolean true/) {
} elsif (m/^\s+boolean false/) {
system "xcalib myprofile.icm";
}
}
I must admit that I haven't checked the scripts - but keep me informed if they don't work and I will modify them. As always, it should work with dispwin as well.

2 comments:

sruckh said...

Is the script supposed to be run from .xinitrc or .xsession file?

The color calibration is actually lost as soon as the screen saver is activated.

I ran it from a shell and backgrounded the process, but it did not appear to do anything.

I tried the gnome-screensaver script as I am using Ubuntu and Gnome.

Thanks for your help.

Neeraj said...

It's ok