#!/usr/bin/perl -w
# Notes:
# Values inside @ARGV:
# /p;593118 - The preview window for Display Properties tries showing the saver
# /c:3411052 - The "Settings" button was clicked
# /s - The "Preview" button was clicked OR the saver started on its own
use Tk;
use Tk::CursorControl;
# Load from config
my $txt = 'Screen Saver';
if (-e "C:/perlss.txt") {
open (TEXT, "C:/perlss.txt");
$txt = <TEXT>;
close (TEXT);
}
if (@ARGV && $ARGV[0] =~ /^\/c/i) {
my $main = MainWindow->new (
-title => 'Configure',
);
$main->Label (-text => 'Text:')->pack;
$main->Entry (
-textvariable => \$txt,
)->pack;
my $blab = $main->Frame ()->pack (-side => 'bottom', -fill => 'x');
$blab->Button (
-text => 'Ok',
-command => sub {
open (WRITE, ">C:/perlss.txt");
print WRITE $txt;
close (WRITE);
exit(0);
},
)->pack (-side => 'left');
$blab->Button (
-text => 'Cancel',
-command => sub {
exit(0);
},
)->pack (-side => 'left');
$main->bind ('<Destroy>', sub {
exit(0);
});
MainLoop;
}
elsif (@ARGV && $ARGV[0] =~ /^\/p/i) {
exit(0);
}
my $main = MainWindow->new (-background => 'black');
$main->overrideredirect(1);
$main->geometry (join('x', $main->screenwidth, $main->screenheight));
$main->MoveToplevelWindow(0,0);
$main->focusForce;
my $env = $main->Label (
-text => 'env vars',
-background => 'black',
-foreground => '#CCCCCC',
-font => [
-family => 'Courier New',
-size => 8,
],
-justify => 'left',
)->place (-x => 0, -y => 0, -anchor => 'nw');
my @envs = ();
foreach (keys %ENV) {
push (@envs, "$_ = $ENV{$_}");
}
push (@envs, "\@ARGV = " . join(";",@ARGV));
$env->configure (-text => join ("\n",@envs));
my $cursor = $main->CursorControl;
$cursor->hide ($main);
$main->bind ('<Motion>', sub {
exit(0);
});
$main->bind ('<KeyPress>', sub {
exit(0);
});
$main->bind ('<Button>', sub {
exit(0);
});
my $lab = $main->Label (
-text => $txt,
-background => 'black',
-foreground => 'yellow',
-font => [
-family => 'Arial',
-size => 36,
-weight => 'bold',
],
)->place (-x => 0, -y => 0);
my $now = time();
while (1) {
$main->update;
select (undef,undef,undef,0.1);
if (time() - $now >= 2) {
my $color = (qw(limegreen cyan yellow white orange skyblue pink))[ int(rand(7)) ];
$lab->configure (-foreground => $color);
my $x = int(rand($main->screenwidth - $lab->width));
my $y = int(rand($main->screenheight - $lab->height));
$lab->place (-x => $x, -y => $y);
$now = time();
}
}