win: move image update code into a function

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-09-19 16:59:36 +01:00
parent de5d5ca9bb
commit 7df9245c81
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 19 additions and 13 deletions

View File

@ -1283,19 +1283,7 @@ static void handle_new_windows(session_t *ps) {
static void refresh_stale_images(session_t *ps) { static void refresh_stale_images(session_t *ps) {
win_stack_foreach_managed(w, &ps->window_stack) { win_stack_foreach_managed(w, &ps->window_stack) {
if ((w->flags & WIN_FLAGS_IMAGE_STALE) != 0 && win_process_flags(ps, w);
(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;
}
}
}
} }
} }

View File

@ -301,6 +301,21 @@ bool win_try_rebind_image(session_t *ps, struct managed_win *w) {
return win_bind_image(ps, 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. * Check if a window has rounded corners.
* XXX This is really dumb * XXX This is really dumb

View File

@ -253,6 +253,9 @@ struct managed_win {
void win_release_image(struct backend_base *base, struct managed_win *w); 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); 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. /// 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); 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); int win_get_name(session_t *ps, struct managed_win *w);