object: Try harder to auto-undeprecate the keys and buttons.

Having the new object layout will be important soon when the
append/remove methods start to get added to the client and the
reborn `awful.keyboard` module.
This commit is contained in:
Emmanuel Lepage Vallee 2019-10-26 17:51:53 -04:00
parent e3959b45d5
commit 10fd4e8883
2 changed files with 44 additions and 4 deletions

View File

@ -88,6 +88,36 @@ function object.capi_index_fallback(class, args)
class.set_newindex_miss_handler(setter) class.set_newindex_miss_handler(setter)
end end
-- Convert the capi objects back into awful ones.
local function deprecated_to_current(content)
local first = content[1]
local current = first and first._private and
first._private._legacy_convert_to or nil
if not current then return nil end
local ret = {current}
for _, o in ipairs(content) do
-- If this is false, someone tried to mix things in a
-- way that is definitely not intentional.
assert(o._private and o._private._legacy_convert_to)
if o._private._legacy_convert_to ~= current then
-- If this is false, someone tried to mix things in a
-- way that is definitely not intentional.
assert(o._private._legacy_convert_to)
table.insert(
ret, o._private._legacy_convert_to
)
current = o._private._legacy_convert_to
end
end
return ret
end
-- (private api) -- (private api)
-- Many legacy Awesome APIs such as `client:tags()`, `root.buttons()`, -- Many legacy Awesome APIs such as `client:tags()`, `root.buttons()`,
@ -130,7 +160,15 @@ local function copy_object(obj, to_set, name, capi_name, is_object, join_if, set
local result = is_formatted and local result = is_formatted and
new_objs or gtable.join(unpack(new_objs)) new_objs or gtable.join(unpack(new_objs))
if capi_name and is_object then -- First, when possible, get rid of the legacy format and go
-- back to the non-deprecated code path.
local current = self["set_"..name]
and deprecated_to_current(result) or nil
if current then
self["set_"..name](self, current)
return capi_name and self[capi_name](self) or self[name]
elseif capi_name and is_object then
return self[capi_name](self, result) return self[capi_name](self, result)
elseif capi_name then elseif capi_name then
return self[capi_name](result) return self[capi_name](result)
@ -166,8 +204,9 @@ function object._legacy_accessors(obj, name, capi_name, is_object, join_if, set_
obj, {}, name, capi_name, is_object, join_if, set_empty obj, {}, name, capi_name, is_object, join_if, set_empty
) )
assert(self._private[name]) local current = deprecated_to_current(self._private[name])
return self._private[name]
return current or self._private[name]
end end
magic_obj["set_"..name] = function(self, objs) magic_obj["set_"..name] = function(self, objs)

View File

@ -66,7 +66,8 @@ function wibox:find_widgets(x, y)
end end
function wibox:_buttons(btns) function wibox:_buttons(btns)
return self.drawin:_buttons(btns) -- The C code uses the argument count, `nil` counts.
return btns and self.drawin:_buttons(btns) or self.drawin:_buttons()
end end
--- Create a widget that reflects the current state of this wibox. --- Create a widget that reflects the current state of this wibox.