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

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:

cf84cbcd131e2763933ebcaaf80c89d17f5e42ea
[etc/awesome.git] / widgets / task.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Jan Xie
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           = io
16 local os           = { date = os.date }
17 local tonumber     = tonumber
18
19 local setmetatable = setmetatable
20
21 -- task notification
22 -- lain.widgets.task
23 local task = {}
24 local task_notification = nil
25
26 function task:hide()
27     if task_notification ~= nil then
28         naughty.destroy(task_notification)
29         task_notification = nil
30     end
31 end
32
33 function task:show(t_out)
34     task:hide()
35
36     local tims = t_out or 0
37     local f, c_text
38     local today = tonumber(os.date('%d'))
39     local init_t = '/usr/bin/cal | sed -r -e "s/(^| )( '
40     -- let's take font only, font size is set in task table
41     local font = beautiful.font:sub(beautiful.font:find(""),
42                  beautiful.font:find(" "))
43
44     if today >= 10
45     then
46        init_t = '/usr/bin/cal | sed -r -e "s/(^| )('
47     end
48
49     task.offset = 0
50     --task.notify_icon = task.icons .. today .. ".png"
51
52     -- bg and fg inverted to highlight today
53     --f = io.popen( init_t .. today ..
54                   --')($| )/\\1<b><span foreground=\\"'
55                   --.. task.bg ..
56                   --'\\" background=\\"'
57                   --.. task.fg ..
58                   --'\\">\\2<\\/span><\\/b>\\3/"' )
59
60
61
62     --c_text = "<tt><span font='" .. font .. " "
63              --.. task.font_size .. "'><b>"
64              --.. f:read() .. "</b>\n\n"
65              --.. f:read() .. "\n"
66              --.. f:read("*all"):gsub("\n*$", "")
67              --.. "</span></tt>"
68     c_text = "hello tasks!"
69     --f:close()
70
71     task_notification = naughty.notify({ text = c_text,
72                                         --icon = task.notify_icon,
73                                         --position = task.position,
74                                         --fg = task.fg,
75                                         --bg = task.bg,
76                                         timeout = tims })
77 end
78
79 function task:attach(widget, args)
80     local args = args or {}
81     task.icons = args.icons or icons_dir .. "cal/white/"
82     task.font_size = tonumber(args.font_size) or 12
83     task.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
84     task.bg = args.bg or beautiful.bg_normal or "#FFFFFF"
85     task.position = args.position or "top_right"
86
87     task.offset = 0
88     task.notify_icon = nil
89
90     widget:connect_signal("mouse::enter", function () task:show() end)
91     widget:connect_signal("mouse::leave", function () task:hide() end)
92     widget:buttons(awful.util.table.join( awful.button({ }, 1, function ()
93                                               task:show(0, -1) end),
94                                           awful.button({ }, 3, function ()
95                                               task:show(0, 1) end) ))
96 end
97
98 return setmetatable(task, { __call = function(_, ...) return create(...) end })