-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar2.lua
118 lines (105 loc) · 3.77 KB
/
calendar2.lua
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
-- original code made by Bzed and published on http://awesome.naquadah.org/wiki/Calendar_widget
-- modified by Marc Dequènes (Duck) <Duck@DuckCorp.org> (2009-12-29), under the same licence,
-- and with the following changes:
-- + transformed to module
-- + the current day formating is customizable
local string = string
--local print = print
local tostring = tostring
local os = os
local capi = {
mouse = mouse,
screen = screen
}
local awful = require("awful")
local naughty = require("naughty")
module("calendar2")
local calendar = {}
local current_day_format = "<u>%s</u>"
function displayMonth(month,year,weekStart)
local t,wkSt=os.time{year=year, month=month+1, day=0},weekStart or 1
local d=os.date("*t",t)
local mthDays,stDay=d.day,(d.wday-d.day-wkSt+1)%7
--print(mthDays .."\n" .. stDay)
local lines = " "
for x=0,6 do
lines = lines .. os.date("%a ",os.time{year=2006,month=1,day=x+wkSt})
end
lines = lines .. "\n" .. os.date(" %V",os.time{year=year,month=month,day=1})
local writeLine = 1
while writeLine < (stDay + 1) do
lines = lines .. " "
writeLine = writeLine + 1
end
for d=1,mthDays do
local x = d
local t = os.time{year=year,month=month,day=d}
if writeLine == 8 then
writeLine = 1
lines = lines .. "\n" .. os.date(" %V",t)
end
if os.date("%Y-%m-%d") == os.date("%Y-%m-%d", t) then
x = string.format(current_day_format, d)
end
if (#(tostring(d)) == 1) then
x = " " .. x
end
lines = lines .. " " .. x
writeLine = writeLine + 1
end
local header = os.date("%B %Y\n",os.time{year=year,month=month,day=1})
return header .. "\n" .. lines
end
function switchNaughtyMonth(switchMonths)
if (#calendar < 3) then return end
local swMonths = switchMonths or 1
calendar[1] = calendar[1] + swMonths
naughty.notify({
text = string.format('<span font_desc="%s">%s</span>', "monospace", displayMonth(calendar[1], calendar[2], 2)),
timeout = 0,
hover_timeout = 0.5,
screen = capi.mouse.screen,
replaces_id = calendar[3].id
})
end
function addCalendarToWidget(mywidget, custom_current_day_format)
if custom_current_day_format then current_day_format = custom_current_day_format end
mywidget:connect_signal('mouse::enter', function ()
local month, year = os.date('%m'), os.date('%Y')
calendar = { month, year,
naughty.notify({
text = string.format('<span font_desc="%s">%s</span>', "monospace", displayMonth(month, year, 2)),
timeout = 0,
hover_timeout = 0.5,
screen = capi.mouse.screen
})
}
end)
mywidget:connect_signal('mouse::leave', function () naughty.destroy(calendar[3]) end)
mywidget:buttons(awful.util.table.join(
awful.button({ }, 1, function()
switchNaughtyMonth(-1)
end),
awful.button({ }, 3, function()
switchNaughtyMonth(1)
end),
awful.button({ }, 4, function()
switchNaughtyMonth(-1)
end),
awful.button({ }, 5, function()
switchNaughtyMonth(1)
end),
awful.button({ 'Shift' }, 1, function()
switchNaughtyMonth(-12)
end),
awful.button({ 'Shift' }, 3, function()
switchNaughtyMonth(12)
end),
awful.button({ 'Shift' }, 4, function()
switchNaughtyMonth(-12)
end),
awful.button({ 'Shift' }, 5, function()
switchNaughtyMonth(12)
end)
))
end