Restructure how we look for Read files slightly.
[fvwm.git] / perllib / FVWM / Tracker / PageInfo.pm
blob446e304cdbfbba01beb0330cc59b70ed6a4725cb
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::Tracker::PageInfo;
19 use strict;
21 use FVWM::Tracker qw(base);
23 sub observables ($) {
24 return [
25 "desk/page changed",
26 "desk only changed",
27 "page only changed",
31 sub start ($) {
32 my $self = shift;
34 $self->{data} = {};
35 $self->add_handler(M_NEW_PAGE, sub {
36 my $event = $_[1];
37 $self->calculate_internals($event->args);
38 });
40 $self->request_windowlist_events;
42 my $result = $self->SUPER::start;
44 $self->delete_handlers;
46 $self->add_handler(M_NEW_PAGE | M_NEW_DESK, sub {
47 my $event = $_[1];
48 if ($event->type == M_NEW_DESK) {
49 my $old_desk_n = $self->{data}->{desk_n};
50 my $new_desk_n = $event->args->{desk_n};
51 $self->{data}->{desk_n} = $new_desk_n;
52 my $really_changed = $old_desk_n != $new_desk_n;
53 $self->notify("desk only changed", $really_changed);
54 return unless $really_changed;
55 } else {
56 $self->calculate_internals($event->args);
57 $self->notify("page only changed");
59 $self->notify("desk/page changed");
60 });
62 return $result;
65 sub calculate_internals ($$) {
66 my $self = shift;
67 my $args = shift;
68 my $data = $self->{data};
70 @$data{keys %$args} = values %$args;
71 $data->{page_nx} = int($data->{vp_x} / $data->{vp_width});
72 $data->{page_ny} = int($data->{vp_y} / $data->{vp_height});
75 sub dump ($) {
76 my $self = shift;
77 my $data = $self->{data};
78 my $string = join(', ', map { "$_=$data->{$_}" } sort keys %$data) . "\n";
79 $string =~ s/^(.*?)(, d.*?)(, p.*?), (v.*)$/$1$3$2\n$4/s;
80 return $string;
85 __END__
87 =head1 DESCRIPTION
89 This B<FVWM::Tracker> subclass provides an information about the current
90 fvwm page and desk and screen dimensions. Like with all trackers, this
91 information is automatically brought up to the date for the entire tracker
92 object life and may be retrieved by its C<data> method.
94 This tracker defines the following observables that enable additional way
95 of work:
97 "desk/page changed",
98 "desk only changed",
99 "page only changed",
101 =head1 SYNOPSYS
103 Using B<FVWM::Module> $module object:
105 my $page_tracker = $module->track("PageInfo");
106 my $page_hash = $page_tracker->data;
107 my $curr_desk = $page_hash->{'desk_n'};
109 =head1 OVERRIDDEN METHODS
111 =over 4
113 =item B<data>
115 Returns hash ref representing the current page/desk, with the following keys
116 (the fvwm variable equivalents are shown on the right):
118 desk_n $[desk.n]
119 page_nx $[page.nx]
120 page_ny $[page.ny]
121 desk_pages_x $[desk.pagesx]
122 desk_pages_y $[desk.pagesy]
123 vp_width $[vp.width]
124 vp_height $[vp.height]
125 vp_x $[vp.x]
126 vp_y $[vp.y]
128 =item B<dump>
130 Returns 2 debug lines representing the current page data (as described in
131 C<data>) in the human readable format.
133 =back
135 =head1 AUTHOR
137 Mikhael Goikhman <migo@homemail.com>.
139 =head1 SEE ALSO
141 For more information, see L<FVWM::Module> and L<FVWM::Tracker>.
143 =cut