diff --git a/lib/awful/util.lua b/lib/awful/util.lua index 866f9e4f0..488dbacf2 100644 --- a/lib/awful/util.lua +++ b/lib/awful/util.lua @@ -60,6 +60,36 @@ function util.deprecate(see) gears_debug.print_warning(msg .. ".\n" .. tb) end +--- Create a class proxy with deprecation messages. +-- This is useful when a class has moved somewhere else. +-- @tparam table fallback The new class +-- @tparam string old_name The old class name +-- @tparam string new_name The new class name +-- @treturn table A proxy class. +function util.deprecate_class(fallback, old_name, new_name) + local message = old_name.." has been renamed to "..new_name + + local function call(_,...) + util.deprecate(message) + + return fallback(...) + end + + local function index(_, k) + util.deprecate(message) + + return fallback[k] + end + + local function newindex(_, k, v) + util.deprecate(message) + + fallback[k] = v + end + + return setmetatable({}, {__call = call, __index = index, __newindex = newindex}) +end + --- Get a valid color for Pango markup -- @param color The color. -- @tparam string fallback The color to return if the first is invalid. (default: black) diff --git a/lib/awful/wibox.lua b/lib/awful/wibox.lua index 276b9f385..f56b38f5f 100644 --- a/lib/awful/wibox.lua +++ b/lib/awful/wibox.lua @@ -7,26 +7,7 @@ -- @module awful.wibox --------------------------------------------------------------------------- local util = require("awful.util") -local wibar = require("awful.wibar") -local function call(_,...) - util.deprecate("awful.wibox has been renamed to awful.wibar") - - return wibar(...) -end - -local function index(_, k) - util.deprecate("awful.wibox has been renamed to awful.wibar") - - return wibar[k] -end - -local function newindex(_, k, v) - util.deprecate("awful.wibox has been renamed to awful.wibar") - - wibar[k] = v -end - -return setmetatable({}, {__call = call, __index = index, __newindex = newindex}) +return util.deprecate_class(require("awful.wibar"), "awful.wibox", "awful.wibar") -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80