1# Copyright (c) 2003-2009 Mikhael Goikhman 2# 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. 7# 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. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, see: <http://www.gnu.org/licenses/> 15 16package FVWM::Tracker::PageInfo; 17 18use strict; 19 20use FVWM::Tracker qw(base); 21 22sub observables ($) { 23 return [ 24 "desk/page changed", 25 "desk only changed", 26 "page only changed", 27 ]; 28} 29 30sub start ($) { 31 my $self = shift; 32 33 $self->{data} = {}; 34 $self->add_handler(M_NEW_PAGE, sub { 35 my $event = $_[1]; 36 $self->calculate_internals($event->args); 37 }); 38 39 $self->request_windowlist_events; 40 41 my $result = $self->SUPER::start; 42 43 $self->delete_handlers; 44 45 $self->add_handler(M_NEW_PAGE | M_NEW_DESK, sub { 46 my $event = $_[1]; 47 if ($event->type == M_NEW_DESK) { 48 my $old_desk_n = $self->{data}->{desk_n}; 49 my $new_desk_n = $event->args->{desk_n}; 50 $self->{data}->{desk_n} = $new_desk_n; 51 my $really_changed = $old_desk_n != $new_desk_n; 52 $self->notify("desk only changed", $really_changed); 53 return unless $really_changed; 54 } else { 55 $self->calculate_internals($event->args); 56 $self->notify("page only changed"); 57 } 58 $self->notify("desk/page changed"); 59 }); 60 61 return $result; 62} 63 64sub calculate_internals ($$) { 65 my $self = shift; 66 my $args = shift; 67 my $data = $self->{data}; 68 69 @$data{keys %$args} = values %$args; 70 $data->{page_nx} = int($data->{vp_x} / $data->{vp_width}); 71 $data->{page_ny} = int($data->{vp_y} / $data->{vp_height}); 72} 73 74sub dump ($) { 75 my $self = shift; 76 my $data = $self->{data}; 77 my $string = join(', ', map { "$_=$data->{$_}" } sort keys %$data) . "\n"; 78 $string =~ s/^(.*?)(, d.*?)(, p.*?), (v.*)$/$1$3$2\n$4/s; 79 return $string; 80} 81 821; 83 84__END__ 85 86=head1 DESCRIPTION 87 88This B<FVWM::Tracker> subclass provides an information about the current 89fvwm page and desk and screen dimensions. Like with all trackers, this 90information is automatically brought up to the date for the entire tracker 91object life and may be retrieved by its C<data> method. 92 93This tracker defines the following observables that enable additional way 94of work: 95 96 "desk/page changed", 97 "desk only changed", 98 "page only changed", 99 100=head1 SYNOPSYS 101 102Using B<FVWM::Module> $module object: 103 104 my $page_tracker = $module->track("PageInfo"); 105 my $page_hash = $page_tracker->data; 106 my $curr_desk = $page_hash->{'desk_n'}; 107 108=head1 OVERRIDDEN METHODS 109 110=over 4 111 112=item B<data> 113 114Returns hash ref representing the current page/desk, with the following keys 115(the fvwm variable equivalents are shown on the right): 116 117 desk_n $[desk.n] 118 page_nx $[page.nx] 119 page_ny $[page.ny] 120 desk_pages_x $[desk.pagesx] 121 desk_pages_y $[desk.pagesy] 122 vp_width $[vp.width] 123 vp_height $[vp.height] 124 vp_x $[vp.x] 125 vp_y $[vp.y] 126 127=item B<dump> 128 129Returns 2 debug lines representing the current page data (as described in 130C<data>) in the human readable format. 131 132=back 133 134=head1 AUTHOR 135 136Mikhael Goikhman <migo@homemail.com>. 137 138=head1 SEE ALSO 139 140For more information, see L<FVWM::Module> and L<FVWM::Tracker>. 141 142=cut 143