-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpv_clock.lua
More file actions
58 lines (51 loc) · 1.64 KB
/
mpv_clock.lua
File metadata and controls
58 lines (51 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- Shows the current OS time in the OSD
-- Pressing 'c' shows it for 5 seconds, and pressing 'C' (Shift+C) toggles it on indefinitely until you toggle it off again.
-- Created by Yuto Takano, inspired by blue-sky-r/mpv.git
-- Edit the cfg below to change the key-bindings, date format, and duration.
local cfg = {
format = "%H:%M",
duration = 5,
key = 'c',
togglekey = 'C',
}
-- global clock show state variable
local is_shown = false
-- global osd timer variable
local osd_timer = nil
-- Simply show clock for the desired duration
local function osd_clock()
local s = os.date(cfg.format)
mp.osd_message(s, cfg.duration)
collectgarbage()
collectgarbage()
end
-- Similar to the above, but is called by the periodic_timer
local function osd_clock_timer()
-- do not run if toggled off. Shouldn't be called since periodic_timer is stop()-ed but just in case.
if is_shown then
local s = os.date(cfg.format)
-- show time for 1 second
mp.osd_message(s, 1)
end
collectgarbage()
collectgarbage()
end
local function osd_clock_toggle()
is_shown = not is_shown
-- make sure timer is defined (n>1 th toggle)
if osd_timer ~= nil then
if is_shown then
osd_timer:resume()
else
osd_timer:stop()
end
else
-- otherwise create a timer to call the clock on every second
osd_clock_timer()
osd_timer = mp.add_periodic_timer(1, osd_clock_timer)
end
end
mp.add_key_binding(cfg.key, 'show-clock', osd_clock)
mp.msg.verbose("key:'"..cfg.key.."' bound to 'show-clock'")
mp.add_key_binding(cfg.togglekey, 'toggle-clock', osd_clock_toggle)
mp.msg.verbose("key:'"..cfg.togglekey.."' bound to 'toggle-clock'")