Tags on a removed screen will be moved to the primary screen.
When disconnecting a screen, it would previously leave the tags on the old screen, throwing errors when trying to move them to an existing screen. This change makes sure that the tags are moved over to an existing screen when the screen is removed. It doesn't make sense to allow tags without screens, since all clients (programs) that were on the old tags will be moved to another tag on an existing screen anyway. awful.screen.connect_for_each_screen(func) can be used to restore tags to a screen when it is connected again. Closes #2.
This commit is contained in:
parent
54f5929fc5
commit
8a7ddc006b
34
init.lua
34
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
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue