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
17 package FVWM
::EventNames
;
22 use constant number
=> 0;
23 use constant bool
=> 1;
24 use constant window
=> 2;
25 use constant pixel
=> 3;
26 use constant string
=> 4;
27 use constant wflags
=> 5;
28 use constant looped
=> 6;
30 use vars
qw($EVENTS_INFO);
32 # ----------------------------------------------------------------------------
33 # start of the would-be-generated part
45 desk_pages_x => number,
46 desk_pages_y => number,
63 # &M_OLD_ADD_WINDOW => {
84 # &M_OLD_CONFIGURE_WINDOW => {
98 &M_DESTROY_WINDOW => {
115 icon_width => number,
116 icon_height => number,
119 frame_width => number,
120 frame_height => number,
132 icon_width => number,
133 icon_height => number,
136 frame_width => number,
137 frame_height => number,
181 &M_END_WINDOWLIST => {
187 &M_ICON_LOCATION => {
229 &M_END_CONFIG_INFO => {
290 &M_DEWINDOWSHADE => {
318 low_windows => looped,
320 loop_format => "L!3a*",
329 format => "L!3l!6l!8L!2l!L!2l!3S4a*",
336 frame_width => number,
337 frame_height => number,
341 win_height => number,
342 resize_width_inc => number,
343 resize_height_inc => number,
344 minimum_width => number,
345 minimum_height => number,
346 maximum_width => number,
347 maximum_height => number,
348 icon_title_id => window,
349 icon_image_id => window,
353 ewmh_layer => number,
354 ewmh_desktop => number,
355 ewmh_window_type => number,
356 title_height => number,
357 border_width => number,
358 dummy_zero_1 => number,
359 dummy_zero_2 => number,
360 window_flags => wflags,
364 &M_CONFIGURE_WINDOW => {
365 format => "L!3l!6l!8L!2l!L!2l!3S4a*",
372 frame_width => number,
373 frame_height => number,
377 win_height => number,
378 resize_width_inc => number,
379 resize_height_inc => number,
380 minimum_width => number,
381 minimum_height => number,
382 maximum_width => number,
383 maximum_height => number,
384 icon_title_id => window,
385 icon_image_id => window,
389 ewmh_layer => number,
390 ewmh_desktop => number,
391 ewmh_window_type => number,
392 title_height => number,
393 border_width => number,
394 dummy_zero_1 => number,
395 dummy_zero_2 => number,
396 window_flags => wflags,
400 # &M_EXTENDED_MSG => {
403 &MX_VISIBLE_ICON_NAME => {
413 &MX_ENTER_WINDOW => {
422 &MX_LEAVE_WINDOW => {
431 &MX_PROPERTY_CHANGE => {
440 type_names => [ qw(NONE BACKGROUND SWALLOW) ],
462 # end of the would-be-generated part
463 # ----------------------------------------------------------------------------
466 use vars
qw(@EXPORT @ISA $EVENT_TYPES $EVENT_NAMES $EVENT_TYPE_NAMES);
468 @FVWM::Constants::EXPORT,
469 qw(event_name event_arg_names event_arg_types event_arg_values event_args),
470 qw(event_loop_arg_names event_loop_arg_types),
471 qw(event_arg_aliases all_event_names all_event_types)
475 sub all_event_type_names
() {
476 if (!defined $EVENT_TYPE_NAMES) {
479 $EVENT_TYPE_NAMES = {};
481 foreach $name (@FVWM::Constants
::EXPORT
) {
482 next unless $name =~ /^MX?_/;
483 next if $name eq 'M_EXTENDED_MSG';
486 next if $name =~ /^MX_/ && !($type & M_EXTENDED_MSG
);
487 push @
$EVENT_TYPES, $type;
488 push @
$EVENT_NAMES, $name;
489 $EVENT_TYPE_NAMES->{$type} = $name;
492 return $EVENT_TYPE_NAMES;
495 sub all_event_names
() {
496 all_event_type_names
();
497 return wantarray? @
$EVENT_NAMES: $EVENT_NAMES;
500 sub all_event_types
() {
501 all_event_type_names
();
502 return wantarray? @
$EVENT_TYPES: $EVENT_TYPES;
507 return all_event_type_names
()->{$type};
510 sub event_type_to_binary
($) {
511 my $type = shift || "no-event-type";
513 return $type unless $type =~ /^\d+$/;
514 return sprintf("%b", $type);
519 unless (defined $EVENTS_INFO->{$type}) {
520 die "FVWM::EventNames: Unknown event type (" .
521 event_type_to_binary
($type) . ")\n";
523 return $EVENTS_INFO->{$type};
526 sub calculate_internals
($) {
529 my $event_info = event_info
($type);
530 $event_info->{names
} = [];
531 $event_info->{types
} = [];
534 foreach (@
{$event_info->{fields
}}) {
535 push @
{$event_info->{names
}}, $_ if ($i % 2) == 0;
536 push @
{$event_info->{types
}}, $_ if ($i % 2) == 1;
540 # handle loop args if any
541 return unless exists $event_info->{loop_fields
};
542 $event_info->{loop_names
} = [];
543 $event_info->{loop_types
} = [];
546 foreach (@
{$event_info->{loop_fields
}}) {
547 push @
{$event_info->{loop_names
}}, $_ if ($i % 2) == 0;
548 push @
{$event_info->{loop_types
}}, $_ if ($i % 2) == 1;
553 sub event_arg_names
($$) {
555 my $arg_values = shift;
557 my $event_info = event_info
($type);
558 my $arg_names = $event_info->{names
};
559 return $arg_names if defined $arg_names;
560 calculate_internals
($type);
561 return $event_info->{names
};
564 sub event_arg_types
($$) {
566 my $arg_values = shift;
568 my $event_info = event_info
($type);
569 my $arg_types = $event_info->{types
};
570 return $arg_types if defined $arg_types;
571 calculate_internals
($type);
572 return $event_info->{types
};
575 sub event_arg_values
($$) {
577 my $packed_str = shift;
579 my $event_info = event_info
($type);
580 my @arg_values = unpack($event_info->{format
}, $packed_str);
581 my $arg_fields = $event_info->{fields
};
582 push @arg_values, (undef) x
((@
$arg_fields / 2) - @arg_values);
584 # process looped args
585 if (@
$arg_fields && $arg_fields->[@
$arg_fields - 1] == looped
) {
586 my @loop_arg_values = ();
588 my $rest_str = pop @arg_values;
589 while ($rest_str ne "") {
590 my @new_arg_values = unpack($event_info->{loop_format
}, $rest_str);
591 die "Internal error, no loop args unpacked ($type)\n" unless @new_arg_values > 1;
592 $rest_str = pop @new_arg_values;
593 push @loop_arg_values, @new_arg_values;
596 push @arg_values, \
@loop_arg_values;
599 # strip everything past the first null (or newline) if needed
600 if (@
$arg_fields && $arg_fields->[-1] == string
) {
601 $arg_values[-1] =~ s/\n*\0.*//s;
607 sub event_loop_arg_names
($$) {
609 my $arg_values = shift;
611 my $event_info = event_info
($type);
612 my $arg_names = $event_info->{loop_names
};
613 return $arg_names if defined $arg_names;
614 calculate_internals
($type);
615 return $event_info->{loop_names
};
618 sub event_loop_arg_types
($$) {
620 my $arg_values = shift;
622 my $event_info = event_info
($type);
623 my $arg_types = $event_info->{loop_types
};
624 return $arg_types if defined $arg_types;
625 calculate_internals
($type);
626 return $event_info->{loop_types
};
629 sub event_args
($$) {
631 my $arg_values = shift;
633 my $arg_names = event_arg_names
($type, $arg_values);
635 die sprintf "Internal error, event type %s (%d names, %d values)\n",
636 event_type_to_binary
($type), scalar @
$arg_names, scalar @
$arg_values
637 if @
$arg_names != @
$arg_values;
639 my $loop_arg_names = event_loop_arg_names
($type, $arg_values);
641 die sprintf "Internal error, event type %s (%d loop names, non array)\n",
642 event_type_to_binary
($type), scalar @
$loop_arg_names
643 if $loop_arg_names && ref($loop_arg_names) ne 'ARRAY'
644 && !@
$loop_arg_names && ref($arg_values->[-1]) ne 'ARRAY';
649 $arg_names->[$i++], ref($value) ne 'ARRAY'?
$value: do {
652 while ($j < @
$value) {
653 my %loop_hash = map { $_, $value->[$j++] } @
$loop_arg_names;
654 push @
$loop_value, \
%loop_hash;
662 sub event_arg_aliases
($) {
665 return event_info
($type)->{aliases
} || {};
668 # ----------------------------------------------------------------------------
672 FVWM::EventNames - names and types of all fvwm event arguments
676 use FVWM::EventNames;
678 print "All event names: ", join(", ", @{all_event_names()}), "\n";
679 print "All event types: ", join(", ", @{all_event_types()}), "\n";
681 my $name = event_name (M_ICON_LOCATION);
682 my $arg_values = event_arg_values(M_ICON_LOCATION, $packed_str);
683 my $arg_names = event_arg_names (M_ICON_LOCATION, $arg_values);
684 my $arg_types = event_arg_types (M_ICON_LOCATION, $arg_values);
685 my $args = event_args (M_ICON_LOCATION, $arg_values);
689 Every event send by I<fvwm> consist of arguments. The argument names and
690 types vary from one event type to another. For example, event of the
691 type B<M_NEW_DESK> consists of only one argument I<desk> of type I<number>.
692 B<M_NEW_PAGE> consists of 5 numeric arguments, B<M_MINI_ICON> consists of 10
693 arguments of different types.
695 This class provides information about all fvwm events. It provides such
696 services as listing all supported event types and their names,
697 converting event type to event name, listing the event argument names/types,
698 constructing event argument values from the plain packet data.
700 Usually you do not need to work with this class directly, but, instead, with
701 B<FVWM::Event> objects. Hovewer, you may need this class source as a
702 reference for the names of the event arguments and their types.
704 =head1 PUBLIC FUNCTIONS
708 =item B<event_name> I<type>
710 Returns the string representation of the numeric event I<type> constant,
711 like I<M_RAISE_WINDOW> or I<MX_ENTER_WINDOW>.
713 =item B<event_arg_values> I<type> I<packed_str>
715 Constructs array ref of argument values for the event I<type>
716 from the I<packed_str> (as received from I<fvwm>).
718 If the last argument type of the event is string, for convenience,
719 everything past the first null (or newline) is automatically stripped
720 from the last argument value.
722 =item B<event_arg_names> I<type> I<arg_values>
724 Returns array ref of argument names of the event type.
726 I<arg_values> is either the real array ref of values (as returned by
727 B<event_arg_values>) or a number of actual values.
728 The returned array has the same number of elements.
730 =item B<event_arg_types> I<type> I<arg_values>
732 Returns array ref of argument types of the event type.
734 I<arg_values> is either the real array ref of values (as returned by
735 B<event_arg_values>) or a number of actual values.
736 The returned array has the same number of elements.
738 =item B<event_loop_arg_names> I<type> I<arg_values>
740 Returns array ref of looped argument names of the event type (or undef).
742 =item B<event_loop_arg_types> I<type> I<arg_values>
744 Returns array ref of looped argument types of the event type (or undef).
746 =item B<event_args> I<type> I<arg_values>
748 Constructs hash ref of the named arguments for the event I<type>
749 from the I<arg_values> array ref (as returned by B<event_arg_values>).
751 =item B<event_arg_aliases> I<type>
753 This method is provided for backward compatibility when argument names
754 are changed. For example, in the past the argument name of I<M_NEW_DESK>
755 was B<desk>, but now it is B<desk_n>. Using this method it is possible
756 to make both names supported. Returns hash ref (old-name => new-name).
758 =item B<all_event_names>
760 Returns array ref of all known event names (strings).
761 In the list context returns list of these names.
763 =item B<all_event_types>
765 Returns array ref of all known event types (numbers).
766 In the list context returns list of these types.
768 =item B<all_event_type_names>
770 Returns hash ref of all known event names and types (type => name).