From f7474388790df81671c338758801d64fa2929da1 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 26 Dec 2018 21:38:08 -0500 Subject: [PATCH] layoutbox: Modernize the constructor. Another step in the long running project to unify all constructors design. --- lib/awful/widget/layoutbox.lua | 35 +++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/awful/widget/layoutbox.lua b/lib/awful/widget/layoutbox.lua index 5583e683..07b12d62 100644 --- a/lib/awful/widget/layoutbox.lua +++ b/lib/awful/widget/layoutbox.lua @@ -1,5 +1,6 @@ --------------------------------------------------------------------------- ---- Layoutbox widget. +--- Display the current client layout (`awful.layout`) icon or name +-- -- -- @author Julien Danjou <julien@danjou.info> -- @copyright 2009 Julien Danjou @@ -13,6 +14,8 @@ local tooltip = require("awful.tooltip") local beautiful = require("beautiful") local wibox = require("wibox") local surface = require("gears.surface") +-- local gdebug = require("gears.debug") +local gtable = require("gears.table") local function get_screen(s) return s and capi.screen[s] @@ -42,10 +45,25 @@ end --- Create a layoutbox widget. It draws a picture with the current layout -- symbol of the current tag. --- @param screen The screen number that the layout will be represented for. --- @return An imagebox widget configured as a layoutbox. --- @constructorfct awful.widget.layoutbox -function layoutbox.new(screen) +-- @tparam table args The arguments. +-- @tparam screen args.screen The screen number that the layout will be represented for. +-- @tparam table args.buttons The `awful.button`s for this layoutbox. +-- @return The layoutbox. +function layoutbox.new(args) + args = args or {} + local screen = nil + + if type(args) == "number" or type(args) == "screen" or args.fake_remove then + screen, args = args, {} +--TODO uncomment +-- gdebug.deprecate( +-- "Use awful.widget.layoutbox{screen=s} instead of awful.widget.layoutbox(screen)", +-- {deprecated_in=5} +-- ) + end + + assert(type(args) == "table") + screen = get_screen(screen or 1) -- Do we already have the update callbacks registered? @@ -80,6 +98,9 @@ function layoutbox.new(screen) w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1} + -- Apply the buttons, visible, forced_width and so on + gtable.crush(w, args) + update(w, screen) boxes[screen] = w end @@ -91,6 +112,10 @@ function layoutbox.mt:__call(...) return layoutbox.new(...) end +--@DOC_widget_COMMON@ + +--@DOC_object_COMMON@ + return setmetatable(layoutbox, layoutbox.mt) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80