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

f2b49f45b74df8e7e97bd52e292a81e167fe5101
[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()
33     task:hide()
34
35     local f, c_text
36
37     f = io.popen('task')
38     c_text = "<tt><span font='" .. task.font .. " "
39              .. task.font_size+2 .. "'><b>Tasks next</b></span>\n"
40              .. "<span font='" .. task.font .. " "
41              .. task.font_size .. "'>"
42              .. f:read("*all") .. "\n"
43              .. "</span></tt>"
44     f:close()
45
46     task_notification = naughty.notify({ text = c_text,
47                                         icon = task.notify_icon,
48                                         position = task.position,
49                                         fg = task.fg,
50                                         bg = task.bg,
51                                         timeout = task.timeout })
52 end
53
54 function task:add(...)
55   local f = io.popen("task add " .. ...)
56   c_text = "<tt><span font='" .. task.font .. " "
57            .. task.font_size .. "'>"
58            .. f:read("*all") .. "\n"
59            .. "</span></tt>"
60
61   naughty.notify({ text = c_text,
62                    icon = task.notify_icon,
63                    position = task.position,
64                    fg = task.fg,
65                    bg = task.bg,
66                    timeout = task.timeout})
67 end
68
69 function task:prompt_add()
70   awful.prompt.run( { prompt = "Add task: " },
71                     mypromptbox[mouse.screen].widget,
72                     function (...)
73                       task:add(...)
74                     end,
75                     nil,
76                     awful.util.getdir("cache") .. "/history_task_add")
77 end
78
79 function task:execute(...)
80   local f = io.popen("task " .. ...)
81   c_text = "<tt><span font='" .. task.font .. " "
82            .. task.font_size .. "'>"
83            .. f:read("*all") .. "\n"
84            .. "</span></tt>"
85
86   naughty.notify({ text = c_text,
87                    icon = task.notify_icon,
88                    position = task.position,
89                    fg = task.fg,
90                    bg = task.bg,
91                    timeout = task.timeout})
92 end
93
94 function task:prompt()
95   awful.prompt.run( { prompt = "Task: " },
96                     mypromptbox[mouse.screen].widget,
97                     function (...)
98                       task:execute(...)
99                     end,
100                     nil,
101                     awful.util.getdir("cache") .. "/history_task")
102 end
103
104 function task:attach(widget, args)
105     local args = args or {}
106     task.font_size = tonumber(args.font_size) or 12
107     task.font = beautiful.font:sub(beautiful.font:find(""),
108                 beautiful.font:find(" "))
109     task.fg = args.fg or beautiful.fg_normal or "#FFFFFF"
110     task.bg = args.bg or beautiful.bg_normal or "#FFFFFF"
111     task.position = args.position or "top_right"
112     task.timeout = args.timeout or 7
113
114     task.notify_icon = icons_dir .. "taskwarrior.png"
115
116     widget:connect_signal("mouse::enter", function () task:show() end)
117     widget:connect_signal("mouse::leave", function () task:hide() end)
118     widget:buttons(awful.util.table.join( awful.button({ }, 1, function ()
119                                               task:show(0, -1) end),
120                                           awful.button({ }, 3, function ()
121                                               task:show(0, 1) end) ))
122 end
123
124 return setmetatable(task, { __call = function(_, ...) return create(...) end })