From 7df9245c819087b5fcbbb4ae626aec66e05a2119 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 19 Sep 2019 16:59:36 +0100 Subject: [PATCH] win: move image update code into a function Signed-off-by: Yuxuan Shui --- src/compton.c | 14 +------------- src/win.c | 15 +++++++++++++++ src/win.h | 3 +++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/compton.c b/src/compton.c index 8a544bc..7f8d514 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1283,19 +1283,7 @@ static void handle_new_windows(session_t *ps) { static void refresh_stale_images(session_t *ps) { win_stack_foreach_managed(w, &ps->window_stack) { - if ((w->flags & WIN_FLAGS_IMAGE_STALE) != 0 && - (w->flags & WIN_FLAGS_IMAGE_ERROR) == 0) { - // Image needs to be updated, update it. - w->flags &= ~WIN_FLAGS_IMAGE_STALE; - if (w->state != WSTATE_UNMAPPING && - w->state != WSTATE_DESTROYING && ps->backend_data) { - // Rebind image only when the window does have an image - // available - if (!win_try_rebind_image(ps, w)) { - w->flags |= WIN_FLAGS_IMAGE_ERROR; - } - } - } + win_process_flags(ps, w); } } diff --git a/src/win.c b/src/win.c index 1c41214..697405b 100644 --- a/src/win.c +++ b/src/win.c @@ -301,6 +301,21 @@ bool win_try_rebind_image(session_t *ps, struct managed_win *w) { return win_bind_image(ps, w); } +void win_process_flags(struct session *ps, struct managed_win *w) { + if ((w->flags & WIN_FLAGS_IMAGE_STALE) != 0 && (w->flags & WIN_FLAGS_IMAGE_ERROR) == 0) { + // Image needs to be updated, update it. + w->flags &= ~WIN_FLAGS_IMAGE_STALE; + if (w->state != WSTATE_UNMAPPING && w->state != WSTATE_DESTROYING && + ps->backend_data) { + // Rebind image only when the window does have an image + // available + if (!win_try_rebind_image(ps, w)) { + w->flags |= WIN_FLAGS_IMAGE_ERROR; + } + } + } +} + /** * Check if a window has rounded corners. * XXX This is really dumb diff --git a/src/win.h b/src/win.h index 6171a8d..fb5086c 100644 --- a/src/win.h +++ b/src/win.h @@ -253,6 +253,9 @@ struct managed_win { void win_release_image(struct backend_base *base, struct managed_win *w); bool must_use win_bind_image(session_t *ps, struct managed_win *w); +/// Process pending images flags on a window. Has to be called in X critical section +void win_process_flags(session_t *ps, struct managed_win *w); + /// Attempt a rebind of window's images. If that failed, the original images are kept. bool must_use win_try_rebind_image(session_t *ps, struct managed_win *w); int win_get_name(session_t *ps, struct managed_win *w);