]> 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:

show next tasks
[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 tonumber     = tonumber
17
18 local setmetatable = setmetatable
19
20 -- task notification
21 -- lain.widgets.task
22 local task = {}
23 local task_notification = nil
24
25 function task:hide()
26     if task_notification ~= nil then
27         naughty.destroy(task_notification)
28         task_notification = nil
29     end
30 end
31
32 function task:show(t_out)
33     task:hide()
34
35     local tims = t_out or 0
36     local f, c_text
37     -- let's take font only, font size is set in task table
38     local font = beautiful.font:sub(beautiful.font:find(""),
39                  beautiful.font:find(" "))
40
41     task.offset = 0
42     --task.notify_icon = task.icons .. today .. ".png"
43
44     f = io.popen('task')
45     c_text = "<tt><span font='" .. font .. " "
46              .. task.font_size .. "'><b>[Next Tasks]</b>\n"
47              .. f:read("*all") .. "\n"
48              .. "</span></tt>"
49     f:close()
50
51     task_notification = naughty.notify({ text = c_text,
52                                         --icon = task.notify_icon,
53                                         --position = task.position,
54                                         --fg = task.fg,
55                                         --bg = task.bg,
56                                         timeout = tims })
57 end
58
59 function task:attach(widget, args)
60     local args = args or {}
61     task.icons = args.icons or icons_dir .. "cal/white/"
62     task.font_size = tonumber(args.font_size) or 12
63     task.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
64     task.bg = args.bg or beautiful.bg_normal or "#FFFFFF"
65     task.position = args.position or "top_right"
66
67     task.offset = 0
68     task.notify_icon = nil
69
70     widget:connect_signal("mouse::enter", function () task:show() end)
71     widget:connect_signal("mouse::leave", function () task:hide() end)
72     widget:buttons(awful.util.table.join( awful.button({ }, 1, function ()
73                                               task:show(0, -1) end),
74                                           awful.button({ }, 3, function ()
75                                               task:show(0, 1) end) ))
76 end
77
78 return setmetatable(task, { __call = function(_, ...) return create(...) end })