7 =head1 NAME $RCSfile: monitorXScreenSaver.pl,v $
9 Monitor xscreensaver and forcefully turn off screens when blanked. Note I had a
10 problem before where the screens wouled unblank and not go into powersave mode.
11 I think my new system doesn't have this problem anymore but I still run this.
13 I'd like to augment this so that after blanking of the screen and some time
14 thereafter the system would suspend. Suspending the system doesn't always work
15 well. It doesn't work well on my MacBook running Ubuntu but it does seem to work
16 OK on my Thelio Desktop from System76. But I have not implemented this yet.
24 Andrew DeFaria <Andrew@DeFaria.com>
32 Fri 09 Apr 2021 10:50:28 AM PDT
42 Usage: monitorXscreenSaver.pl [-u|sage] [-h|elp] [-v|erbose] [-de|bug]
43 [-[no]da|emon] [-l|ogpath]
46 -u|sage Print this usage
48 -v|erbose: Verbose mode
49 -d|ebug: Print debug messages
50 -l|ogpath <path>: Path to logfile (Default: /var/local/log)
51 -da|emon Run in daemon mode (Default: -daemon)
55 This script will monitor the xscreensaver process and forcefully powersave the
56 monitors when blanked.
64 use lib "$FindBin::Bin/lib";
71 usage => sub { pod2usage },
72 help => sub { pod2usage(-verbose => 2)},
73 verbose => sub { set_verbose },
74 debug => sub { set_debug },
76 logpath => '/var/local/log',
79 my ($xscreensaver, $log);
82 $log->msg("$FindBin::Script shutdown");
99 $SIG{INT} = \&interrupt;
102 path => $opts{logpath},
104 append => $opts{append},
111 $log->msg('Started monitoring XScreenSaver');
114 # Perl complains if we reference $DB::OUT only once
116 EnterDaemonMode unless defined $DB::OUT or get_debug;
120 open $xscreensaver, '-|', 'xscreensaver-command -watch'
121 or $log->err("Unable to start xscreensaver-command -watch - $!", 1);
123 while (<$xscreensaver>) {
124 $log->dbug("Received: $_");
127 $log->msg('Locked screen');
130 my $cmd = 'xset dpms force off';
132 $log->dbug("Calling $cmd");
136 $log->dbug("Returned from $cmd");
139 $log->dbug('Success');
141 $log->err("Unable to call $cmd- $!");
143 } elsif ($locked and /^UNBLANK/) {
144 $log->msg('Unlocked screen');