]> git.madduck.net Git - etc/awesome.git/blob - widgets/contrib/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:

Merge branch 'trap000d-master'
[etc/awesome.git] / widgets / contrib / task.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Jan Xie                         
6                                                   
7 --]]
8
9 local helpers = require("lain.helpers")
10 local markup  = require("lain.util").markup
11 local awful   = require("awful")
12 local naughty = require("naughty")
13 local string  = { format = string.format, gsub = string.gsub }
14
15 -- Taskwarrior notification
16 -- lain.widgets.contrib.task
17 local task = {}
18
19 function task.hide()
20     if not task.notification then return end
21     naughty.destroy(task.notification)
22     task.notification = nil
23 end
24
25 function task.show(scr)
26     task.hide()
27
28     if task.followtag then
29         task.notification_preset.screen = awful.screen.focused()
30     elseif scr then
31         task.notification_preset.screen = scr
32     end
33
34     helpers.async(task.show_cmd, function(f)
35         task.notification = naughty.notify({
36             preset = task.notification_preset,
37             title  = task.show_cmd,
38             text   = markup.font(task.notification_preset.font,
39                      awful.util.escape(f:gsub("\n*$", "")))
40         })
41     end)
42 end
43
44 function task.prompt()
45     awful.prompt.run {
46         prompt       = task.prompt_text,
47         textbox      = awful.screen.focused().mypromptbox.widget,
48         exe_callback = function(t)
49             helpers.async(t, function(f)
50                 naughty.notify {
51                     preset = task.notification_preset,
52                     title    = t,
53                     text     = markup.font(task.notification_preset.font,
54                                awful.util.escape(f:gsub("\n*$", "")))
55                 }
56             end)
57         end,
58         history_path = awful.util.getdir("cache") .. "/history_task"
59     }
60 end
61
62 function task.attach(widget, args)
63     local args               = args or {}
64     task.show_cmd            = args.show_cmd or "task next"
65     task.prompt_text         = args.prompt_text or "Enter task command: "
66     task.followtag           = args.followtag or false
67     task.notification_preset = args.notification_preset
68
69     if not task.notification_preset then
70         task.notification_preset = {
71             font = "Monospace 10",
72             icon = helpers.icons_dir .. "/taskwarrior.png"
73         }
74     end
75
76     if widget then
77         widget:connect_signal("mouse::enter", function () task.show() end)
78         widget:connect_signal("mouse::leave", function () task.hide() end)
79     end
80 end
81
82 return task