cvsimport
[fvwm.git] / tests / perl / module-example
bloba2432b6493de5d066f7030117d0d617fa769e45c
1 #!/usr/bin/perl -w
3 # This is a simple fvwm module written in perl using the supplied perl library.
4 # Iconifies new windows, auto-raises windows and terminates itself in 1 minute.
5 # Either place this module in FVWM_MODULEDIR or run it using the full path.
7 use strict;
8 use lib `fvwm-perllib dir`;
9 use FVWM::Module;
11 my $new_window_handler = sub {
12 my ($self, $event) = @_;
13 #$self->send("Echo M_ADD_WINDOW " . join(", ", %{$event->args}));
15 # auto iconify all new windows
16 $self->send("Iconify true", $event->_win_id);
19 my $module = new FVWM::Module(
20 Name => "FvwmPerlBasedExample", # used in config and debug
21 Mask => M_ADD_WINDOW | M_FOCUS_CHANGE, # request two these events
24 # do some funny harm
25 $module->show_message("started");
26 $module->send("Beep");
27 $module->send("All (FvwmConsole) Iconify true");
29 # undo harm
30 my $on_exit = sub { $_[0]->send("Beep\nAll (FvwmConsole) Iconify false") };
32 # auto-exit in 60 seconds; a mere die() in ALRM signal handler is ok too
33 local $SIG{ALRM} = sub { $module->terminate(); };
34 alarm(60);
36 # auto-iconify new windows
37 $module->add_handler(M_ADD_WINDOW, $new_window_handler);
38 # auto-raise all windows with delay of 500 msec
39 $module->add_handler(M_FOCUS_CHANGE, sub {
40 my $win_id = $_[1]->_win_id;
41 $_[0]->send("Deschedule 1234\nSchedule 500 1234 WindowId $win_id Raise");
42 });
43 # do a clean-up on exit
44 $module->add_handler(ON_EXIT, $on_exit);
46 # enter the main event loop
47 $module->event_loop();
49 # this is only reached when the mutual connection with fvwm is lost
50 $module->show_message("finished");