2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
20 use ExtUtils::PkgConfig;
24 %sn_config = ExtUtils::PkgConfig->find('xcb-shape');
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>
31 static xcb_connection_t *conn;
33 void init_ctx(void *connptr) {
34 conn = (xcb_connection_t*)connptr;
38 * Set the shape for the window consisting of the following zones:
46 * - Zone A is completly opaque.
47 * - Zone B is clickable through (input shape).
48 * - Zone C is completly transparent (bounding shape).
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);
63 init_ctx($x->get_xcb_conn());
65 my ($ws, $win1, $win1_focus, $win2, $win2_focus);
67 ################################################################################
68 # Case 1: make floating window, then set shape
69 ################################################################################
71 $ws = fresh_workspace;
73 $win1 = open_floating_window(rect => [0, 0, 100, 100], background_color => '#ff0000');
74 $win1_focus = get_focused($ws);
76 $win2 = open_floating_window(rect => [0, 0, 100, 100], background_color => '#00ff00');
77 $win2_focus = get_focused($ws);
80 $win1->warp_pointer(75, 25);
82 is(get_focused($ws), $win1_focus, 'focus switched to the underlying window');
84 $win1->warp_pointer(25, 25);
86 is(get_focused($ws), $win2_focus, 'focus switched to the top window');
90 ################################################################################
91 # Case 2: set shape first, then make window floating
92 ################################################################################
94 $ws = fresh_workspace;
96 $win1 = open_window(rect => [0, 0, 100, 100], background_color => '#ff0000');
97 $win1_focus = get_focused($ws);
98 cmd 'floating toggle';
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';
106 $win1->warp_pointer(75, 25);
108 is(get_focused($ws), $win1_focus, 'focus switched to the underlying window');
110 $win1->warp_pointer(25, 25);
112 is(get_focused($ws), $win2_focus, 'focus switched to the top window');