diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 0b9f35e8..f199ac57 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -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 = "" + mylayoutbox[screen].text = + "" + + -- Update tag history + awful.tag.history.update(screen) -- Uncomment if you want mouse warping --[[ diff --git a/lib/awful.lua.in b/lib/awful.lua.in index 97bc977f..11211438 100644 --- a/lib/awful.lua.in +++ b/lib/awful.lua.in @@ -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.