From b11a8fb52ce891481025b043a70b4a0762b4ad2f Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Nov 2021 23:10:43 -0800 Subject: [PATCH] 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. --- lib/awful/widget/tasklist.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/awful/widget/tasklist.lua b/lib/awful/widget/tasklist.lua index 41998c777..5d269458a 100644 --- a/lib/awful/widget/tasklist.lua +++ b/lib/awful/widget/tasklist.lua @@ -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) }