Adapt to new API changes

This commit is contained in:
Emmanuel Lepage Vallee 2016-04-12 02:48:51 -04:00
parent a82098b75a
commit 8a5b519da4
1 changed files with 24 additions and 27 deletions

View File

@ -36,6 +36,10 @@ local function get_class(c)
return awful.client.property.get(c, "overwrite_class") or c.class or "N/A" return awful.client.property.get(c, "overwrite_class") or c.class or "N/A"
end end
local function get_screen_idx(s)
return type(s) == "number" and s or s.index
end
--Load tags, this cannot be undone --Load tags, this cannot be undone
local function load_tags(tyrannical_tags) local function load_tags(tyrannical_tags)
for k,v in ipairs(tyrannical_tags) do for k,v in ipairs(tyrannical_tags) do
@ -43,13 +47,13 @@ local function load_tags(tyrannical_tags)
if type(v.screen) == "table" then if type(v.screen) == "table" then
local screens = v.screen --TODO remove local screens = v.screen --TODO remove
for k2,v2 in pairs(screens) do for k2,v2 in pairs(screens) do
if v2 <= capi.screen.count() then if (type(v2) == "number" and v2 or v2.index) <= capi.screen.count() then
v.screen = v2 --TODO remove v.screen = v2 --TODO remove
awful.tag.add(v.name,v,{screen = v2}) awful.tag.add(v.name,v,{screen = v2})
end end
end end
v.screen = screens --TODO remove v.screen = screens --TODO remove
elseif (v.screen or 1) <= capi.screen.count() then elseif (v.screen and (type(v.screen) == "number" and v.screen or v.screen.index) or 1) <= capi.screen.count() then
awful.tag.add(v.name,v) awful.tag.add(v.name,v)
end end
elseif v.volatile == nil then elseif v.volatile == nil then
@ -84,8 +88,8 @@ end
function module.focus_client(c,properties) function module.focus_client(c,properties)
local properties = properties or (c_rules.instance[string.lower(c.instance or "N/A")] or {}).properties or (c_rules.class[string.lower(get_class(c))] or {}).properties or {} local properties = properties or (c_rules.instance[string.lower(c.instance or "N/A")] or {}).properties or (c_rules.class[string.lower(get_class(c))] or {}).properties or {}
if (((not c.transient_for) or (c.transient_for==capi.client.focus) or (not settings.block_children_focus_stealing)) and (not properties.no_autofocus)) then if (((not c.transient_for) or (c.transient_for==capi.client.focus) or (not settings.block_children_focus_stealing)) and (not properties.no_autofocus)) then
if not awful.util.table.hasitem(c:tags(), awful.tag.selected(c.screen or 1)) and (not prop(c:tags()[1],"no_focus_stealing_in")) then if not awful.util.table.hasitem(c:tags(), (c.screen or capi.screen[1]).selected_tag) and (not prop(c:tags()[1],"no_focus_stealing_in")) then
awful.tag.viewonly(c:tags()[1]) c:tags()[1]:view_only()
end end
capi.client.focus = c capi.client.focus = c
c:raise() c:raise()
@ -102,10 +106,6 @@ local function apply_properties(c,override,normal)
for k,_ in pairs(props) do for k,_ in pairs(props) do
c[k] = props[k] c[k] = props[k]
end end
--Force floating state, if necessary
if props.floating ~= nil then
awful.client.floating.set(c, props.floating)
end
--Center client --Center client
if props.centered == true then if props.centered == true then
awful.placement.centered(c, nil) awful.placement.centered(c, nil)
@ -120,7 +120,7 @@ local function apply_properties(c,override,normal)
elseif props.tag then elseif props.tag then
ret = c:tags(type(props.tag) == "function" and props.tag(c) or (type(props.tag) == "table" and props.tag or { props.tag })) ret = c:tags(type(props.tag) == "function" and props.tag(c) or (type(props.tag) == "table" and props.tag or { props.tag }))
elseif props.intrusive == true or (settings.force_odd_as_intrusive and c.type ~= "normal") then elseif props.intrusive == true or (settings.force_odd_as_intrusive and c.type ~= "normal") then
local tag = awful.tag.selected(c.screen) or awful.tag.viewonly(awful.tag.gettags(c.screen)[1]) or awful.tag.selected(c.screen) local tag = c.screen.selected_tag or c.screen.tags[1]:view_only() or c.screen.selected_tag
if tag then --Can be false if there is no tags if tag then --Can be false if there is no tags
ret = c:tags({tag}) ret = c:tags({tag})
end end
@ -141,7 +141,7 @@ local function match_client(c, startup)
local forced_tags,props = apply_properties(c,props,rules and rules.properties) local forced_tags,props = apply_properties(c,props,rules and rules.properties)
if #tags == 0 and c.transient_for and (settings.group_children or (rules and rules.properties.intrusive_popup)) then if #tags == 0 and c.transient_for and (settings.group_children or (rules and rules.properties.intrusive_popup)) then
c.sticky = c.transient_for.sticky or false c.sticky = c.transient_for.sticky or false
c:tags(awful.util.table.join(c.transient_for:tags(),(rules and rules.properties.intrusive_popup) and awful.tag.selectedlist(c.screen))) c:tags(awful.util.table.join(c.transient_for:tags(),(rules and rules.properties.intrusive_popup) and c.screen.selected_tags))
return module.focus_client(c,props) return module.focus_client(c,props)
elseif forced_tags then elseif forced_tags then
return module.focus_client(c,props) return module.focus_client(c,props)
@ -151,42 +151,45 @@ local function match_client(c, startup)
for j=1,#(#tags == 0 and rules.tags or {}) do for j=1,#(#tags == 0 and rules.tags or {}) do
local tag,cache = rules.tags[j],rules.tags[j].screen local tag,cache = rules.tags[j],rules.tags[j].screen
tag.instances,has_screen = tag.instances or setmetatable({}, { __mode = 'v' }),(type(tag.screen)=="table" and awful.util.table.hasitem(tag.screen,c_src)~=nil) tag.instances,has_screen = tag.instances or setmetatable({}, { __mode = 'v' }),(type(tag.screen)=="table" and awful.util.table.hasitem(tag.screen,c_src)~=nil)
tag.screen = tag.screen and get_screen_idx(tag.screen) or nil
tag.screen = (tag.force_screen ~= true and c_src) or (has_screen and c_src or type(tag.screen)=="table" and tag.screen[1] or tag.screen) tag.screen = (tag.force_screen ~= true and c_src) or (has_screen and c_src or type(tag.screen)=="table" and tag.screen[1] or tag.screen)
tag.screen,match = (capi.screen[tag.screen]) and tag.screen or mouse_s,tag.instances[tag.screen] tag.screen = tag.screen and get_screen_idx(tag.screen) or nil
tag.screen,match = (capi.screen[tag.screen]) and tag.screen or mouse_s,tag.instances[get_screen_idx(tag.screen)]
tag.screen = tag.screen and get_screen_idx(tag.screen) or nil
local max_clients = match and (type(prop(match,"max_clients")) == "function" and prop(match,"max_clients")(c,match) or prop(match,"max_clients")) or 999 local max_clients = match and (type(prop(match,"max_clients")) == "function" and prop(match,"max_clients")(c,match) or prop(match,"max_clients")) or 999
if (not match and not (fav_scr == true and mouse_s ~= tag.screen)) or (max_clients <= #match:clients()) then if (not match and not (fav_scr == true and mouse_s ~= tag.screen)) or (max_clients <= #match:clients()) then
awful.tag.setproperty(awful.tag.add(tag.name,tag),"volatile",match and (max_clients ~= nil) or tag.volatile) awful.tag.add(tag.name,tag).volatile = match and (max_clients ~= nil) or tag.volatile
end end
tags_src[tag.screen],fav_scr = tags_src[tag.screen] or {},fav_scr or (tag.screen == mouse_s) --Reset if a better screen is found tags_src[tag.screen],fav_scr = tags_src[tag.screen] or {},fav_scr or (tag.screen == mouse_s) --Reset if a better screen is found
tags_src[tag.screen][#tags_src[tag.screen]+1] = tag.instances[tag.screen] tags_src[tag.screen][#tags_src[get_screen_idx(tag.screen)]+1] = tag.instances[get_screen_idx(tag.screen)]
tag.screen = cache tag.screen = cache
end end
for k,t in ipairs(tags_src[mouse_s] or tags_src[c_src] or select(2,next(tags_src)) or awful.util.table.join(unpack(tags_src))) do for k,t in ipairs(tags_src[mouse_s] or tags_src[c_src] or select(2,next(tags_src)) or awful.util.table.join(unpack(tags_src))) do
tags[#tags+1] = prop(t,"locked") ~= true and t.activated and t or nil --Do not add to locked tags tags[#tags+1] = prop(t,"locked") ~= true and t.activated and t or nil --Do not add to locked tags
end end
c.screen = tags[1] and awful.tag.getscreen(tags[1]) or c_src c.screen = tags[1] and tags[1].screen or c_src
if #tags > 0 then if #tags > 0 then
c:tags(tags) c:tags(tags)
return module.focus_client(c,props) return module.focus_client(c,props)
end end
end end
--Add to the current tag if not exclusive --Add to the current tag if not exclusive
local cur_tag = awful.tag.selected(c.screen) local cur_tag = c.screen.selected_tag
if cur_tag and prop(cur_tag,"exclusive") ~= true and prop(cur_tag,"locked") ~= true then if cur_tag and prop(cur_tag,"exclusive") ~= true and prop(cur_tag,"locked") ~= true then
c:tags({cur_tag}) c:tags({cur_tag})
return module.focus_client(c,props) return module.focus_client(c,props)
end end
--Add to the fallback tags --Add to the fallback tags
if #c:tags((function(arr) for k,v in ipairs(fallbacks) do if #c:tags((function(arr) for k,v in ipairs(fallbacks) do
arr[#arr+1]=awful.tag.getscreen(v) == c.screen and v or nil arr[#arr+1]=v.screen == c.screen and v or nil
end; return arr end; return arr
end)({})) > 0 then -- Select the first fallback tag if the current tag isn't a fallback end)({})) > 0 then -- Select the first fallback tag if the current tag isn't a fallback
return module.focus_client(c,props) return module.focus_client(c,props)
end end
--Last resort, create a new tag --Last resort, create a new tag
c_rules.class[low_c] = c_rules.class[low_c] or {tags={},properties={}} c_rules.class[low_c] = c_rules.class[low_c] or {tags={},properties={}}
local tmp,tag = c_rules.class[low_c],awful.tag.add(get_class(c),{name=get_class(c),onetimer=true,volatile=true,exclusive=true,screen=(c.screen <= capi.screen.count()) local tmp,tag = c_rules.class[low_c],awful.tag.add(get_class(c),{name=get_class(c),onetimer=true,volatile=true,exclusive=true,screen=(c.screen.index <= capi.screen.count())
and c.screen or 1,layout=settings.tag.layout or settings.default_layout or awful.layout.suit.max}) and c.screen or capi.screen.primary or capi.screen[1],layout=settings.tag.layout or settings.default_layout or awful.layout.suit.max})
tmp.tags[#tmp.tags+1] = {name=get_class(c),instances = setmetatable({[c.screen]=tag}, { __mode = 'v' }),volatile=true,screen=c.screen,exclusive=true} tmp.tags[#tmp.tags+1] = {name=get_class(c),instances = setmetatable({[c.screen]=tag}, { __mode = 'v' }),volatile=true,screen=c.screen,exclusive=true}
c:tags({tag}) c:tags({tag})
return module.focus_client(c,props) return module.focus_client(c,props)
@ -209,11 +212,11 @@ awful.tag.withcurrent,awful.tag._add = function(c, startup)
local tags,old_tags = {},c:tags() local tags,old_tags = {},c:tags()
--Safety to prevent --Safety to prevent
for k, t in ipairs(old_tags) do for k, t in ipairs(old_tags) do
tags[#tags+1] = (awful.tag.getscreen(t) == c.screen) and t or nil tags[#tags+1] = (t.screen == c.screen) and t or nil
end end
--Necessary when dragging clients --Necessary when dragging clients
if startup == nil and old_tags[1] and old_tags[1].screen ~= c.screen then --nil != false if startup == nil and old_tags[1] and old_tags[1].screen ~= c.screen then --nil != false
local sellist = awful.tag.selectedlist(c.screen) local sellist = c.screen.selected_tags
if #sellist > 0 then --Use already selected tag if #sellist > 0 then --Use already selected tag
tags = sellist tags = sellist
else --Select a tag else --Select a tag
@ -223,7 +226,7 @@ awful.tag.withcurrent,awful.tag._add = function(c, startup)
c:tags(tags) c:tags(tags)
end,awful.tag.add end,awful.tag.add
awful.tag.add,awful.tag._viewonly = function(tag,props,override) awful.tag.add = function(tag,props,override)
props.screen,props.instances = props.screen or capi.mouse.screen,props.instances or setmetatable({}, { __mode = 'v' }) props.screen,props.instances = props.screen or capi.mouse.screen,props.instances or setmetatable({}, { __mode = 'v' })
props.mwfact,props.layout = props.mwfact or settings.tag.mwfact or settings.mwfact,props.layout or settings.default_layout or awful.layout.max props.mwfact,props.layout = props.mwfact or settings.tag.mwfact or settings.mwfact,props.layout or settings.default_layout or awful.layout.max
local t = awful.tag._add(tag,awful.util.table.join(settings.tag,props,override)) local t = awful.tag._add(tag,awful.util.table.join(settings.tag,props,override))
@ -232,12 +235,6 @@ awful.tag.add,awful.tag._viewonly = function(tag,props,override)
t.selected = props.selected or false t.selected = props.selected or false
props.instances[props.screen] = t props.instances[props.screen] = t
return t return t
end,awful.tag.viewonly
awful.tag.viewonly = function(t)
if not t then return end
if not awful.tag.getscreen(t) then awful.tag.setscreen(capi.mouse.screen, t) end
awful.tag._viewonly(t)
end end
capi.tag.connect_signal("property::fallback",function(t) capi.tag.connect_signal("property::fallback",function(t)