core: track whether server is grabbed

This commit is contained in:
Yuxuan Shui 2019-08-08 00:46:56 +01:00
parent 02139b7c9f
commit 4e915837a4
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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;