Skip to content

Commit

Permalink
core: unmap overlay window when we first acquire it
Browse files Browse the repository at this point in the history
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 <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Apr 27, 2019
1 parent b3d8dfb commit f38ae36
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
29 changes: 13 additions & 16 deletions src/compton.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
17 changes: 14 additions & 3 deletions src/x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down

0 comments on commit f38ae36

Please sign in to comment.