tasklist: Add a `count` property.

This is mostly for the signal handler. It will allow to do things
like replace the template or layout based on the number of clients.
This commit is contained in:
Emmanuel Lepage Vallee 2021-11-09 23:10:43 -08:00
parent 70c6821997
commit b11a8fb52c
1 changed files with 20 additions and 0 deletions

View File

@ -491,6 +491,11 @@ local function tasklist_update(s, self, buttons, filter, data, style, update_fun
end
end
if self._private.last_count ~= #clients then
self:emit_signal("property::count", #clients, self._private.last_count)
self._private.last_count = #clients
end
local function label(c, tb) return tasklist_label(c, style, tb) end
update_function(self._private.base_layout, buttons, label, data, clients, {
@ -499,6 +504,13 @@ local function tasklist_update(s, self, buttons, filter, data, style, update_fun
})
end
--- The current number of clients.
--
-- @property count
-- @readonly
-- @tparam number The number of client.
-- @propemits true false
--- Set the tasklist layout.
--
-- @property base_layout
@ -559,6 +571,14 @@ function tasklist:set_base_layout(layout)
self:emit_signal("property::base_layout", layout)
end
function tasklist:get_count()
if not self._private.last_count then
self._do_tasklist_update_now()
end
return self._private.last_count
end
function tasklist:layout(_, width, height)
if self._private.base_layout then
return { base.place_widget_at(self._private.base_layout, 0, 0, width, height) }