Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[RFC] Implement wibox.widget.template: An abstract widget that handles a preset of concrete widget. #3421

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
08109a6
add(w.w.template) template widget
Aire-One Aug 28, 2021
d09a704
fix(spec) add `awesome.api_level` preload
Aire-One Aug 28, 2021
18ae7bb
add(spec) `wibox.widget.template` unit tests
Aire-One Aug 28, 2021
d5dbb9d
add(update_callback) allow nil callback
Aire-One Sep 29, 2021
a005967
fix: variable declaration
Aire-One Sep 29, 2021
2f2beb6
add: natural management of update arguments
Aire-One Sep 29, 2021
b824d99
fix(update_args) move to _private property
Aire-One Sep 30, 2021
29ea4dd
fix(spec) remove dead code
Aire-One Sep 30, 2021
f4088ca
fix: rename parameter
Aire-One Oct 23, 2021
e7db5e3
fix: format
Aire-One Oct 23, 2021
086eb14
add(w.w.template) implement widget as child
Aire-One Nov 11, 2021
33d5de5
add(w.w.template) constructor `buttons` param
Aire-One Nov 11, 2021
f12bb57
fix(w.w.template) fit and layout methods
Aire-One Nov 11, 2021
cd5dda3
fix(w.w.template) draw
Aire-One Nov 11, 2021
aaec225
fix(w.w.template) free queued_updates array
Aire-One Nov 11, 2021
45a458a
doc(w.w.template) module description
Aire-One Nov 12, 2021
bfe4832
doc(w.w.template) current methods
Aire-One Nov 12, 2021
8803878
doc(w.w.template) 3rd party lib usage example
Aire-One Nov 12, 2021
d5382b0
add(spec) more `wibox.widget.template` tests
Aire-One Nov 25, 2021
2542c3b
add(w.w.template) constructor accepts widget props
Aire-One Nov 25, 2021
2dab6c3
add(w.w.template) set_template check widget
Aire-One Nov 25, 2021
a7932b1
add(w.w.template) template can't be a callback
Aire-One Nov 26, 2021
495922c
shims: Fix some missing client property::* signals.
Elv13 Oct 16, 2022
67b2b26
template: Bring to feature parity with the awful.widget.common implem…
Elv13 Oct 16, 2022
3765efa
wibox.template: Remove the `args` in favor of passing the template di…
Elv13 Oct 23, 2022
0759096
template: Rename to `wibox.template`.
Elv13 Oct 23, 2022
cc7feb9
doc: Fix a compiler warning.
Elv13 Oct 23, 2022
7aab54e
template: Make sure the template is loaded when calling `get_children…
Elv13 Oct 23, 2022
8fc30ae
Port all "old" `widget_template` to use `wibox.template`.
Elv13 Oct 23, 2022
452d21a
tests: Test `wibox.template` `:set_property()`.
Elv13 Oct 23, 2022
c8016f0
template: Fix forced_height/forced_width and other fixup.
Elv13 Nov 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/89-NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/config.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -165,6 +165,7 @@ local type_name_linting = {
["double"] = "number",
["float"] = "number",
["bool"] = "boolean",
["template"] = "wibox.template",
}

local metadata_tags = {
Expand Down
5 changes: 2 additions & 3 deletions lib/awful/widget/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -51,7 +50,7 @@ function common.create_buttons(buttons, object)
end

local function custom_template(args)
local l = base.make_widget_from_value(args.widget_template)
local l = wibox.template.make_from_value(args.widget_template)

-- The template system requires being able to get children elements by ids.
-- This is not optimal, but for now there is no way around it.
Expand All @@ -72,7 +71,7 @@ end

local function default_template()
return custom_template {
widget_template = {
widget_template = wibox.template {
id = 'background_role',
border_strategy = 'inner',
widget = wibox.container.background,
Expand Down
4 changes: 2 additions & 2 deletions lib/awful/widget/layoutlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' })
Expand Down
17 changes: 14 additions & 3 deletions lib/awful/widget/taglist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
})
Expand Down
13 changes: 7 additions & 6 deletions lib/awful/widget/tasklist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -391,7 +392,7 @@ local function default_template(self)
or self._private.style.tasklist_disable_icon
or beautiful.tasklist_disable_icon

return {
return wtemplate {
{
(not has_no_icon) and {
clienticon,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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' })
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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' })
})
Expand Down
1 change: 1 addition & 0 deletions lib/gears/shape.lua
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ end
-- @tparam number height The shape height
-- @tparam[opt=5] number x_offset The shadow area horizontal offset.
-- @tparam[opt=5] number y_offset The shadow area vertical offset.
-- @noreturn
function module.solid_rectangle_shadow(cr, w, h, x_offset, y_offset)
x_offset, y_offset = x_offset or 5, y_offset or 5
w, h = w - math.abs(x_offset), h - math.abs(y_offset)
Expand Down
10 changes: 6 additions & 4 deletions lib/naughty/layout/box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ end)
--
-- The default template is (less or more):
--
-- {
-- wibox.template {
-- {
-- {
-- {
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions lib/naughty/list/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions lib/naughty/list/notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {}
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
36 changes: 26 additions & 10 deletions lib/naughty/notification.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
-- @copyright 2017 Emmanuel Lepage Vallee
-- @coreclassmod naughty.notification
---------------------------------------------------------------------------
local capi = { screen = screen }
local gobject = require("gears.object")
local gtable = require("gears.table")
local timer = require("gears.timer")
local gfs = require("gears.filesystem")
local cst = require("naughty.constants")
local naughty = require("naughty.core")
local gdebug = require("gears.debug")
local pcommon = require("awful.permissions._common")
local capi = { screen = screen }
local gobject = require("gears.object")
local gtable = require("gears.table")
local timer = require("gears.timer")
local gfs = require("gears.filesystem")
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 = {}

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions lib/wibox/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ wibox.container = require("wibox.container")
wibox.widget = require("wibox.widget")
wibox.drawable = require("wibox.drawable")
wibox.hierarchy = require("wibox.hierarchy")
wibox.template = require("wibox.template")

local force_forward = {
shape_bounding = true,
Expand Down
Loading