From 2c08c2fa396d3522041c2f15365c508f00340810 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Fri, 28 Dec 2018 03:06:03 -0500 Subject: [PATCH] quality: Port all legacy `:buttons()` to `.buttons`. --- lib/awful/hotkeys_popup/widget.lua | 9 +++++---- lib/awful/menu.lua | 5 +++-- lib/awful/widget/button.lua | 14 ++++++------- lib/awful/widget/calendar_popup.lua | 31 ++++++++++++++++------------- lib/awful/widget/common.lua | 2 +- lib/awful/widget/keyboardlayout.lua | 7 +++---- lib/awful/widget/launcher.lua | 7 ++----- lib/naughty/layout/legacy.lua | 24 ++++++++++------------ tests/test-leak-client.lua | 16 +++++++-------- 9 files changed, 57 insertions(+), 58 deletions(-) diff --git a/lib/awful/hotkeys_popup/widget.lua b/lib/awful/hotkeys_popup/widget.lua index a3aeab256..3fc82ce37 100644 --- a/lib/awful/hotkeys_popup/widget.lua +++ b/lib/awful/hotkeys_popup/widget.lua @@ -458,10 +458,11 @@ function widget.new(args) height = height, }) mywibox:set_widget(pages[1]) - mywibox:buttons(gtable.join( - awful.button({ }, 1, function () widget_obj:hide() end), - awful.button({ }, 3, function () widget_obj:hide() end) - )) + + mywibox.buttons = { + awful.button({ }, 1, function () widget_obj:hide() end), + awful.button({ }, 3, function () widget_obj:hide() end) + } function widget_obj.page_next(_self) if _self.current_page == #pages then return end diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index d6fa20490..ea265f982 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -446,13 +446,14 @@ function menu:add(args, index) -- Create bindings - item._background:buttons(gtable.join( + item._background.buttons = { button({}, 3, function () self:hide() end), button({}, 1, function () local num = gtable.hasitem(self.items, item) self:item_enter(num, { mouse = true }) self:exec(num, { exec = true, mouse = true }) - end ))) + end) + } item._mouse = function () diff --git a/lib/awful/widget/button.lua b/lib/awful/widget/button.lua index c71bab851..dcbaf5b3c 100644 --- a/lib/awful/widget/button.lua +++ b/lib/awful/widget/button.lua @@ -1,12 +1,12 @@ --------------------------------------------------------------------------- -- A simple button widget. --- @usage local button = awful.widget.button() --- button:buttons(gears.table.join( --- button:buttons(), --- awful.button({}, 1, nil, function () --- print("Mouse was clicked") --- end) --- )) +-- +-- button.buttons = { +-- awful.button({}, 1, nil, function () +-- print("Mouse was clicked") +-- end) +-- } +-- -- @author Julien Danjou <julien@danjou.info> -- @copyright 2008-2009 Julien Danjou -- @widgetmod awful.widget.button diff --git a/lib/awful/widget/calendar_popup.lua b/lib/awful/widget/calendar_popup.lua index f7e480f03..709300252 100644 --- a/lib/awful/widget/calendar_popup.lua +++ b/lib/awful/widget/calendar_popup.lua @@ -254,7 +254,8 @@ function calendar_popup:attach(widget, position, args) position = position or "tr" args = args or {} if args.on_hover == nil then args.on_hover=true end - widget:buttons(gears.table.join( + + widget.buttons = { abutton({ }, 1, function () if not self.visible or self._calendar_clicked_on then self:call_calendar(0, position) @@ -264,7 +265,8 @@ function calendar_popup:attach(widget, position, args) end), abutton({ }, 4, function () self:call_calendar(-1) end), abutton({ }, 5, function () self:call_calendar( 1) end) - )) + } + if args.on_hover then widget:connect_signal("mouse::enter", function () if not self._calendar_clicked_on then @@ -330,18 +332,19 @@ local function get_cal_wibox(caltype, args) } ret:set_widget(widget) - ret:buttons(gears.table.join( - abutton({ }, 1, function () - ret.visible=false - ret._calendar_clicked_on=false - end), - abutton({ }, 3, function () - ret.visible=false - ret._calendar_clicked_on=false - end), - abutton({ }, 4, function () ret:call_calendar(-1) end), - abutton({ }, 5, function () ret:call_calendar( 1) end) - )) + ret.buttons = { + abutton({ }, 1, function () + ret.visible=false + ret._calendar_clicked_on=false + end), + abutton({ }, 3, function () + ret.visible=false + ret._calendar_clicked_on=false + end), + abutton({ }, 4, function () ret:call_calendar(-1) end), + abutton({ }, 5, function () ret:call_calendar( 1) end) + } + return ret end diff --git a/lib/awful/widget/common.lua b/lib/awful/widget/common.lua index 3b8dc6a6e..db67b0629 100644 --- a/lib/awful/widget/common.lua +++ b/lib/awful/widget/common.lua @@ -129,7 +129,7 @@ function common.list_update(w, buttons, label, data, objects, args) cache = (args and args.widget_template) and custom_template(args) or default_template() - cache.primary:buttons(common.create_buttons(buttons, o)) + cache.primary.buttons = {common.create_buttons(buttons, o)} if cache.create_callback then cache.create_callback(cache.primary, o, i, objects) diff --git a/lib/awful/widget/keyboardlayout.lua b/lib/awful/widget/keyboardlayout.lua index a87b556a1..99d9e7a9f 100644 --- a/lib/awful/widget/keyboardlayout.lua +++ b/lib/awful/widget/keyboardlayout.lua @@ -8,7 +8,6 @@ local capi = {awesome = awesome} local setmetatable = setmetatable local textbox = require("wibox.widget.textbox") local button = require("awful.button") -local gtable = require("gears.table") local widget_base = require("wibox.widget.base") local gdebug = require("gears.debug") @@ -295,9 +294,9 @@ function keyboardlayout.new() function () update_status(self) end); -- Mouse bindings - self:buttons( - gtable.join(button({ }, 1, self.next_layout)) - ) + self.buttons = { + button({ }, 1, self.next_layout) + } return self end diff --git a/lib/awful/widget/launcher.lua b/lib/awful/widget/launcher.lua index 4c2ff0c47..e6596dee4 100644 --- a/lib/awful/widget/launcher.lua +++ b/lib/awful/widget/launcher.lua @@ -5,7 +5,6 @@ --------------------------------------------------------------------------- local setmetatable = setmetatable -local gtable = require("gears.table") local spawn = require("awful.spawn") local wbutton = require("awful.widget.button") local button = require("awful.button") @@ -22,14 +21,12 @@ function launcher.new(args) local w = wbutton(args) if not w then return end - local b if args.command then - b = gtable.join(w:buttons(), button({}, 1, nil, function () spawn(args.command) end)) + w:add_button(button({}, 1, nil, function () spawn(args.command) end)) elseif args.menu then - b = gtable.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end)) + w:add_button(button({}, 1, nil, function () args.menu:toggle() end)) end - w:buttons(b) return w end diff --git a/lib/naughty/layout/legacy.lua b/lib/naughty/layout/legacy.lua index 3f89101fc..ab8d38420 100644 --- a/lib/naughty/layout/legacy.lua +++ b/lib/naughty/layout/legacy.lua @@ -31,7 +31,6 @@ local screen = require("awful.screen") local button = require("awful.button") local beautiful = require("beautiful") local surface = require("gears.surface") -local gtable = require("gears.table") local wibox = require("wibox") local gfs = require("gears.filesystem") local timer = require("gears.timer") @@ -446,14 +445,11 @@ function naughty.default_notification_handler(notification, args) local action_height = h + 2 * margin local action_width = w + 2 * margin - actionmarginbox:buttons(gtable.join( - button({ }, 1, function() - action:invoke(notification) - end), - button({ }, 3, function() - action:invoke(notification) - end) - )) + actionmarginbox.buttons = { + button({ }, 1, function() action:invoke(notification) end), + button({ }, 3, function() action:invoke(notification) end), + } + actionslayout:add(actionmarginbox) actions_total_height = actions_total_height + action_height @@ -584,10 +580,12 @@ function naughty.default_notification_handler(notification, args) notification.box:set_widget(completelayout) -- Setup the mouse events - layout:buttons(gtable.join(button({}, 1, nil, run), - button({}, 3, nil, function() - die(naughty.notification_closed_reason.dismissed_by_user) - end))) + layout.buttons = { + button({}, 1, nil, run), + button({}, 3, nil, function() + die(naughty.notification_closed_reason.dismissed_by_user) + end), + } -- insert the notification to the table table.insert(current_notifications[s][notification.position], notification) diff --git a/tests/test-leak-client.lua b/tests/test-leak-client.lua index 1d67be92a..ca989b231 100644 --- a/tests/test-leak-client.lua +++ b/tests/test-leak-client.lua @@ -7,29 +7,29 @@ local gtable = require("gears.table") -- Create a titlebar and return a table with references to its member widgets. local function create_titlebar(c) local parts = {} - local buttons = gtable.join( + local buttons = { awful.button({ }, 1, function() client.focus = c c:raise() awful.mouse.client.move(c) end), awful.button({ }, 3, function() - client.focus = c - c:raise() - awful.mouse.client.resize(c) - end) - ) + client.focus = c + c:raise() + awful.mouse.client.resize(c) + end) + } -- Widgets that are aligned to the left parts.icon = awful.titlebar.widget.iconwidget(c) local left_layout = wibox.layout.fixed.horizontal(parts.icon) - left_layout:buttons(buttons) + left_layout.buttons = buttons -- The title goes in the middle parts.title = awful.titlebar.widget.titlewidget(c) parts.title:set_align("center") local middle_layout = wibox.layout.flex.horizontal(parts.title) - middle_layout:buttons(buttons) + middle_layout.buttons = buttons parts.floating_button = awful.titlebar.widget.floatingbutton(c) parts.maximized_button = awful.titlebar.widget.maximizedbutton(c)