awful: implement tag history

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-30 15:37:05 +02:00
parent 2dcd2d11cb
commit f0af665795
2 changed files with 58 additions and 2 deletions

View File

@ -187,6 +187,7 @@ end
keybinding({ modkey }, "Left", awful.tag.viewprev):add()
keybinding({ modkey }, "Right", awful.tag.viewnext):add()
keybinding({ modkey }, "Escape", awful.tag.history.restore):add()
-- Standard program
keybinding({ modkey }, "Return", function () awful.spawn(terminal) end):add()
@ -346,8 +347,11 @@ end
-- Hook function to execute when arranging the screen
-- (tag switch, new client, etc)
function hook_arrange(screen)
local layout = awful.layout.get(screen)
mylayoutbox[screen].text = "<bg image=\"@AWESOME_ICON_PATH@/layouts/" .. layout .. "w.png\" resize=\"true\"/>"
mylayoutbox[screen].text =
"<bg image=\"@AWESOME_ICON_PATH@/layouts/" .. awful.layout.get(screen) .. "w.png\" resize=\"true\"/>"
-- Update tag history
awful.tag.history.update(screen)
-- Uncomment if you want mouse warping
--[[

View File

@ -45,6 +45,10 @@ P.screen = {}
P.layout = {}
P.client = {}
P.tag = {}
P.tag.history = {}
P.tag.history.data = {}
P.tag.history.data.past = {}
P.tag.history.data.current = {}
P.titlebar = {}
P.widget = {}
P.widget.taglist = {}
@ -174,6 +178,54 @@ function P.screen.focus(i)
mouse.coords = screen.coords_get(s)
end
--- Compare 2 tables of tags.
-- @param a The first table.
-- @param b The second table of tags.
-- @return True if the tables are identical, false otherwise.
local function tag_compare_select(a, b)
if not a or not b then
return false
end
-- Quick size comparison
if #a ~= #b then
return false
end
for ka, va in pairs(a) do
if b[ka] ~= va.selected then
return false
end
end
for kb, vb in pairs(b) do
if a[kb].selected ~= vb then
return false
end
end
return true
end
--- Update the tag history.
-- @param screen The screen number.
function P.tag.history.update(screen)
local curtags = tag.geti(screen)
if not tag_compare_select(curtags, P.tag.history.data.current[screen]) then
P.tag.history.data.past[screen] = P.tag.history.data.current[screen]
P.tag.history.data.current[screen] = {}
for k, v in ipairs(curtags) do
P.tag.history.data.current[screen][k] = v.selected
end
end
end
-- Revert tag history.
-- @param screen The screen number.
function P.tag.history.restore(screen)
local s = screen or mouse.screen
local tags = tag.geti(s)
for k, t in pairs(tags) do
t.selected = P.tag.history.data.past[s][k]
end
end
--- Return a table with all visible tags
-- @param s Screen number.
-- @return A table with all selected tags.