From 5e49ab08610aa241a609a577cf7ca1464e8cb45d Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Fri, 25 Jan 2019 00:27:38 +0000 Subject: [PATCH] Make sure draw_idle is stopped in all cases Previously, compton fails to stop draw_idle in some cases when sw_opti is enabled. sw_opti is a feature that limits the draw frequence to vblank frequence. It adds a delay to drawing when the screen is updated more frequently than the vblank frequence. However when the delay is not used (i.e. the screen is updated infrequent enough), compton will start drawing the frame directly without using the delay. And specically in this case, compton will fail to stop the draw_idle, causing a callback to be called once per loop of the mainloop, resulting in high CPU usage. Fixes #92 Signed-off-by: Yuxuan Shui --- src/compton.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compton.c b/src/compton.c index d5dcc52..4a0cd00 100644 --- a/src/compton.c +++ b/src/compton.c @@ -2482,12 +2482,16 @@ static void delayed_draw_callback(EV_P_ ev_idle *w, int revents) { // This function is only used if we are using --swopti session_t *ps = session_ptr(w, draw_idle); - if (ev_is_active(&ps->delayed_draw_timer)) - return; + assert(ps->redraw_needed); + assert(!ev_is_active(&ps->delayed_draw_timer)); double delay = swopti_handle_timeout(ps); - if (delay < 1e-6) + if (delay < 1e-6) { + if (!ps->o.benchmark) { + ev_idle_stop(ps->loop, &ps->draw_idle); + } return _draw_callback(EV_A_ ps, revents); + } // This is a little bit hacky. When we get to this point in code, we need // to update the screen , but we will only be updating after a delay, So