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 for the awful.widget.layoutbox #3521

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

Aire-One
Copy link
Member

Hello,

With my other PR (#3421) being ready for review, here is the implementation of the template widget for the awful.widget.layoutbox. This branch is based on the other PR, only the last commit (eba12a0) is relevant.

With the current implementation, an end-user can use/copypast this code example in the awesomerc.lua to customize the layoutbox:

    s.mylayoutbox = awful.widget.layoutbox {
        screen  = s,
        buttons = {
            awful.button({ }, 1, function () awful.layout.inc( 1) end),
            awful.button({ }, 3, function () awful.layout.inc(-1) end),
            awful.button({ }, 4, function () awful.layout.inc(-1) end),
            awful.button({ }, 5, function () awful.layout.inc( 1) end),
        },
        widget_template = {
            template = wibox.widget.textbox,
            update_callback = function(widget_template, args)
                local layout_name = args and args.screen and awful.layout.getname(awful.layout.get(args.screen)) or "dunno"

                widget_template.widget.text = "custom layoutbox : " .. layout_name
            end,
        },
    }

I open this PR in draft mode, waiting for the other one to be merged. After the merge, I'll rebase this branch, and it'll be ready.

This is a needed property from the awesome global object to allow unit tests
to be checked now that widget.base implements different features based on the
current API level.
The previous implementation for these methods was a naive attempt at
making the base widget working. We need to make sure computing the
widget's sizes is more robust for complex widget_template definition.
The draw method exists only for widgets. When dealing with more complex
widget, this method is not necessary implemented (i.e. with layouts).

We need to check the method is defined by the child before calling it.
This is a small cleanup to not keep in memory a value we don't need.

After the update_callback callback is called, we don't need to remember
it happens this callback was  queued before. (It also prevents a
possible memory leak (of a boolean value) when widgets are destroyed)
Containers and layouts don't allow to build a widget from a callback, so
there is no reason to have this feature here.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant