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

util.quake: removed onlyone parameters; wiki updated; counters #339
[etc/awesome.git] / widget / contrib / task.lua
1 --[[
2
3      Licensed under GNU General Public License v2
4       * (c) 2013, Jan Xie
5
6 --]]
7
8 local helpers = require("lain.helpers")
9 local markup  = require("lain.util").markup
10 local awful   = require("awful")
11 local naughty = require("naughty")
12 local mouse   = mouse
13 local string  = { format = string.format, gsub = string.gsub }
14
15 -- Taskwarrior notification
16 -- lain.widget.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
27     if task.followtag then
28         task.notification_preset.screen = awful.screen.focused()
29     elseif scr then
30         task.notification_preset.screen = scr
31     end
32
33     helpers.async({ awful.util.shell, "-c", task.show_cmd }, function(f)
34         local widget_focused = true
35
36         if mouse.current_widgets then
37             widget_focused = false
38             for _,v in ipairs(mouse.current_widgets) do
39                 if task.widget == v then
40                     widget_focused = true
41                     break
42                 end
43             end
44         end
45
46         if widget_focused then
47             task.hide()
48             task.notification = naughty.notify({
49                     preset = task.notification_preset,
50                     title  = "task next",
51                     text   = markup.font(task.notification_preset.font,
52                         awful.util.escape(f:gsub("\n*$", "")))
53                 })
54         end
55     end)
56 end
57
58 function task.prompt()
59     awful.prompt.run {
60         prompt       = task.prompt_text,
61         textbox      = awful.screen.focused().mypromptbox.widget,
62         exe_callback = function(t)
63             helpers.async(t, function(f)
64                 naughty.notify {
65                     preset = task.notification_preset,
66                     title  = t,
67                     text   = markup.font(task.notification_preset.font,
68                              awful.util.escape(f:gsub("\n*$", "")))
69                 }
70             end)
71         end,
72         history_path = awful.util.getdir("cache") .. "/history_task"
73     }
74 end
75
76 function task.attach(widget, args)
77     local args               = args or {}
78     task.show_cmd            = args.show_cmd or "task next"
79     task.prompt_text         = args.prompt_text or "Enter task command: "
80     task.followtag           = args.followtag or false
81     task.notification_preset = args.notification_preset
82     task.widget              = widget
83
84     if not task.notification_preset then
85         task.notification_preset = {
86             font = "Monospace 10",
87             icon = helpers.icons_dir .. "/taskwarrior.png"
88         }
89     end
90
91     if widget then
92         widget:connect_signal("mouse::enter", function () task.show() end)
93         widget:connect_signal("mouse::leave", function () task.hide() end)
94     end
95 end
96
97 return task