tag: Refactor awful.tag.setproperty to call setters
*WARNING* This introduce a minor API break as awful.tag.setscreen arguments are now swapped for consistency This allow to introduce logic for each properties and improve awful.tag.add and execute logic when setting properties.
This commit is contained in:
parent
0d1c98a314
commit
ab0e3b6112
|
@ -67,7 +67,7 @@ function tag.move(new_index, target_tag)
|
||||||
|
|
||||||
for i=new_index < rm_index and new_index or rm_index, #tmp_tags do
|
for i=new_index < rm_index and new_index or rm_index, #tmp_tags do
|
||||||
local tmp_tag = tmp_tags[i]
|
local tmp_tag = tmp_tags[i]
|
||||||
tag.setscreen(tmp_tag, scr)
|
tag.setscreen(scr, tmp_tag)
|
||||||
tag.setproperty(tmp_tag, "index", i)
|
tag.setproperty(tmp_tag, "index", i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -78,23 +78,23 @@ end
|
||||||
function tag.swap(tag1, tag2)
|
function tag.swap(tag1, tag2)
|
||||||
local idx1, idx2 = tag.getidx(tag1), tag.getidx(tag2)
|
local idx1, idx2 = tag.getidx(tag1), tag.getidx(tag2)
|
||||||
local src2, src1 = tag.getscreen(tag2), tag.getscreen(tag1)
|
local src2, src1 = tag.getscreen(tag2), tag.getscreen(tag1)
|
||||||
tag.setscreen(tag2, src1)
|
tag.setscreen(src1, tag2)
|
||||||
tag.move(idx1, tag2)
|
tag.move(idx1, tag2)
|
||||||
tag.setscreen(tag1, scr2)
|
tag.setscreen(scr2, tag1)
|
||||||
tag.move(idx2, tag1)
|
tag.move(idx2, tag1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Add a tag.
|
--- Add a tag.
|
||||||
-- @param name The tag name, a string
|
-- @param name The tag name, a string
|
||||||
-- @param props The tags properties, a table
|
-- @param props The tags inital properties, a table
|
||||||
-- @return The created tag
|
-- @return The created tag
|
||||||
function tag.add(name, props)
|
function tag.add(name, props)
|
||||||
local properties = props or {}
|
local properties = props or {}
|
||||||
|
|
||||||
-- Be sure to set the screen before the tag is activated to avoid function
|
-- Be sure to set the screen before the tag is activated to avoid function
|
||||||
-- connected to property::activated to be called without a valid tag.
|
-- connected to property::activated to be called without a valid tag.
|
||||||
-- set properies cannot be used as this has to be set before the first signal
|
-- set properties cannot be used as this has to be set before the first
|
||||||
-- is sent
|
-- signal is sent
|
||||||
properties.screen = properties.screen or ascreen.focused()
|
properties.screen = properties.screen or ascreen.focused()
|
||||||
|
|
||||||
-- Index is also required
|
-- Index is also required
|
||||||
|
@ -304,19 +304,26 @@ function tag.gettags(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set a tag's screen
|
--- Set a tag's screen
|
||||||
-- @param t tag object
|
|
||||||
-- @param s Screen number
|
-- @param s Screen number
|
||||||
function tag.setscreen(t, s)
|
-- @param t tag object
|
||||||
|
function tag.setscreen(s, t)
|
||||||
|
|
||||||
|
-- For API consistency, the arguments have been swapped for Awesome 3.6
|
||||||
|
if type(t) == "number" then
|
||||||
|
util.deprecate("tag.setscreen arguments are now (s, t) instead of (t, s)")
|
||||||
|
s, t = t, s
|
||||||
|
end
|
||||||
|
|
||||||
local s = s or ascreen.focused()
|
local s = s or ascreen.focused()
|
||||||
local sel = tag.selected
|
local sel = tag.selected
|
||||||
local old_screen = tag.getproperty(t, "screen")
|
local old_screen = tag.getproperty(t, "screen")
|
||||||
if s == old_screen then return end
|
if s == old_screen then return end
|
||||||
|
|
||||||
-- Keeping the old index make very little sense when changing screen
|
-- Keeping the old index make very little sense when changing screen
|
||||||
tag.setproperty(t, "index", nil)
|
tag.setproperty(t, "index", nil, true)
|
||||||
|
|
||||||
-- Change the screen
|
-- Change the screen
|
||||||
tag.setproperty(t, "screen", s)
|
tag.setproperty(t, "screen", s, true)
|
||||||
|
|
||||||
-- Make sure the client's screen matches its tags
|
-- Make sure the client's screen matches its tags
|
||||||
for k,c in ipairs(t:clients()) do
|
for k,c in ipairs(t:clients()) do
|
||||||
|
@ -327,7 +334,7 @@ function tag.setscreen(t, s)
|
||||||
-- Update all indexes
|
-- Update all indexes
|
||||||
for _,screen in ipairs {old_screen, s} do
|
for _,screen in ipairs {old_screen, s} do
|
||||||
for i,t in ipairs(tag.gettags(screen)) do
|
for i,t in ipairs(tag.gettags(screen)) do
|
||||||
tag.setproperty(t, "index", i)
|
tag.setproperty(t, "index", i, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -372,7 +379,7 @@ end
|
||||||
function tag.setmwfact(mwfact, t)
|
function tag.setmwfact(mwfact, t)
|
||||||
local t = t or tag.selected()
|
local t = t or tag.selected()
|
||||||
if mwfact >= 0 and mwfact <= 1 then
|
if mwfact >= 0 and mwfact <= 1 then
|
||||||
tag.setproperty(t, "mwfact", mwfact)
|
tag.setproperty(t, "mwfact", mwfact, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -396,7 +403,7 @@ end
|
||||||
function tag.setgap(useless_gap, t)
|
function tag.setgap(useless_gap, t)
|
||||||
local t = t or tag.selected()
|
local t = t or tag.selected()
|
||||||
if useless_gap >= 0 then
|
if useless_gap >= 0 then
|
||||||
tag.setproperty(t, "useless_gap", useless_gap)
|
tag.setproperty(t, "useless_gap", useless_gap, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -427,7 +434,7 @@ end
|
||||||
-- @tparam[opt=tag.selected()] tag t The tag to modify
|
-- @tparam[opt=tag.selected()] tag t The tag to modify
|
||||||
function tag.setmfpol(policy, t)
|
function tag.setmfpol(policy, t)
|
||||||
local t = t or tag.selected()
|
local t = t or tag.selected()
|
||||||
tag.setproperty(t, "master_fill_policy", policy)
|
tag.setproperty(t, "master_fill_policy", policy, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Toggle size fill policy for the master client(s)
|
--- Toggle size fill policy for the master client(s)
|
||||||
|
@ -457,7 +464,7 @@ end
|
||||||
function tag.setnmaster(nmaster, t)
|
function tag.setnmaster(nmaster, t)
|
||||||
local t = t or tag.selected()
|
local t = t or tag.selected()
|
||||||
if nmaster >= 0 then
|
if nmaster >= 0 then
|
||||||
tag.setproperty(t, "nmaster", nmaster)
|
tag.setproperty(t, "nmaster", nmaster, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -499,7 +506,7 @@ end
|
||||||
-- @param _tag the tag
|
-- @param _tag the tag
|
||||||
function tag.seticon(icon, _tag)
|
function tag.seticon(icon, _tag)
|
||||||
local _tag = _tag or tag.selected()
|
local _tag = _tag or tag.selected()
|
||||||
tag.setproperty(_tag, "icon", icon)
|
tag.setproperty(_tag, "icon", icon, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the tag icon
|
--- Get the tag icon
|
||||||
|
@ -515,7 +522,7 @@ end
|
||||||
function tag.setncol(ncol, t)
|
function tag.setncol(ncol, t)
|
||||||
local t = t or tag.selected()
|
local t = t or tag.selected()
|
||||||
if ncol >= 1 then
|
if ncol >= 1 then
|
||||||
tag.setproperty(t, "ncol", ncol)
|
tag.setproperty(t, "ncol", ncol, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -674,13 +681,19 @@ end
|
||||||
-- @param _tag The tag.
|
-- @param _tag The tag.
|
||||||
-- @param prop The property name.
|
-- @param prop The property name.
|
||||||
-- @param value The value.
|
-- @param value The value.
|
||||||
function tag.setproperty(_tag, prop, value)
|
-- @param ignore_setters Ignore the setter function for "prop" (boolean)
|
||||||
|
function tag.setproperty(_tag, prop, value, ignore_setters)
|
||||||
if not data.tags[_tag] then
|
if not data.tags[_tag] then
|
||||||
data.tags[_tag] = {}
|
data.tags[_tag] = {}
|
||||||
end
|
end
|
||||||
if data.tags[_tag][prop] ~= value then
|
|
||||||
data.tags[_tag][prop] = value
|
if (not ignore_setters) and tag["set"..prop] then
|
||||||
_tag:emit_signal("property::" .. prop)
|
tag["set"..prop](value, _tag)
|
||||||
|
else
|
||||||
|
if data.tags[_tag][prop] ~= value then
|
||||||
|
data.tags[_tag][prop] = value
|
||||||
|
_tag:emit_signal("property::" .. prop)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue