reno/widgets/base/clock.lua

52 lines
2.3 KiB
Lua
Raw Permalink Normal View History

2022-08-31 12:20:58 +00:00
-- This file is part of Reno desktop.
--
-- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
-- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
2022-08-21 12:28:28 +00:00
-- wibox.widget.textclock but with awmtk2 templates.
local awmtk2 = require("awmtk2")
local wibox = require("wibox")
local gears = require("gears")
local awful = require("awful")
local beautiful = require("beautiful")
local glib = require("lgi").GLib
local DateTime = glib.DateTime
local TimeZone = glib.TimeZone
return function(args)
2022-09-05 21:54:11 +00:00
local style = awmtk2.create_style("clock",
2023-01-19 13:42:20 +00:00
awmtk2.generic.status_widget,args.style,args.vertical)
2022-08-21 12:28:28 +00:00
local templates = awmtk2.create_template_lib("clock",awmtk2.templates,args.templates)
2023-01-16 12:47:51 +00:00
local t = awmtk2.build_templates(templates,style,args.vertical)
2022-08-21 12:28:28 +00:00
-- Don't mind me just stealing default library code
local format = args.format or "%a %b %d, %H:%M"
local refresh = args.refresh or 60
local tzid = args.tzid
local timezone = (tzid and TimeZone.new(tzid)) or TimeZone.new_local()
-- Seriously, was it so hard to add a font parameter for textclock?
-- Do you actually expect of nobody to change the font to something like
-- idk, 7-segment display? Goddamnit awesome. I trusted you.
local widget = wibox.widget(t.container(t.textbox({
id = "clocktext"
})))
local textbox = widget:get_children_by_id("clocktext")[1]
widget.clocktimer = gears.timer {
timeout = refresh,
call_now = true,
autostart = true,
callback = function()
local str = DateTime.new_now(timezone):format(format)
if str == nil then
require("gears.debug").print_warning("clock: "
.. "g_date_time_format() failed for format "
.. "'" .. format .. "'")
end
textbox:set_markup(str)
end
}
return widget
end