From 9cf8f90004f37d7987e2cd4d82b8456deed9ef85 Mon Sep 17 00:00:00 2001 From: Drauthius Date: Sat, 30 Jan 2021 10:11:28 +0100 Subject: [PATCH] Fix moving of tags on disconnected screen Resolves #7 --- init.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index b731f35..6fc87f6 100644 --- a/init.lua +++ b/init.lua @@ -117,26 +117,31 @@ function sharedtags.movetag(tag, screen) screen = screen or awful.screen.focused() local oldscreen = tag.screen - -- If the specified tag is allocated to another screen, we need to move it. - if oldscreen ~= screen then - local oldsel = oldscreen.selected_tag - tag.screen = screen + -- If the specified tag is allocated to another screen, we need to move it, + -- or if the tag no longer belongs to a screen. + if oldscreen ~= screen or not oldscreen then + -- Try to find a new tag to show on the previous screen if the currently + -- selected tag is the one that was moved away. + if oldscreen then + local oldsel = oldscreen.selected_tag + tag.screen = screen - if oldsel == tag then - -- The tag has been moved away. In most cases the tag history - -- function will find the best match, but if we really want we can - -- try to find a fallback tag as well. - if not oldscreen.selected_tag then - local newtag = awful.tag.find_fallback(oldscreen) - if newtag then - newtag:view_only() + if oldsel == tag then + -- The tag has been moved away. In most cases the tag history + -- function will find the best match, but if we really want we can + -- try to find a fallback tag as well. + if not oldscreen.selected_tag then + local newtag = awful.tag.find_fallback(oldscreen) + if newtag then + newtag:view_only() + end end end end -- Also sort the tag in the taglist, by reapplying the index. This is just a nicety. local unpack = unpack or table.unpack - for _,s in ipairs({ screen, oldscreen }) do + for _,s in ipairs({ screen, oldscreen or { tags = {} } }) do local tags = { unpack(s.tags) } -- Copy table.sort(tags, function(a, b) return a.sharedtagindex < b.sharedtagindex end) for i,t in ipairs(tags) do