shifty: auto prefix position to tag name

This commit is contained in:
Vincent Bernat 2012-09-10 22:25:13 +02:00
parent f6db47d7e1
commit 62db148161
2 changed files with 49 additions and 33 deletions

View file

@ -7,7 +7,6 @@
-- Modified version for my own use (Vincent Bernat) -- Modified version for my own use (Vincent Bernat)
-- --
-- TODO: -- TODO:
-- - Add tag position before the name automatically
-- - Auto numbering of tags. -- - Auto numbering of tags.
-- - Don't ask for names for new tag, just put a number. -- - Don't ask for names for new tag, just put a number.
-- - Maybe name a tag after first client. -- - Maybe name a tag after first client.
@ -61,6 +60,31 @@ local matchp = ""
local index_cache = {} local index_cache = {}
for i = 1, capi.screen.count() do index_cache[i] = {} end for i = 1, capi.screen.count() do index_cache[i] = {} end
--getname: return the "user" name of a tag
-- @param t : tag
-- @return username of the tag
local function getname(t)
local name = awful.tag.getproperty(t, "shortname")
if name then
return name
end
return t.name
end
--setname: set the "user" name of a tag and update its name
-- @param t : tag
-- @param name : new name
local function setname(t, name)
if name then
local dispname = name
awful.tag.setproperty(t, "shortname", name)
if awful.tag.getproperty(t, "position") then
dispname = awful.tag.getproperty(t, "position") .. '' .. dispname
end
t.name = dispname
end
end
--name2tags: matches string 'name' to tag objects --name2tags: matches string 'name' to tag objects
-- @param name : tag name to find -- @param name : tag name to find
-- @param scr : screen to look for tags on -- @param scr : screen to look for tags on
@ -70,7 +94,7 @@ function name2tags(name, scr)
local a, b = scr or 1, scr or capi.screen.count() local a, b = scr or 1, scr or capi.screen.count()
for s = a, b do for s = a, b do
for i, t in ipairs(capi.screen[s]:tags()) do for i, t in ipairs(capi.screen[s]:tags()) do
if name == t.name then if name == getname(t) then
table.insert(ret, t) table.insert(ret, t)
end end
end end
@ -95,16 +119,14 @@ end
--rename --rename
--@param tag: tag object to be renamed --@param tag: tag object to be renamed
--@param prefix: if any prefix is to be added function rename(tag, no_selectall)
--@param no_selectall:
function rename(tag, prefix, no_selectall)
local theme = beautiful.get() local theme = beautiful.get()
local t = tag or awful.tag.selected(capi.mouse.screen) local t = tag or awful.tag.selected(capi.mouse.screen)
local scr = t.screen local scr = t.screen
local bg = nil local bg = nil
local fg = nil local fg = nil
local text = prefix or t.name local text = getname(t)
local before = t.name local before = getname(t)
if t == awful.tag.selected(scr) then if t == awful.tag.selected(scr) then
bg = theme.bg_focus or '#535d6c' bg = theme.bg_focus or '#535d6c'
@ -118,12 +140,12 @@ function rename(tag, prefix, no_selectall)
fg_cursor = fg, bg_cursor = bg, ul_cursor = "single", fg_cursor = fg, bg_cursor = bg, ul_cursor = "single",
text = text, selectall = not no_selectall}, text = text, selectall = not no_selectall},
taglist[scr][tag2index(scr, t) * 2], taglist[scr][tag2index(scr, t) * 2],
function (name) if name:len() > 0 then t.name = name; end end, function (name) if name:len() > 0 then setname(t, name); end end,
completion, completion,
awful.util.getdir("cache") .. "/history_tags", awful.util.getdir("cache") .. "/history_tags",
nil, nil,
function () function ()
if t.name == before then if getname(t) == before then
if awful.tag.getproperty(t, "initial") then del(t) end if awful.tag.getproperty(t, "initial") then del(t) end
else else
awful.tag.setproperty(t, "initial", true) awful.tag.setproperty(t, "initial", true)
@ -213,11 +235,11 @@ function set(t, args)
if not args then args = {} end if not args then args = {} end
-- set the name -- set the name
t.name = args.name or t.name setname(t, args.name or getname(t))
-- attempt to load preset on initial run -- attempt to load preset on initial run
local preset = (awful.tag.getproperty(t, "initial") and local preset = (awful.tag.getproperty(t, "initial") and
config.tags[t.name]) or {} config.tags[getname(t)]) or {}
-- pick screen and get its tag table -- pick screen and get its tag table
local scr = args.screen or local scr = args.screen or
@ -304,8 +326,8 @@ function set(t, args)
elseif props.position then elseif props.position then
idx = pos2idx(props.position, scr) idx = pos2idx(props.position, scr)
if t_idx and t_idx < idx then idx = idx - 1 end if t_idx and t_idx < idx then idx = idx - 1 end
elseif config.remember_index and index_cache[scr][t.name] then elseif config.remember_index and index_cache[scr][getname(t)] then
idx = index_cache[scr][t.name] idx = index_cache[scr][getname(t)]
elseif not t_idx then elseif not t_idx then
idx = #tags + 1 idx = #tags + 1
end end
@ -314,7 +336,7 @@ function set(t, args)
if idx then if idx then
if t_idx then table.remove(tags, t_idx) end if t_idx then table.remove(tags, t_idx) end
table.insert(tags, idx, t) table.insert(tags, idx, t)
index_cache[scr][t.name] = idx index_cache[scr][getname(t)] = idx
end end
-- set tag properties and push the new tag table -- set tag properties and push the new tag table
@ -362,18 +384,13 @@ function add(args)
-- get the name or rename -- get the name or rename
if args.name then if args.name then
t.name = args.name setname(t, args.name)
else else
-- FIXME: hack to delay rename for un-named tags for -- FIXME: hack to delay rename for un-named tags for
-- tackling taglist refresh which disabled prompt -- tackling taglist refresh which disabled prompt
-- from being rendered until input -- from being rendered until input
awful.tag.setproperty(t, "initial", true) awful.tag.setproperty(t, "initial", true)
local f local f = function() rename(t); tmr:stop() end
if args.position then
f = function() rename(t, args.rename, true); tmr:stop() end
else
f = function() rename(t); tmr:stop() end
end
tmr = capi.timer({timeout = 0.01}) tmr = capi.timer({timeout = 0.01})
tmr:add_signal("timeout", f) tmr:add_signal("timeout", f)
tmr:start() tmr:start()
@ -400,7 +417,7 @@ function del(tag)
if #clients > sticky then return end if #clients > sticky then return end
-- store index for later -- store index for later
index_cache[scr][t.name] = idx index_cache[scr][getname(t)] = idx
-- remove tag -- remove tag
t.screen = nil t.screen = nil
@ -740,8 +757,7 @@ function getpos(pos, scr_arg)
if not v then if not v then
-- not existing, not preconfigured -- not existing, not preconfigured
v = add({position = pos, v = add({position = pos,
rename = pos .. '', name = i,
no_selectall = true,
noswitch = not switch}) noswitch = not switch})
end end
return v return v
@ -830,7 +846,7 @@ function completion(cmd, cur_pos, ncomp, sources, matchers)
capi.mouse.screen + i - 1) capi.mouse.screen + i - 1)
local tags = capi.screen[s]:tags() local tags = capi.screen[s]:tags()
for j, t in pairs(tags) do for j, t in pairs(tags) do
table.insert(ret, t.name) table.insert(ret, getname(t))
end end
end end
return ret return ret

View file

@ -11,7 +11,7 @@ local tagicon = function(icon)
end end
shifty.config.tags = { shifty.config.tags = {
["3↭www"] = { www = {
position = 3, position = 3,
mwfact = 0.7, mwfact = 0.7,
exclusive = true, exclusive = true,
@ -21,7 +21,7 @@ shifty.config.tags = {
spawn = browser, spawn = browser,
icon = tagicon("web") icon = tagicon("web")
}, },
["2↭emacs"] = { emacs = {
position = 2, position = 2,
mwfact = 0.6, mwfact = 0.6,
exclusive = true, exclusive = true,
@ -29,7 +29,7 @@ shifty.config.tags = {
spawn = "emacs", spawn = "emacs",
icon = tagicon("dev"), icon = tagicon("dev"),
}, },
["1↭xterm"] = { xterm = {
position = 1, position = 1,
layout = awful.layout.suit.fair, layout = awful.layout.suit.fair,
exclusive = true, exclusive = true,
@ -37,7 +37,7 @@ shifty.config.tags = {
spawn = config.terminal, spawn = config.terminal,
icon = tagicon("main"), icon = tagicon("main"),
}, },
["4↭im"] = { im = {
position = 4, position = 4,
mwfact = 0.2, mwfact = 0.2,
exclusive = true, exclusive = true,
@ -50,20 +50,20 @@ shifty.config.tags = {
shifty.config.apps = { shifty.config.apps = {
{ {
match = { role = { "browser" } }, match = { role = { "browser" } },
tag = "3↭www", tag = "www",
}, },
{ {
match = { "emacs" }, match = { "emacs" },
tag = "2↭emacs", tag = "emacs",
}, },
{ {
match = { role = { "conversation", "buddy_list" } }, match = { role = { "conversation", "buddy_list" } },
tag = "4↭im", tag = "im",
}, },
{ {
match = { "URxvt" }, match = { "URxvt" },
startup = { startup = {
tag = "1↭xterm" tag = "xterm"
}, },
intrusive = true, -- Display even on exclusive tags intrusive = true, -- Display even on exclusive tags
}, },