diff --git a/init.lua b/init.lua index 40868ef..e2c5d11 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,9 @@ -- Grab environment we need local awful = require("awful") +local capi = { + screen = screen +} local sharedtags = { _VERSION = "sharedtags v1.0.0 for v4.0", @@ -36,6 +39,35 @@ local sharedtags = { ]] } +-- Add a signal for each new screen, which just listens for the remove +-- event, and moves over all tags when it happens. +awful.screen.connect_for_each_screen(function(s) + -- When the screen is removed, all tags need to be moved over to an existing + -- screen. If they are not, accessing the tags will result in an error. It + -- doesn't make sense to fix the error, since clients on the now-hidden tags + -- will automatically be moved to a tag on a visible screen. + s:connect_signal("removed",function() + -- The screen to move the orphaned tags to. + local newscreen = capi.screen.primary + -- The currently selected tags on that screen. + local seltags = newscreen.selected_tags + + -- Move over all tags to an existing screen. + for _,tag in ipairs(s.tags) do + sharedtags.movetag(tag, newscreen) + end + + -- Restore the viewed tags on the new screen. + for i,tag in ipairs(seltags) do + if i == 1 then + tag:view_only() + else + awful.tag.viewtoggle(tag) + end + end + end) +end) + --- Create new tag objects. -- The first tag defined for each screen will be automatically selected. -- @tparam table def A list of tables with the optional keys `name`, `layout` @@ -60,7 +92,7 @@ function sharedtags.new(def) for i,t in ipairs(def) do tags[i] = awful.tag.add(t.name or i, { - screen = t.screen or awful.screen.primary, + screen = (t.screen and t.screen <= capi.screen.count()) and t.screen or capi.screen.primary, layout = t.layout, sharedtagindex = i })