core: only grab X server when there indeed is new windows

Shouldn't grab X server for nothing.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-04-25 04:14:32 +01:00
parent 46b8eb8d4d
commit cfbd1819ed
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 30 additions and 20 deletions

View File

@ -378,9 +378,11 @@ typedef struct session {
// Cached blur convolution kernels. // Cached blur convolution kernels.
xcb_render_fixed_t *blur_kerns_cache[MAX_BLUR_PASS]; xcb_render_fixed_t *blur_kerns_cache[MAX_BLUR_PASS];
/// Reset program after next paint. /// Reset program after next paint.
bool reset; bool reset:1;
/// If compton should quit /// If compton should quit
bool quit; bool quit:1;
/// If new window has been added and not been handled
bool has_new_window:1;
// === Expose event related === // === Expose event related ===
/// Pointer to an array of <code>XRectangle</code>-s of exposed region. /// Pointer to an array of <code>XRectangle</code>-s of exposed region.

View File

@ -855,8 +855,7 @@ void configure_win(session_t *ps, xcb_configure_notify_event_t *ce) {
// If window geometry change, free old extents // If window geometry change, free old extents
if (mw->g.x != ce->x || mw->g.y != ce->y || mw->g.width != ce->width || if (mw->g.x != ce->x || mw->g.y != ce->y || mw->g.width != ce->width ||
mw->g.height != ce->height || mw->g.border_width != ce->border_width) mw->g.height != ce->height || mw->g.border_width != ce->border_width) {
{
factor_change = true; factor_change = true;
} }
@ -1412,6 +1411,7 @@ static void handle_new_windows(session_t *ps) {
} }
} }
} }
ps->has_new_window = false;
} }
/** /**
@ -1429,10 +1429,14 @@ static void fade_timer_callback(EV_P_ ev_timer *w, int revents) {
} }
static void _draw_callback(EV_P_ session_t *ps, int revents) { static void _draw_callback(EV_P_ session_t *ps, int revents) {
if (ps->has_new_window) {
log_debug("Delayed handling of new window events, entering critical "
"section");
auto e = xcb_request_check(ps->c, xcb_grab_server_checked(ps->c)); auto e = xcb_request_check(ps->c, xcb_grab_server_checked(ps->c));
if (e) { if (e) {
log_fatal("failed to grab x server"); log_fatal("failed to grab x server");
x_print_error(e->full_sequence, e->major_code, e->minor_code, e->error_code); x_print_error(e->full_sequence, e->major_code, e->minor_code,
e->error_code);
return quit_compton(ps); return quit_compton(ps);
} }
@ -1445,9 +1449,12 @@ static void _draw_callback(EV_P_ session_t *ps, int revents) {
e = xcb_request_check(ps->c, xcb_ungrab_server_checked(ps->c)); e = xcb_request_check(ps->c, xcb_ungrab_server_checked(ps->c));
if (e) { if (e) {
log_fatal("failed to ungrab x server"); log_fatal("failed to ungrab x server");
x_print_error(e->full_sequence, e->major_code, e->minor_code, e->error_code); x_print_error(e->full_sequence, e->major_code, e->minor_code,
e->error_code);
return quit_compton(ps); return quit_compton(ps);
} }
log_debug("Exiting critical section");
}
if (ps->o.benchmark) { if (ps->o.benchmark) {
if (ps->o.benchmark_wid) { if (ps->o.benchmark_wid) {

View File

@ -958,6 +958,7 @@ static struct win *add_win(session_t *ps, xcb_window_t id, struct list_node *pre
new_w->destroyed = false; new_w->destroyed = false;
HASH_ADD_INT(ps->windows, id, new_w); HASH_ADD_INT(ps->windows, id, new_w);
ps->has_new_window = true;
return new_w; return new_w;
} }