From 4e915837a4556c8578d628df2a521a4c9922adec Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 8 Aug 2019 00:46:56 +0100 Subject: [PATCH] core: track whether server is grabbed --- src/common.h | 2 ++ src/compton.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index d48961d..c55f758 100644 --- a/src/common.h +++ b/src/common.h @@ -158,6 +158,8 @@ typedef struct session { struct ev_loop *loop; // === Display related === + /// Whether the X server is grabbed by us + bool server_grabbed; /// Display in use. Display *dpy; /// Previous handler of X errors diff --git a/src/compton.c b/src/compton.c index bfb4d73..b3a1145 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1328,6 +1328,8 @@ static void _draw_callback(EV_P_ session_t *ps, int revents attr_unused) { return quit_compton(ps); } + ps->server_grabbed = true; + // Catching up with X server handle_queued_x_events(EV_A_ & ps->event_check, 0); @@ -1342,6 +1344,8 @@ static void _draw_callback(EV_P_ session_t *ps, int revents attr_unused) { // Refresh pixmaps refresh_stale_images(ps); + ps->server_grabbed = false; + e = xcb_request_check(ps->c, xcb_ungrab_server_checked(ps->c)); if (e) { log_fatal("failed to ungrab x server"); @@ -1990,6 +1994,8 @@ static session_t *session_init(int argc, char **argv, Display *dpy, goto err; } + ps->server_grabbed = true; + // We are going to pull latest information from X server now, events sent by X // earlier is irrelavant at this point. // A better solution is probably grabbing the server from the very start. But I @@ -2000,12 +2006,13 @@ static session_t *session_init(int argc, char **argv, Display *dpy, xcb_query_tree_reply(ps->c, xcb_query_tree(ps->c, ps->root), NULL); e = xcb_request_check(ps->c, xcb_ungrab_server(ps->c)); - if (e) { log_error("Failed to ungrab server"); free(e); } + ps->server_grabbed = false; + if (query_tree_reply) { xcb_window_t *children; int nchildren;