1 # Copyright (c) 2003-2009 Mikhael Goikhman
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 my $arg_values = shift;
27 my $is_special = defined $arg_values ?
0 : 1;
28 my $is_extended = $type & M_EXTENDED_MSG ?
1 : 0;
31 $arg_values = event_arg_values
($is_special ?
"faked" : $type, $arg_values)
32 unless ref($arg_values);
36 args
=> undef, # lazy hash of event arguments
37 arg_values
=> $arg_values,
38 propagation_allowed
=> 1,
39 is_special
=> $is_special,
40 is_extended
=> $is_extended,
50 return $self->{'type'};
55 return $self->{'arg_values'};
60 return event_arg_names
($self->type, $self->arg_values);
65 return event_arg_types
($self->type, $self->arg_values);
68 sub loop_arg_names
($) {
70 return event_loop_arg_names
($self->type, $self->arg_values);
73 sub loop_arg_types
($) {
75 return event_loop_arg_types
($self->type, $self->arg_values);
80 $self->{'args'} ||= event_args
($self->type, $self->arg_values);
81 return $self->{'args'};
86 return $self->{'is_extended'};
91 return event_name
($self->type);
94 sub propagation_allowed
($;$) {
97 $self->{'propagation_allowed'} = $value if defined $value;
99 return $self->{'propagation_allowed'};
104 my $args = $self->args;
105 my $string = $self->name . "\n";
107 my @arg_names = @
{$self->arg_names};
108 my @arg_types = @
{$self->arg_types};
109 my @arg_values = @
{$self->arg_values};
112 my $name = shift @arg_names;
113 my $type = shift @arg_types;
114 my $value = shift @arg_values;
117 if ($type == FVWM
::EventNames
::number
) {
119 $text = "*undefined*" unless defined $value;
120 } elsif ($type == FVWM
::EventNames
::bool
) {
121 $text = $value?
"True": "False";
122 } elsif ($type == FVWM
::EventNames
::window
) {
123 $text = sprintf("0x%07lx", $value);
124 } elsif ($type == FVWM
::EventNames
::pixel
) {
125 $text = "rgb:" . join('/',
126 sprintf("%06lx", $value) =~ /(..)(..)(..)/);
127 } elsif ($type == FVWM
::EventNames
::string
) {
129 $text = qq("$value");
130 } elsif ($type == FVWM
::EventNames
::looped
) {
131 my $loop_arg_names = $self->loop_arg_names;
132 my $loop_arg_types = $self->loop_arg_types;
134 while ($j < @
$value) {
136 foreach (@
$loop_arg_names) {
137 my $i = int($j / @
$loop_arg_names) + 1;
138 push @arg_names, "[$i] $_";
139 push @arg_types, $loop_arg_types->[$k];
140 push @arg_values, $value->[$j];
144 $text = sprintf("(%d)", @
$value / @
$loop_arg_names);
145 } elsif ($type == FVWM
::EventNames
::wflags
) {
146 $text = qq([window flags are
not supported yet
]);
148 $text = qq([unsupported arg type
$type] "$value");
152 $name_len = int((length($name) + 5) / 6) * 6
153 if length($name) > $name_len;
154 $string .= sprintf "\t%-${name_len}s %s\n", $name, $text;
163 my $method = $FVWM::Event
::AUTOLOAD
;
165 # remove the package name
167 # DESTROY messages should never be propagated
168 return if $method eq 'DESTROY';
170 if ($method =~ s/^_//) {
171 my $arg_value = $self->args->{$method};
172 return $arg_value if defined $arg_value;
174 my $alias = event_arg_aliases
($self->type)->{$method} || '*none*';
175 $arg_value = $self->args->{$alias};
176 return $arg_value if defined $arg_value;
178 die "Unknown argument $method for event " . $self->name . "\n";
181 die "Unknown method $method on $self called\n";
184 # ----------------------------------------------------------------------------
188 FVWM::Event - the fvwm event object passed to event handlers
192 use lib `fvwm-perllib dir`;
195 my $module = new FVWM::Module(Mask => M_FOCUS_CHANGE);
197 # auto-raise all windows
198 sub auto_raise ($$) {
199 my ($module, $event) = @_;
200 $module->debug("Got " . $event->name . "\n");
201 $module->debug("\t$_: " . $event->args->{$_} . "\n")
202 foreach sort keys %{$event->args};
203 $module->send("Raise", $event->_win_id);
205 $module->add_handler(M_FOCUS_CHANGE, \&auto_raise);
217 =item B<new> I<type> I<arg_values>
219 Constructs event object of the given I<type>.
220 I<arg_values> is either an array ref of event's arguments (every event type
221 has its own argument list, see L<FVWM::EventNames>) or a packed string of
222 these arguments as received from the I<fvwm> pipe.
226 Returns event's type (usually long integer).
230 Returns an array ref of the event argument names.
232 print "$_ " foreach @{$event->arg_names});
234 Note that this array of names is statical for any given event type.
238 Returns an array ref of the event argument types.
240 print "$_ " foreach @{$event->arg_types});
242 Note that this array of types is statical for any given event type.
244 =item B<loop_arg_names>
246 Returns an array ref of the looped argument names of the event (or undef).
248 =item B<loop_arg_types>
250 Returns an array ref of the looped argument types of the event (or undef).
254 Returns an array ref of the event argument values.
255 In the previous versions of the library, all argument values were passed
256 to event handlers, now only one event object is passed. Calling this
257 method is the way to emulate the old behaviour.
259 Note that you should know the order of arguments, so the suggested way
260 is to use C<args> instead, although it is a bit slower.
264 Returns hash ref of the named event argument values.
266 print "[Debug] Got event ", $event->type, " with args:\n";
267 while (($name, $value) = each %{$event->args})
268 { print "\t$name: $value\n"; }
272 For technical reasons there are 2 categories of fvwm events, regular and
273 extended. This was done to enable more events. With introdution of the
274 extended event types (with the highest bit set) it is now possible to have
275 31+31=62 different event types rather than 32. This is a good point, the bad
276 point is that only event types of the same category may be masked (or-ed)
277 together. This method returns 1 or 0 depending on whether the event is
282 Returns a string representing the event name (like "M_ADD_WINDOW"), it is
283 the same as the corresponding C/Perl constant. May be (and in fact is)
286 =item B<propagation_allowed> [I<bool>]
288 Sets or returns a boolean value that indicates enabling or disabling of
289 this event propagation.
293 Returns a string representation of the event object, basically the event
294 name and all argument name=value lines.
298 This is a shortcut for $event->args->{'I<name>'}. Returns the named event
299 argument. See L<FVWM::EventNames> for names of all event argument names.
305 Mikhael Goikhman <migo@homemail.com>.
309 For more information, see L<fvwm>, L<FVWM::Module>, L<FVWM::Constants> and