Debian Codegraph @

t/wm-tcl.t

raw
1 #!/usr/bin/perl -w
2 # -*- perl -*-
3
4 # This file is a Tcl script to test out Tk's interactions with
5 # the window manager, including the "wm" command. It is organized
6 # in the standard fashion for Tcl tests.
7 #
8 # Copyright (c) 1992-1994 The Regents of the University of California.
9 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
10 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # All rights reserved.
12 #
13 # RCS: @(#) $Id$
14
15 # This file tests window manager interactions that work across
16 # platforms. Window manager tests that only work on a specific
17 # platform should be placed in unixWm.test or winWm.test.
18
19 #
20 # Translated by Slaven Rezic (2006-11, from CVS version 1.36)
21 #
22
23 # Some tests are marked as TODO because they fail with
24 # some window managers.
25 #
26 # Window managers passing all tests:
27 # * fvwm 2.4.19
28 # * twm
29 # * windowmaker 0.92.0
30 #
31 # Window managers with test failures
32 # * metacity 2.16.3
33 # * metacity 2.10.3 (even more failures)
34 # * fvwm 2.5.18
35 # * fvwm 2.6.5
36 # * blackbox 0.70.1
37 # * KWin: 3.0
38 # * Xfwm4: 4.2.3.2
39 # * X11 on Mac OS X 10.5.1
40 # * fluxbox 1.0.0
41
42 use strict;
43 use FindBin;
44 use lib $FindBin::RealBin;
45
46 use Tk;
47 use Getopt::Long;
48
49 use TkTest qw(wm_info);
50
51 BEGIN {
52 if (!eval q{
53 use Test::More;
54 1;
55 }) {
56 print "1..0 # skip: no Test::More module\n";
57 exit;
58 }
59 }
60
61 plan tests => 315;
62
63 my $mw = MainWindow->new;
64 my %wm_info = wm_info($mw);
65 my $wm_name = $wm_info{name};
66
67 my $wm_problems = $Tk::platform eq 'unix';
68 my $kwin_problems = defined $wm_name && $wm_name eq 'KWin';
69 my $xfwm4_problems = defined $wm_name && $wm_name eq 'Xfwm4';
70 my $macosx_x11_problems = $Tk::platform eq 'unix' && $^O eq 'darwin';
71 my $fluxbox_problems = defined $wm_name && $wm_name eq 'Fluxbox';
72 my $fvwm_problems = defined $wm_name && $wm_name eq 'FVWM';
73 my $compiz_problems = defined $wm_name && $wm_name eq 'Compiz';
74
75 my $poswin = 1;
76 my $netwm = 0;
77 GetOptions("poswin!" => \$poswin,
78 "trace!" => sub { $mw->wmTracing(1) },
79 "netwm!" => \$netwm,
80 "nowmproblems" => sub { $wm_problems = 0 },
81 )
82 or die "usage: $0 [-poswin] [-trace] [-netwm]
83 -noposwin: turn off fixed geometry setting (fixed geometry setting is needed
84 for some window managers like twm with default manual positioning)
85 -trace: turns wmTracing on
86 -netwm: set this is using modern opendesktop compliant X11 window manager
87 -nowmproblems: set this if you believe your X11 window manager implements
88 all ICCCM specifications correctly
89 ";
90
91
92 $mw->geometry("+10+10");
93
94 # Create entries in the option database to be sure that geometry options
95 # like border width have predictable values.
96 $mw->optionAdd('*Toplevel.borderWidth', 0);
97
98 $mw->deiconify;
99 if (!$mw->ismapped) {
100 $mw->waitVisibility;
101 }
102
103 # Weak guess whether a window manager is running at all (only done on
104 # X11)
105 my $wm_running = 1;
106 if ($Tk::platform eq 'unix') {
107 $mw->iconify;
108 $wm_running = $mw->state eq 'iconic';
109 $mw->deiconify;
110 }
111
112 my $t;
113
114 sub stdWindow () {
115 $t->destroy if Tk::Exists($t);
116 $t = $mw->Toplevel(qw(-width 100 -height 50));
117 $t->geometry("+0+0");
118 $t->update
119 }
120
121 sub deleteWindows () {
122 eval { $_->destroy } for $mw->children;
123 }
124
125 # [raise] and [lower] may return before the window manager
126 # has completed the operation. The raiseDelay procedure
127 # idles for a while to give the operation a chance to complete.
128 #
129
130 sub raiseDelay () {
131 $mw->after(100);
132 $mw->update;
133 }
134
135 sub raiseDelayLonger () {
136 $mw->after(2000);
137 $mw->update;
138 }
139
140 sub maybeRetryWithDelay (){}
141
142
143 sub poswin ($;@) {
144 if ($poswin) {
145 for (@_) {
146 $_->geometry("+0+0");
147 }
148 }
149 }
150
151 deleteWindows;
152 stdWindow;
153
154 {
155 my $b = $mw->Button(-text => "hello");
156 eval { Tk::Wm::geometry($b) }; # one shouldn't do this anyway
157 like($@, qr{window ".button" isn't a top-level window},
158 q{Tk_WmObjCmd procedure, miscellaneous errors});
159 $b->destroy;
160 }
161
162 ### wm aspect ###
163 {
164 eval { $mw->aspect("_") };
165 like($@, qr{\Qwrong # args: should be "wm aspect window ?minNumer minDenom maxNumer maxDenom?"\E},
166 "wm aspect usage");
167
168 eval { $mw->aspect("_", "_", "_") };
169 like($@, qr{\Qwrong # args: should be "wm aspect window ?minNumer minDenom maxNumer maxDenom?"\E});
170
171 eval { $mw->aspect("_", "_", "_", "_", "_") };
172 like($@, qr{\Qwrong # args: should be "wm aspect window ?minNumer minDenom maxNumer maxDenom?"\E});
173
174 eval { $mw->aspect(qw(bad 14 15 16)) };
175 like($@, qr{'bad' isn't numeric});
176
177 eval { $mw->aspect(qw(13 foo 15 16)) };
178 like($@, qr{'foo' isn't numeric});
179
180 eval { $mw->aspect(qw(13 14 bar 16)) };
181 like($@, qr{'bar' isn't numeric});
182
183 eval { $mw->aspect(qw(13 14 15 baz)) };
184 like($@, qr{'baz' isn't numeric});
185
186 eval { $mw->aspect(qw(0 14 15 16)) };
187 like($@, qr{\Qaspect number can't be <= 0});
188
189 eval { $mw->aspect(qw(13 0 15 16)) };
190 like($@, qr{\Qaspect number can't be <= 0});
191
192 eval { $mw->aspect(qw(13 14 0 16)) };
193 like($@, qr{\Qaspect number can't be <= 0});
194
195 eval { $mw->aspect(qw(13 14 15 0)) };
196 like($@, qr{\Qaspect number can't be <= 0});
197 }
198
199 {
200 is_deeply([$mw->aspect], [], "setting and reading aspect values");
201 $mw->aspect(qw(3 4 10 2));
202 is_deeply([$mw->aspect], [qw(3 4 10 2)]);
203 $mw->aspect(undef,undef,undef,undef);
204 is_deeply([$mw->aspect],[]);
205 }
206
207 ### wm attributes ###
208 {
209 eval { $mw->attributes(-alpha => 1.0, '-disabled') };
210 if ($Tk::platform eq 'MSWin32') {
211 local $TODO = "-alpha and -fullscreen not yet implemented";
212 like($@, qr{\Qwrong # args: should be "wm attributes window ?-alpha ?double?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"});
213 } else {
214 like($@, qr{\Qwrong # args: should be "wm attributes window ?-attribute ?value ...??});
215 }
216
217 SKIP: {
218 skip("works only on windows", 1)
219 if $Tk::platform ne 'MSWin32';
220 local $TODO = "Still fails...";
221 eval { $mw->attributes('-to') };
222 like($@, qr{\Qwrong # args: should be "wm attributes window ?-alpha ?double?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"});
223 }
224
225 SKIP: {
226 skip("works only on unix", 1)
227 if $Tk::platform ne 'unix';
228 eval { $mw->attributes("_") };
229 like($@, qr{\Qbad attribute "_": must be -alpha, -topmost, -zoomed, or -fullscreen},
230 "wm attributes usage");
231 }
232
233 SKIP: {
234 skip("works only on aqua", 1)
235 if $Tk::platform ne 'aqua';
236 die <<EOF;
237 not yet translated:
238 test wm-attributes-1.2.5 {usage} aqua {
239 list [catch {wm attributes . _} err] \$err
240 } {1 {bad attribute "_": must be -alpha, -modified, -notify, or -titlepath}}
241 EOF
242 }
243 }
244
245 {
246 ### wm client ###
247 is($t->client, undef, "wm client, setting and reading values");
248 $t->client('Miffo');
249 is($t->client, 'Miffo');
250 $t->client(undef);
251 is($t->client, undef);
252 }
253
254 SKIP: {
255 skip("fullscreen tests only on windows", 38)
256 if $Tk::platform ne 'MSWin32';
257 skip("fullscreen tests NYI on windows", 38);
258 ## Getting fullscreen attribute is not yet implemented for X11
259 # skip("fullscreen tests only on windows or on X11 with option -netwm", 38)
260 # if !($Tk::platform eq 'MSWin32' || ($Tk::platform eq 'unix' && $netwm));
261
262 {
263 deleteWindows;
264 my $t = $mw->Toplevel;
265 is($t->attributes(-fullscreen), 0,
266 "default -fullscreen value");
267 }
268
269 {
270 deleteWindows;
271 my $t = $mw->Toplevel;
272 $t->attributes(-fullscreen => 1);
273 is($t->attributes(-fullscreen), 1,
274 q{change -fullscreen before map});
275 }
276
277 {
278 deleteWindows;
279 my $t = $mw->Toplevel;
280 poswin $t;
281 $t->attributes(-fullscreen => 1);
282 $mw->update;
283 is($t->attributes(-fullscreen), 1,
284 q{change -fullscreen before map});
285 }
286
287 {
288 deleteWindows;
289 my $t = $mw->Toplevel;
290 poswin $t;
291 $mw->update;
292 $t->attributes(-fullscreen => 1);
293 is($t->attributes(-fullscreen), 1,
294 q{change -fullscreen after map});
295 }
296
297 {
298 deleteWindows;
299 my $t = $mw->Toplevel;
300 poswin $t;
301 $mw->update;
302 is($t->attributes(-fullscreen), 0,
303 q{change -fullscreen after map});
304 $t->attributes(-fullscreen => 1);
305 is($t->attributes(-fullscreen), 1);
306 # Query above should not clear fullscreen state
307 is($t->attributes(-fullscreen), 1);
308 $t->attributes(-fullscreen => 0);
309 is($t->attributes(-fullscreen), 0);
310 }
311
312 {
313 deleteWindows;
314 my $t = $mw->Toplevel;
315 my $normal_geom = "301x302+101+102";
316 my $fullscreen_geom = $mw->screenwidth . "x" . $mw->screenheight . "+0+0";
317 $t->geometry($normal_geom);
318 $mw->update;
319 is($t->geometry, $normal_geom, q{change -fullscreen after map});
320 $t->attributes(-fullscreen => 1);
321 is($t->geometry, $fullscreen_geom);
322 $t->attributes(-fullscreen => 0);
323 is($t->geometry, $normal_geom);
324 }
325
326 {
327 deleteWindows;
328 my $t = $mw->Toplevel;
329 poswin $t;
330 $mw->update;
331 $t->attributes(-fullscreen => 1);
332 $t->withdraw;
333 $t->deiconify;
334 is($t->attributes(-fullscreen), 1,
335 q{state change does not change -fullscreen});
336 }
337
338 {
339 deleteWindows;
340 my $t = $mw->Toplevel;
341 $mw->update;
342 $t->attributes(-fullscreen => 1);
343 $t->iconify;
344 $t->deiconify;
345 is($t->attributes(-fullscreen), 1,
346 q{state change (iconify) does not change -fullscreen});
347 }
348
349 {
350 deleteWindows;
351 my $t = $mw->Toplevel(Name => "t");
352 poswin $t;
353 $mw->update;
354 $t->overrideredirect(1);
355 eval { $t->attributes(-fullscreen => 1) };
356 like($@, qr{\Qcan't set fullscreen attribute for ".t": override-redirect flag is set},
357 q{override-redirect not compatible with fullscreen attribute});
358 }
359
360 {
361 deleteWindows;
362 my $t = $mw->Toplevel(Name => "t");
363 poswin $t;
364 $mw->update;
365 $t->maxsize(5000, 450);
366 eval { $t->attributes(-fullscreen => 1) };
367 like($@, qr{\Qcan't set fullscreen attribute for ".t": max width/height is too small},
368 q{max height too small});
369 }
370
371 {
372 deleteWindows;
373 my $t = $mw->Toplevel(Name => "t");
374 poswin $t;
375 $mw->update;
376 $t->maxsize(450, 5000);
377 eval { $t->attributes(-fullscreen => 1) };
378 like($@, qr{\Qcan't set fullscreen attribute for ".t": max width/height is too small},
379 q{max width too small});
380 }
381
382 {
383 deleteWindows;
384 my $t = $mw->Toplevel;
385 poswin $t;
386 $mw->update;
387 $t->attributes(-alpha => 1.0, -fullscreen => 1);
388 is($t->attributes(-fullscreen), 1,
389 q{another attribute, then -fullscreen});
390 }
391
392 {
393 deleteWindows;
394 my $t = $mw->Toplevel;
395 poswin $t;
396 $mw->update;
397 # This was originally -toolwindow instead of -alpha; changed
398 # this to make the test runnable under X11
399 $t->attributes(-alpha => 0.1, -fullscreen => 1, -topmost => 0);
400 is($t->attributes(-fullscreen), 1,
401 q{another attribute, then -fullscreen, then another});
402 }
403
404 {
405 deleteWindows;
406 $mw->focusForce;
407 my $t = $mw->Toplevel;
408 poswin $t;
409 $t->lower;
410 $mw->update;
411 is($mw->focus, $mw,
412 q{setting/unsetting fullscreen does not change the focus});
413
414 my $done;
415 $t->attributes(-fullscreen => 1);
416 $mw->after(200, sub { $done = 1 });
417 $mw->waitVariable(\$done);
418 is($mw->focus, $mw);
419
420 $done = 0;
421 $t->attributes(-fullscreen => 0);
422 $mw->after(200, sub { $done = 1 });
423 $mw->waitVariable(\$done);
424 is($mw->focus, $mw);
425 }
426
427 {
428 deleteWindows;
429 my(@focusin, $done);
430 $mw->focusForce;
431 my $t = $mw->Toplevel(Name => "t");
432 poswin $t;
433 my $te = $t->Entry(Name => "e")->pack;
434 $t->lower;
435 $t->bind("<FocusIn>", [sub {push @focusin, $_[0]}, Ev('W')]);
436 $mw->after(200, sub { $done = 1 });
437 $mw->waitVariable(\$done);
438
439 push @focusin, 1;
440 $te->focusForce;
441 $mw->after(200, sub { $done = 2 });
442 $mw->waitVariable(\$done);
443
444 push @focusin, 2;
445 $t->attributes(-fullscreen => 1);
446 $mw->after(200, sub { $done = 3 });
447 $mw->waitVariable(\$done);
448
449 push @focusin, 3;
450 $t->attributes(-fullscreen => 0);
451 $mw->after(200, sub { $done = 4 });
452 $mw->waitVariable(\$done);
453
454 push @focusin, "final";
455
456 $mw->bind("<FocusIn>" => '');
457 $t->bind("<FocusIn>" => '');
458
459 is_deeply(\@focusin, [1, $t, $te, 2, 3, "final", $te],
460 q{setting fullscreen does not generate FocusIn on wrapper create});
461 }
462
463 {
464 deleteWindows;
465 my $t = $mw->Toplevel(Name => "t");
466 is_deeply([$mw->stackorder], ["."],
467 "fullscreen stackorder");
468 my $done;
469 $mw->after(200, sub { $done = 1 });
470 $mw->waitVariable(\$done);
471 is_deeply([$mw->stackorder], [".", ".t"]);
472
473 # Default stacking is on top of other windows
474 # on the display. Setting the fullscreen attribute
475 # does not change this.
476 $t->attributes(qw(-fullscreen 1));
477 $mw->after(200, sub { $done = 2 });
478 $mw->waitVariable(\$done);
479 is_deeply([$mw->stackorder], [".", ".t"]);
480 }
481
482 {
483 deleteWindows;
484 my $t = $mw->Toplevel(Name => "t");
485 poswin $t;
486 $t->lower;
487 my $done;
488 $mw->after(200, sub { $done = 1 });
489 $mw->waitVariable(\$done);
490 is_deeply([$mw->stackorder], [".t", "."],
491 q{fullscreen stackorder});
492
493 # If stacking order is explicitly set, then
494 # setting the fullscreen attribute should
495 # not change it.
496 $t->attributes(-fullscreen => 1);
497 $mw->after(200, sub { $done = 2 });
498 $mw->waitVariable(\$done);
499 is_deeply([$mw->stackorder], [".t", "."]);
500 }
501
502 {
503 deleteWindows;
504 my $t = $mw->Toplevel(Name => "t");
505 poswin $t;
506 # lower forces the window to be mapped, it would not be otherwise
507 $t->lower;
508 is_deeply([$mw->stackorder], [".t", "."]);
509
510 # If stacking order is explicitly set
511 # for an unmapped window, then setting
512 # the fullscreen attribute should
513 # not change it.
514 $t->attributes(qw(-fullscreen 1));
515 my $done;
516 $mw->after(200 => sub { $done = 1 });
517 $mw->waitVariable(\$done);
518 is_deeply([$mw->stackorder], [".t", "."]);
519 }
520
521 {
522 deleteWindows;
523 my $t = $mw->Toplevel(Name => "t");
524 my $done;
525 $mw->after(200, sub { $done = 1});
526 $mw->waitVariable(\$done);
527 is_deeply([$mw->stackorder], [".", ".t"],
528 q{fullscreen stackorder});
529
530 $t->attributes(qw(-fullscreen 1));
531 $mw->after(200, sub { $done = 2});
532 $mw->waitVariable(\$done);
533 is_deeply([$mw->stackorder], [".", ".t"]);
534
535 # Unsetting the fullscreen attribute
536 # should not change the stackorder.
537 $t->attributes(qw(-fullscreen 0));
538 $mw->after(200, sub { $done = 3 });
539 $mw->waitVariable(\$done);
540 is_deeply([$mw->stackorder], [".", ".t"]);
541 }
542
543 {
544 deleteWindows;
545 my $t = $mw->Toplevel(Name => "t");
546 poswin $t;
547 $t->lower;
548 my $done;
549 $mw->after(200, sub { $done = 1 });
550 $mw->waitVariable(\$done);
551 is_deeply([$mw->stackorder], [".t", "."]);
552
553 $t->attributes(qw(-fullscreen 1));
554 $mw->after(200, sub { $done = 2 });
555 $mw->waitVariable(\$done);
556 is_deeply([$mw->stackorder], [".t", "."]);
557
558 # Unsetting the fullscreen attribute
559 # should not change the stackorder.
560 $t->attributes(qw(-fullscreen 0));
561 $mw->after(200, sub { $done = 3});
562 $mw->waitVariable(\$done);
563 is_deeply([$mw->stackorder], [".t", "."]);
564 }
565
566 {
567 deleteWindows;
568 my $a = $mw->Toplevel(Name => "a");
569 my $b = $mw->Toplevel(Name => "b");
570 my $c = $mw->Toplevel(Name => "c");
571 poswin $a, $b, $c;
572 $a->raise;
573 $b->raise;
574 $c->raise;
575 my $done;
576 $mw->after(200, sub { $done = 1});
577 $mw->waitVariable(\$done);
578 is_deeply([$mw->stackorder], [".", ".a", ".b", ".c"]);
579
580 $b->attributes(-fullscreen => 1);
581 $mw->after(200, sub { $done = 2});
582 $mw->waitVariable(\$done);
583 is_deeply([$mw->stackorder], [".", ".a", ".b", ".c"]);
584
585 # Unsetting the fullscreen attribute
586 # should not change the stackorder.
587 $b->attributes(qw(-fullscreen 0));
588 $mw->after(200, sub { $done = 3});
589 $mw->waitVariable(\$done);
590 is_deeply([$mw->stackorder], [".", ".a", ".b", ".c"]);
591 }
592 }
593
594 deleteWindows;
595 stdWindow;
596
597 {
598 ### wm colormapwindows ###
599 eval { $mw->colormapwindows("_","_") };
600 like($@, qr{\Qwrong # args: should be "wm colormapwindows window ?windowList?"},
601 "wm colormapwindows usage");
602
603 eval { $mw->colormapwindows("foo") };
604 like($@, qr{bad window path name "foo"});
605 }
606
607 {
608 my $t1 = $mw->Toplevel(qw(Name toplevel1 -width 200 -height 200 -colormap new));
609 poswin $t1;
610 my $t1a = $t1->Frame(qw(-width 100 -height 30));
611 my $t1b = $t1->Frame(qw(-width 100 -height 30 -colormap new));
612 Tk::pack($t1a, $t1b, qw(-side top));
613 $mw->update;
614
615 is_deeply([$t1->colormapwindows], [".toplevel1.frame1", ".toplevel1"],
616 "wm colormapwindows reading values");
617
618 my $t1c = $t1->Frame(qw(-width 100 -height 30 -colormap new))->pack(-side => "top");
619 $mw->update;
620
621 {
622 local $TODO;
623 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
624 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
625 $TODO = "May fail on MacOSX" if !$TODO && $macosx_x11_problems;
626 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
627 is_deeply([$t1->colormapwindows], [".toplevel1.frame1", ".toplevel1.frame2", ".toplevel1"]);
628 }
629
630 $t1->destroy;
631 }
632
633 {
634 my $t1 = $mw->Toplevel(qw(Name toplevel2 -width 200 -height 200));
635 poswin $t1;
636 my @f;
637 for (1 .. 3) {
638 push @f, $t1->Frame(qw(-width 100 -height 30))->pack(-side => "top");
639 }
640 $t1->colormapwindows([$f[1], $f[0]]);
641 is_deeply([$t1->colormapwindows], [".toplevel2.frame1", ".toplevel2.frame"],
642 "wm colormapwindows, setting and reading values");
643 }
644
645 {
646 ### wm command ###
647 eval { $mw->command("_", "_") };
648 like($@, qr{\Qwrong # args: should be "wm command window ?value?"},
649 "wm command usage");
650
651 is_deeply([$t->command],[], "wm command, setting and reading values");
652 {
653 local $TODO;
654 $TODO = "Fails on windows" if $Tk::platform eq 'MSWin32';
655 $t->command([qw(Miffo Foo)]);
656 is_deeply([$t->command],[qw(Miffo Foo)]);
657 }
658 $t->command(undef);
659 is_deeply([$t->command],[]);
660 }
661
662 {
663 ### wm deiconify ###
664 my $icon = $mw->Toplevel(qw(Name icon -width 50 -height 50 -bg red));
665 $t->iconwindow($icon);
666 eval { $icon->deiconify };
667 like($@, qr{can't deiconify .icon: it is an icon for .t}, "wm deiconify");
668 $icon->destroy;
669 }
670
671 {
672 if ($Tk::platform eq 'MSWin32') {
673 # test embedded window for Windows
674 my $tf = $t->Frame(-container => 1);
675 my $embed = $mw->Toplevel(Name => "embed", -use => $tf->id);
676 eval { $embed->deiconify };
677 like($@, qr{\Qcan't deiconify .embed: \E(the container does not support the request|it is an embedded window)},
678 "wm deiconify embedded window");
679 $embed->destroy;
680 $tf->destroy;
681 } else {
682 my $tf = $t->Frame(-container => 1);
683 my $embed = $mw->Toplevel(Name => "embed", -use => $tf->id);
684 eval { $embed->deiconify };
685 like($@, qr{\Qcan't deiconify .embed: it is an embedded window},
686 "wm deiconify embedded window");
687 $embed->destroy;
688 $tf->destroy;
689 }
690 }
691
692 {
693 deleteWindows;
694 $t = $mw->Toplevel;
695 $t->deiconify;
696 ok(!$t->ismapped,
697 q{a window that has never been mapped should not be mapped by deiconify()});
698 }
699
700 {
701 deleteWindows;
702 $t = $mw->Toplevel;
703 poswin $t;
704 $mw->idletasks;
705 $t->withdraw;
706 $t->deiconify;
707 if ($fvwm_problems && !$t->ismapped) { $t->deiconify }
708 ok($t->ismapped,
709 q{a window that has already been mapped should be mapped by deiconify()});
710 }
711
712 {
713 deleteWindows;
714 $t = $mw->Toplevel(qw(-width 200 -height 200));
715 is($t->geometry, "1x1+0+0");
716 $t->deiconify;
717 is($t->geometry, "1x1+0+0",
718 q{geometry for an unmapped window should not be calculated by deiconify()});
719 poswin $t;
720 $mw->idletasks;
721 like($t->geometry, qr{^200x200},
722 q{... it should be done at idle time});
723 }
724
725 {
726 deleteWindows;
727 $t = $mw->Toplevel;
728 $t->withdraw;
729 $t->deiconify;
730 $t->destroy;
731 $mw->update;
732 pass(q{invoking destroy after a deiconify should not result in a crash});
733 # ... because of a callback set on the toplevel
734 }
735
736 {
737 ### wm focusmodel ###
738 eval { $mw->focusmodel("_", "_") };
739 like($@, qr{\Qwrong # args: should be "wm focusmodel window ?active|passive?"},
740 "wm focusmodel usage");
741
742 eval { $mw->focusmodel("bogus") };
743 like($@, qr{\Qbad argument "bogus": must be active, or passive});
744 }
745
746 stdWindow;
747
748 {
749 is($t->focusmodel, "passive",
750 "wm focusmodel, setting and reading values");
751 $t->focusmodel("active");
752 is($t->focusmodel, "active");
753 $t->focusmodel("passive");
754 is($t->focusmodel, "passive");
755 }
756
757 {
758 ### wm frame ###
759 ok(defined $mw->frame, "wm frame");
760 }
761
762 {
763 ### wm geometry ###
764 eval { $mw->geometry("_", "_") };
765 like($@, qr{\Qwrong # args: should be "wm geometry window ?newGeometry?"},
766 "wm geometry usage");
767
768 eval { $mw->geometry("bogus") };
769 like($@, qr{\Qbad geometry specifier "bogus"});
770 }
771
772 {
773 local $TODO;
774 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
775 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x)" if !$TODO && $wm_problems;
776
777 $t->geometry("150x150+50+50");
778 $t->update;
779 is($t->geometry, "150x150+50+50",
780 "wm geometry, setting and getting values");
781 $t->geometry(undef);
782 $t->update;
783 isnt($t->geometry, "150x150+50+50", "geometry should change and is now " . $t->geometry);
784 }
785
786 {
787 ### wm grid ###
788 for my $args (1, 3, 5) {
789 eval { $mw->wmGrid(("_")x$args) };
790 like($@, qr{\Qwrong # args: should be "wm grid window ?baseWidth baseHeight widthInc heightInc?"},
791 "wm grid usage (tried $args args)");
792 }
793
794 eval { $mw->wmGrid(qw(bad 14 16 16)) };
795 like($@, qr{'bad' isn't numeric});
796
797 eval { $mw->wmGrid(qw(13 foo 16 16)) };
798 like($@, qr{'foo' isn't numeric});
799
800 eval { $mw->wmGrid(qw(13 14 bar 16)) };
801 like($@, qr{'bar' isn't numeric});
802
803 eval { $mw->wmGrid(qw(13 14 15 baz)) };
804 like($@, qr{'baz' isn't numeric});
805
806 eval { $mw->wmGrid(qw(-1 14 15 16)) };
807 like($@, qr{baseWidth can't be < 0});
808
809 eval { $mw->wmGrid(qw(13 -1 15 16)) };
810 like($@, qr{baseHeight can't be < 0});
811
812 eval { $mw->wmGrid(qw(13 14 -1 16)) };
813 like($@, qr{widthInc can't be <= 0});
814
815 eval { $mw->wmGrid(qw(13 14 15 -1)) };
816 like($@, qr{heightInc can't be <= 0});
817
818 is_deeply([$t->wmGrid],[], "wm grid, setting and reading values");
819 $t->wmGrid(qw(3 4 10 2));
820 is_deeply([$t->wmGrid],[qw(3 4 10 2)]);
821 $t->wmGrid((undef)x4);
822 is_deeply([$t->wmGrid],[]);
823 }
824
825 {
826 ### wm group ###
827 eval { $mw->group(12, 13) };
828 like($@, qr{\Qwrong # args: should be "wm group window ?pathName?"},
829 q{wm group usage});
830
831 eval { $mw->group("bogus") };
832 like($@, qr{bad window path name "bogus"});
833
834 is($t->group, undef, "wm group, setting and reading values");
835 $t->group($mw);
836 is($t->group, ".");
837 $t->group(undef);
838 is($t->group, undef);
839 }
840
841 {
842 ### wm iconbitmap ###
843 SKIP: {
844 skip("test only for unix", 1)
845 if $Tk::platform ne "unix";
846 eval { $mw->iconbitmap(12, 13) };
847 like($@, qr{\Qwrong # args: should be "wm iconbitmap window ?bitmap?"},
848 "wm iconbitmap usage on unix");
849 }
850
851 SKIP: {
852 skip("test only for windows", 2)
853 if $Tk::platform ne "MSWin32";
854
855 eval { $mw->iconbitmap(12, 13, 14) };
856 like($@, qr{\Qwrong # args: should be "wm iconbitmap window ?-default? ?image?"},
857 "wm iconbitmap usage on windows");
858
859 eval { $mw->iconbitmap(12, 13) };
860 like($@, qr{\Qillegal option "12" must be "-default"});
861 }
862
863 eval { $mw->iconbitmap("bad-bitmap") };
864 like($@, qr{bitmap "bad-bitmap" not defined});
865
866 is($t->iconbitmap, undef, "wm iconbitmap, setting and reading values");
867 $t->iconbitmap("hourglass");
868 is($t->iconbitmap, "hourglass");
869 $t->iconbitmap(undef);
870 is($t->iconbitmap, undef);
871 }
872
873 {
874 ### wm iconify ###
875 my $t2 = $mw->Toplevel(qw(Name toplevel2));
876 $t2->geometry("+10+10");
877 $t2->overrideredirect(1);
878 eval { $t2->iconify };
879 like($@, qr{\Qcan't iconify ".toplevel2": override-redirect flag is set},
880 "wm iconify, misc errors");
881 $t2->destroy;
882 }
883
884 {
885 my $t2 = $mw->Toplevel(qw(Name toplevel2));
886 poswin $t2;
887 $t2->transient($t);
888 eval { $t2->iconify };
889 like($@, qr{\Qcan't iconify ".toplevel2": it is a transient});
890 $t2->destroy;
891 }
892
893 {
894 my $t2 = $mw->Toplevel(qw(Name toplevel2));
895 poswin $t2;
896 $t->iconwindow($t2);
897 eval { $t2->iconify };
898 like($@, qr{can't iconify .toplevel2: it is an icon for .toplevel});
899 $t2->destroy;
900 }
901
902 {
903 if ($Tk::platform eq 'MSWin32') {
904 # test embedded window for Windows
905 my $tf = $t->Frame(qw(Name f -container 1));
906 my $t2 = $mw->Toplevel(qw(Name toplevel2), -use => $tf->id);
907 eval { $t2->iconify };
908 like($@, qr{\Qcan't iconify .toplevel2: \E(the container does not support the request|it is an embedded window)});
909 $t2->destroy;
910 } else {
911 # test embedded window for other platforms
912 my $tf = $t->Frame(qw(Name f -container 1));
913 my $t2 = $mw->Toplevel(qw(Name toplevel2), -use => $tf->id);
914 eval { $t2->iconify };
915 like($@, qr{\Qcan't iconify .toplevel2: it is an embedded window});
916 $t2->destroy;
917 }
918 }
919
920 SKIP: {
921 skip("Needs a window manager", 2)
922 if !$wm_running;
923
924 my $t2 = $mw->Toplevel;
925 $t2->geometry("-0+0");
926 $mw->update;
927 ok($t2->ismapped);
928 $t2->iconify;
929 $mw->update;
930 ok(!$t2->ismapped);
931 }
932
933 {
934 ### wm iconmask ###
935 eval { $mw->iconmask(12, 13) };
936 like($@, qr{\Qwrong # args: should be "wm iconmask window ?bitmap?"},
937 q{wm iconmask usage});
938
939 eval { $mw->iconmask("bad-bitmap") };
940 like($@, qr{\Qbitmap "bad-bitmap" not defined});
941
942 is($t->iconmask, undef, "wm iconmask, setting and reading values");
943 $t->iconmask("hourglass");
944 is($t->iconmask, "hourglass");
945 $t->iconmask(undef);
946 is($t->iconmask, undef);
947 }
948
949 {
950 ### wm iconname ###
951 eval { $mw->iconname(12, 13) };
952 like($@, qr{\Qwrong # args: should be "wm iconname window ?newName?"},
953 q{wm iconname usage});
954
955 # This is somewhat inconsistent ('' vs. undef)
956 is($t->iconname, '', "wm iconname, setting and reading values");
957 $t->iconname("ThisIconHasAName");
958 is($t->iconname, "ThisIconHasAName");
959 $t->iconname(undef);
960 is($t->iconname, '');
961 }
962
963 SKIP: {
964 skip("iconphoto not implemented on Windows", 4)
965 if $Tk::platform eq 'MSWin32';
966
967 ### wm iconphoto ###
968 eval { $mw->iconphoto };
969 like($@, qr{\Qwrong # args: should be "wm iconphoto window ?-default? image1 ?image2 ...?"},
970 "wm iconphoto usage");
971
972 eval { $mw->iconphoto("notanimage") };
973 like($@, qr{\Qcan't use "notanimage" as iconphoto: not a photo image});
974
975 eval { $mw->iconphoto("-default") };
976 like($@, qr{\Qwrong # args: should be "wm iconphoto window ?-default? image1 ?image2 ...?"});
977
978 my $photo = $mw->Photo(-file => Tk->findINC("icon.gif"));
979 $mw->iconphoto($photo);
980 pass("Set iconphoto");
981
982 # All other iconphoto tests are platform specific
983 }
984
985 {
986 ### wm iconposition ###
987 eval { $mw->iconposition(12) };
988 like($@, qr{\Qwrong # args: should be "wm iconposition window ?x y?"},
989 "wm iconposition usage");
990
991 eval { $mw->iconposition(12,13,14) };
992 like($@, qr{\Qwrong # args: should be "wm iconposition window ?x y?"});
993
994 eval { $mw->iconposition('bad', 13) };
995 like($@, qr{\Q'bad' isn't numeric});
996
997 eval { $mw->iconposition(13, 'lousy') };
998 like($@, qr{\Q'lousy' isn't numeric});
999
1000 is_deeply([$mw->iconposition], [], "wm iconposition, setting and reading values");
1001 $mw->iconposition(10, 20);
1002 is_deeply([$mw->iconposition], [10, 20]);
1003 $mw->iconposition(undef, undef);
1004 is_deeply([$mw->iconposition], []);
1005 }
1006
1007 {
1008 ### wm iconwindow ###
1009 eval { $mw->iconwindow(12, 13) };
1010 like($@, qr{\Qwrong # args: should be "wm iconwindow window ?pathName?"},
1011 q{wm iconwindow usage});
1012
1013 eval { $mw->iconwindow("bogus") };
1014 like($@, qr{bad window path name "bogus"});
1015 }
1016
1017 {
1018 my $b = $mw->Button(Name => "b", -text => "Help");
1019 eval { $t->iconwindow($b) };
1020 like($@, qr{\Qcan't use .b as icon window: not at top level});
1021 $b->destroy;
1022 }
1023
1024 {
1025 my $icon = $mw->Toplevel(Name => "icon",
1026 qw(-width 50 -height 50 -bg green));
1027 my $t2 = $mw->Toplevel(Name => "t2");
1028 poswin $t2;
1029 $t2->iconwindow($icon);
1030 eval { $t->iconwindow($icon) };
1031 like($@, qr{\Q.icon is already an icon for .t2});
1032
1033 $t2->destroy;
1034 $icon->destroy;
1035 }
1036
1037 {
1038 is($t->iconwindow, undef, "wm iconwindow, setting and reading values");
1039 my $icon = $mw->Toplevel(Name => "icon",
1040 qw(-width 50 -height 50 -bg green));
1041 $t->iconwindow($icon);
1042 is($t->iconwindow, $icon);
1043 $t->iconwindow(undef);
1044 is($t->iconwindow, undef);
1045 }
1046
1047 {
1048 ### wm maxsize ###
1049 eval { $mw->maxsize("a") };
1050 like($@, qr{\Qwrong # args: should be "wm maxsize window ?width height?"},
1051 q{wm maxsize usage});
1052
1053 eval { $mw->maxsize(qw(a b c)) };
1054 like($@, qr{\Qwrong # args: should be "wm maxsize window ?width height?"});
1055
1056 eval { $mw->maxsize(qw(x 100)) };
1057 like($@, qr{'x' isn't numeric});
1058
1059 eval { $mw->maxsize(qw(100 bogus)) };
1060 like($@, qr{'bogus' isn't numeric});
1061 }
1062
1063 {
1064 my $t2 = $mw->Toplevel;
1065 poswin $t2;
1066 $t2->maxsize(300, 200);
1067 is_deeply([$t2->maxsize], [300,200]);
1068 $t2->destroy;
1069 }
1070
1071 {
1072 my $t = $mw->Toplevel;
1073 poswin $t;
1074 my($t_width, $t_height) = $t->maxsize;
1075 my($s_width, $s_height) = ($t->screenwidth, $t->screenheight);
1076 cmp_ok($t_width, "<=", $s_width,
1077 "maxsize must be <= screen size");
1078 cmp_ok($t_height, "<=", $s_height);
1079 $t->destroy;
1080 }
1081
1082 {
1083 local $TODO;
1084 $TODO = "Fails currently on Windows" if $Tk::platform eq 'MSWin32';
1085 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1086 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x)" if !$TODO && $wm_problems;
1087
1088 my $t = $mw->Toplevel(qw(-width 300 -height 300));
1089 poswin $t;
1090 $t->update;
1091 $t->maxsize(200, 150);
1092 # UpdateGeometryInfo invoked at idle
1093 $t->update;
1094
1095 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1096 is($w, 200, q{setting the maxsize to a smaller value will resize a toplevel});
1097 is($h, 150);
1098 $t->destroy;
1099 }
1100
1101 {
1102 local $TODO;
1103 $TODO = "Fails currently on Windows" if $Tk::platform eq 'MSWin32';
1104 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1105 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x)" if !$TODO && $wm_problems;
1106
1107 my $t = $mw->Toplevel;
1108 poswin $t;
1109 $t->wmGrid(0,0,50,50);
1110 $t->geometry("6x6");
1111 $t->update;
1112 $t->maxsize(4, 3);
1113 # UpdateGeometryInfo invoked at idle
1114 $t->update;
1115
1116 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1117 is($w, 4, q{setting the maxsize to a smaller value will resize a gridded toplevel});
1118 is($h, 3);
1119 $t->destroy;
1120 }
1121
1122 {
1123 local $TODO;
1124 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1125 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
1126 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1127 $TODO = "May fail on MacOSX" if !$TODO && $macosx_x11_problems;
1128 $TODO = "May fail on Compiz" if !$TODO && $compiz_problems;
1129
1130 my $t = $mw->Toplevel(qw(-width 200 -height 200));
1131 poswin $t;
1132 $t->maxsize(300, 250);
1133 $t->update;
1134 $t->geometry("400x300");
1135 $t->update;
1136 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1137 is($w, 300, q{attempting to resize to a value bigger than the current maxsize});
1138 # ... will set it to the max size
1139 is($h, 250);
1140 $t->destroy;
1141 }
1142
1143 {
1144 local $TODO;
1145 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1146 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
1147 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1148 $TODO = "May fail on Compiz" if !$TODO && $compiz_problems;
1149
1150 my $t = $mw->Toplevel;
1151 poswin $t;
1152 $t->wmGrid(qw(1 1 50 50));
1153 $t->geometry("4x4");
1154 $t->maxsize(6, 5);
1155 $t->update;
1156 $t->geometry("8x6");
1157 $t->update;
1158 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1159 is($w, 6, q{attempting to resize a gridded toplevel to a value bigger});
1160 # ... than the current maxsize will set it to the max size
1161 is($h, 5);
1162 $t->destroy;
1163 }
1164
1165 {
1166 my $t = $mw->Toplevel;
1167 poswin $t;
1168 my $tf = $t->Frame(qw(-width 400 -height 400))->pack;
1169 $t->idletasks;
1170 is($t->reqwidth, 400);
1171 is($t->reqheight, 400);
1172 $t->maxsize(300, 300);
1173 $t->update;
1174
1175 local $TODO;
1176 $TODO = "Fails currently on Windows" if $Tk::platform eq 'MSWin32';
1177 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1178 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x)" if !$TODO && $wm_problems;
1179
1180 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1181 is($w, 300, q{Use max size if window size is not explicitly set});
1182 # ... and the reqWidth/reqHeight are bigger than the max size
1183 is($h, 300);
1184 }
1185
1186 {
1187 ### wm minsize ###
1188 eval { $mw->minsize("a") };
1189 like($@, qr{\Qwrong # args: should be "wm minsize window ?width height?"},
1190 q{wm minsize usage});
1191
1192 eval { $mw->minsize(qw(a b c)) };
1193 like($@, qr{\Qwrong # args: should be "wm minsize window ?width height?"});
1194
1195 eval { $mw->minsize(qw(x 100)) };
1196 like($@, qr{'x' isn't numeric});
1197
1198 eval { $mw->minsize(qw(100 bogus)) };
1199 like($@, qr{'bogus' isn't numeric});
1200 }
1201
1202 {
1203 my $t2 = $mw->Toplevel;
1204 poswin $t2;
1205 $t2->minsize(300, 200);
1206 is_deeply([$t2->minsize], [300,200]);
1207 $t2->destroy;
1208 }
1209
1210 {
1211 local $TODO;
1212 $TODO = "Fails currently on Windows" if $Tk::platform eq 'MSWin32';
1213 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1214 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
1215 $TODO = "May fail on MacOSX" if !$TODO && $macosx_x11_problems;
1216 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1217
1218 my $t = $mw->Toplevel(qw(-width 200 -height 200));
1219 poswin $t;
1220 $t->update;
1221 $t->minsize(400, 300);
1222 # UpdateGeometryInfo invoked at idle
1223 $t->update;
1224
1225 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1226 is($w, 400, q{setting the minsize to a larger value will resize a toplevel});
1227 is($h, 300);
1228 $t->destroy;
1229 }
1230
1231 {
1232 local $TODO;
1233 $TODO = "Fails currently on Windows" if $Tk::platform eq 'MSWin32';
1234 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1235 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
1236 $TODO = "May fail on MacOSX" if !$TODO && $macosx_x11_problems;
1237 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1238 $TODO = "May fail on Compiz" if !$TODO && $compiz_problems;
1239
1240 my $t = $mw->Toplevel;
1241 poswin $t;
1242 $t->wmGrid(qw(1 1 50 50));
1243 $t->geometry("4x4");
1244 $t->update;
1245 $t->minsize(8,8);
1246 # UpdateGeometryInfo invoked at idle
1247 $t->update;
1248
1249 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1250 is($w, 8, q{setting the minsize to a larger value will resize a gridded toplevel});
1251 is($h, 8);
1252 $t->destroy;
1253 }
1254
1255 {
1256 local $TODO;
1257 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1258 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x)" if !$TODO && $wm_problems;
1259
1260 my $t = $mw->Toplevel(qw(-width 400 -height 400));
1261 poswin $t;
1262 $t->minsize(300, 300);
1263 $t->update;
1264 $t->geometry("200x200");
1265 $t->update;
1266 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1267 is($w, 300, q{attempting to resize to a value smaller than the current minsize});
1268 # ... will set it to the minsize
1269 is($h, 300);
1270 $t->destroy;
1271 }
1272
1273 {
1274 local $TODO;
1275 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1276 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x)" if !$TODO && $wm_problems;
1277
1278 my $t = $mw->Toplevel;
1279 poswin $t;
1280 $t->wmGrid(qw(1 1 50 50));
1281 $t->geometry("8x8");
1282 $t->minsize(6, 6);
1283 $t->update;
1284 $t->geometry("4x4");
1285 $t->update;
1286 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1287 is($w, 6, q{attempting to resize a gridded toplevel to a value smaller});
1288 # than the current minsize will set it to the minsize when gridded
1289 is($h, 6);
1290 $t->destroy;
1291 }
1292
1293 {
1294 my $t = $mw->Toplevel;
1295 poswin $t;
1296 my $tf = $t->Frame(qw(-width 250 -height 250))->pack;
1297 $t->idletasks;
1298 is($t->reqwidth, 250);
1299 is($t->reqheight, 250);
1300 $t->minsize(300, 300);
1301 $t->update;
1302
1303 local $TODO;
1304 $TODO = "Fails currently on Windows" if $Tk::platform eq 'MSWin32';
1305 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1306 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
1307 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1308 $TODO = "May fail on Compiz" if !$TODO && $compiz_problems;
1309
1310 my($w,$h) = $t->geometry =~ m{(\d+)x(\d+)};
1311 is($w, 300, q{Use min size if window size is not explicitly set});
1312 # ... and the reqWidth/reqHeight are smaller than the min size
1313 is($h, 300);
1314 $t->destroy;
1315 }
1316
1317 {
1318 ### wm overrideredirect ###
1319 eval { $mw->overrideredirect(1, 2) };
1320 like($@, qr{\Qwrong # args: should be "wm overrideredirect window ?boolean?"},
1321 "wm overrideredirect usage");
1322
1323 ## In Perl probably interpreted as a true value
1324 #eval { $mw->overrideredirect("boo") };
1325 #like($@, qr{\Qexpected boolean value but got "boo"});
1326
1327 is($mw->overrideredirect, 0, "wm overrideredirect, setting and reading values");
1328 $mw->overrideredirect(1);
1329 is($mw->overrideredirect, 1);
1330 $mw->overrideredirect(0);
1331 is($mw->overrideredirect, 0);
1332 }
1333
1334 {
1335 ### wm positionfrom ###
1336 eval { $mw->positionfrom(1, 2) };
1337 like($@, qr{\Qwrong # args: should be "wm positionfrom window ?user/program?"},
1338 "wm positionfrom usage");
1339
1340 eval { $mw->positionfrom("none") };
1341 like($@, qr{bad argument "none": must be program, or user});
1342 }
1343
1344 {
1345 my $t2 = $mw->Toplevel;
1346 poswin $t2;
1347 $t2->positionfrom("user");
1348 is($t2->positionfrom, "user", "wm positionfrom, setting and reading values");
1349 $t2->positionfrom("program");
1350 is($t2->positionfrom, "program");
1351 $t2->positionfrom(undef);
1352 is($t2->positionfrom, undef);
1353 $t2->destroy;
1354 }
1355
1356 {
1357 ### wm protocol ###
1358 eval { $mw->protocol(1, 2, 3) };
1359 like($@, qr{\Qwrong # args: should be "wm protocol window ?name? ?command?"},
1360 "wm protocol usage");
1361 }
1362
1363 {
1364 my $t = $mw->Toplevel;
1365 poswin $t;
1366 $t->protocol("foo a", "a b c");
1367 $t->protocol("bar", "test script for bar");
1368 is_deeply([$t->protocol], ["bar", "foo a"],
1369 "wm protocol, setting and reading values");
1370 $t->protocol("foo a", undef);
1371 $t->protocol("bar", undef);
1372 is_deeply([$t->protocol], []);
1373 $t->destroy;
1374 }
1375
1376 {
1377 my $t = $mw->Toplevel;
1378 poswin $t;
1379 $t->protocol("foo", "a b c");
1380 $t->protocol("bar", "test script for bar");
1381 isa_ok($t->protocol("foo"), "Tk::Callback");
1382 isa_ok($t->protocol("bar"), "Tk::Callback");
1383 $t->protocol("foo", undef);
1384 $t->protocol("bar", undef);
1385 is($t->protocol("foo"), undef);
1386 is($t->protocol("bar"), undef);
1387 $t->destroy;
1388 }
1389
1390 {
1391 my $t = $mw->Toplevel;
1392 poswin $t;
1393 my $code1 = sub { "a b c" };
1394 $t->protocol("foo", $code1);
1395 my $code2 = sub { "test script" };
1396 $t->protocol("foo", $code2);
1397 is($t->protocol("foo")->[0], $code2);
1398 $t->protocol("foo", ["bla"]);
1399 isa_ok($t->protocol("foo"), "Tk::Callback");
1400 is($t->protocol("foo")->[0], "bla");
1401 $t->destroy;
1402 }
1403
1404 {
1405 ### wm resizable ###
1406 eval { $mw->resizable(1) };
1407 like($@, qr{\Qwrong # args: should be "wm resizable window ?width height?"},
1408 "wm resizable usage");
1409
1410 eval { $mw->resizable(1,2,3) };
1411 like($@, qr{\Qwrong # args: should be "wm resizable window ?width height?"});
1412
1413 ## Valid in Perl, "bad" is a boolean value
1414 #eval { $mw->resizable("bad", 0) };
1415
1416 $mw->resizable(0, 1);
1417 is_deeply([$mw->resizable], [0, 1], "wm resizable, setting and reading values");
1418 $mw->resizable(1, 0);
1419 is_deeply([$mw->resizable], [1, 0]);
1420 $mw->resizable(1, 1);
1421 is_deeply([$mw->resizable], [1, 1]);
1422 }
1423
1424 {
1425 ### wm sizefrom ###
1426 eval { $mw->sizefrom(1, 2) };
1427 like($@, qr{\Qwrong # args: should be "wm sizefrom window ?user|program?"},
1428 "wm sizefrom usage");
1429
1430 eval { $mw->sizefrom("bad") };
1431 like($@, qr{bad argument "bad": must be program, or user});
1432
1433 $t->sizefrom("user");
1434 is($t->sizefrom, "user", "wm sizefrom, setting and reading values");
1435 $t->sizefrom("program");
1436 is($t->sizefrom, "program");
1437 $t->sizefrom(undef);
1438 is($t->sizefrom, undef);
1439 }
1440
1441 {
1442 ### wm stackorder ###
1443 eval { $mw->stackorder("_") };
1444 like($@, qr{\Qwrong # args: should be "wm stackorder window ?isabove|isbelow window?"},
1445 "wm stackorder usage");
1446
1447 eval { $mw->stackorder("_", "_", "_") };
1448 like($@, qr{\Qwrong # args: should be "wm stackorder window ?isabove|isbelow window?"});
1449
1450 eval { $mw->stackorder("is", ".") };
1451 like($@, qr{\Qambiguous argument "is": must be isabove, or isbelow});
1452
1453 eval { $mw->stackorder("isabove", "_") };
1454 like($@, qr{\Qbad window path name "_"});
1455 }
1456
1457 for my $is ("isabove", "isbelow") {
1458 my $t = $mw->Toplevel(Name => "t");
1459 poswin $t;
1460 my $tb = $t->Button(Name => "b")->pack;
1461 $mw->update;
1462 eval { $mw->stackorder($is, $tb) };
1463 like($@, qr{\Qwindow ".t.b" isn't a top-level window});
1464 $t->destroy;
1465 }
1466
1467 for my $is ("isabove", "isbelow") {
1468 my $t = $mw->Toplevel(Name => "t");
1469 poswin $t;
1470 $t->update;
1471 $t->withdraw;
1472 eval { $t->stackorder($is, $mw) };
1473 like($@, qr{\Qwindow ".t" isn't mapped},
1474 "wm stackorder usage, isabove|isbelow toplevels must be mapped");
1475 $t->destroy;
1476 }
1477
1478 deleteWindows;
1479
1480 # stackorder was not defined before Tk804.027_001
1481 eval {
1482 {
1483 local $TODO;
1484 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1485 $TODO = "May fail on xfwm4" if !$TODO && $xfwm4_problems;
1486
1487 my $t = $mw->Toplevel(Name => "t");
1488 poswin $t;
1489 $t->update;
1490 is_deeply([$mw->stackorder], [".", ".t"]);
1491 $t->destroy;
1492 }
1493
1494 {
1495 local $TODO;
1496 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1497 $TODO = "May fail sometimes on some older window managers (e.g. metacity 2.10.x)" if !$TODO && $wm_problems;
1498
1499 my $t = $mw->Toplevel(Name => "t");
1500 poswin $t;
1501 $t->update;
1502 $mw->raise;
1503 raiseDelay;
1504 is_deeply([$mw->stackorder], [".t", "."]);
1505 $t->destroy;
1506 }
1507
1508 {
1509 local $TODO;
1510 $TODO = "May fail sometimes on some window managers (e.g. metacity)"
1511 if $wm_problems;
1512
1513 my $t = $mw->Toplevel(Name => "t");
1514 poswin $t;
1515 $t->update;
1516 my $t2 = $mw->Toplevel(Name => "t2");
1517 poswin $t2;
1518 $t2->update;
1519 $mw->raise;
1520 $t2->raise;
1521 raiseDelay;
1522 is_deeply([$mw->stackorder], [".t", ".", ".t2"]);
1523 Tk::destroy($t, $t2);
1524 }
1525
1526 {
1527 local $TODO;
1528 $TODO = "May fail sometimes on some window managers (e.g. metacity)"
1529 if $wm_problems;
1530
1531 my $t = $mw->Toplevel(Name => "t");
1532 poswin $t;
1533 $t->update;
1534 my $t2 = $mw->Toplevel(Name => "t2");
1535 poswin $t2;
1536 $t2->update;
1537 $mw->raise;
1538 $t2->lower;
1539 raiseDelay;
1540 is_deeply([$mw->stackorder], [".t2", ".t", "."]);
1541 Tk::destroy($t, $t2);
1542 }
1543
1544 {
1545 local $TODO;
1546 $TODO = "May fail sometimes on some window managers (e.g. metacity)"
1547 if $wm_problems;
1548
1549 my $parent = $mw->Toplevel(Name => "parent");
1550 poswin $parent;
1551 $parent->update;
1552 my $parent_child1 = $parent->Toplevel(Name => "child1");
1553 poswin $parent_child1;
1554 $parent_child1->update;
1555 my $parent_child2 = $parent->Toplevel(Name => "child2");
1556 poswin $parent_child2;
1557 $parent_child2->update;
1558 my $extra = $mw->Toplevel(Name => "extra");
1559 poswin $extra;
1560 $extra->update;
1561 $parent->raise;
1562 $parent_child2->lower;
1563 raiseDelay;
1564 is_deeply([$parent->stackorder], [qw(.parent.child2 .parent.child1 .parent)]);
1565 }
1566
1567 deleteWindows;
1568
1569 {
1570 local $TODO;
1571 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1572 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1573
1574 my $t1 = $mw->Toplevel(Name => "t1");
1575 poswin $t1;
1576 my $t1b = $t1->Button->pack;
1577 $mw->update;
1578 is_deeply([$mw->stackorder], [".", ".t1"],
1579 q{non-toplevel widgets ignored});
1580 }
1581
1582 deleteWindows;
1583
1584 {
1585 is_deeply([$mw->stackorder], ["."],
1586 q{no children returns self});
1587 }
1588
1589 deleteWindows;
1590
1591 SKIP: {
1592 skip("Needs a window manager", 1)
1593 if !$wm_running;
1594
1595 local $TODO;
1596 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1597
1598 my $t1 = $mw->Toplevel(Name => "t1");
1599 poswin $t1;
1600 $t1->update;
1601 my $t2 = $mw->Toplevel(Name => "t2");
1602 poswin $t2;
1603 $t2->update;
1604 $t1->iconify;
1605 is_deeply([$mw->stackorder], [".", ".t2"],
1606 "unmapped toplevel");
1607 $t2->destroy;
1608 $t1->destroy;
1609 }
1610
1611
1612 {
1613 local $TODO;
1614 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1615
1616 my $t1 = $mw->Toplevel(Name => "t1");
1617 poswin $t1;
1618 $t1->update;
1619 my $t2 = $mw->Toplevel(Name => "t2");
1620 poswin $t2;
1621 $t2->update;
1622 $t2->withdraw;
1623 is_deeply([$mw->stackorder], [".", ".t1"]);
1624 $t2->destroy;
1625 $t1->destroy;
1626 }
1627
1628 {
1629 my $t1 = $mw->Toplevel(Name => "t1");
1630 poswin $t1;
1631 $t1->update;
1632 my $t2 = $mw->Toplevel(Name => "t2");
1633 poswin $t2;
1634 $t2->update;
1635 $t2->withdraw;
1636 is_deeply([$t2->stackorder], []);
1637 $t2->destroy;
1638 $t1->destroy;
1639 }
1640
1641 {
1642 my $t1 = $mw->Toplevel(Name => "t1");
1643 poswin $t1;
1644 $t1->update;
1645 my $t1t2 = $t1->Toplevel(Name => "t2");
1646 poswin $t1t2;
1647 $t1t2->update;
1648 $t1t2->withdraw;
1649 is_deeply([$t1->stackorder], [".t1"]);
1650 $t1t2->destroy;
1651 $t1->destroy;
1652 }
1653
1654 {
1655 my $t1 = $mw->Toplevel(Name => "t1");
1656 poswin $t1;
1657 $t1->update;
1658 my $t1t2 = $t1->Toplevel(Name => "t2");
1659 poswin $t1t2;
1660 $t1t2->update;
1661 $t1->withdraw;
1662 is_deeply([$t1->stackorder], [".t1.t2"]);
1663 $t1t2->destroy;
1664 $t1->destroy;
1665 }
1666
1667 {
1668 local $TODO;
1669 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1670 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1671
1672 my $t1 = $mw->Toplevel(Name => "t1");
1673 poswin $t1;
1674 $t1->update;
1675 my $t1t2 = $t1->Toplevel(Name => "t2");
1676 poswin $t1t2;
1677 $t1t2->update;
1678 my $t1t2t3 = $t1t2->Toplevel(Name => "t3");
1679 poswin $t1t2t3;
1680 $t1t2t3->update;
1681 $t1t2->withdraw;
1682 is_deeply([$t1->stackorder],[".t1", ".t1.t2.t3"]);
1683 $t1t2t3->destroy;
1684 $t1t2->destroy;
1685 $t1->destroy;
1686 }
1687
1688 {
1689 my $t1 = $mw->Toplevel(Name => "t1");
1690 poswin $t1;
1691 $t1->update;
1692 my $t1t2 = $t1->Toplevel(Name => "t2");
1693 poswin $t1t2;
1694 $t1t2->update;
1695 $t1->withdraw;
1696 is_deeply([$t1->stackorder], [".t1.t2"],
1697 q{unmapped toplevel, mapped children returned});
1698 $t1t2->destroy;
1699 $t1->destroy;
1700 }
1701
1702 {
1703 my $t1 = $mw->Toplevel;
1704 is_deeply([$mw->stackorder], ["."],
1705 q{toplevel mapped in idle callback});
1706 $t1->destroy;
1707 }
1708
1709 deleteWindows;
1710
1711 {
1712 local $TODO;
1713 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1714 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1715
1716 my $t = $mw->Toplevel;
1717 poswin $t;
1718 $t->update;
1719 $t->raise;
1720 is($mw->stackorder("isabove", $t), 0,
1721 q{wm stackorder isabove|isbelow});
1722 $t->destroy;
1723 }
1724
1725 {
1726 local $TODO;
1727 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1728 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
1729
1730 my $t = $mw->Toplevel;
1731 poswin $t;
1732 $t->update;
1733 $t->raise;
1734 is($mw->stackorder("isbelow", $t), 1);
1735 $t->destroy;
1736 }
1737
1738 {
1739 local $TODO;
1740 $TODO = "May fail sometimes on some older window managers (e.g. metacity 2.10.x)"
1741 if $wm_problems;
1742
1743 my $t = $mw->Toplevel;
1744 poswin $t;
1745 $t->update;
1746 $mw->raise;
1747 raiseDelay;
1748 is($t->stackorder("isa", $mw), 0);
1749 $t->destroy;
1750 }
1751
1752 {
1753 local $TODO;
1754 $TODO = "May fail sometimes on some older window managers (e.g. metacity 2.10.x)"
1755 if $wm_problems;
1756
1757 my $t = $mw->Toplevel;
1758 poswin $t;
1759 $t->update;
1760 $mw->raise;
1761 raiseDelay;
1762 is($t->stackorder("isb", $mw), 1);
1763 $t->destroy;
1764 }
1765
1766 deleteWindows;
1767
1768 {
1769 local $TODO;
1770 $TODO = "May fail sometimes on some older window managers (e.g. metacity 2.10.x)"
1771 if $wm_problems;
1772
1773 my $t = $mw->Toplevel(Name => "t");
1774 poswin $t;
1775 my $tm = $t->Menu(-type => "menubar");
1776 $tm->add("cascade", -label => "File");
1777 $t->configure(-menu => $tm);
1778 $mw->update;
1779 $mw->raise;
1780 raiseDelay;
1781 is_deeply([$mw->stackorder], [".t", "."],
1782 q{a menu is not a toplevel});
1783 $t->destroy;
1784 }
1785
1786 {
1787 my $t = $mw->Toplevel(Name => "t");
1788 poswin $t;
1789 $t->overrideredirect(1);
1790 $mw->raise;
1791 $mw->update;
1792 raiseDelay;
1793 if ($mw->stackorder("isabove", $t)) {
1794 # Problem seen with twm on travis-ci system
1795 # and on a Mac OS X system
1796 # (http://www.cpantesters.org/cpan/report/404e4ab4-3738-11e3-850b-7bc3a04c628c)
1797 diag "Window manager too slow? Delay and retry...";
1798 raiseDelayLonger;
1799 }
1800 is($mw->stackorder("isabove", $t), 0,
1801 q{A normal toplevel can't be raised above an overrideredirect toplevel});
1802 $t->destroy;
1803 }
1804
1805 {
1806 my $t = $mw->Toplevel(Name => "t");
1807 poswin $t;
1808 $t->overrideredirect(1);
1809 $mw->lower;
1810 $mw->update;
1811 raiseDelay;
1812 is($mw->stackorder("isbelow", $t), 1,
1813 q{A normal toplevel can be explicitely lowered});
1814 $t->destroy;
1815 }
1816
1817 {
1818 local $TODO;
1819 $TODO = "May fail on KDE" if !$TODO && $kwin_problems;
1820
1821 my $real = $mw->Toplevel(Name => "real", -container => 1);
1822 poswin $real;
1823 my $embd = $mw->Toplevel(Name => "embd",
1824 -bg => "blue", -use => $real->id);
1825 poswin $embd;
1826 $mw->update;
1827 is_deeply([$mw->stackorder], [".", ".real"],
1828 q{An embedded toplevel does not appear in the stacking order});
1829 $embd->destroy;
1830 $real->destroy;
1831 }
1832 };
1833 if ($@) {
1834 fail("stackorder tests failed: $@");
1835 }
1836
1837 stdWindow;
1838
1839 {
1840 ### wm title ###
1841 eval { $mw->title("1", "2") };
1842 like($@, qr{\Qwrong # args: should be "wm title window ?newTitle?"},
1843 "wm title usage");
1844
1845 my $t = $mw->Toplevel;
1846 is($t->title, "Toplevel", "wm title, setting and reading values");
1847 $t->title("Apa");
1848 is($t->title, "Apa");
1849 $t->title(undef);
1850 is($t->title, "");
1851 $t->destroy;
1852 }
1853
1854 {
1855 ### wm transient ###
1856 my $t = $mw->Toplevel(Name => "t");
1857 eval { $t->transient(1, 2) };
1858 like($@, qr{\Qwrong # args: should be "wm transient window ?master?"},
1859 "wm transient usage");
1860
1861 eval { $t->transient("foo") };
1862 like($@, qr{bad window path name "foo"});
1863 }
1864
1865 {
1866 deleteWindows;
1867 my $master = $mw->Toplevel(Name => "master");
1868 my $subject = $mw->Toplevel(Name => "subject");
1869 $subject->transient($master);
1870 eval { $subject->iconify };
1871 like($@, qr{\Qcan't iconify ".subject": it is a transient});
1872 }
1873
1874 {
1875 deleteWindows;
1876 my $icon = $mw->Toplevel(Name => "icon", -bg => "blue");
1877 my $top = $mw->Toplevel(Name => "top");
1878 $top->iconwindow($icon);
1879 my $dummy = $mw->Toplevel;
1880 eval { $icon->transient($dummy) };
1881 like($@, qr{\Qcan't make ".icon" a transient: it is an icon for .top});
1882 }
1883
1884 {
1885 deleteWindows;
1886 my $icon = $mw->Toplevel(Name => "icon", -bg => "blue");
1887 my $top = $mw->Toplevel(Name => "top");
1888 $top->iconwindow($icon);
1889 my $dummy = $mw->Toplevel;
1890 eval { $dummy->transient($icon) };
1891 like($@, qr{\Qcan't make ".icon" a master: it is an icon for .top});
1892 }
1893
1894 {
1895 deleteWindows;
1896 my $master = $mw->Toplevel(Name => "master");
1897 eval { $master->transient($master) };
1898 like($@, qr{\Qcan't make ".master" its own master});
1899 }
1900
1901 {
1902 deleteWindows;
1903 my $master = $mw->Toplevel(Name => "master");
1904 my $f = $master->Frame(Name => "f");
1905 eval { $master->transient($f) };
1906 like($@, qr{\Qcan't make ".master" its own master});
1907 }
1908
1909 {
1910 deleteWindows;
1911 my $master = $mw->Toplevel(Name => "master");
1912 my $subject = $mw->Toplevel(Name => "subject");
1913 is($subject->transient, undef, "basic get/set of master");
1914 $subject->transient($master);
1915 is($subject->transient, $master);
1916 $subject->transient(undef);
1917 is($subject->transient, undef);
1918 }
1919
1920 {
1921 deleteWindows;
1922 my $master = $mw->Toplevel(Name => "master");
1923 my $f = $master->Frame;
1924 my $subject = $mw->Toplevel(Name => "subject");
1925 $subject->transient($f);
1926 is($subject->transient, $master,
1927 "first toplevel parent of non-toplevel master is used");
1928 }
1929
1930 {
1931 deleteWindows;
1932 my $master = $mw->Toplevel(Name => "master");
1933 poswin $master;
1934 $master->withdraw;
1935 $mw->update;
1936 my $subject = $mw->Toplevel(Name => "subject");
1937 poswin $subject;
1938 $subject->transient($master);
1939 $mw->update;
1940 is($subject->state, "withdrawn",
1941 "transient toplevel is withdrawn when mapped if master is withdrawn");
1942 is($subject->ismapped, 0);
1943 }
1944
1945 {
1946 deleteWindows;
1947 my $master = $mw->Toplevel(Name => "master");
1948 poswin $master;
1949 $master->withdraw;
1950 $mw->update;
1951 my $subject = $mw->Toplevel(Name => "subject");
1952 poswin $subject;
1953 $mw->update;
1954 $subject->transient($master);
1955 $mw->update;
1956 is($subject->state, "withdrawn",
1957 q{already mapped transient toplevel takes on withdrawn state of master});
1958 is($subject->ismapped, 0);
1959 }
1960
1961 {
1962 deleteWindows;
1963 my $master = $mw->Toplevel;
1964 my $subject = $mw->Toplevel;
1965 poswin $master, $subject;
1966 $mw->update;
1967 $subject->transient($master);
1968 $master->withdraw;
1969 $mw->update;
1970 is($subject->state, "withdrawn",
1971 q{withdraw on the master also does a withdraw on the transient});
1972 is($subject->ismapped, 0);
1973 $master->deiconify;
1974 $mw->update;
1975
1976 local $TODO;
1977 $TODO = "May fail on some window managers (e.g. fvwm 2.5.x)"
1978 if $wm_problems;
1979
1980 is($subject->state, "normal",
1981 q{deiconify on the master also does a deiconify on the transient});
1982 is($subject->ismapped, 1);
1983 }
1984
1985 SKIP: {
1986 skip("Needs a window manager", 2)
1987 if !$wm_running;
1988
1989 local $TODO;
1990 $TODO = "May fail on some window managers (e.g. metacity)"
1991 if $wm_problems;
1992
1993 deleteWindows;
1994 my $master = $mw->Toplevel;
1995 poswin $master;
1996 $master->iconify;
1997 $mw->update;
1998 my $subject = $mw->Toplevel;
1999 poswin $subject;
2000 $subject->transient($master);
2001 $mw->update;
2002 is($subject->state, "withdrawn",
2003 q{transient toplevel is withdrawn when mapped if master is iconic});
2004 is($subject->ismapped, 0);
2005 }
2006
2007 SKIP: {
2008 skip("Needs a window manager", 2)
2009 if !$wm_running;
2010
2011 local $TODO;
2012 $TODO = "May fail on some window managers (e.g. metacity)"
2013 if $wm_problems;
2014
2015 deleteWindows;
2016 my $master = $mw->Toplevel;
2017 poswin $master;
2018 $master->iconify;
2019 $mw->update;
2020 my $subject = $mw->Toplevel;
2021 poswin $subject;
2022 $mw->update;
2023 $subject->transient($master);
2024 $mw->update;
2025 is($subject->state, "withdrawn",
2026 q{already mapped transient toplevel is withdrawn if master is iconic});
2027 is($subject->ismapped, 0);
2028 }
2029
2030 SKIP: {
2031 skip("Needs a window manager", 4)
2032 if !$wm_running;
2033
2034 deleteWindows;
2035 my $master = $mw->Toplevel;
2036 my $subject = $mw->Toplevel;
2037 poswin $master, $subject;
2038 $mw->update;
2039 $subject->transient($master);
2040 $master->iconify;
2041 $mw->update;
2042 is($subject->state, "withdrawn",
2043 q{iconify on the master does a withdraw on the transient});
2044 is($subject->ismapped, 0);
2045 $master->deiconify;
2046 $mw->update;
2047
2048 local $TODO;
2049 $TODO = "May fail on fluxbox" if !$TODO && $fluxbox_problems;
2050
2051 is($subject->state, "normal",
2052 q{deiconify on the master does a deiconify on the transient});
2053 is($subject->ismapped, 1);
2054 }
2055
2056 {
2057 deleteWindows;
2058 my $master = $mw->Toplevel;
2059 my $subject = $mw->Toplevel;
2060 poswin $master, $subject;
2061 $mw->update;
2062 $subject->transient($master);
2063 eval { $subject->transient(".bad") };
2064 ok($@, q{error during transient should not cause deletion of map/unmap binding});
2065 $master->withdraw;
2066 $mw->update;
2067
2068 local $TODO;
2069 $TODO = "May fail on some window managers (e.g. fvwm 2.5.x)"
2070 if $wm_problems;
2071
2072 is($subject->state, "withdrawn");
2073 $master->deiconify;
2074 $mw->update;
2075 is($subject->state, "normal");
2076 }
2077
2078 {
2079 deleteWindows;
2080 my $master = $mw->Toplevel;
2081 my $subject = $mw->Toplevel;
2082 poswin $master, $subject;
2083 $subject->transient($master);
2084 $mw->update;
2085 $master->destroy;
2086 $mw->update;
2087 is($subject->transient, undef,
2088 q{remove transient property when master is destroyed});
2089 }
2090
2091 {
2092 deleteWindows;
2093 my $master = $mw->Toplevel;
2094 my $subject = $mw->Toplevel;
2095 $subject->transient($master);
2096 $master->destroy;
2097 is($subject->transient, undef,
2098 q{remove transient property from unmapped window when master is destroyed});
2099 }
2100
2101 {
2102 deleteWindows;
2103 my $master = $mw->Toplevel;
2104 my $subject = $mw->Toplevel;
2105 poswin $master, $subject;
2106 $mw->update;
2107 $subject->transient($master);
2108 $subject->withdraw;
2109 $master->withdraw;
2110 $master->deiconify;
2111 # idle handler should not map the transient
2112 $mw->update;
2113 is($subject->state, q{withdrawn},
2114 q{a withdrawn transient does not track state changes in the master});
2115 }
2116
2117 {
2118 local $TODO;
2119 $TODO = "May fail on some window managers (e.g. fvwm 2.5.x)"
2120 if $wm_problems;
2121
2122 deleteWindows;
2123 my $master = $mw->Toplevel;
2124 my $subject = $mw->Toplevel;
2125 poswin $master, $subject;
2126 $mw->update;
2127 $subject->transient($master);
2128 $subject->withdraw;
2129 $master->withdraw;
2130 $master->deiconify;
2131 # idle handler should not map the transient
2132 $mw->update;
2133 is($subject->state, "withdrawn",
2134 q{a withdrawn transient does not track state changes in the master});
2135 $subject->deiconify;
2136 is($subject->state, "normal");
2137 $master->withdraw;
2138 is($subject->state, "withdrawn");
2139 $master->deiconify;
2140 # idle handler should map transient
2141 $mw->update;
2142 is($subject->state, "normal");
2143 }
2144
2145 {
2146 deleteWindows;
2147 my $master = $mw->Toplevel;
2148 my $subject = $mw->Toplevel;
2149 poswin $master, $subject;
2150 $mw->update;
2151 # withdraw before making window a transient
2152 $subject->withdraw;
2153 $subject->transient($master);
2154 $master->withdraw;
2155 $master->deiconify;
2156 # idle handler should not map the transient
2157 $mw->update;
2158 is($subject->state, q{withdrawn},
2159 q{a withdrawn transient does not track state changes in the master});
2160 }
2161
2162 {
2163 # wm-transient-7.*: See SF Tk Bug #592201 "wm transient fails with two masters"
2164 # wm-transient-7.3 through 7.5 all caused panics on Unix in Tk 8.4b1.
2165 # 7.1 and 7.2 added to catch (potential) future errors.
2166
2167 deleteWindows;
2168 my $t = $mw->Toplevel;
2169 my $transient = $mw->Toplevel;
2170 $transient->transient($t);
2171 $transient->destroy;
2172 $t->destroy;
2173 pass("Destroying transient did not cause a panic");
2174 }
2175
2176 {
2177 my $t = $mw->Toplevel;
2178 my $transient = $mw->Toplevel;
2179 $transient->transient($t);
2180 $t->destroy;
2181 is($transient->transient, undef);
2182 $transient->destroy;
2183 pass("Destroying master did not cause a panic");
2184 }
2185
2186 {
2187 deleteWindows;
2188 my $t1 = $mw->Toplevel;
2189 my $t2 = $mw->Toplevel;
2190 my $transient = $mw->Toplevel;
2191 $transient->transient($t1);
2192 $transient->transient($t2);
2193 $t1->destroy; # Caused panic in 8.4b1
2194 $t2->destroy;
2195 $transient->destroy;
2196 pass(q{Reassign transient, destroy old master});
2197 }
2198
2199 {
2200 deleteWindows;
2201 my $t1 = $mw->Toplevel;
2202 my $t2 = $mw->Toplevel;
2203 my $transient = $mw->Toplevel;
2204 $transient->transient($t1);
2205 $transient->transient($t2);
2206 $t2->destroy; # caused panic in 8.4b1
2207 $t1->destroy;
2208 $transient->destroy;
2209 pass(q{Reassign transient, destroy new master});
2210 }
2211
2212 {
2213 my $t1 = $mw->Toplevel;
2214 my $t2 = $mw->Toplevel;
2215 my $transient = $mw->Toplevel;
2216 $transient->transient($t1);
2217 $transient->transient($t2);
2218 $transient->destroy;
2219 $t2->destroy; # caused panic in 8.4b1
2220 $t1->destroy; # so did this
2221 pass(q{Reassign transient, destroy transient});
2222 }
2223
2224 {
2225 ### wm state ###
2226 eval { $mw->state("_", "_") };
2227 like($@, qr{\Qwrong # args: should be "wm state window ?state?"},
2228 "wm state usage");
2229 }
2230
2231 {
2232 deleteWindows;
2233 my $t = $mw->Toplevel;
2234 is($t->state, "normal", "initial state");
2235 }
2236
2237 {
2238 deleteWindows;
2239 my $t = $mw->Toplevel;
2240 $t->state("withdrawn");
2241 is($t->state, "withdrawn",
2242 q{state change before map});
2243 }
2244
2245 {
2246 deleteWindows;
2247 my $t = $mw->Toplevel;
2248 $t->withdraw;
2249 is($t->state, "withdrawn",
2250 q{state change before map});
2251 }
2252
2253 {
2254 deleteWindows;
2255 my $t = $mw->Toplevel;
2256 poswin $t;
2257 $mw->update;
2258 $t->state("withdrawn");
2259 is($t->state, "withdrawn",
2260 q{state change after map});
2261 }
2262
2263 {
2264 deleteWindows;
2265 my $t = $mw->Toplevel;
2266 poswin $t;
2267 $mw->update;
2268 $t->withdraw;
2269 is($t->state, "withdrawn",
2270 q{state change after map});
2271 }
2272
2273 SKIP: {
2274 skip("Needs a window manager", 1)
2275 if !$wm_running;
2276
2277 deleteWindows;
2278 my $t = $mw->Toplevel;
2279 $t->state("iconic");
2280 is($t->state, q{iconic},
2281 q{state change before map, iconic});
2282 }
2283
2284 {
2285 deleteWindows;
2286 my $t = $mw->Toplevel;
2287 $t->iconify;
2288 is($t->state, q{iconic},
2289 q{state change before map, iconic});
2290 }
2291
2292 SKIP: {
2293 skip("Needs a window manager", 1)
2294 if !$wm_running;
2295
2296 deleteWindows;
2297 my $t = $mw->Toplevel;
2298 poswin $t;
2299 $mw->update;
2300 $t->state("iconic");
2301 is($t->state, q{iconic},
2302 q{state change after map, iconic});
2303 }
2304
2305 SKIP: {
2306 skip("Needs a window manager", 1)
2307 if !$wm_running;
2308
2309 local $TODO;
2310 $TODO = "May fail on some window managers (e.g. fvwm 2.4.x or xfwm4 4.2.3.2)" if !$TODO && $wm_problems;
2311
2312 deleteWindows;
2313 my $t = $mw->Toplevel;
2314 poswin $t;
2315 $mw->update;
2316 $t->iconify;
2317 is($t->state, q{iconic},
2318 q{state change after map, iconic});
2319 }
2320
2321 {
2322 deleteWindows;
2323 my $t = $mw->Toplevel;
2324 $t->withdraw;
2325 $t->state("normal");
2326 is($t->state, "normal",
2327 q{state change before map, normal});
2328 }
2329
2330 {
2331 deleteWindows;
2332 my $t = $mw->Toplevel;
2333 $t->withdraw;
2334 $t->deiconify;
2335 is($t->state, "normal",
2336 q{state change before map, normal});
2337 }
2338
2339 {
2340 deleteWindows;
2341 my $t = $mw->Toplevel;
2342 poswin $t;
2343 $mw->update;
2344 $t->withdraw;
2345 $t->state("normal");
2346 if ($fvwm_problems && $t->state ne 'normal') { $t->deiconify }
2347 is($t->state, "normal",
2348 q{state change after map, normal});
2349 }
2350
2351 {
2352 deleteWindows;
2353 my $t = $mw->Toplevel;
2354 poswin $t;
2355 $mw->update;
2356 $t->withdraw;
2357 $t->deiconify;
2358 if ($fvwm_problems && $fvwm_problems && $t->state ne 'normal') { $t->deiconify }
2359 is($t->state, "normal",
2360 q{state change after map, normal});
2361 }
2362
2363 {
2364 deleteWindows;
2365 my $t = $mw->Toplevel;
2366 $t->iconify;
2367 $t->state("normal");
2368 is($t->state, "normal",
2369 q{state change before map, iconify+normal});
2370 }
2371
2372 {
2373 deleteWindows;
2374 my $t = $mw->Toplevel;
2375 $t->iconify;
2376 $t->deiconify;
2377 is($t->state, "normal",
2378 q{state change before map, iconify+normal});
2379 }
2380
2381 {
2382 deleteWindows;
2383 my $t = $mw->Toplevel;
2384 poswin $t;
2385 $mw->update;
2386 $t->iconify;
2387 $t->state("normal");
2388 is($t->state, "normal",
2389 q{state change after map, iconify+normal});
2390 }
2391
2392 {
2393 deleteWindows;
2394 my $t = $mw->Toplevel;
2395 poswin $t;
2396 $mw->update;
2397 $t->iconify;
2398 $t->deiconify;
2399 is($t->state, "normal",
2400 q{state change after map, iconify+normal});
2401 }
2402
2403 SKIP: {
2404 skip("zoomed only implemented on win", 1)
2405 if $Tk::platform ne 'MSWin32';
2406 deleteWindows;
2407 my $t = $mw->Toplevel;
2408 poswin $t;
2409 $mw->update;
2410 $t->state("zoomed");
2411 is($t->state, "zoomed",
2412 q{state change after map, zoomed});
2413 }
2414
2415 {
2416 ### wm withdraw ###
2417 eval { $mw->withdraw("_") };
2418 like($@, qr{\Qwrong # args: should be "wm withdraw window"},
2419 "wm withdraw usage");
2420 }
2421
2422 {
2423 deleteWindows;
2424 my $t = $mw->Toplevel(Name => "t");
2425 my $t2 = $mw->Toplevel(Name => "t2");
2426 poswin $t;
2427 $t->iconwindow($t2);
2428 eval { $t2->withdraw };
2429 like($@, qr{\Qcan't withdraw .t2: it is an icon for .t});
2430
2431 $mw->update;
2432 $t->withdraw;
2433 is($t->state, "withdrawn");
2434 is($t->ismapped, 0);
2435 $t->deiconify;
2436 if ($fvwm_problems && $t->state ne 'normal') { $t->deiconify }
2437 is($t->state, "normal");
2438 is($t->ismapped, 1);
2439 }
2440
2441 ### Misc. wm tests ###
2442
2443 if (0) {
2444 ## This test probably cannot be translated to Perl/Tk;
2445 ## also needs TK_ALT_DISPLAY defined
2446
2447 # See Tk Bug #671330 "segfault when e.g. deiconifying destroyed window"
2448 my $w = $mw->Toplevel(Name => "t", -screen => $ENV{TK_ALT_DISPLAY});
2449 my $w2 = $w;
2450 $w->deiconify ;# this caches the WindowRep
2451 $w->destroy;
2452 eval { $w2->deiconify };
2453 like($@, qr{\Qbad window path name ".t"},
2454 q{Deletion epoch on multiple displays});
2455 }
2456
2457 # FIXME:
2458
2459 # Test delivery of virtual events to the WM. We could check to see
2460 # if the window was raised after a button click for example.
2461 # This sort of testing may not be possible.
2462
2463 __END__