Want draw graphic on root



hi,
i write a very simple gtk2-perl script, want draw on root window. i test a lot of methods, but still can not get expose event handler. please help me, kid on Gtk2::Gdk. below is my script(a lot of commentary). :D thanks.
--------------------------------
#!/usr/bin/perl

use Gtk2 "-init";
use Cairo;

my $event;
$file="$ENV{HOME}/tt.png";
#$file="/usr/share/pixmaps/vim.svg";

Gtk2->init;
#$screen=Gtk2::Gdk::Screen->get_default;
#$screen->broadcast_client_message(Gtk2::Gdk::Event->new("expose"));
#$window=$screen->get_root_window;
$window=Gtk2::Gdk->get_default_root_window;
#$mask=$window->get_events;
#$window->set_events($window->get_events|GDK_EXPOSURE_MASK);
#$window->set_events("GDK_EXPOSURE_MASK");
#Gtk2::Gdk::Event->handler_set(\&gdkevent);
#Gtk2::Gdk::Event::handler_set(\&gdkevent);
#$window->add_events("GDK_EXPOSURE_MASK");
Gtk2::Gdk::Event->handler_set (sub {
   ($event) = @_;
        print "gdkevent\n";
#   my $window = $event->window;
        if($event->type=="GDK_EXPOSURE"){
        cairo();
        }

#   ($event_cb{$window} && $event_cb{$window}->($event))
#      or Gtk2->main_do_event ($event);
});
#GDK_EXPOSURE_MASK              = 1 << 1,

#$gc = Gtk2::Gdk::GC->new ($window, undef);
#($drawable,$x_offset,$y_offset)=$window->get_internal_paint_info;
#$drawable->signal_connect('expose_event',\&expose);

#$pixbuf=Gtk2::Gdk::Pixbuf->new_from_file($file);
#($format,$width,$height)=$pixbuf->get_file_info($file);

$cr=Gtk2::Gdk::Cairo::Context->create($window);
cairo();
#while(Gtk2::Gdk::Event->get_graphics_expose($window)){
#cairo();
#}
#Gtk2->main_iteration while Gtk2->events_pending;
#while(1){
#if(Gtk2::Gdk::Event->get_graphics_expose($window)){expose();}
#}
#Gtk2->main();
Gtk2->main_do_event ($event);
#main Gtk2;
#Gtk2::Gdk->mainloop();
#Gtk2->main_iteration;
#sub gdkevent{
#        my ($event,$data) = @_;
#}

sub cairo {
#$pixbuf->render_to_drawable($drawable,$gc,0,0,200,100,$width,$height,'normal',0,0);

$cr->select_font_face("Amerika Sans",'normal','bold');
#$cr->select_font_face("Vera Sans YuanTi",'normal','bold');
$cr->set_font_size(60);
$cr->set_source_rgba(0,0,70,0.5);
$cr->move_to(100,300);
$cr->show_text("Cairo on Root");

my $img = Cairo::ImageSurface->create_from_png ($file);
$cr->scale(0.5,0.5);
$cr->set_source_surface($img,300,300);
$cr->paint;

print "draw\n";
}
--------------------------------

--



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]