Tops.pm untested

filter: Statementstmt 0.0% 0 / 384 Branchbran 0.0% 0 / 92 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 0.0% 0 / 53 Podpod 0.0% 0 / 46 totaltotal 0.0% 0 / 617 CC 47 SCAR 30.9
CC
47
Cov
0%
parse_geometry
90.0
update
42.0
choosechar
42.0
CRAP 22.0
1 # $Source: /home/keck/lib/perl/X11/RCS/Tops.pm,v $
2 # $Revision: 3.25 $$Date: 2007/07/07 07:52:11 $
3 # Contents
4 # 1 standard 13 X 25 command
5 # 2 constants 14 match 26 monitor changes
6 # 3 new 15 active 27 raise & lower
7 # 4 fetch_ids 16 stacking 28 geometry
8 # 5 update_ids 17 gravity 29 frame_geometry
9 # 6 update_from_props 18 monitor changes 30 wm_normal_hints
10 # 7 update 19 X11::Top 31 parse_geometry
11 # 8 byid 20 instance 32 requested geometry
12 # 9 choosechar 21 class 33 move
13 # 10 sort 22 title 34 expand
14 # 11 sorted 23 icon 35 notes
15 # 12 bychar 24 char 36 pod
16  
17 # ----------------------------------------------------------------------
18  
19 #1# standard
20  
21 package X11::Tops;
22  
23 use X11::Protocol;
24 use Carp;
25 use Data::Dumper;
26 use strict;
27 use warnings;
28  
29 our $VERSION = 0.2;
30  
31 # ----------------------------------------------------------------------
32  
33 #2# constants
34  
35 my @getpropconst = ('AnyPropertyType', 0, -1, 0);
36  
37 # ----------------------------------------------------------------------
38  
39 #3# new
40  
41 sub new {
42 my $X = shift;
43 $X = X11::Protocol->new() unless ref $X;
44 my $xtops;
45 $xtops->{X} = $X;
46 $xtops->{root} = $X->root; # assumes only 1 screen
47 $xtops->{$_} = $X->InternAtom($_, 0) for qw(
48 _NET_CLIENT_LIST
49 _XCHAR_CHAR
50 _XCHAR_COMMAND
51 );
52 $xtops->{$_} = $X->atom($_) for qw(
53 _WIN_CLIENT_LIST
54 _NET_ACTIVE_WINDOW
55 _NET_CLIENT_LIST_STACKING
56 WM_CLASS
57 WM_NAME
58 WM_ICON_NAME
59 STRING
60 WM_NORMAL_HINTS
61 WM_SIZE_HINTS
62 );
63 $xtops->{$_} || croak("failed to create atom $_") for qw(
64 _XCHAR_CHAR
65 _XCHAR_COMMAND
66 );
67 bless $xtops;
68 }
69  
70 # ----------------------------------------------------------------------
71  
72 #4# fetch_ids
73  
74 sub fetch_ids {
75 my $xtops = shift;
76 my $X = $xtops->{X};
77 my $root = $xtops->{root};
78 my $_NET_CLIENT_LIST = $xtops->{_NET_CLIENT_LIST};
79 my ($value, $type, $format, $bytes_after) =
80 $X->GetProperty($root, $_NET_CLIENT_LIST, @getpropconst);
81 my @ids = unpack('L*', $value);
82 \@ids;
83 }
84  
85 # ----------------------------------------------------------------------
86  
87 #5# update_ids
88  
89 sub update_ids {
90 my $xtops = shift;
91 my $ids = $xtops->fetch_ids;
92 $xtops->{byid}{$_} =
93 bless { xtops => $xtops, id => $_ }, 'X11::Top'
94 for @$ids;
95 $xtops;
96 }
97  
98 # ----------------------------------------------------------------------
99  
100 #6# update_from_props
101  
102 sub update_from_props {
103 my $xtops = shift;
104 $xtops->update_ids;
105 for my $xtop (values %{$xtops->{byid}}) {
106 $xtop->class;
107 $xtop->char;
108 }
109 $xtops;
110 }
111  
112 # ----------------------------------------------------------------------
113  
114 #7# update
115  
116 sub update {
117 my $xtops = shift;
118 my @deleted = ();
119 my $newids = $xtops->fetch_ids;
120 if ($xtops->{byid}) {
121 my %seen;
122 for my $id (@$newids) {
123 $seen{$id} = 1;
124 $xtops->{byid}{$id} =
125 bless { xtops => $xtops, id => $id }, 'X11::Top'
126 unless $xtops->{byid}{$id};
127 }
128 for my $id (keys %{$xtops->{byid}}) {
129 push(@deleted, $xtops->{byid}{$id}) unless $seen{$id};
130 }
131 for my $xtop (@deleted) {
132 delete $xtops->{byid}{$xtop->{id}};
133 delete $xtops->{chars_in_use}{$xtop->{char}};
134 }
135 } else {
136 for my $id (@$newids) {
137 $xtops->{byid}{$id} =
138 bless { xtops => $xtops, id => $id }, 'X11::Top';
139 }
140 }
141 for my $xtop (values %{$xtops->{byid}}) {
142 $xtop->{instance} = $xtop->instance unless
143 defined $xtop->{instance};
144 $xtop->{char} = $xtops->choosechar($xtop) unless
145 defined $xtop->{char};
146 }
147 $xtops->sort;
148 @deleted;
149 }
150  
151 # ----------------------------------------------------------------------
152  
153 #8# byid
154  
155 sub byid {
156 my $xtops = shift;
157 $xtops->{byid};
158 }
159  
160 # ----------------------------------------------------------------------
161  
162 #9# choosechar
163  
164 # assume instances set
165  
166 sub choosechar {
167 my ($xtops, $xtop) = @_;
168 $xtops->{char} = sub { ['a' .. 'z', '0' .. '9'] }
169 unless $xtops->{char};
170 my $instance = $xtop->{instance};
171 croak("\$xtop->{instance} not set for \$xtop->{id} = $xtop->{id}")
172 unless defined $instance;
173 my $char = &{$xtops->{char}}($instance);
174 if (ref $char) {
175 for my $c (@$char) {
176 $char = $c, last unless $xtops->{chars_in_use}{$c};
177 }
178 }
179 croak("no char matches instance '$instance'") unless defined $char;
180 $xtops->{chars_in_use}{$char} = 1;
181 $xtop->char($char);
182 $char;
183 }
184  
185 # ----------------------------------------------------------------------
186  
187 #10# sort
188  
189 # assume chars chosen, as after update()
190  
191 sub sort {
192 my $xtops = shift;
193 my $order = $xtops->{order}; # hashref char->integer
194 my $max = -1;
195 if ($order) {
196 for (values %$order) {
197 croak(
198 "values in order hash should be nonnegative integers," .
199 " not '$_'"
200 ) unless /^\d+$/;
201 $max = $_ if $max < $_;
202 }
203 }
204 for my $n (0 .. 127) {
205 my $char = chr($n);
206 next if defined $order->{$char};
207 $order->{$char} = $max + 1 + $n;
208 }
209 @{$xtops->{sorted}} =
210 sort { $order->{$a->{char}} <=> $order->{$b->{char}} }
211 values %{$xtops->byid};
212 }
213  
214 # ----------------------------------------------------------------------
215  
216 #11# sorted
217  
218 sub sorted {
219 my $xtops = shift;
220 $xtops->sort unless $xtops->{sorted};
221 $xtops->{sorted};
222 }
223  
224 # ----------------------------------------------------------------------
225  
226 #12# bychar
227  
228 # assume chars chosen, as after update()
229  
230 sub bychar {
231 my $xtops = shift;
232 my $bychar = {};
233 for my $xtop (values %{$xtops->byid}) {
234 $bychar->{$xtop->{char}} = $xtop;
235 }
236 $bychar;
237 }
238  
239 # ----------------------------------------------------------------------
240  
241 #13# X
242  
243 sub X {
244 my $xtops = shift;
245 $xtops->{X};
246 }
247  
248 # ----------------------------------------------------------------------
249  
250 #14# match
251  
252 sub match {
253 my ($xtops, $prop, $regex) = @_;
254 for my $xtop (values %{$xtops->{byid}}) {
255 my $value = $xtop->{$prop};
256 $value = eval "\$xtop->$prop" unless defined $value;
257 return $xtop if $value =~ $regex;
258 }
259 }
260  
261 for my $sub (qw(class instance title icon char)) {
262 no strict 'refs';
263 *$sub = sub {
264 my ($xtops, $regex) = @_;
265 $xtops->match($sub, $regex);
266 }
267 }
268  
269 # ----------------------------------------------------------------------
270  
271 #15# active
272  
273 # argument normally $xtops, but not used except to find this
274  
275 sub active {
276 my $xtops = shift;
277 my $X = $xtops->{X};
278 my $root = $xtops->{root};
279 my $_NET_ACTIVE_WINDOW = $xtops->{_NET_ACTIVE_WINDOW};
280 my ($value, $type, $format, $bytes_after) =
281 $X->GetProperty($root, $_NET_ACTIVE_WINDOW, @getpropconst);
282 unpack('L*', $value);
283 }
284  
285 # ----------------------------------------------------------------------
286  
287 #16# stacking
288  
289 # see raise & lower
290  
291 # argument normally $xtops, but not used except to find this
292  
293 sub stacking {
294 my $xtops = shift;
295 my $X = $xtops->{X};
296 my $root = $xtops->{root};
297 my $_NET_CLIENT_LIST_STACKING = $xtops->{_NET_CLIENT_LIST_STACKING};
298 my ($value, $type, $format, $bytes_after) =
299 $X->GetProperty($root, $_NET_CLIENT_LIST_STACKING, @getpropconst);
300 unpack('L*', $value);
301 }
302  
303 # ----------------------------------------------------------------------
304  
305 #17# gravity
306  
307 sub NorthWest () { 1; }
308 sub North () { 2; }
309 sub NorthEast () { 3; }
310 sub West () { 4; }
311 sub Center () { 5; }
312 sub East () { 6; }
313 sub SouthWest () { 7; }
314 sub South () { 8; }
315 sub SouthEast () { 9; }
316  
317 sub Gravity {
318 my $arg = shift;
319 $arg = shift if ref $arg;
320 return undef unless $arg =~ /^\d$/;
321 ( undef,
322 qw(
323 NorthWest
324 North
325 NorthEast
326 West
327 Center
328 East
329 SouthWest
330 South
331 SouthEast
332 )
333 )[$arg];
334 }
335  
336 # ----------------------------------------------------------------------
337  
338 #18# monitor changes
339  
340 # also X11::Top method
341  
342 sub monitor_property_change {
343 my $xtops = shift;
344 my $X = $xtops->{X};
345 my $id = $xtops->{root};
346 $X->ChangeWindowAttributes(
347 $id,
348 event_mask => $X->pack_event_mask('PropertyChange')
349 );
350 }
351 # ----------------------------------------------------------------------
352  
353 #19# X11::Top
354  
355 package X11::Top;
356 use Data::Dumper;
357  
358 sub id {
359 my $xtop = shift;
360 $xtop->{id}
361 }
362  
363 # ----------------------------------------------------------------------
364  
365 #20# instance
366  
367 sub instance {
368 my $xtop = shift;
369 my $xtops = $xtop->{xtops};
370 my $X = $xtops->{X};
371 my $WM_CLASS = $xtops->{WM_CLASS};
372 return $xtop->{instance} if defined $xtop->{instance};
373 my ($value, $type, $format, $bytes_after) =
374 $X->GetProperty($xtop->{id}, $WM_CLASS, @getpropconst);
375 my ($instance, $class) = split "\0", $value;
376 $xtop->{instance} = $instance;
377 $xtop->{class} = $class;
378 $instance;
379 }
380  
381 # ----------------------------------------------------------------------
382  
383 #21# class
384  
385 sub class {
386 my $xtop = shift;
387 my $xtops = $xtop->{xtops};
388 return $xtop->{class} if defined $xtop->{class};
389 my $X = $xtops->{X};
390 my $WM_CLASS = $xtops->{WM_CLASS};
391 my ($value, $type, $format, $bytes_after) =
392 $X->GetProperty($xtop->{id}, $WM_CLASS, @getpropconst);
393 croak("failed to fetch WM_CLASS for window $xtop") unless $value;
394 my ($instance, $class) = split "\0", $value;
395 $xtop->{instance} = $instance;
396 $xtop->{class} = $class;
397 $class;
398 }
399  
400 # ----------------------------------------------------------------------
401  
402 #22# title
403  
404 sub title {
405 my $xtop = shift;
406 my $xtops = $xtop->{xtops};
407 my $X = $xtops->{X};
408 my $WM_NAME = $xtops->{WM_NAME};
409 my ($value, $type, $format, $bytes_after) =
410 $X->GetProperty($xtop->{id}, $WM_NAME, @getpropconst);
411 $value;
412 }
413  
414 # ----------------------------------------------------------------------
415  
416 #23# icon
417  
418 sub icon {
419 my $xtop = shift;
420 my $xtops = $xtop->{xtops};
421 my $X = $xtops->{X};
422 my $WM_ICON_NAME = $xtops->{WM_ICON_NAME};
423 my ($value, $type, $format, $bytes_after) =
424 $X->GetProperty($xtop->{id}, $WM_ICON_NAME, @getpropconst);
425 $value;
426 }
427  
428 # ----------------------------------------------------------------------
429  
430 #24# char
431  
432 sub char {
433 my ($xtop, $char) = @_;
434 my $xtops = $xtop->{xtops};
435 my $X = $xtops->{X};
436 my $_XCHAR_CHAR = $xtops->{_XCHAR_CHAR};
437 unless (defined $char) {
438 return $xtop->{char} if defined $xtop->{char};
439 my ($value, $type, $format, $bytes_after) =
440 $X->GetProperty($xtop->{id}, $_XCHAR_CHAR, @getpropconst);
441 return $xtop->{char} = $value;
442 }
443 $xtop->{char} = $char;
444 my $STRING = $xtops->{STRING};
445 $X->ChangeProperty(
446 $xtop->{id}, # window
447 $_XCHAR_CHAR, # property
448 $STRING, # type
449 8, # format
450 'Replace', # mode
451 $char, # data
452 );
453 }
454  
455 # ----------------------------------------------------------------------
456  
457 #25# command
458  
459 sub command {
460 my ($xtop, $command) = @_;
461 my $xtops = $xtop->{xtops};
462 my $X = $xtops->{X};
463 my $_XCHAR_COMMAND = $xtops->{_XCHAR_COMMAND};
464 my $STRING = $xtops->{STRING};
465 unless (defined $command) {
466 my ($value, $type, $format, $bytes_after) =
467 $X->GetProperty($xtop->{id}, $_XCHAR_COMMAND, @getpropconst);
468 return $value;
469 }
470 $X->ChangeProperty(
471 $xtop->{id}, # window
472 $_XCHAR_COMMAND, # property
473 $STRING, # type
474 8, # format
475 'Replace', # mode
476 $command, # data
477 );
478 }
479  
480 # ----------------------------------------------------------------------
481  
482 #26# monitor changes
483  
484 # also X11::Tops method
485 sub monitor_property_change {
486 my $xtop = shift;
487 my $xtops = $xtop->{xtops};
488 my $X = $xtops->{X};
489 my $id = $xtop->{id};
490 $X->ChangeWindowAttributes(
491 $id,
492 event_mask => $X->pack_event_mask('PropertyChange')
493 );
494 }
495  
496 sub monitor_property_and_visibility_change {
497 my $xtop = shift;
498 my $xtops = $xtop->{xtops};
499 my $X = $xtops->{X};
500 my $id = $xtop->{id};
501 $X->ChangeWindowAttributes(
502 $id,
503 event_mask =>
504 $X->pack_event_mask('PropertyChange', 'VisibilityChange')
505 );
506 }
507  
508 # doesn't work with fvwm [+taskbar3] or twm [+taskbar4] ...
509 sub monitor_property_and_structure_change {
510 my $xtop = shift;
511 my $xtops = $xtop->{xtops};
512 my $X = $xtops->{X};
513 my $id = $xtop->{id};
514 $X->ChangeWindowAttributes(
515 $id,
516 event_mask =>
517 $X->pack_event_mask('PropertyChange', 'SubstructureNotifyMask')
518 );
519 }
520  
521 sub attributes {
522 my $xtop = shift;
523 my $xtops = $xtop->{xtops};
524 my $X = $xtops->{X};
525 my $id = $xtop->{id};
526 $X->GetWindowAttributes($id); # %attributes
527 }
528  
529 # ----------------------------------------------------------------------
530  
531 #27# raise & lower
532  
533 # see stacking
534  
535 sub raise {
536 my $xtop = shift;
537 my $xtops = $xtop->{xtops};
538 my $X = $xtops->{X};
539 my $id = $xtop->{id};
540 $X->MapWindow($id);
541 $X->ConfigureWindow($id, stack_mode => 'Above');
542 }
543  
544 # if call $xtop->geometry then mouse & focus often don't move ...
545 sub raise_and_focus {
546 my $xtop = shift;
547 my $xtops = $xtop->{xtops};
548 my $X = $xtops->{X};
549 my $id = $xtop->{id};
550 $X->MapWindow($id);
551 $X->ConfigureWindow($id, stack_mode => 'Above');
552 my %geometry = $X->GetGeometry($id);
553 my $x = int($geometry{width} / 2);
554 my $y = int($geometry{height} / 2);
555 $X->WarpPointer('None', $id, 0, 0, 0, 0, $x, $y);
556 $X->SetInputFocus($id, 'RevertToPointerRoot', 'CurrentTime');
557 }
558  
559 sub lower {
560 my $xtop = shift;
561 my $xtops = $xtop->{xtops};
562 my $X = $xtops->{X};
563 my $id = $xtop->{id};
564 $X->ConfigureWindow($id, stack_mode => 'Below');
565 }
566  
567 # ----------------------------------------------------------------------
568  
569 #28# geometry
570  
571 sub geometry {
572 my $xtop = shift;
573 my $xtops = $xtop->{xtops};
574 my $X = $xtops->{X};
575 my $id = $xtop->{id};
576 my %geom = $X->GetGeometry($id);
577 my ($root2, $parent, @kids) = $X->QueryTree($id);
578 my ($same_screen, $child, $x, $y) =
579 $X->TranslateCoordinates($parent, $root2, $geom{x}, $geom{y});
580 return ($geom{width}, $geom{height}, $x, $y);
581 }
582  
583 # ----------------------------------------------------------------------
584  
585 #29# frame_geometry
586  
587 sub frame_geometry {
588 my $xtop = shift;
589 my $xtops = $xtop->{xtops};
590 my $X = $xtops->{X};
591 my $frame = $xtop->{id};
592 while (1) {
593 my ($root2, $parent, @kids) = $X->QueryTree($frame);
594 last if $parent == $root2;
595 $frame = $parent;
596 }
597 my %geom = $X->GetGeometry($frame);
598 ($geom{width}, $geom{height}, $geom{x}, $geom{y});
599 }
600  
601 # ----------------------------------------------------------------------
602  
603 #30# wm_normal_hints
604  
605 our @wm_normal_hints = qw(
606 flags
607 user_x user_y user_w user_h
608 min_width min_height
609 max_width max_height
610 width_inc height_inc
611 min_aspect_num min_aspect_den
612 max_aspect_num max_aspect_den
613 base_width base_height
614 gravity
615 );
616  
617 my @wm_normal_hints_flags = (
618 [qw(user_x user_y)], # USPosition
619 [qw(user_w user_h)], # USSize
620 [], # PPosition
621 [], # PSize
622 [qw(min_width min_height)], # PMinSize
623 [qw(max_width max_height)], # PMaxSize
624 [qw(width_inc height_inc)], # PResizeInc
625 [qw(min_aspect_num min_aspect_den
626 max_aspect_num max_aspect_den)], # PAspect
627 [qw(base_width base_height)], # PBaseSize
628 [qw(gravity)], # PWinGravity
629 );
630  
631 sub wm_normal_hints {
632 my $xtop = shift;
633 my $xtops = $xtop->{xtops};
634 my $X = $xtops->{X};
635 my $WM_NORMAL_HINTS = $xtops->{WM_NORMAL_HINTS};
636 my $WM_SIZE_HINTS = $xtops->{WM_SIZE_HINTS};
637 my %wm_normal_hints = @_;
638 if (%wm_normal_hints) {
639 my $value =
640 pack('L*', map { $wm_normal_hints{$_} || 0 } @wm_normal_hints);
641 $X->ChangeProperty(
642 $xtop->{id}, # window
643 $WM_NORMAL_HINTS, # property
644 $WM_SIZE_HINTS, # type
645 32, # format
646 'Replace', # mode
647 $value # data
648 );
649 return;
650 }
651 my ($value, $type, $format, $bytes_after) =
652 $X->GetProperty($xtop->{id}, $WM_NORMAL_HINTS, @getpropconst);
653 my %xxx;
654 @xxx{@wm_normal_hints} = unpack('L*', $value);
655 my $flags = $wm_normal_hints{flags} = $xxx{flags};
656 for my $i (@wm_normal_hints_flags) {
657 $wm_normal_hints{$_} = $flags & 1 ? $xxx{$_} : undef for @$i;
658 $flags >>= 1;
659 }
660 %wm_normal_hints
661 }
662  
663 # ----------------------------------------------------------------------
664  
665 #31# parse_geometry
666  
667 sub parse_geometry {
668 my ($xtop, $geometry) = @_;
669 my $X = $xtop->{xtops}{X};
670 my ($w, $h, $x, $y) =
671 $geometry =~ /^(\d+)x(\d+)([+-]-?\d+)([+-]-?\d+)$/;
672 my $g; # gravity
673 my $screenwidth = $X->width_in_pixels;
674 my $screenheight = $X->height_in_pixels;
675  
676 if ($w == 0 || $h == 0 || $x eq '00' || $y eq '00') {
677 my %xtop;
678 @xtop{qw(w h x y)} = $xtop->geometry;
679 $w = $xtop{w} if $w == 0;
680 $h = $xtop{h} if $h == 0;
681 $x = $xtop{x} if $x eq '00';
682 $y = $xtop{y} if $y eq '00';
683 }
684  
685 if (my ($a) = $x =~ /^-\+?(-?\d+)/) {
686 if (my ($b) = $y =~ /^-\+?(-?\d+)/) {
687 $g = X11::Tops::SouthEast;
688 $x = $screenwidth - $w - $a;
689 $y = $screenheight - $h - $b;
690 } else {
691 $g = X11::Tops::NorthEast;
692 $x = $screenwidth - $w - $a;
693 $y =~ s/^\+//;
694 $y = 0 + $y;
695 }
696 } else {
697 if (my ($b) = $y =~ /^-\+?(-?\d+)/) {
698 $g = X11::Tops::SouthWest;
699 $x =~ s/^\+//;
700 $x = 0 + $x;
701 $y = $screenheight - $h - $b;
702 } else {
703 $g = X11::Tops::NorthWest;
704 $x =~ s/^\+//;
705 $y =~ s/^\+//;
706 $x = 0 + $x;
707 $y = 0 + $y;
708 }
709 }
710 ($w, $h, $x, $y, $g);
711 }
712  
713 # ----------------------------------------------------------------------
714  
715 #32# requested geometry
716  
717 sub requested_geometry {
718 my $xtop = shift;
719  
720 my %geometry;
721 @geometry{qw(w h x y)} = $xtop->geometry;
722  
723 my %frame_geometry;
724 @frame_geometry{qw(w h x y)} = $xtop->frame_geometry;
725  
726 my %wm_normal_hints = $xtop->wm_normal_hints;
727 my $gravity = $wm_normal_hints{gravity};
728  
729 my $w = $geometry{w};
730 my $h = $geometry{h};
731  
732 my $x =
733 $gravity == X11::Tops::NorthWest || $gravity == X11::Tops::SouthWest ?
734 $frame_geometry{x} :
735 $gravity == X11::Tops::NorthEast || $gravity == X11::Tops::SouthEast ?
736 $frame_geometry{x} - $frame_geometry{w} + $geometry{w} :
737 croak("unknown gravity '$gravity'");
738  
739 my $y =
740 $gravity == X11::Tops::NorthWest || $gravity == X11::Tops::NorthEast ?
741 $frame_geometry{y} :
742 $gravity == X11::Tops::SouthEast || $gravity == X11::Tops::SouthWest ?
743 $frame_geometry{y} - $frame_geometry{h} + $geometry{h} :
744 croak("unknown gravity '$gravity'");
745  
746 ($w, $h, $x, $y, $gravity);
747 }
748  
749 # ----------------------------------------------------------------------
750  
751 #33# move
752  
753 # +taskbar7
754  
755 sub move {
756 my ($xtop, $geometry) = @_; # (src, dst)
757 my $X = $xtop->{xtops}{X};
758  
759 my %src_wm_normal_hints = $xtop->wm_normal_hints;
760  
761 my %dst;
762 @dst{qw(w h x y g)} = $xtop->parse_geometry($geometry);
763  
764 my %dst_wm_normal_hints = %src_wm_normal_hints;
765 $dst_wm_normal_hints{gravity} = $dst{g};
766  
767 $xtop->wm_normal_hints(%dst_wm_normal_hints);
768  
769 $X->ConfigureWindow(
770 $xtop->{id},
771 width => $dst{w}, height => $dst{h},
772 x => $dst{x}, y => $dst{y}
773 );
774 }
775  
776 # ----------------------------------------------------------------------
777  
778 #34# expand
779  
780 # +taskbar[78]
781  
782 sub expand {
783 my ($xtop, $geometry) = @_; # (src, dst)
784 my $X11 = $xtop->{xtops}{X};
785  
786 my %src;
787 @src{qw(w h x y g)} = $xtop->requested_geometry;
788 $src{X} = $src{x} + $src{w};
789 $src{Y} = $src{y} + $src{h};
790  
791 my %dst;
792 @dst{qw(w h x y g)} = $xtop->parse_geometry($geometry);
793 $dst{X} = $dst{x} + $dst{w};
794 $dst{Y} = $dst{y} + $dst{h};
795  
796 my $x = $src{x} < $dst{x} ? $src{x} : $dst{x};
797 my $y = $src{y} < $dst{y} ? $src{y} : $dst{y};
798 my $X = $src{X} > $dst{X} ? $src{X} : $dst{X};
799 my $Y = $src{Y} > $dst{Y} ? $src{Y} : $dst{Y};
800 my $w = $X - $x;
801 my $h = $Y - $y;
802  
803 my %wm_normal_hints = $xtop->wm_normal_hints;
804 my %base;
805 $base{w} = $wm_normal_hints{base_width};
806 $base{h} = $wm_normal_hints{base_height};
807 my %inc;
808 $inc{w} = $wm_normal_hints{width_inc};
809 $inc{h} = $wm_normal_hints{height_inc};
810 if ($inc{w} && $inc{h}) {
811 $w += ($base{w} - $w) % $inc{w};
812 $h += ($base{h} - $h) % $inc{h};
813 }
814  
815 $wm_normal_hints{gravity} = X11::Tops::NorthWest;
816 $wm_normal_hints{user_w} = $w;
817 $wm_normal_hints{user_h} = $h;
818 $wm_normal_hints{user_x} = $x;
819 $wm_normal_hints{user_y} = $y;
820 $wm_normal_hints{max_width} = $w;
821 $wm_normal_hints{max_height} = $h;
822  
823 $xtop->wm_normal_hints(%wm_normal_hints);
824  
825 $X11->ConfigureWindow($xtop->{id},
826 width => $w,
827 height => $h,
828 x => $x,
829 y => $y
830 );
831 }
832  
833 # ----------------------------------------------------------------------
834  
835 1;
836 __END__