#!/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. :-) # message, x-position, y-position, on-all-desktops my ($message,$x,$y,$u) = @_; $message ||= 'Perl Gtk2 does transparency!'; $x ||= 100; $y ||= 100; $u ||= 1; #make on top on all virtual desktops my $window= Gtk2::Window->new('popup'); $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 $img = Gtk2::Image->new_from_pixmap( undef, undef ); $eventbox->add( $img ); $vbox->pack_start( $eventbox, FALSE, FALSE, 0 ); $window->add( $vbox ); $window->show_all(); my $drawing_area = Gtk2::DrawingArea->new; $drawing_area->set_size_request( 1600, 1600 ); $vbox->pack_start( $drawing_area, FALSE, FALSE, 0 ); $drawing_area->realize; my $pango_layout = $drawing_area->create_pango_layout( "" ); my $colormap = Gtk2::Gdk::Colormap->get_system; &new_screen; # 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; sub new_screen { my $ts = ret_time(); #Set our pango layout, to reflect the text and format that we want. #NOTE We deliberately set the background to a certain color to convert #that color to a alpha channel, that will give us the "clear" backgrou +nd. $pango_layout->set_markup( "<span background = '#000000' foreground = '#FF0000' size = '20000' weight ='heavy'>Message at $ts: </span><span background = '#000000' foreground= '#00FF00' size='30000' weight = 'ultralight'><i><u>$message</u></i></span> +" ); #Get the size of this layout after the text was set. my ( $pango_w, $pango_h ) = $pango_layout->get_pixel_size; #Now we have the size, we can create a pixmap that will be the #'Gtk2::Gdk::Drawable' that we will draw upon my $pixmap = Gtk2::Gdk::Pixmap->new( $drawing_area->window, $pango_w, $pango_h, + -1 ); #Draw a black block on $pixmap the size of the pango text. #This allow us to use newlines in the pango text, just make sure the p +ango #background is also black, as to convert all the black to a alpha chan +nel $pixmap->draw_rectangle( $drawing_area->style->black_gc, TRUE, 0, 0, $pango_w, $pango_h ); #draw the pango layout on the drawable. $pixmap->draw_layout( $drawing_area->style->white_gc, 0, 0, $pango_ +layout ); #create a Gtk2::Gdk::Pixbuf that we will use to grab the pango text fr +om the #drawable (Gtk2::Gdk::Pixmap which is a Gtk2::Gdk::Drawable) my $pixbuf = Gtk2::Gdk::Pixbuf->new( 'rgb', TRUE, 8, $pango_w, $pan +go_h ); #here we get create a pixbuff from the drawable, this is where we need + the colormap $pixbuf->get_from_drawable( $pixmap, $colormap, 0, 0, 0, 0, $pango_ +w, $pango_h ); #Remove the background (we use the color we specified as the pango tex +t's #background $pixbuf = $pixbuf->add_alpha( TRUE, 0, 0, 0 ); #create a pixmap and mask from the Gtk2::Gdk::Pixbuf my ( $pm, $m ) = $pixbuf->render_pixmap_and_mask( 255 ); #shrink our window to make sure the mask and pixmap will be on the sam +e spot. $window->resize( 4, 4 ); #replace the old $img with the new pixmap and mask $img->set_from_pixmap( $pm, $m ); #shape our window accordingly $window->shape_combine_mask( $m, 0, 0 ); return TRUE; } sub ret_time { #sub to return a string containing the time my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)= localtime(tim +e+3600); my @lst =("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); my $thisday =$lst[$wday]; $year = $year + 1900; ($sec =~ m/\d{2}/)||($sec = "0".$sec); ($min =~ m/\d{2}/)||($min = "0".$min); ($hour =~ m/\d{2}/)||($hour = "0".$hour); $mon = $mon +1; #print("\n"); my $ts = "$thisday $mday/$mon/$year $hour:$min:$sec"; return $ts; }
In reply to Gtk2 transparent screen messages by zentara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |