From ae0d306114920e5f26c204f475c823dd277bf55e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 23 May 2016 00:46:01 -0400 Subject: [PATCH] textclock: Move to wibox.widget It doesn't depend on `awful`, so it doesn't belong in `awful`. --- awesomerc.lua | 2 +- lib/awful/tooltip.lua | 2 +- lib/awful/widget/textclock.lua | 51 +++++--------------------------- lib/wibox/widget/init.lua | 1 + lib/wibox/widget/textclock.lua | 53 ++++++++++++++++++++++++++++++++++ tests/_wibox_helper.lua | 2 +- tests/test-leaks.lua | 2 +- 7 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 lib/wibox/widget/textclock.lua diff --git a/awesomerc.lua b/awesomerc.lua index c50fb151..d7132042 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -115,7 +115,7 @@ mykeyboardlayout = awful.widget.keyboardlayout() -- {{{ Wibox -- Create a textclock widget -mytextclock = awful.widget.textclock() +mytextclock = wibox.widget.textclock() -- Create a wibox for each screen and add it mywibox = {} diff --git a/lib/awful/tooltip.lua b/lib/awful/tooltip.lua index 57b37699..6f44e47d 100644 --- a/lib/awful/tooltip.lua +++ b/lib/awful/tooltip.lua @@ -10,7 +10,7 @@ -- How to create a tooltip? -- --- -- --- myclock = awful.widget.textclock({}, "%T", 1) +-- myclock = wibox.widget.textclock({}, "%T", 1) -- myclock_t = awful.tooltip({ -- objects = { myclock }, -- timer_function = function() diff --git a/lib/awful/widget/textclock.lua b/lib/awful/widget/textclock.lua index a4a0f90c..74cf949d 100644 --- a/lib/awful/widget/textclock.lua +++ b/lib/awful/widget/textclock.lua @@ -1,52 +1,17 @@ --------------------------------------------------------------------------- ---- Text clock widget. +-- This widget has moved to `wibox.widget.textclock` -- -- @author Julien Danjou <julien@danjou.info> --- @copyright 2009 Julien Danjou +-- @copyright 2008-2009 Julien Danjou -- @release @AWESOME_VERSION@ -- @classmod awful.widget.textclock --------------------------------------------------------------------------- +local util = require("awful.util") -local setmetatable = setmetatable -local os = os -local textbox = require("wibox.widget.textbox") -local timer = require("gears.timer") -local DateTime = require("lgi").GLib.DateTime - -local textclock = { mt = {} } - ---- This lowers the timeout so that it occurs "correctly". For example, a timeout --- of 60 is rounded so that it occurs the next time the clock reads ":00 seconds". -local function calc_timeout(real_timeout) - return real_timeout - os.time() % real_timeout -end - ---- Create a textclock widget. It draws the time it is in a textbox. --- --- @param format The time format. Default is " %a %b %d, %H:%M ". --- @param timeout How often update the time. Default is 60. --- @return A textbox widget. -function textclock.new(format, timeout) - format = format or " %a %b %d, %H:%M " - timeout = timeout or 60 - - local w = textbox() - local t - function w._textclock_update_cb() - w:set_markup(DateTime.new_now_local():format(format)) - t.timeout = calc_timeout(timeout) - t:again() - return true -- Continue the timer - end - t = timer.weak_start_new(timeout, w._textclock_update_cb) - t:emit_signal("timeout") - return w -end - -function textclock.mt:__call(...) - return textclock.new(...) -end - -return setmetatable(textclock, textclock.mt) +return util.deprecate_class( + require("wibox.widget.textclock"), + "awful.widget.textclock", + "wibox.widget.textclock" +) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/wibox/widget/init.lua b/lib/wibox/widget/init.lua index 5283fb4e..0fb702d8 100644 --- a/lib/wibox/widget/init.lua +++ b/lib/wibox/widget/init.lua @@ -12,6 +12,7 @@ return setmetatable({ imagebox = require("wibox.widget.imagebox"); background = require("wibox.widget.background"); systray = require("wibox.widget.systray"); + textclock = require("wibox.widget.textclock"); }, {__call = function(_, args) return base.make_widget_declarative(args) end}) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/lib/wibox/widget/textclock.lua b/lib/wibox/widget/textclock.lua new file mode 100644 index 00000000..aec44521 --- /dev/null +++ b/lib/wibox/widget/textclock.lua @@ -0,0 +1,53 @@ +--------------------------------------------------------------------------- +--- Text clock widget. +-- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2009 Julien Danjou +-- @release @AWESOME_VERSION@ +-- @classmod wibox.widget.textclock +--------------------------------------------------------------------------- + +local setmetatable = setmetatable +local os = os +local textbox = require("wibox.widget.textbox") +local timer = require("gears.timer") +local DateTime = require("lgi").GLib.DateTime + +local textclock = { mt = {} } + +--- This lowers the timeout so that it occurs "correctly". For example, a timeout +-- of 60 is rounded so that it occurs the next time the clock reads ":00 seconds". +local function calc_timeout(real_timeout) + return real_timeout - os.time() % real_timeout +end + +--- Create a textclock widget. It draws the time it is in a textbox. +-- +-- @tparam[opt=" %a %b %d, %H:%M "] string format The time format. +-- @tparam[opt=60] number timeout How often update the time (in seconds). +-- @treturn table A textbox widget. +-- @function wibox.widget.textclock +function textclock.new(format, timeout) + format = format or " %a %b %d, %H:%M " + timeout = timeout or 60 + + local w = textbox() + local t + function w._textclock_update_cb() + w:set_markup(DateTime.new_now_local():format(format)) + t.timeout = calc_timeout(timeout) + t:again() + return true -- Continue the timer + end + t = timer.weak_start_new(timeout, w._textclock_update_cb) + t:emit_signal("timeout") + return w +end + +function textclock.mt:__call(...) + return textclock.new(...) +end + +return setmetatable(textclock, textclock.mt) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/_wibox_helper.lua b/tests/_wibox_helper.lua index d21ebbfe..5c7afdc2 100644 --- a/tests/_wibox_helper.lua +++ b/tests/_wibox_helper.lua @@ -13,7 +13,7 @@ return { create_wibox = function() -- Widgets that are aligned to the right local right_layout = wibox.layout.fixed.horizontal() - local textclock = awful.widget.textclock() + local textclock = wibox.widget.textclock() right_layout:add(textclock) right_layout:add(awful.widget.layoutbox(1)) diff --git a/tests/test-leaks.lua b/tests/test-leaks.lua index 725ed169..6977189c 100644 --- a/tests/test-leaks.lua +++ b/tests/test-leaks.lua @@ -63,7 +63,7 @@ collectable(wibox.layout.align.horizontal()) -- Then some random widgets from awful collectable(awful.widget.launcher({ image = cairo.ImageSurface(cairo.Format.ARGB32, 20, 20), command = "bash" })) collectable(awful.widget.prompt()) -collectable(awful.widget.textclock()) +collectable(wibox.widget.textclock()) collectable(awful.widget.layoutbox(1)) -- Some widgets do things via timer.delayed_call