]> git.madduck.net Git - etc/awesome.git/blob - widgets/calendar.lua.orig

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Delete asyncshell_LOCAL_1080.lua
[etc/awesome.git] / widgets / calendar.lua.orig
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Luke Bonham                     
6                                                   
7 --]]
8
9 local icons_dir    = require("lain.helpers").icons_dir
10
11 local awful        = require("awful")
12 local beautiful    = require("beautiful")
13 local naughty      = require("naughty")
14
15 local io           = { popen = io.popen }
16 local os           = { date = os.date }
17 <<<<<<< HEAD
18 =======
19 local mouse        = mouse
20 >>>>>>> upstream/master
21 local tonumber     = tonumber
22
23 local setmetatable = setmetatable
24
25 -- Calendar notification
26 -- lain.widgets.calendar
27 local calendar = {}
28 local cal_notification = nil
29
30 function calendar:hide()
31     if cal_notification ~= nil then
32         naughty.destroy(cal_notification)
33         cal_notification = nil
34     end
35 end
36
37 function calendar:show(t_out, inc_offset, scr)
38     calendar:hide()
39
40     local offs = inc_offset or 0
41     local tims = t_out or 0
42     local f, c_text
43     local today = tonumber(os.date('%d'))
44     local init_t = calendar.cal .. ' ' .. calendar.post_cal  .. ' ' ..
45         ' | sed -r -e "s/_\\x08//g" | sed -r -e "s/(^| )('
46
47     calendar.offset = calendar.offset + offs
48
49     if offs == 0 or calendar.offset == 0
50     then -- current month showing, today highlighted
51         calendar.offset = 0
52         calendar.notify_icon = calendar.icons .. today .. ".png"
53
54         -- bg and fg inverted to highlight today
55         f = io.popen( init_t .. today ..
56                       ')($| )/\\1<b><span foreground=\\"'
57                       .. calendar.bg ..
58                       '\\" background=\\"'
59                       .. calendar.fg ..
60                       '\\">\\2<\\/span><\\/b>\\3/"' )
61
62     else -- no current month showing, no day to highlight
63        local month = tonumber(os.date('%m'))
64        local year = tonumber(os.date('%Y'))
65
66        month = month + calendar.offset
67
68        if month > 12 then
69            month = month % 12
70            year = year + 1
71            if month <= 0 then
72                month = 12
73            end
74        elseif month < 1 then
75            month = month + 12
76            year = year - 1
77            if month <= 0 then
78                month = 1
79            end
80        end
81
82        calendar.notify_icon = nil
83
84        f = io.popen(calendar.cal .. ' ' .. month .. ' ' .. year .. ' ' ..
85             calendar.post_cal)
86     end
87
88     c_text = "<tt><span font='" .. calendar.font .. " "
89              .. calendar.font_size .. "'><b>"
90              .. f:read() .. "</b>\n\n"
91              .. f:read() .. "\n"
92 <<<<<<< HEAD
93              .. f:read("*a"):gsub("\n*$", "")
94              .. "</span></tt>"
95     f:close()
96
97 =======
98              .. f:read("*all"):gsub("\n*$", "")
99              .. "</span></tt>"
100     f:close()
101
102     if calendar.followmouse then
103         scrp = mouse.screen
104     else
105         scrp = scr or calendar.scr_pos
106     end
107
108 >>>>>>> upstream/master
109     cal_notification = naughty.notify({
110         text = c_text,
111         icon = calendar.notify_icon,
112         position = calendar.position,
113         fg = calendar.fg,
114         bg = calendar.bg,
115         timeout = tims,
116 <<<<<<< HEAD
117         screen = scr or 1
118 =======
119         screen = scrp
120 >>>>>>> upstream/master
121     })
122 end
123
124 function calendar:attach(widget, args)
125     local args = args or {}
126 <<<<<<< HEAD
127     calendar.cal       = args.cal or "/usr/bin/cal"
128     calendar.post_cal  = args.post_cal or ""
129     calendar.icons     = args.icons or icons_dir .. "cal/white/"
130     calendar.font      = args.font or beautiful.font:sub(beautiful.font:find(""),
131                          beautiful.font:find(" "))
132     calendar.font_size = tonumber(args.font_size) or 11
133     calendar.fg        = args.fg or beautiful.fg_normal or "#FFFFFF"
134     calendar.bg        = args.bg or beautiful.bg_normal or "#FFFFFF"
135     calendar.position  = args.position or "top_right"
136     calendar.scr_pos   = args.scr_pos or 1
137
138     calendar.offset = 0
139     calendar.notify_icon = nil
140
141     widget:connect_signal("mouse::enter", function () calendar:show(0, 0, scr_pos) end)
142     widget:connect_signal("mouse::leave", function () calendar:hide() end)
143     widget:buttons(awful.util.table.join( awful.button({ }, 1, function ()
144                                               calendar:show(0, -1, scr_pos) end),
145                                           awful.button({ }, 3, function ()
146                                               calendar:show(0, 1, scr_pos) end),
147                                           awful.button({ }, 4, function ()
148                                               calendar:show(0, -1, scr_pos) end),
149                                           awful.button({ }, 5, function ()
150                                               calendar:show(0, 1, scr_pos) end)))
151 =======
152
153     calendar.cal         = args.cal or "/usr/bin/cal"
154     calendar.post_cal    = args.post_cal or ""
155     calendar.icons       = args.icons or icons_dir .. "cal/white/"
156     calendar.font        = args.font or beautiful.font:sub(beautiful.font:find(""),
157                            beautiful.font:find(" "))
158     calendar.font_size   = tonumber(args.font_size) or 11
159     calendar.fg          = args.fg or beautiful.fg_normal or "#FFFFFF"
160     calendar.bg          = args.bg or beautiful.bg_normal or "#FFFFFF"
161     calendar.position    = args.position or "top_right"
162     calendar.scr_pos     = args.scr_pos or 1
163     calendar.followmouse = args.followmouse or false
164
165     calendar.offset      = 0
166     calendar.notify_icon = nil
167
168     widget:connect_signal("mouse::enter", function () calendar:show(0, 0, calendar.scr_pos) end)
169     widget:connect_signal("mouse::leave", function () calendar:hide() end)
170     widget:buttons(awful.util.table.join(awful.button({ }, 1, function ()
171                                              calendar:show(0, -1, calendar.scr_pos) end),
172                                          awful.button({ }, 3, function ()
173                                              calendar:show(0, 1, calendar.scr_pos) end),
174                                          awful.button({ }, 4, function ()
175                                              calendar:show(0, -1, calendar.scr_pos) end),
176                                          awful.button({ }, 5, function ()
177                                              calendar:show(0, 1, calendar.scr_pos) end)))
178 >>>>>>> upstream/master
179 end
180
181 return setmetatable(calendar, { __call = function(_, ...) return create(...) end })