#!/usr/bin/perl -w
#
# Fullscreen program launcher, [email protected]
#

use strict;
use Tk;
use Tk::PNG;

my $main = MainWindow->new(-title => 'DeskPad Launcher',-background => 'black');
$main->overrideredirect (1);
$main->MoveToplevelWindow (0,0);
$main->geometry(join('x',$main->screenwidth,$main->screenheight));
$main->after(30000, sub { $main->destroy; });
$main->bind('<Key-Escape>', sub { $main->destroy; });
$main->bind('<ButtonRelease-1>', sub { $main->destroy; });

my $control = $main->Toplevel(-title => 'DeskPad');
$control->geometry("50x50");
$control->MoveToplevelWindow(-150,-150);
$control->bind('<FocusIn>', sub { $main->focusForce; });

# Load buttons from config file
open my $cfgfile, $ENV{"HOME"}."/.deskpad" or die "Could not open config file: $!\n";

while(my $line = <$cfgfile>)  {
       if (chomp($line) ne "") {
               my @iconData = split(":",$line);

               $image = $main->Photo('-format' => 'png', -file => $iconData[0]);
               $main->Button(
                       -background => 'black',
                       -activebackground => 'black',
                       -highlightthickness => '0',
                       -borderwidth => '0',
                       -relief => 'flat',
                       -command => sub { exec($iconData[1]) },
                       -image => $image,
               )->pack->place(-x=>$iconData[2],-y=>$iconData[3]);
       }
}

close $cfgfile;
MainLoop;