#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

# I derived it from the clock.pl example that comes in
# the Gtk2-Perl study guide of Dirk Van Der Walt, at
# http://forgeftp.novell.com/gtk2-perl-study/download/
# Dirk deserves credit for figuring this out. :-)

#
# 2008-07-28 Modified by Yann Droneaud <ydroneaud@mandriva.com>
#

my $filename = shift || 'sample.png';

#my $window= Gtk2::Window->new('popup');
my $window= Gtk2::Window->new('toplevel');

$window->signal_connect ("delete_event", sub { Gtk2->main_quit; });        
#$window->move($x,$y);
$window->set_position( 'center-always' );
#if($u ==1){$window->stick}

my $vbox = Gtk2::VBox->new( FALSE, 0 );
my $eventbox = Gtk2::EventBox->new();

my $pixbufin = Gtk2::Gdk::Pixbuf->new_from_file($filename);

# create the image from the content of the pixbuf
my $img = Gtk2::Image->new_from_pixbuf($pixbufin);

# create a bitmap (pixmap with 1bit depth)
my $mask = Gtk2::Gdk::Pixmap->new(undef, $pixbufin->get_width, $pixbufin->get_height, 1);

# create the mask: 
#  all pixels with an alpha level under 127 will be fully transparent
#  all pixels with an alpha level over 127 will be fully opaque
$pixbufin->render_threshold_alpha($mask, 0, 0, 0, 0, $pixbufin->get_width, $pixbufin->get_height, 127);

# create a shaped window from the mask created above
# this is binary: either fully transparent either fully opaque
$window->shape_combine_mask($mask, 0, 0 );

$eventbox->add( $img );
$vbox->pack_start( $eventbox, FALSE, FALSE, 0 );
$window->add( $vbox );

$window->show_all();

# since the text is hard to get your mouse over for focus
# just destroy it if the mouse passes over it, very easy
#$window->signal_connect('enter-notify-event' => sub{ exit });

Gtk2->main;

