-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.lua
More file actions
92 lines (79 loc) · 2.42 KB
/
Copy pathclock.lua
File metadata and controls
92 lines (79 loc) · 2.42 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
-- SPDX-FileCopyrightText: Robert Ryszard Paciorek <rrp@opcode.eu.org>
-- SPDX-License-Identifier: MIT
require "cairo"
require "utils"
local stdlib = require "posix.stdlib"
local time = require "posix.time"
local tz = 1
-------------------------
--- Cairo widgets ---
-------------------------
function clock_set_tz(timezone_idx)
tz = timezone_idx
stdlib.setenv("TZ", TIME_ZONES[tz], 1)
time.tzset()
end
function clock_event(event)
if (event.y > CLOCK.Y and event.x > CLOCK.X and event.x < CLOCK.X + CLOCK.W) then
if event.type == "mouse_move" then
tooltip_show(CLOCK, event.x, event.y)
elseif event.type == "button_down" then
tooltip_until = os.time() + 2
os.execute([[
wl=$(xdotool search --name 'ConkyCalendarWidget')
if [ "$wl" != "" ]; then
for w in $wl; do
kill $(xdotool getwindowpid $w)
done;
else
yad --calendar --show-weeks --posx=-55 --posy=-60 --close-on-unfocus --undecorated --no-buttons --skip-taskbar --title ConkyCalendarWidget &
fi
]])
elseif event.type == "mouse_scroll" then
if event.direction == "up" then
tz = tz + 1
if (tz > TIME_ZONES_MAX) then tz = 1 end
else
tz = tz - 1
if (tz == 0) then tz = TIME_ZONES_MAX end
end
clock_set_tz(tz)
end
return true
end
return false
end
function draw_clock(cr, conf)
cairo_set_source_rgba(cr, 1, 1, 1, 1)
cairo_select_font_face(cr, "DejaVu Sans", 0, 1)
cairo_set_font_size(cr, 18)
local str = os.date("%T %Z")
cairo_text_extents(cr, str, te)
local align = math.max(0, math.abs(math.floor((conf.W - te.width) / 2)))
local y = conf.Y + te.height
cairo_move_to(cr, conf.X+align, y)
cairo_show_text(cr, str)
cairo_set_font_size(cr, 14)
local str = os.date("%F")
cairo_text_extents(cr, str, te)
local align = math.max(0, math.abs(math.floor((conf.W - te.width) / 2)))
y = y + te.height+7
cairo_move_to(cr, conf.X+align, y)
cairo_show_text(cr, os.date(str))
local str = os.date("%A")
cairo_text_extents(cr, str, te)
local align = math.max(0, math.abs(math.floor((conf.W - te.width) / 2)))
y = y + te.height+3
cairo_move_to(cr, conf.X+align, y)
cairo_show_text(cr, os.date(str))
end
function draw_clock_tooltip(cr, conf)
if not is_tooltip_visible(conf) then return end
local tm = time.localtime(time.time())
local str = {
time.strftime("%B", tm),
time.strftime("%j day of year, %u day of %V week", tm),
time.strftime("epoch: %s, TZ: UTC%z", tm),
}
tooltip_draw(cr, str)
end