Re: desktop exit signals



On Mon, 28 Nov 2005 21:13:39 +0100
Jaap Karssenberg <j g karssenberg student utwente nl> wrote:

Hi,

I was wondering which signal I need to intercept if I want to know when 
the desktop exits while my application is still open. I tried catching 
SIGHUP, SIGTERM and SIGKILL but no luck so far. (The obvious purpose of 
this is to save the state of the application before it exits.)

I know this has been discussed before and the "right" way to do this 
would be using gnome session. The problem is that I do not want to 
depend on gnome libs unless really necessary.

I have this working on ICEWM. It will save on a logout from X, but
not a Control-Alt-Backspace. It will also save if you accidently
hit the X in the Window Manager's toolbar.  You can prevent 
Cntrl-Alt-BS in Xorg.conf, so it might be useful.

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

# will save on a Window Manager logout under ICEWM
# or clicking the WM X button.
# but not a Control-Alt-Backspace

$SIG{__DIE__} = sub {&save_it(); exit};
$SIG{INT} = sub {&save_it(); exit};

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&save_it );
$window->set_border_width(10);
$window->set_size_request(300,200);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);
$hbox->set_border_width(2);

$vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0);

my $button = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => \&delete_event );

$window->show_all();
Gtk2->main;
#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}  
#####################################
sub save_it{
  open(FH,"> save.txt");
  print FH 'saved '.time."\n";
  close FH;
  exit;
}
__END__



-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



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