2020-09-16 19:34:38 +02:00
|
|
|
-- This project is licensed under the MIT License (see LICENSE).
|
|
|
|
|
2019-09-16 19:55:41 +02:00
|
|
|
--- Manage tags based on viewports.
|
|
|
|
--
|
|
|
|
-- Once connected to a screen via `viewport.connect(screen)`, selecting a single
|
2020-11-25 00:12:09 +01:00
|
|
|
-- tag will make that tag the active viewport. This tag will remember any other
|
2019-09-16 19:55:41 +02:00
|
|
|
-- selected tags when the viewport changes, so that when it is re-selected,
|
|
|
|
-- all previously selected tags are viewed.
|
|
|
|
--
|
|
|
|
-- @author James Reed <jcrd@tuta.io>
|
2020-11-25 00:12:09 +01:00
|
|
|
-- @copyright 2019-2020 James Reed
|
2019-09-16 19:55:41 +02:00
|
|
|
-- @module awesome-viewport
|
|
|
|
|
|
|
|
local awful = require("awful")
|
|
|
|
local gtable = require("gears.table")
|
|
|
|
|
|
|
|
local viewport = {}
|
|
|
|
|
|
|
|
local function update(s)
|
|
|
|
local selected = s.viewport and s.viewport.selected
|
|
|
|
if #s.selected_tags == 1 then
|
|
|
|
if selected then
|
|
|
|
s.viewport.scene = nil
|
|
|
|
return
|
|
|
|
end
|
|
|
|
s.viewport = s.selected_tag
|
|
|
|
if s.viewport.scene then
|
|
|
|
awful.tag.viewmore(s.viewport.scene, s)
|
|
|
|
end
|
|
|
|
elseif selected then
|
|
|
|
s.viewport.scene = s.selected_tags
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-25 00:12:09 +01:00
|
|
|
--- Get the active viewport of a given screen.
|
2019-10-23 20:26:44 +02:00
|
|
|
--
|
|
|
|
-- @param s The screen, defaults to `awful.screen.focused().selected_tag`.
|
|
|
|
-- @return The viewport tag.
|
|
|
|
-- @function viewport
|
|
|
|
local function get_viewport(s)
|
|
|
|
s = s or awful.screen.focused()
|
|
|
|
return s.viewport or s.selected_tag
|
|
|
|
end
|
2019-09-16 19:55:41 +02:00
|
|
|
|
|
|
|
local function tag(c)
|
|
|
|
if not c.first_tag then
|
2019-10-23 20:26:44 +02:00
|
|
|
c:toggle_tag(get_viewport(c.screen))
|
2019-09-16 19:55:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Begin managing the tags on a given screen.
|
|
|
|
--
|
|
|
|
-- @param s The screen.
|
|
|
|
function viewport.connect(s)
|
|
|
|
s:connect_signal("tag::history::update", update)
|
|
|
|
client.connect_signal("request::tag", tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Stop managing the tags on a given screen.
|
|
|
|
--
|
|
|
|
-- @param s The screen.
|
|
|
|
function viewport.disconnect(s)
|
|
|
|
s:disconnect_signal("tag::history::update", update)
|
|
|
|
client.disconnect_signal("request::tag", tag)
|
|
|
|
end
|
|
|
|
|
|
|
|
setmetatable(viewport, {__call = function (_, s) return get_viewport(s) end})
|
|
|
|
|
|
|
|
return viewport
|