From a40fdb86e105c22191c52cd1fd1419f69224bc96 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 27 Apr 2019 14:15:40 +0100 Subject: [PATCH] core: unmap overlay window when we first acquire it It used to be unmap when we receive its MapNotify, but now since we discard events received before we grab X server, that event it lost. But it turns out we can just unmap it when it's first created, no need to wait for the MapNotify. Partially fix #160 Signed-off-by: Yuxuan Shui --- src/compton.c | 29 +++++++++++++---------------- src/event.c | 1 - src/x.h | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/compton.c b/src/compton.c index c4b4b30c..0ed54e4f 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1104,20 +1104,17 @@ static bool init_overlay(session_t *ps) { if (ps->overlay) { // Set window region of the overlay window, code stolen from // compiz-0.8.8 - xcb_generic_error_t *e; - e = XCB_SYNCED_VOID(xcb_shape_mask, ps->c, XCB_SHAPE_SO_SET, - XCB_SHAPE_SK_BOUNDING, ps->overlay, 0, 0, 0); - if (e) { + if (!XCB_AWAIT_VOID(xcb_shape_mask, ps->c, XCB_SHAPE_SO_SET, + XCB_SHAPE_SK_BOUNDING, ps->overlay, 0, 0, 0)) { log_fatal("Failed to set the bounding shape of overlay, giving " "up."); - exit(1); + return false; } - e = XCB_SYNCED_VOID(xcb_shape_rectangles, ps->c, XCB_SHAPE_SO_SET, + if (!XCB_AWAIT_VOID(xcb_shape_rectangles, ps->c, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_CLIP_ORDERING_UNSORTED, - ps->overlay, 0, 0, 0, NULL); - if (e) { + ps->overlay, 0, 0, 0, NULL)) { log_fatal("Failed to set the input shape of overlay, giving up."); - exit(1); + return false; } // Listen to Expose events on the overlay @@ -1128,17 +1125,15 @@ static bool init_overlay(session_t *ps) { // overlay // root_damage = XDamageCreate(ps->dpy, root, XDamageReportNonEmpty); - // Unmap overlay, firstly. But this typically does not work because - // the window isn't created yet. - // xcb_unmap_window(c, ps->overlay); - // XFlush(ps->dpy); + // Unmap the overlay, we will map it when needed in redir_start + XCB_AWAIT_VOID(xcb_unmap_window, ps->c, ps->overlay); } else { log_error("Cannot get X Composite overlay window. Falling " "back to painting on root window."); } log_debug("overlay = %#010x", ps->overlay); - return ps->overlay; + return true; } /** @@ -1850,7 +1845,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy, log_fatal("No XRandR extension. sw-opti, refresh-rate or " "xinerama-shadow-crop " "cannot be enabled."); - exit(1); + goto err; } } @@ -1864,7 +1859,9 @@ static session_t *session_init(int argc, char **argv, Display *dpy, // Overlay must be initialized before double buffer, and before creation // of OpenGL context. - init_overlay(ps); + if (!init_overlay(ps)) { + goto err; + } ps->drivers = detect_driver(ps->c, ps->backend_data, ps->root); diff --git a/src/event.c b/src/event.c index afbcdde2..ed46fce9 100644 --- a/src/event.c +++ b/src/event.c @@ -169,7 +169,6 @@ static inline void ev_focus_out(session_t *ps, xcb_focus_out_event_t *ev) { static inline void ev_create_notify(session_t *ps, xcb_create_notify_event_t *ev) { assert(ev->parent == ps->root); - // TODO delay fill_win add_win_top(ps, ev->window); } diff --git a/src/x.h b/src/x.h index fbaa2fdf..7440a3e9 100644 --- a/src/x.h +++ b/src/x.h @@ -47,9 +47,20 @@ struct xvisual_info { xcb_visualid_t visual; }; -#define XCB_SYNCED_VOID(func, c, ...) \ - xcb_request_check(c, func##_checked(c, __VA_ARGS__)); -#define XCB_SYNCED(func, c, ...) \ +#define XCB_AWAIT_VOID(func, c, ...) \ + ({ \ + bool success = true; \ + __auto_type e = xcb_request_check(c, func##_checked(c, __VA_ARGS__)); \ + if (e) { \ + x_print_error(e->sequence, e->major_code, e->minor_code, \ + e->error_code); \ + free(e); \ + success = false; \ + } \ + success; \ + }) + +#define XCB_AWAIT(func, c, ...) \ ({ \ xcb_generic_error_t *e = NULL; \ __auto_type r = func##_reply(c, func(c, __VA_ARGS__), &e); \