From d8a93dafa316dd9f3f0b0cd2e4891a7e1295f4fa Mon Sep 17 00:00:00 2001 From: cdump Date: Wed, 2 Jan 2013 15:06:45 +0100 Subject: [PATCH] awful.tag: add index property for custom tag order Signed-off-by: Uli Schlachter --- lib/awful/tag.lua.in | 20 +++++++++++++++++++- lib/awful/widget/taglist.lua.in | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in index 0a5899b5d..cbaed182a 100644 --- a/lib/awful/tag.lua.in +++ b/lib/awful/tag.lua.in @@ -55,7 +55,8 @@ function tag.move(new_index, target_tag) table.insert(tmp_tags, new_index, target_tag) - for _, tmp_tag in ipairs(tmp_tags) do + for i, tmp_tag in ipairs(tmp_tags) do + tag.setproperty(tmp_tag, "index", i) tag.setscreen(tmp_tag, scr) end end @@ -244,6 +245,22 @@ function tag.gettags(s) table.insert(tags, t) end end + + local without_index = 0 + for _, t in ipairs(tags) do + if not tag.getproperty(t, "index") then + without_index = without_index + 1 + end + end + if without_index > 0 then + for _, t in ipairs(tags) do + if not tag.getproperty(t, "index") then + tag.setproperty(t, "index", (#tags - without_index + 1)) + end + end + end + + table.sort(tags, function(a, b) return tag.getproperty(a, "index") < tag.getproperty(b, "index") end) return tags end @@ -563,6 +580,7 @@ capi.tag.add_signal("property::ncol") capi.tag.add_signal("property::nmaster") capi.tag.add_signal("property::windowfact") capi.tag.add_signal("property::screen") +capi.tag.add_signal("property::index") for s = 1, capi.screen.count() do capi.screen[s]:add_signal("tag::history::update") diff --git a/lib/awful/widget/taglist.lua.in b/lib/awful/widget/taglist.lua.in index f9b77079a..e10b4cfc5 100644 --- a/lib/awful/widget/taglist.lua.in +++ b/lib/awful/widget/taglist.lua.in @@ -162,6 +162,7 @@ function taglist.new(screen, filter, buttons, style, update_function, base_widge tag.attached_connect_signal(screen, "property::name", ut) tag.attached_connect_signal(screen, "property::activated", ut) tag.attached_connect_signal(screen, "property::screen", ut) + tag.attached_connect_signal(screen, "property::index", ut) capi.client.connect_signal("property::urgent", uc) capi.client.connect_signal("property::screen", function(c) -- If client change screen, refresh it anyway since we don't from