From 3230a414507238e146d083be2a0da347dc67f448 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 26 Dec 2018 17:36:54 -0500 Subject: [PATCH] root: Turn root.button() into a property. This is the first commit of a series to turn all function based accessors into object properties. This will bring consistency across the codebase. --- lib/awful/_compat.lua | 18 +++++++----------- root.c | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/awful/_compat.lua b/lib/awful/_compat.lua index 4b3bb2816..135e32b17 100644 --- a/lib/awful/_compat.lua +++ b/lib/awful/_compat.lua @@ -1,9 +1,10 @@ -- This file contains all global backward compatibility workarounds for the -- Core API changes. local gtimer = require("gears.timer") -local util = require("awful.util" ) +local util = require("awful.util") local spawn = require("awful.spawn") local gdebug = require("gears.debug") +local gprop = require("gears.object.properties") local capi = {root = root} @@ -64,13 +65,8 @@ end -- de-facto read-only due the confusion related the difference between the -- capi and "high level" format difference. - ---- Get or set global mouse bindings. --- --- This binding will be available when you click on the root window (usually --- the wallpaper area). --- @tparam[opt=nil] table|nil The list of `button` objects to set. --- @treturn table The list of root window buttons. -function root.buttons(btns) - return root._buttons(btns) -end +gprop._legacy_accessors(capi.root, "buttons", "_buttons", false, function(new_btns) + return new_btns[1] and ( + type(new_btns[1]) == "button" or new_btns[1]._is_capi_button + ) or false +end, true) diff --git a/root.c b/root.c index c9ed472d9..778838d9d 100644 --- a/root.c +++ b/root.c @@ -374,13 +374,22 @@ luaA_root_keys(lua_State *L) return 1; } -/* Get or set global mouse bindings. - * This binding will be available when you click on the root window. +/** + * Store the list of mouse buttons to be applied on the wallpaper (also + * known as root window). * - * @param button_table An array of mouse button bindings objects, or nothing. - * @return The array of mouse button bindings objects. - * @staticfct buttons + * @property buttons + * @tparam[opt={}] table buttons The list of buttons. + * @see awful.button + * + * @usage + * root.buttons = { + * awful.button({ }, 3, function () mymainmenu:toggle() end), + * awful.button({ }, 4, awful.tag.viewnext), + * awful.button({ }, 5, awful.tag.viewprev), + * } */ + static int luaA_root_buttons(lua_State *L) {