]> git.sur5r.net Git - i3/i3/blob - testcases/t/301-shape.t
attach_to_workspace: set new parent before tree_render
[i3/i3] / testcases / t / 301-shape.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 # Test shape support.
18 # Ticket: #2742
19 use i3test;
20 use ExtUtils::PkgConfig;
21
22 my %sn_config;
23 BEGIN {
24     %sn_config = ExtUtils::PkgConfig->find('xcb-shape');
25 }
26
27 use Inline C => Config => LIBS => $sn_config{libs}, CCFLAGS => $sn_config{cflags};
28 use Inline C => <<'END_OF_C_CODE';
29 #include <xcb/shape.h>
30
31 static xcb_connection_t *conn;
32
33 void init_ctx(void *connptr) {
34     conn = (xcb_connection_t*)connptr;
35 }
36
37 /*
38  * Set the shape for the window consisting of the following zones:
39  *
40  *   +---+---+
41  *   | A | B |
42  *   +---+---+
43  *   |   C   |
44  *   +-------+
45  *
46  * - Zone A is completly opaque.
47  * - Zone B is clickable through (input shape).
48  * - Zone C is completly transparent (bounding shape).
49  */
50 void set_shape(long window_id) {
51     xcb_rectangle_t bounding_rectangle = { 0, 0, 100, 50 };
52     xcb_shape_rectangles(conn, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING,
53                          XCB_CLIP_ORDERING_UNSORTED, window_id,
54                          0, 0, 1, &bounding_rectangle);
55     xcb_rectangle_t input_rectangle = { 0, 0, 50, 50 };
56     xcb_shape_rectangles(conn, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT,
57                          XCB_CLIP_ORDERING_UNSORTED, window_id,
58                          0, 0, 1, &input_rectangle);
59     xcb_flush(conn);
60 }
61 END_OF_C_CODE
62
63 init_ctx($x->get_xcb_conn());
64
65 my ($ws, $win1, $win1_focus, $win2, $win2_focus);
66
67 ################################################################################
68 # Case 1: make floating window, then set shape
69 ################################################################################
70
71 $ws = fresh_workspace;
72
73 $win1 = open_floating_window(rect => [0, 0, 100, 100], background_color => '#ff0000');
74 $win1_focus = get_focused($ws);
75
76 $win2 = open_floating_window(rect => [0, 0, 100, 100], background_color => '#00ff00');
77 $win2_focus = get_focused($ws);
78 set_shape($win2->id);
79
80 $win1->warp_pointer(75, 25);
81 sync_with_i3;
82 is(get_focused($ws), $win1_focus, 'focus switched to the underlying window');
83
84 $win1->warp_pointer(25, 25);
85 sync_with_i3;
86 is(get_focused($ws), $win2_focus, 'focus switched to the top window');
87
88 kill_all_windows;
89
90 ################################################################################
91 # Case 2: set shape first, then make window floating
92 ################################################################################
93
94 $ws = fresh_workspace;
95
96 $win1 = open_window(rect => [0, 0, 100, 100], background_color => '#ff0000');
97 $win1_focus = get_focused($ws);
98 cmd 'floating toggle';
99
100 $win2 = open_window(rect => [0, 0, 100, 100], background_color => '#00ff00');
101 $win2_focus = get_focused($ws);
102 set_shape($win2->id);
103 cmd 'floating toggle';
104 sync_with_i3;
105
106 $win1->warp_pointer(75, 25);
107 sync_with_i3;
108 is(get_focused($ws), $win1_focus, 'focus switched to the underlying window');
109
110 $win1->warp_pointer(25, 25);
111 sync_with_i3;
112 is(get_focused($ws), $win2_focus, 'focus switched to the top window');
113
114 done_testing;