2 -- Copyright (c) 2007, Bart Trojanowski <bart@jukie.net>
4 -- Simple clock applet for wmii bar.
6 local wmii
= require("wmii")
7 local os
= require("os")
11 -- ------------------------------------------------------------
12 -- CLOCK CONFIGURATION VARIABLES
14 -- these can be overridden by wmiirc
16 wmii
.set_conf ("clock.update", 1)
17 wmii
.set_conf ("clock.format", "%Y/%m/%d %H:%M:%S")
19 -- ------------------------------------------------------------
22 local widet
= nil -- the display on the bar
23 local timer
= nil -- the 1/second tick timer
25 -- ------------------------------------------------------------
28 -- First, we create a function to handle the Left|Middle|Right
31 -- Note that widgets are sorted in ascending order from left to
32 -- right on wmii's bar. By convention this is a 3 digit number
33 -- and is prefixed to the widget name. There is currently no
34 -- way to reorder a widget, but it is planed for a future release.
37 local function clock_event_handler (ev
)
38 if ev
== "LeftBarClick" then
40 elseif ev
== "MiddleBarClick" then
42 elseif ev
== "RightBarClick" then
43 -- and now something completely different
51 widget
= wmii
.widget
:new ("999_clock", clock_event_handler
)
53 -- ------------------------------------------------------------
56 -- The timer function will be called every X seconds. If the
57 -- timer function returns a number
59 local function clock_timer (time_since_update
)
60 local fmt
= wmii
.get_conf("clock.format") or "%c"
61 widget
:show (os
.date(fmt
))
63 -- returning a positive number of seconds before next wakeup, or
64 -- nil (or no return at all) repeats the last schedule, or
65 -- -1 to stop the timer
69 timer
= wmii
.timer
:new (clock_timer
, 1)