From c10322c82cea1d9b404fb25d4086ed81aadceea9 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 14 Sep 2012 14:40:59 +0200 Subject: [PATCH] lissajoux: Fix SHM-related errors This commit is a bad one. It does several things that ought to be separated into multiple commits: - It makes the main loop print a message on errors instead of silently ignoring them. This helps finding problems. - Instead of blindly assuming that SHM works, this now uses xcb_request_check() to make sure that the ShmAttach request really suceeds. - This makes the code open an override-redirect window because the drawing code uses (Shm)GetImage on the window, but nothing in the code waits for the first expose events. This means that if the WM isn't super fast and immediately maps the window, this will cause a Match error because the window wasn't mapped yet. Signed-off-by: Uli Schlachter --- tests/lissajoux.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/lissajoux.c b/tests/lissajoux.c index 2fa4378..c5c4834 100644 --- a/tests/lissajoux.c +++ b/tests/lissajoux.c @@ -130,6 +130,7 @@ void shm_test (Data *datap) { xcb_shm_query_version_reply_t *rep; + xcb_generic_error_t *error = NULL; rep = xcb_shm_query_version_reply (datap->conn, xcb_shm_query_version (datap->conn), @@ -157,14 +158,14 @@ shm_test (Data *datap) datap->image->data = shminfo.shmaddr; shminfo.shmseg = xcb_generate_id (datap->conn); - xcb_shm_attach (datap->conn, shminfo.shmseg, - shminfo.shmid, 0); + error = xcb_request_check (datap->conn, + xcb_shm_attach_checked (datap->conn, shminfo.shmseg, shminfo.shmid, 0)); shmctl_status = shmctl(shminfo.shmid, IPC_RMID, 0); assert(shmctl_status != -1); free (rep); } - if (datap->image) + if (datap->image && error == NULL) { printf ("Use of shm.\n"); do_shm = 1; @@ -175,6 +176,7 @@ shm_test (Data *datap) shmdt (shminfo.shmaddr); shmctl (shminfo.shmid, IPC_RMID, 0); datap->image = NULL; + free (error); } } @@ -188,7 +190,7 @@ main (int argc, char *argv[]) xcb_gcontext_t bgcolor; uint32_t mask; uint32_t valgc[2]; - uint32_t valwin[3]; + uint32_t valwin[4]; xcb_rectangle_t rect_coord = { 0, 0, W_W, W_H}; xcb_generic_event_t *e; int try_shm; @@ -229,10 +231,11 @@ main (int argc, char *argv[]) xcb_create_gc (data.conn, bgcolor, win, mask, valgc); data.draw = xcb_generate_id (data.conn); - mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE; + mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE; valwin[0] = screen->white_pixel; - valwin[1] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE; - valwin[2] = XCB_EVENT_MASK_BUTTON_PRESS; + valwin[1] = 1; + valwin[2] = XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE; + valwin[3] = XCB_EVENT_MASK_BUTTON_PRESS; xcb_create_window (data.conn, 0, data.draw, screen->root, @@ -264,6 +267,7 @@ main (int argc, char *argv[]) t_previous = 0.0; while (1) { + xcb_generic_error_t *error; e = xcb_poll_for_event(data.conn); if (e) { @@ -273,6 +277,11 @@ main (int argc, char *argv[]) xcb_copy_area(data.conn, rect, data.draw, bgcolor, 0, 0, 0, 0, W_W, W_H); break; + case 0: + error = (xcb_generic_error_t *) e; + printf("X error: request=(major %d, minor %d), error=%d\n", + error->major_code, error->minor_code, error->error_code); + break; } free (e); } -- 1.7.10.4