assert(w);
window_unlink(w);
+ w->cache->n_windows--;
free(w);
}
w = new0(Window, 1);
if (!w)
return NULL;
+ m->n_windows++;
} else {
/* Reuse an existing one */
c->window = NULL;
LIST_REMOVE(Context, by_window, w->contexts, c);
- if (!w->contexts) {
+ if (!w->contexts && !w->keep_always) {
/* Not used anymore? */
LIST_PREPEND(Window, unused, c->cache->unused, w);
if (!c->cache->last_unused)
context_detach_window(c);
- if (!w->contexts) {
+ if (w->in_unused) {
/* Used again? */
LIST_REMOVE(Window, unused, c->cache->unused, w);
- if (!c->cache->last_unused)
- c->cache->last_unused = w;
+ if (c->cache->last_unused == w)
+ c->cache->last_unused = w->unused_prev;
w->in_unused = false;
}