Skip to content

Commit 2bff4f1

Browse files
committed
Synchronize with i3bar+i3, not just i3.
1 parent ce21de8 commit 2bff4f1

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

i3bar/include/xcb_atoms.def

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ ATOM_DO(_NET_SYSTEM_TRAY_OPCODE)
99
ATOM_DO(_NET_SYSTEM_TRAY_COLORS)
1010
ATOM_DO(_XEMBED_INFO)
1111
ATOM_DO(_XEMBED)
12+
ATOM_DO(I3_SYNC)
1213
#undef ATOM_DO

i3bar/src/xcb.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,26 @@ static void configure_trayclients(void) {
678678
*
679679
*/
680680
static void handle_client_message(xcb_client_message_event_t *event) {
681-
if (event->type == atoms[_NET_SYSTEM_TRAY_OPCODE] &&
682-
event->format == 32) {
681+
if (event->type == atoms[I3_SYNC]) {
682+
xcb_window_t window = event->data.data32[0];
683+
uint32_t rnd = event->data.data32[1];
684+
DLOG("[i3 sync protocol] Forwarding random value %d, X11 window 0x%08x to i3\n", rnd, window);
685+
686+
void *reply = scalloc(32, 1);
687+
xcb_client_message_event_t *ev = reply;
688+
689+
ev->response_type = XCB_CLIENT_MESSAGE;
690+
ev->window = window;
691+
ev->type = atoms[I3_SYNC];
692+
ev->format = 32;
693+
ev->data.data32[0] = window;
694+
ev->data.data32[1] = rnd;
695+
696+
xcb_send_event(conn, false, xcb_root, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char *)ev);
697+
xcb_flush(conn);
698+
free(reply);
699+
} else if (event->type == atoms[_NET_SYSTEM_TRAY_OPCODE] &&
700+
event->format == 32) {
683701
DLOG("_NET_SYSTEM_TRAY_OPCODE received\n");
684702
/* event->data.data32[0] is the timestamp */
685703
uint32_t op = event->data.data32[1];

testcases/lib/i3test/XTEST.pm

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use ExtUtils::PkgConfig;
1414
use Exporter ();
1515
our @EXPORT = qw(
1616
inlinec_connect
17+
xtest_sync_with
1718
xtest_sync_with_i3
1819
set_xkb_group
1920
xtest_key_press
@@ -118,7 +119,7 @@ bool inlinec_connect() {
118119
return true;
119120
}
120121
121-
void xtest_sync_with_i3() {
122+
void xtest_sync_with(int window) {
122123
xcb_client_message_event_t ev;
123124
memset(&ev, '\0', sizeof(xcb_client_message_event_t));
124125
@@ -131,7 +132,7 @@ void xtest_sync_with_i3() {
131132
ev.data.data32[0] = sync_window;
132133
ev.data.data32[1] = nonce;
133134
134-
xcb_send_event(conn, false, root_window, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char *)&ev);
135+
xcb_send_event(conn, false, (xcb_window_t)window, XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, (char *)&ev);
135136
xcb_flush(conn);
136137
137138
xcb_generic_event_t *event = NULL;
@@ -176,6 +177,10 @@ void xtest_sync_with_i3() {
176177
free(event);
177178
}
178179
180+
void xtest_sync_with_i3() {
181+
xtest_sync_with((int)root_window);
182+
}
183+
179184
// NOTE: while |group| should be a uint8_t, Inline::C will not define the
180185
// function unless we use an int.
181186
bool set_xkb_group(int group) {
@@ -287,6 +292,11 @@ Sends a ButtonRelease event via XTEST, with the specified C<$button>.
287292
288293
Returns false when there was an X11 error, true otherwise.
289294
295+
=head2 xtest_sync_with($window)
296+
297+
Ensures the specified window has processed all X11 events which were triggered
298+
by this module, provided the window response to the i3 sync protocol.
299+
290300
=head2 xtest_sync_with_i3()
291301
292302
Ensures i3 has processed all X11 events which were triggered by this module.

testcases/t/525-i3bar-mouse-bindings.t

+11-7
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sub i3bar_present {
6161
for my $node (@{$nodes}) {
6262
my $props = $node->{window_properties};
6363
if (defined($props) && $props->{class} eq 'i3bar') {
64-
return 1;
64+
return $node->{window};
6565
}
6666
}
6767

@@ -73,13 +73,17 @@ sub i3bar_present {
7373
return i3bar_present(\@children);
7474
}
7575

76-
if (i3bar_present($i3->get_tree->recv->{nodes})) {
76+
my $i3bar_window = i3bar_present($i3->get_tree->recv->{nodes});
77+
if ($i3bar_window) {
7778
ok(1, 'i3bar present');
7879
} else {
7980
my $con = $cv->recv;
8081
ok($con, 'i3bar appeared');
82+
$i3bar_window = $con->{window};
8183
}
8284

85+
diag('i3bar window = ' . $i3bar_window);
86+
8387
my $left = open_window;
8488
my $right = open_window;
8589
sync_with_i3;
@@ -99,7 +103,7 @@ subtest 'button 1 moves focus left', \&focus_subtest,
99103
sub {
100104
xtest_button_press(1, 3, 3);
101105
xtest_button_release(1, 3, 3);
102-
xtest_sync_with_i3;
106+
xtest_sync_with($i3bar_window);
103107
},
104108
[ $left->{id} ],
105109
'button 1 moves focus left';
@@ -108,7 +112,7 @@ subtest 'button 2 moves focus right', \&focus_subtest,
108112
sub {
109113
xtest_button_press(2, 3, 3);
110114
xtest_button_release(2, 3, 3);
111-
xtest_sync_with_i3;
115+
xtest_sync_with($i3bar_window);
112116
},
113117
[ $right->{id} ],
114118
'button 2 moves focus right';
@@ -117,7 +121,7 @@ subtest 'button 3 moves focus left', \&focus_subtest,
117121
sub {
118122
xtest_button_press(3, 3, 3);
119123
xtest_button_release(3, 3, 3);
120-
xtest_sync_with_i3;
124+
xtest_sync_with($i3bar_window);
121125
},
122126
[ $left->{id} ],
123127
'button 3 moves focus left';
@@ -126,7 +130,7 @@ subtest 'button 4 moves focus right', \&focus_subtest,
126130
sub {
127131
xtest_button_press(4, 3, 3);
128132
xtest_button_release(4, 3, 3);
129-
xtest_sync_with_i3;
133+
xtest_sync_with($i3bar_window);
130134
},
131135
[ $right->{id} ],
132136
'button 4 moves focus right';
@@ -135,7 +139,7 @@ subtest 'button 5 moves focus left', \&focus_subtest,
135139
sub {
136140
xtest_button_press(5, 3, 3);
137141
xtest_button_release(5, 3, 3);
138-
xtest_sync_with_i3;
142+
xtest_sync_with($i3bar_window);
139143
},
140144
[ $left->{id} ],
141145
'button 5 moves focus left';

0 commit comments

Comments
 (0)