]> git.sur5r.net Git - i3/i3/blob - testcases/t/221-floating-type-hints.t
Respect minimum size hints for floating windows. (#2508)
[i3/i3] / testcases / t / 221-floating-type-hints.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Verifies that windows with properties that indicate they should be floating
18 # are indeed opened floating.
19 # Ticket: #1182
20 # Bug still in: 4.7.2-97-g84fc808
21 use i3test;
22 use X11::XCB qw(PROP_MODE_REPLACE);
23
24 sub open_with_type {
25     my $window_type = shift;
26
27     my $window = open_window(
28         window_type => $x->atom(name => $window_type),
29     );
30     return $window;
31 }
32
33 sub open_with_state {
34     my $window_state = shift;
35
36     my $window = open_window(
37         before_map => sub {
38             my ($window) = @_;
39
40             my $atomname = $x->atom(name => '_NET_WM_STATE');
41             my $atomtype = $x->atom(name => 'ATOM');
42             $x->change_property(
43                 PROP_MODE_REPLACE,
44                 $window->id,
45                 $atomname->id,
46                 $atomtype->id,
47                 32,
48                 1,
49                 pack('L1', $x->atom(name => $window_state)->id),
50             );
51         },
52     );
53
54     return $window;
55 }
56
57 sub open_with_fixed_size {
58     # The type of the WM_NORMAL_HINTS property is WM_SIZE_HINTS
59     # http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.3
60     my $XCB_ICCCM_SIZE_HINT_P_MIN_SIZE = 0x32;
61     my $XCB_ICCCM_SIZE_HINT_P_MAX_SIZE = 0x16;
62
63     my $flags = $XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | $XCB_ICCCM_SIZE_HINT_P_MAX_SIZE;
64
65     my $min_width = 150;
66     my $max_width = 150;
67     my $min_height = 100;
68     my $max_height = 100;
69
70     my $pad = 0x00;
71
72     my $window = open_window(
73         before_map => sub {
74             my ($window) = @_;
75
76             my $atomname = $x->atom(name => 'WM_NORMAL_HINTS');
77             my $atomtype = $x->atom(name => 'WM_SIZE_HINTS');
78             $x->change_property(
79                 PROP_MODE_REPLACE,
80                 $window->id,
81                 $atomname->id,
82                 $atomtype->id,
83                 32,
84                 12,
85                 pack('C5N7', $flags, $pad, $pad, $pad, $pad, 0, 0, 0, $min_width, $min_height, $max_width, $max_height),
86             );
87         },
88     );
89
90     return $window;
91 }
92
93 my $ws = fresh_workspace;
94
95 my $window = open_with_type '_NET_WM_WINDOW_TYPE_DIALOG';
96 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window}, $window->id, 'Dialog window opened floating');
97 $window->unmap;
98
99 $window = open_with_type '_NET_WM_WINDOW_TYPE_UTILITY';
100 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window}, $window->id, 'Utility window opened floating');
101 $window->unmap;
102
103 $window = open_with_type '_NET_WM_WINDOW_TYPE_TOOLBAR';
104 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window}, $window->id, 'Toolbar window opened floating');
105 $window->unmap;
106
107 $window = open_with_type '_NET_WM_WINDOW_TYPE_SPLASH';
108 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window}, $window->id, 'Splash window opened floating');
109 $window->unmap;
110
111 $window = open_with_state '_NET_WM_STATE_MODAL';
112 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window}, $window->id, 'Modal window opened floating');
113 $window->unmap;
114
115 $window = open_with_fixed_size;
116 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window}, $window->id, 'Fixed size window opened floating');
117 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window_rect}->{width}, 150, 'Fixed size window opened with minimum width');
118 is(get_ws($ws)->{floating_nodes}[0]->{nodes}[0]->{window_rect}->{height}, 100, 'Fixed size window opened with minimum height');
119 $window->unmap;
120
121 done_testing;