tag: tag.get() now returns an 'hash' table

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-18 16:04:49 +02:00
parent 7709b22261
commit 471e0f1088
2 changed files with 23 additions and 16 deletions

View File

@ -138,7 +138,7 @@ local function tag_selectedlist(s)
local screen = s or mouse.screen_get() local screen = s or mouse.screen_get()
local tags = tag.get(screen) local tags = tag.get(screen)
local vtags = {} local vtags = {}
for i, t in ipairs(tags) do for i, t in pairs(tags) do
if t:isselected() then if t:isselected() then
vtags[idx] = t vtags[idx] = t
idx = idx + 1 idx = idx + 1
@ -204,7 +204,7 @@ end
-- View no tag -- View no tag
local function tag_viewnone() local function tag_viewnone()
local tags = tag.get(mouse.screen_get()) local tags = tag.get(mouse.screen_get())
for i, t in ipairs(tags) do for i, t in pairs(tags) do
t:view(false) t:view(false)
end end
end end
@ -212,11 +212,13 @@ end
local function tag_viewidx(r) local function tag_viewidx(r)
local tags = tag.get(mouse.screen_get()) local tags = tag.get(mouse.screen_get())
local sel = tag_selected() local sel = tag_selected()
local i = 1
tag_viewnone() tag_viewnone()
for i, t in ipairs(tags) do for name, t in pairs(tags) do
if t == sel then if t == sel then
tags[array_boundandcycle(tags, i + r)]:view(true) tags[array_boundandcycle(tags, i + r)]:view(true)
end end
i = i + 1
end end
end end
@ -237,7 +239,7 @@ end
local function tag_viewmore(tags) local function tag_viewmore(tags)
tag_viewnone() tag_viewnone()
for i, t in ipairs(tags) do for i, t in pairs(tags) do
t:view(true) t:view(true)
end end
end end
@ -245,7 +247,7 @@ end
local function client_movetotag(target, c) local function client_movetotag(target, c)
local sel = c or client.focus_get(); local sel = c or client.focus_get();
local tags = tag.get(mouse.screen_get()) local tags = tag.get(mouse.screen_get())
for i, t in ipairs(tags) do for i, t in pairs(tags) do
sel:tag(t, false) sel:tag(t, false)
end end
sel:tag(target, true) sel:tag(target, true)
@ -254,16 +256,18 @@ end
local function client_toggletag(target, c) local function client_toggletag(target, c)
local sel = c or client.focus_get(); local sel = c or client.focus_get();
local toggle = false local toggle = false
-- Count how many tags has the client if sel then
-- an only toggle tag if the client has at least one tag other than target -- Count how many tags has the client
for k, v in ipairs(tag.get(sel:screen_get())) do -- an only toggle tag if the client has at least one tag other than target
if target ~= v and sel:istagged(v) then for k, v in pairs(tag.get(sel:screen_get())) do
toggle = true if target ~= v and sel:istagged(v) then
break toggle = true
break
end
end
if toggle then
sel:tag(target, not sel:istagged(target))
end end
end
if toggle and sel then
sel:tag(target, not sel:istagged(target))
end end
end end

7
tag.c
View File

@ -267,8 +267,12 @@ luaA_tag_add(lua_State *L)
for(i = 0; i < globalconf.screens_info->nscreen; i++) for(i = 0; i < globalconf.screens_info->nscreen; i++)
for(t = globalconf.screens[i].tags; t; t = t->next) for(t = globalconf.screens[i].tags; t; t = t->next)
{
if(*tag == t) if(*tag == t)
luaL_error(L, "tag already on screen %d", i + 1); luaL_error(L, "tag already on screen %d", i + 1);
else if(t->screen == screen && !a_strcmp((*tag)->name, t->name))
luaL_error(L, "a tag with the name `%s' is already on screen %d", t->name, i + 1);
}
(*tag)->screen = screen; (*tag)->screen = screen;
tag_append_to_screen(*tag, screen); tag_append_to_screen(*tag, screen);
@ -287,7 +291,6 @@ luaA_tag_get(lua_State *L)
{ {
int screen = luaL_checknumber(L, 1) - 1; int screen = luaL_checknumber(L, 1) - 1;
tag_t *tag; tag_t *tag;
int i = 1;
luaA_checkscreen(screen); luaA_checkscreen(screen);
@ -296,7 +299,7 @@ luaA_tag_get(lua_State *L)
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
{ {
luaA_tag_userdata_new(tag); luaA_tag_userdata_new(tag);
lua_rawseti(L, -2, i++); lua_setfield(L, -2, tag->name);
} }
return 1; return 1;