textclock: Move to wibox.widget
It doesn't depend on `awful`, so it doesn't belong in `awful`.
This commit is contained in:
parent
44a4eca40e
commit
ae0d306114
|
@ -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 = {}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue