From f84187228d2ec7c3b25c3988631acfcdd977a0f8 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Mon, 10 Sep 2012 22:45:46 +0200 Subject: [PATCH] shifty: automatically add a position if there is a free one --- lib/shifty.lua | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/shifty.lua b/lib/shifty.lua index 487b706..0357082 100644 --- a/lib/shifty.lua +++ b/lib/shifty.lua @@ -7,8 +7,6 @@ -- Modified version for my own use (Vincent Bernat) -- -- TODO: --- - Auto numbering of tags. --- - Don't ask for names for new tag, just put a number. -- - Maybe name a tag after first client. @@ -85,6 +83,37 @@ local function setname(t, name) end end +--freeposition: get a free position +local function freeposition() + local positions = {1, 2, 3, 4, 5, 6, 7, 8, 9} + for k, a in pairs(config.tags) do + if a.startup then + a = awful.util.table.join(a, a.startup) + end + if a.position then + local idx = awful.util.table.hasitem(positions, a.position) + if idx then + table.remove(positions, idx) + end + end + end + for s = 1, capi.screen.count() do + for i, t in ipairs(capi.screen[s]:tags()) do + local pos = awful.tag.getproperty(t, "position") + if pos then + local idx = awful.util.table.hasitem(positions, pos) + if idx then + table.remove(positions, idx) + end + end + end + end + if #positions > 0 then + return positions[1] + end + return nil +end + --name2tags: matches string 'name' to tag objects -- @param name : tag name to find -- @param scr : screen to look for tags on @@ -294,7 +323,7 @@ function set(t, args) awful.tag.getproperty(t, "max_clients"), config.defaults.max_clients}, position = select{args.position, preset.position, - awful.tag.getproperty(t, "position")}, + awful.tag.getproperty(t, "position"), freeposition()}, icon = select{args.icon and capi.image(args.icon), preset.icon and capi.image(preset.icon), awful.tag.getproperty(t, "icon"),