Howdy. The commit title is self explanatory. However:

1. please test first
2. the changeset is incomplete in terms of tag selection handling in
the default rc:

-- taglist right click won't atm affect history since it doesn't use
awful functions:

   awful.button({ }, 3, function (tag) tag.selected = not tag.selected end)

we could replace it with some kind of awful.tag.viewtoggle:

  function(t)
    t.selected = not tag.selected
    capi.screen[screen]:emit_signal("tag::update_history")
  end

or just add that emit to the rc.lua but that's dirty. Suggestions as
to preferred solution welcome, patches will follow.

-- same with default binding:

  awful.key({ modkey, "Control" }, i,



good?
k
From 80889280c009bc1288e476a53497638c1dd4ef9e Mon Sep 17 00:00:00 2001
From: koniu <gkusni...@gmail.com>
Date: Thu, 27 Aug 2009 15:03:45 +0100
Subject: [PATCH] awful.tag: fix tag history

This fixes a long standing tag history breakage. To store history
of tag switching we rely on a special signal "tag::update_history"
which needs to be emitted by any function which deals with tag
selection. 

The history is now multi-level and limited to 20 steps.

Signed-off-by: koniu <gkusni...@gmail.com>
---
 lib/awful/tag.lua.in |   36 ++++++++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in
index 8ec1bbd..5ef4f45 100644
--- a/lib/awful/tag.lua.in
+++ b/lib/awful/tag.lua.in
@@ -24,7 +24,6 @@ module("awful.tag")
 -- Private data
 local data = {}
 data.history = {}
-data.history.past = {}
 data.history.current = {}
 data.tags = setmetatable({}, { __mode = 'k' })
 
@@ -77,15 +76,22 @@ function new(names, screen, layout)
 end
 
 --- Update the tag history.
--- @param screen The screen number.
-function history.update(screen)
+-- @param obj Screen object.
+function history.update(obj)
+    local screen = obj.index
     local curtags = capi.screen[screen]:tags()
-    if not compare_select(curtags, data.history.current[screen]) then
-        data.history.past[screen] = data.history.current[screen]
-        data.history.current[screen] = {}
-        for k, v in ipairs(curtags) do
-            data.history.current[screen][k] = v.selected
+    if not compare_select(curtags, data.history.current[screen]) and #selectedlist(screen) > 0 then
+        -- create history table
+        if not data.history[screen] then
+          data.history[screen] = {} 
+        -- limit history to 20 steps
+        elseif #data.history[screen] == 20 then
+            table.remove(data.history[screen])
         end
+        -- store previously selected tags in the history table
+        table.insert(data.history[screen], 1, data.history.current[screen])
+        -- store currently selected tags
+        data.history.current[screen] = selectedlist(screen)
     end
 end
 
@@ -94,9 +100,12 @@ end
 function history.restore(screen)
     local s = screen or capi.mouse.screen
     local tags = capi.screen[s]:tags()
-    for k, t in pairs(tags) do
-        t.selected = data.history.past[s][k]
+    viewnone(s)
+    for _, t in ipairs(data.history[s][1]) do
+        t.selected = true
     end
+    data.history.current[screen] = data.history[s][1]
+    table.remove(data.history[s], 1)
 end
 
 --- Return a table with all visible tags
@@ -231,6 +240,7 @@ function viewidx(i, screen)
             showntags[util.cycle(#showntags, k + i)].selected = true
         end
     end
+    capi.screen[screen]:emit_signal("tag::update_history")
 end
 
 --- View next tag. This is the same as tag.viewidx(1).
@@ -250,6 +260,7 @@ end
 function viewonly(t)
     viewnone(t.screen)
     t.selected = true
+    capi.screen[t.screen]:emit_signal("tag::update_history")
 end
 
 --- View only a set of tags.
@@ -260,6 +271,7 @@ function viewmore(tags, screen)
     for i, t in pairs(tags) do
         t.selected = true
     end
+    capi.screen[screen]:emit_signal("tag::update_history")
 end
 
 --- Get tag data table.
@@ -339,6 +351,10 @@ capi.client.add_signal("manage", function(c)
     c:add_signal("property::screen", withcurrent)
 end)
 
+for s = 1, capi.screen.count() do
+    capi.screen[s]:add_signal("tag::update_history", history.update)
+end
+
 setmetatable(_M, { __call = function (_, ...) return new(...) end })
 
 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
-- 
1.6.3.3

Reply via email to