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")
9 module("clock") -- module name
10 api_version
=0.1 -- api version, see doc/plugin-api
12 -- ------------------------------------------------------------
13 -- CLOCK CONFIGURATION VARIABLES
15 -- these can be overridden by wmiirc
17 wmii
.set_conf ("clock.update", 1)
18 wmii
.set_conf ("clock.format", "%Y/%m/%d %H:%M:%S")
20 -- ------------------------------------------------------------
23 local widget
= nil -- the display on the bar
24 local timer
= nil -- the 1/second tick timer
26 -- ------------------------------------------------------------
29 -- Note that widgets are sorted in ascending order from left to
30 -- right on wmii's bar. By convention this is a 3 digit number
31 -- and is prefixed to the widget name. There is currently no
32 -- way to reorder a widget, but it is planed for a future release.
34 local widget
= wmii
.widget
:new ("999_clock")
36 local xmessagebox
= "xmessage -center -buttons quit:0 -default quit -file -"
37 local function button_handler (ev
, button
)
40 os
.execute("ncal -y | wmiisetsid " .. xmessagebox
.. "&")
44 widget
:add_event_handler("RightBarClick", button_handler
)
48 -- ------------------------------------------------------------
51 -- The timer function will be called every X seconds. If the
52 -- timer function returns a number
54 local function clock_timer (time_since_update
)
55 local fmt
= wmii
.get_conf("clock.format") or "%c"
56 widget
:show (os
.date(fmt
))
58 -- returning a positive number of seconds before next wakeup, or
59 -- nil (or no return at all) repeats the last schedule, or
60 -- -1 to stop the timer
64 local timer
= wmii
.timer
:new (clock_timer
, 1)