From: Michael Stapelberg Date: Sun, 31 Jul 2011 17:33:56 +0000 (+0200) Subject: Bugfix: Same xcb_send_event fix as 1e0033bce4 X-Git-Tag: 4.0~14^2~8 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fa1fe3cfedacdc52267ecf82ea74d6d2a42a6820;p=i3%2Fi3 Bugfix: Same xcb_send_event fix as 1e0033bce4 --- diff --git a/src/x.c b/src/x.c index 5136bf44..e93e90e7 100644 --- a/src/x.c +++ b/src/x.c @@ -215,20 +215,23 @@ void x_window_kill(xcb_window_t window, kill_window_t kill_window) { return; } - xcb_client_message_event_t ev; - - memset(&ev, 0, sizeof(xcb_client_message_event_t)); - - ev.response_type = XCB_CLIENT_MESSAGE; - ev.window = window; - ev.type = A_WM_PROTOCOLS; - ev.format = 32; - ev.data.data32[0] = A_WM_DELETE_WINDOW; - ev.data.data32[1] = XCB_CURRENT_TIME; + /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. + * In order to properly initialize these bytes, we allocate 32 bytes even + * though we only need less for an xcb_configure_notify_event_t */ + void *event = scalloc(32); + xcb_client_message_event_t *ev = event; + + ev->response_type = XCB_CLIENT_MESSAGE; + ev->window = window; + ev->type = A_WM_PROTOCOLS; + ev->format = 32; + ev->data.data32[0] = A_WM_DELETE_WINDOW; + ev->data.data32[1] = XCB_CURRENT_TIME; LOG("Sending WM_DELETE to the client\n"); - xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char*)&ev); + xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char*)ev); xcb_flush(conn); + free(event); } /* diff --git a/src/xcb.c b/src/xcb.c index 82991c9a..4497338b 100644 --- a/src/xcb.c +++ b/src/xcb.c @@ -219,19 +219,21 @@ void fake_absolute_configure_notify(Con *con) { * */ void send_take_focus(xcb_window_t window) { - xcb_client_message_event_t ev; - - memset(&ev, 0, sizeof(xcb_client_message_event_t)); + /* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes. + * In order to properly initialize these bytes, we allocate 32 bytes even + * though we only need less for an xcb_configure_notify_event_t */ + void *event = scalloc(32); + xcb_client_message_event_t *ev = event; - ev.response_type = XCB_CLIENT_MESSAGE; - ev.window = window; - ev.type = A_WM_PROTOCOLS; - ev.format = 32; - ev.data.data32[0] = A_WM_TAKE_FOCUS; - ev.data.data32[1] = XCB_CURRENT_TIME; + ev->response_type = XCB_CLIENT_MESSAGE; + ev->window = window; + ev->type = A_WM_PROTOCOLS; + ev->format = 32; + ev->data.data32[0] = A_WM_TAKE_FOCUS; + ev->data.data32[1] = XCB_CURRENT_TIME; DLOG("Sending WM_TAKE_FOCUS to the client\n"); - xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char*)&ev); + xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char*)ev); } /*