Port all "old" `widget_template` to use `wibox.template`.

This doesn't actually use `set_property`, but it at least covert the
old table to `wibox.template` object. Future cleanup can take care
of the code duplication.
This commit is contained in:
Emmanuel Lepage Vallee 2022-10-22 21:58:01 -07:00
parent 7aab54ed19
commit 8fc30ae693
11 changed files with 66 additions and 33 deletions

View File

@ -88,6 +88,9 @@ This document was last updated at commit v4.3-197-g9085ed631.
* Pango 1.44 is now the oldest recommended Pango version. Older versions are
still supported, but will lack the ability to use some textbox properties,
mainly `wibox.widget.textbox.line_spacing_factor`.
* Passing a widget to any `widget_template` property now prints an error. It
wasn't working before, but wasn't printing an error. Replace `wibox.widget`
with `wibox.template` in your widget definition.
<a name="v43"></a>
# Awesome window manager framework version 4.3 changes

View File

@ -126,7 +126,7 @@ local type_fallback_description = {
"string An [XFT string](https://wiki.archlinux.org/title/X_Logical_Font_Description), such as `\"-*-dejavu sans mono-medium-r-normal--*-80-*-*-*-*-iso10646-1\"`.",
},
template = {
["wibox.template"] = {
"table A table containing a widget tree definition. WARNING: This is really a table"..
" and **NOT** a widget object. Use the `widget = come.class.here` to define the "..
" topmost class rather than construct an instance."
@ -165,6 +165,7 @@ local type_name_linting = {
["double"] = "number",
["float"] = "number",
["bool"] = "boolean",
["template"] = "wibox.template",
}
local metadata_tags = {

View File

@ -17,7 +17,6 @@ local capi = { button = button }
local wibox = require("wibox")
local gdebug = require("gears.debug")
local dpi = require("beautiful").xresources.apply_dpi
local base = require("wibox.widget.base")
--- Common utilities for awful widgets
local common = {}

View File

@ -190,7 +190,7 @@ local layoutlist = {}
--- The delegate widget template.
--
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
-- @propemits true false
--- The layoutlist screen.
@ -362,7 +362,7 @@ function layoutlist:get_count()
end
function layoutlist:set_widget_template(widget_template)
self._private.widget_template = widget_template
self._private.widget_template = wibox.template.make_from_value(widget_template)
-- Remove the existing instances
self._private.data = setmetatable({}, { __mode = 'k' })

View File

@ -56,6 +56,7 @@ local gstring = require("gears.string")
local gdebug = require("gears.debug")
local base = require("wibox.widget.base")
local gtable = require("gears.table")
local wtemplate = require("wibox.template")
local function get_screen(s)
return s and capi.screen[s]
@ -525,7 +526,7 @@ end
--- A templete used to genetate the individual tag widgets.
--
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
for _, prop in ipairs { "filter", "update_function", "widget_template", "source", "screen" } do
taglist["set_"..prop] = function(self, value)
@ -545,6 +546,16 @@ for _, prop in ipairs { "filter", "update_function", "widget_template", "source"
end
end
function taglist:set_widget_template(widget_template)
self._private.widget_template = wtemplate.make_from_value(widget_template)
self._do_taglist_update()
self:emit_signal("widget::layout_changed")
self:emit_signal("widget::redraw_needed")
self:emit_signal("property::widget_template", self._private.widget_template)
end
--- Create a new taglist widget. The last two arguments (update_function
-- and layout) serve to customize the layout of the taglist (eg. to
-- make it vertical). For that, you will need to copy the
@ -561,7 +572,7 @@ end
-- is wibox.layout.fixed.horizontal().
-- @tparam[opt=awful.widget.taglist.source.for_screen] function args.source The
-- function used to generate the list of tag.
-- @tparam[opt] table args.widget_template A custom widget to be used for each tag
-- @tparam[opt] wibox.template args.widget_template A custom widget to be used for each tag
-- @tparam[opt={}] table args.style The style overrides default theme.
-- @tparam[opt=beautiful.taglist_fg_focus] string|pattern args.style.fg_focus
-- @tparam[opt=beautiful.taglist_bg_focus] string|pattern args.style.bg_focus
@ -658,7 +669,7 @@ function taglist.new(args, filter, buttons, style, update_function, base_widget)
buttons = args.buttons,
filter = args.filter,
update_function = args.update_function,
widget_template = args.widget_template,
widget_template = wtemplate.make_from_value(args.widget_template),
source = args.source,
screen = screen
})

View File

@ -95,6 +95,7 @@ local wmargin = require("wibox.container.margin")
local wtextbox = require("wibox.widget.textbox")
local clienticon = require("awful.widget.clienticon")
local wbackground = require("wibox.container.background")
local wtemplate = require("wibox.template")
local gtable = require("gears.table")
local function get_screen(s)
@ -678,7 +679,7 @@ end
-- @DOC_sequences_client_tasklist_widget_template1_EXAMPLE@
--
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
-- @propemits true false
--- A function to gather the clients to display.
@ -794,7 +795,7 @@ function tasklist:set_screen(value)
end
function tasklist:set_widget_template(widget_template)
self._private.widget_template = widget_template
self._private.widget_template = wtemplate.make_from_value(widget_template)
-- Remove the existing instances
self._private.data = setmetatable({}, { __mode = 'k' })
@ -803,7 +804,7 @@ function tasklist:set_widget_template(widget_template)
self:emit_signal("widget::layout_changed")
self:emit_signal("widget::redraw_needed")
self:emit_signal("property::widget_template", widget_template)
self:emit_signal("property::widget_template", self._private.widget_template)
end
--- Create a new tasklist widget.
@ -824,7 +825,7 @@ end
-- is `wibox.layout.flex.horizontal`.
-- @tparam[opt=awful.widget.tasklist.source.all_clients] function args.source The
-- function used to generate the list of client.
-- @tparam[opt] table args.widget_template A custom widget to be used for each client
-- @tparam[opt] wibox.template args.widget_template A custom widget to be used for each client
-- @tparam[opt={}] table args.style The style overrides default theme.
-- @tparam[opt=beautiful.tasklist_fg_normal] string|pattern args.style.fg_normal
-- @tparam[opt=beautiful.tasklist_bg_normal] string|pattern args.style.bg_normal
@ -922,7 +923,7 @@ function tasklist.new(args, filter, buttons, style, update_function, base_widget
buttons = args.buttons,
style = args.style or {},
screen = screen,
widget_template = args.widget_template,
widget_template = wtemplate.make_from_value(args.widget_template),
source = args.source,
data = setmetatable({}, { __mode = 'k' })
})

View File

@ -209,7 +209,7 @@ end)
-- }
--
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
-- @usebeautiful beautiful.notification_max_width The maximum width for the
-- resulting widget.
@ -324,7 +324,7 @@ end
--
-- @constructorfct naughty.layout.box
-- @tparam[opt=nil] table args
-- @tparam table args.widget_template A widget definition template which will
-- @tparam wibox.template args.widget_template A widget definition template which will
-- be instantiated for each box.
-- @tparam naughty.notification args.notification The notification object.
-- @tparam string args.position The position. See `naughty.notification.position`.
@ -364,7 +364,9 @@ local function new(args)
local ret = popup(new_args)
ret._private.notification = {}
ret._private.widget_template = args.widget_template
ret._private.widget_template = wibox.template.make_from_value(
args.widget_template
)
ret._private.position = args.position
gtable.crush(ret, box, true)

View File

@ -203,7 +203,7 @@ local actionlist = {}
--- The actionlist parent notification.
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
-- @propemits true false
--- A table with values to override each `beautiful.notification_action` values.
@ -271,7 +271,7 @@ function actionlist:set_base_layout(layout)
end
function actionlist:set_widget_template(widget_template)
self._private.widget_template = widget_template
self._private.widget_template = wibox.template.make_from_value(widget_template)
-- Remove the existing instances
self._private.data = {}
@ -280,7 +280,7 @@ function actionlist:set_widget_template(widget_template)
self:emit_signal("widget::layout_changed")
self:emit_signal("widget::redraw_needed")
self:emit_signal("property::widget_template", widget_template)
self:emit_signal("property::widget_template", self._private.widget_template)
end
function actionlist:set_style(style)

View File

@ -182,7 +182,7 @@ local notificationlist = {}
--- The notificationlist parent notification.
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
-- @propertydefault The default template displays the icon, title, message and
-- actions.
-- @propemits true false
@ -208,7 +208,7 @@ local notificationlist = {}
-- @usebeautiful beautiful.notification_bgimage_selected Fallback.
function notificationlist:set_widget_template(widget_template)
self._private.widget_template = widget_template
self._private.widget_template = wibox.template.make_from_value(widget_template)
-- Remove the existing instances
self._private.data = {}
@ -217,7 +217,7 @@ function notificationlist:set_widget_template(widget_template)
self:emit_signal("widget::layout_changed")
self:emit_signal("widget::redraw_needed")
self:emit_signal("property::widget_template", widget_template)
self:emit_signal("property::widget_template", self._private.widget_template)
end
function notificationlist:set_style(style)
@ -289,7 +289,7 @@ end
-- @tparam gears.color|string args.style.fg_selected
-- @tparam gears.surface|string args.style.bgimage_normal
-- @tparam gears.surface|string args.style.bgimage_selected
-- @tparam[opt] table args.widget_template A custom widget to be used for each
-- @tparam[opt] wibox.template args.widget_template A custom widget to be used for each
-- notifications.
-- @treturn widget The notification list widget.
-- @constructorfct naughty.list.notifications

View File

@ -24,6 +24,7 @@ local cst = require("naughty.constants")
local naughty = require("naughty.core")
local gdebug = require("gears.debug")
local pcommon = require("awful.permissions._common")
local wtemplate = require("wibox.template")
local notification = {}
@ -514,7 +515,7 @@ local notification = {}
-- off with a specialized notification widget.
--
-- @property widget_template
-- @tparam[opt=nil] template|nil widget_template
-- @tparam[opt=nil] wibox.template|nil widget_template
-- @propertydefault The default template as the icon, title, message and actions.
-- @propemits true false
@ -857,6 +858,21 @@ function notification:append_actions(new_actions)
end
function notification:set_widget_template(value)
self._private.widget_template = wtemplate.make_from_value(value)
self:emit_signal("property::widget_template", value)
-- When a notification is updated over dbus or by setting a property,
-- it is usually convenient to reset the timeout.
local reset = ((not self.suspended) or self._private.ignore_suspend)
and self.auto_reset_timeout ~= false
and naughty.auto_reset_timeout
if reset then
self:reset_timeout()
end
end
function notification:set_screen(s)
assert(not self._private.screen)

View File

@ -164,7 +164,7 @@ end
-- will still be honored.
--
-- @property template
-- @tparam[opt=nil] template|nil template The new widget to use as a
-- @tparam[opt=nil] table|nil template The new widget to use as a
-- template.
-- @emits widget::redraw_needed
-- @emits widget::layout_changed