2

After docking and undocking the laptop, as a result of two screens disappearing and one screen appearing or vice-a-versa, all windows are migrated to one screen.

How to accomplish the following desired behavior: keep windows associated with disconnected screens, with the tags the had on those screens, letting these windows be invisible (that's ok), until I explicitly choose to migrate a specific window to the current screen (via a lua command / script of some sort that lets me browse the list of windows). Also, when the screen configuration changes back (e.g. upon re-docking), all windows should become accessible, as if no screen changes ever happened. The use case is that, while undocked, I don't need to access all windows.

I looked at no_offscreen, but it didn't seem to be related. Not really sure where to begin.

2 Answers 2

2

You need to implement a request::screen handler on the tag and move the tags to the remaining screen. Then optionally add a taglist filter to hide them. Once the screen is back, move the tags back to the original screen

See https://www.reddit.com/r/awesomewm/comments/5r9mgu/client_layout_not_preserved_when_switching/ for a close enough example.

Another way would be to stop using "real" screens and use "fake" ones. This way you can ignore the fact that they are disconnected and keep it as if it was still there. This require some more mechanic to prevent the "real" screen from overlapping a the fake one (a recipe for disaster)

1

Taking Emmanuel's answer as the guide, here's what seems to work for me.

My screen.outputs where nil, so I created an ID from resolution:

function firstkey(t) -- sorry, not a Lua programmer...
for i, e in pairs(t) do
    return i
end
return nil
end

local function get_screen_id(s)
    return tostring(s.geometry.width) .. "x" .. tostring(s.geometry.height) .. "x" .. tostring(firstkey(s.outputs))
end

In awful.screen.connect_for_each_screen(function(s):

-- Check if existing tags belong to this new screen that's being added
local restored = false;
local all_tags = root.tags()
for i, t in pairs(all_tags) do
    if get_screen_id(s) == t.screen_id then
        t.screen = s
        restored = true;
    end
end

-- On restored screen, select a tag
-- If this screen is entirely brand new, then create tags for it
if restored then
    local first_tag = nil;
    for i, t in pairs(s.tags) do -- not sure how else to get first elem
        first_tag = t
        break
    end
    first_tag.selected = true
else
    -- Each screen has its own tag table.
    awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layoutThens[1])

    -- Assign the tag to this screen, to restore as the screen disconnects/connects
    for k, v in pairs(s.tags) do
        v.screen_id = get_screen_id(s)
    end
end

And handle the signal when screen disappears:

tag.connect_signal("request::screen", function(t)
    -- Screen has disconnected, re-assign orphan tags to a live screen

    -- Find a live screen
    local live_screen = nil;
    for s in screen do
        if s ~= t.screen then
            live_screen = s;
            break
        end
    end

    -- Move the orphaned tag to the live screen
    t.screen = live_screen
end)
2
  • for i, t in pairs(s.tags) do -- not sure how else to get first elem Use: s.tags[1] Commented Feb 5, 2017 at 23:49
  • I think the live_screen code can be replaced by mouse.screen or screen.primary. This will need to be tested. Commented Feb 5, 2017 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.