From 66ad236d2e7bf4187271e69c8f4b2cb7d5d1b6eb Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 16 Apr 2016 14:58:00 +0200 Subject: [PATCH] Clean up after a removed screen When a screen is removed, we have to update screen.primary (if it was the removed screen) and assign a different screen to all clients which were on the removed screen. Signed-off-by: Uli Schlachter --- objects/screen.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/objects/screen.c b/objects/screen.c index cb5e441a..61d62662 100644 --- a/objects/screen.c +++ b/objects/screen.c @@ -506,6 +506,24 @@ screen_scan(void) screen_update_primary(); } +/* Called when a screen is removed, removes references to the old screen */ +static void +screen_removed(lua_State *L, int sidx) +{ + screen_t *screen = luaA_checkudata(L, sidx, &screen_class); + + luaA_object_emit_signal(L, sidx, "removed", 0); + + if (globalconf.primary_screen == screen) + globalconf.primary_screen = NULL; + + foreach(c, globalconf.clients) { + if((*c)->screen == screen) + screen_client_moveto(*c, screen_getbycoord( + (*c)->geometry.x, (*c)->geometry.y), false); + } +} + void screen_refresh(void) { @@ -547,14 +565,14 @@ screen_refresh(void) foreach(new_screen, new_screens) found |= (*new_screen)->xid == old_screen->xid; if(!found) { - luaA_object_push(L, old_screen); - luaA_object_emit_signal(L, -1, "removed", 0); - lua_pop(L, 1); screen_array_take(&globalconf.screens, i); + i--; + + luaA_object_push(L, old_screen); + screen_removed(L, -1); + lua_pop(L, 1); luaA_object_unref(L, old_screen); old_screen->valid = false; - - i--; } }