install core/*.lua in ~/.wmii-3.5/core/
[wmiirc-lua.git] / plugins / clock.lua
blobdf6c177d6aff7ebea305563f4928a73d01a45221
1 --
2 -- Copyright (c) 2007, Bart Trojanowski <bart@jukie.net>
3 --
4 -- Simple clock applet for wmii bar.
5 --
6 local wmii = require("wmii")
7 local os = require("os")
9 module("clock")
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 -- ------------------------------------------------------------
20 -- MODULE VARIABLES
22 local widet = nil -- the display on the bar
23 local timer = nil -- the 1/second tick timer
25 -- ------------------------------------------------------------
26 -- THE TIMER WIDGET
28 -- First, we create a function to handle the Left|Middle|Right
29 -- events.
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
39 -- something
40 elseif ev == "MiddleBarClick" then
41 -- something else
42 elseif ev == "RightBarClick" then
43 -- and now something completely different
44 timer:delete()
45 timer = nil
46 widget:delete()
47 widget = nil
48 end
49 end
51 widget = wmii.widget:new ("999_clock", clock_event_handler)
53 -- ------------------------------------------------------------
54 -- THE TIMER FUNCTION
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
66 return 1
67 end
69 timer = wmii.timer:new (clock_timer, 1)