Found this http://dotshare.it/dots/1421/ sometime ago and thought it could be nice with a "analogue" desktop clock...
...modified it a tiny bit, so it fits with NetBSD colors :wink:
Just create a file named clock.lua
with the following content:
-- Clock (GNU - GPLv2)
-- * (c) 2017, Luke Bonham
-- * (c) 2013, maisvendoo
-- modified Sep.2018, pin
local timer = require("gears.timer")
local wibox = require("wibox")
local date = os.date
local math = math
local clock = {}
-- Clock parameters
function clock.new(args)
local args = args or {}
local screen = 1
-- Clock font
local font = "Liberation Mono"
-- Clock size
local width = 225
local height = 225
-- Clock placement on screen
local x = 1300
local y = 600
-- Background color and transperency
local bg = "#00000000"
-- Create wibox
clock.wibox = wibox {
bg = bg,
width = width,
height = height,
ontop = false,
visible = true,
screen = screen
}
-- Reference widget size and draw callback for cairo
clock.wibox : geometry { x = x, y = y }
clock.wibox : setup {
fit = function(self, context, width, height)
return width, height
end,
draw = function(self, context, cr, width, height)
-- Any params calculation
local radius = width/2 - 5
local cx = width/2
local cy = height/2
local hour_len = 13
local min_len = 4
-- Draw dial
-- Draw hour divisions
cr:set_line_width(4)
cr:set_source_rgba(0.852, 0.352, 0.062, 1)
local kx = 1.0
local ky = 1.0
for i = 0,11 do
cr:move_to(cx + kx*(radius - hour_len)*math.sin(i*math.rad(30)), cy - kx*(radius - hour_len)*math.cos(i*math.rad(30)) )
cr:line_to(cx + ky*radius*math.sin(i*math.rad(30)), cy - ky*radius*math.cos(i*math.rad(30)) )
cr:stroke()
end
-- Draw minute divisions
cr:set_line_width(2)
cr:set_source_rgba(0.852, 0.352, 0.062, 1)
for i = 0,59 do
cr:move_to(cx + kx*(radius - min_len)*math.sin(i*math.rad(6)), cy - ky*(radius - min_len)*math.cos(i*math.rad(6)) )
cr:line_to(cx + kx*radius*math.sin(i*math.rad(6)), cy - ky*radius*math.cos(i*math.rad(6)) )
cr:stroke()
end
-- Draw digits on dial
-- local dig_size = 18
local dig_radius = radius/1.35
local n_hours = 12
cr:select_font_face(font, 0, 0)
cr:set_font_size(dig_size)
for i = 1,n_hours do
local dig = math.floor(i*12/n_hours)
local extents = cr:text_extents(dig)
local dx = cx + kx*dig_radius*math.sin(i*math.rad(360/n_hours))
local dy = cy - ky*dig_radius*math.cos(i*math.rad(360/n_hours))
local tx = dx - extents.width/2
local ty = dy + extents.height/2
cr:move_to(tx, ty)
cr:show_text(dig)
end
-- Draw arrows
-- Get local time
local sec = date('%S')
local min = date('%M')
local hour = date('%H')
-- Set arrow length
local hour_arrow_len = radius/1.8
local min_arrow_len = radius - min_len - 15
local sec_arrow_len = radius - min_len - 6
-- Draw hour arrow
cr:set_line_width (6)
cr:set_source_rgba (0.852, 0.352, 0.062, 1)
cr:move_to(cx, cy)
cr:line_to(cx + hour_arrow_len*math.sin(math.rad((hour + min/60 + sec/3600)*30)), cy - hour_arrow_len*math.cos(math.rad((hour + min/60 + sec/3600)*30)) )
cr:stroke()
-- Draw minute arrow
cr:set_line_width(4)
cr:set_source_rgba(0.852, 0.352, 0.062, 1)
cr:move_to(cx, cy)
cr:line_to(cx + min_arrow_len*math.sin(math.rad((min + sec/60)*6)), cy - sec_arrow_len*math.cos(math.rad((min + sec/60)*6)) )
cr:stroke()
-- Draw second arrow
cr:set_line_width(2)
cr:set_source_rgba(0.738, 0.738, 0.738, 1)
cr:move_to(cx, cy)
cr:line_to(cx + sec_arrow_len*math.sin(sec*math.rad(6)), cy - sec_arrow_len*math.cos(sec*math.rad(6)) )
cr:stroke()
end,
layout = wibox.widget.base.make_widget
}
-- Create timer
clock.timer = timer { timeout = 1 }
-- Set timer callback
clock.timer:connect_signal("timeout", function()
clock.wibox.widget:emit_signal("widget::redraw_needed")
end)
-- Start timer
clock.timer:start()
end
return clock
Place the file in your ~/.config/awesome
Now edit your rc.lua
file, adding the following lines to it:
At the beginning of the file declare it...
local clock = require("clock")
then find the lines that read
--Wallpapper
set_wallpaper(s)
and add just bellow
--Clock
clock.new({ screen = 1 })
Save and reload rc.lua
How it looks like?!
Obviously, you can place the clock anywhere on the screen, just play with x and y coordinates. The same goes for colors, size, etc...
Regards