From 6362a9082580edc8cdce71ebc1611a6f6eb2034f Mon Sep 17 00:00:00 2001 From: Perry Hargrave Date: Fri, 28 May 2010 16:39:17 -0700 Subject: [PATCH] tag.lua: move() re-index tags tag.move(i, t): move tag 't', or tag.selected(), to index 'i' in the current screen's tags table. Signed-off-by: Perry Hargrave Signed-off-by: Julien Danjou --- lib/awful/tag.lua.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/awful/tag.lua.in b/lib/awful/tag.lua.in index a984ed58..e2dc3b5a 100644 --- a/lib/awful/tag.lua.in +++ b/lib/awful/tag.lua.in @@ -30,6 +30,28 @@ data.tags = setmetatable({}, { __mode = 'k' }) history = {} history.limit = 20 +--- Move a tag to an absolute position in the screen[]:tags() table. +-- @param new_index Integer absolute position in the table to insert. +function move(new_index, target_tag) + local target_tag = target_tag or selected() + local scr = target_tag.screen + local tmp_tags = capi.screen[scr]:tags() + + if (not new_index) or (new_index < 1) or (new_index > #tmp_tags) then + return + end + + for i, t in ipairs(tmp_tags) do + if t == target_tag then + table.remove(tmp_tags, i) + break + end + end + + table.insert(tmp_tags, new_index, target_tag) + capi.screen[scr]:tags(tmp_tags) +end + --- Create a set of tags and attach it to a screen. -- @param names The tag name, in a table -- @param screen The tag screen, or 1 if not set.