From 8de50754122d838cb51016c08311ae33cc11e6b7 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 30 Jun 2009 12:20:21 +0200 Subject: [PATCH] awful.widget.textclock: import Signed-off-by: Julien Danjou --- lib/awful/widget/init.lua.in | 1 + lib/awful/widget/textclock.lua.in | 35 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 lib/awful/widget/textclock.lua.in diff --git a/lib/awful/widget/init.lua.in b/lib/awful/widget/init.lua.in index db39ed55..f68d0861 100644 --- a/lib/awful/widget/init.lua.in +++ b/lib/awful/widget/init.lua.in @@ -12,6 +12,7 @@ require("awful.widget.prompt") require("awful.widget.progressbar") require("awful.widget.graph") require("awful.widget.layoutbox") +require("awful.widget.textclock") require("awful.widget.layout") --- Widget module for awful diff --git a/lib/awful/widget/textclock.lua.in b/lib/awful/widget/textclock.lua.in new file mode 100644 index 00000000..62290790 --- /dev/null +++ b/lib/awful/widget/textclock.lua.in @@ -0,0 +1,35 @@ +--------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2009 Julien Danjou +-- @release @AWESOME_VERSION@ +--------------------------------------------------------------------------- + +local setmetatable = setmetatable +local os = os +local capi = { widget = widget, + timer = timer } + +--- Text clock widget. +module("awful.widget.textclock") + +--- Create a textclock widget. It draws the time it is in a textbox. +-- @param args Standard arguments for textbox widget. +-- @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 new(args, format, timeout) + local args = args or {} + local format = format or " %a %b %d, %H:%M " + local timeout = timeout or 60 + args.type = "textbox" + local w = capi.widget(args) + local timer = capi.timer { timeout = timeout } + w.text = os.date(format) + timer:add_signal("timeout", function() w.text = os.date(format) end) + timer:start() + return w +end + +setmetatable(_M, { __call = function(_, ...) return new(...) end }) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80