From 6cfa589f03b10d379ca1a035e1be6a4ed8364f4a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 18 Jun 2008 17:56:24 +0200 Subject: [PATCH] tag: introduce geti() to get tag with numbers as index Signed-off-by: Julien Danjou --- awful.lua | 10 ++++------ tag.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/awful.lua b/awful.lua index 907004a5..cef35bb1 100644 --- a/awful.lua +++ b/awful.lua @@ -136,7 +136,7 @@ end local function tag_selectedlist(s) local idx = 1 local screen = s or mouse.screen_get() - local tags = tag.get(screen) + local tags = tag.geti(screen) local vtags = {} for i, t in pairs(tags) do if t:isselected() then @@ -210,15 +210,13 @@ local function tag_viewnone() end local function tag_viewidx(r) - local tags = tag.get(mouse.screen_get()) + local tags = tag.geti(mouse.screen_get()) local sel = tag_selected() - local i = 1 tag_viewnone() - for name, t in pairs(tags) do + for i, t in ipairs(tags) do if t == sel then tags[array_boundandcycle(tags, i + r)]:view(true) end - i = i + 1 end end @@ -247,7 +245,7 @@ end local function client_movetotag(target, c) local sel = c or client.focus_get(); local tags = tag.get(mouse.screen_get()) - for i, t in pairs(tags) do + for k, t in pairs(tags) do sel:tag(t, false) end sel:tag(target, true) diff --git a/tag.c b/tag.c index a0041f45..71943491 100644 --- a/tag.c +++ b/tag.c @@ -282,7 +282,7 @@ luaA_tag_add(lua_State *L) * * \luastack * \lparam A screen number. - * \lreturn A table with all tags from the screen specified. + * \lreturn A table with all tags from the screen specified, indexed by tag name. */ static int luaA_tag_get(lua_State *L) @@ -303,6 +303,33 @@ luaA_tag_get(lua_State *L) return 1; } +/** Get all tags from a screen. + * \param L The Lua VM state. + * + * \luastack + * \lparam A screen number. + * \lreturn A table with all tags from the screen specified, ordered and indexed + * by number. + */ +static int +luaA_tag_geti(lua_State *L) +{ + int i = 1, screen = luaL_checknumber(L, 1) - 1; + tag_t *tag; + + luaA_checkscreen(screen); + + lua_newtable(L); + + for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) + { + luaA_tag_userdata_new(tag); + lua_rawseti(L, -2, i++); + } + + return 1; +} + /** Create a new tag. * \param L The Lua VM state. * @@ -581,7 +608,8 @@ DO_LUA_EQ(tag_t, tag, "tag") const struct luaL_reg awesome_tag_methods[] = { { "new", luaA_tag_new }, - { "get", luaA_tag_get}, + { "get", luaA_tag_get }, + { "geti", luaA_tag_geti }, { NULL, NULL } }; const struct luaL_reg awesome_tag_meta[] =