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

add screen and tag arguments to useless_gaps_resize function
[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     if task.followtag then
27         task.notification_preset.screen = awful.screen.focused()
28     elseif scr then
29         task.notification_preset.screen = scr
30     end
31
32     helpers.async({ awful.util.shell, "-c", task.show_cmd }, function(f)
33         local widget_focused = true
34
35         if mouse.current_widgets then
36             widget_focused = false
37             for _,v in ipairs(mouse.current_widgets) do
38                 if task.widget == v then
39                     widget_focused = true
40                     break
41                 end
42             end
43         end
44
45         if widget_focused then
46             task.hide()
47             task.notification = naughty.notify({
48                     preset = task.notification_preset,
49                     title  = "task next",
50                     text   = markup.font(task.notification_preset.font,
51                              awful.util.escape(f:gsub("\n*$", "")))
52                 })
53         end
54     end)
55 end
56
57 function task.prompt()
58     awful.prompt.run {
59         prompt       = task.prompt_text,
60         textbox      = awful.screen.focused().mypromptbox.widget,
61         exe_callback = function(t)
62             helpers.async(t, function(f)
63                 naughty.notify {
64                     preset = task.notification_preset,
65                     title  = t,
66                     text   = markup.font(task.notification_preset.font,
67                              awful.util.escape(f:gsub("\n*$", "")))
68                 }
69             end)
70         end,
71         history_path = awful.util.getdir("cache") .. "/history_task"
72     }
73 end
74
75 function task.attach(widget, args)
76     local args               = args or {}
77     task.show_cmd            = args.show_cmd or "task next"
78     task.prompt_text         = args.prompt_text or "Enter task command: "
79     task.followtag           = args.followtag or false
80     task.notification_preset = args.notification_preset
81     task.widget              = widget
82
83     if not task.notification_preset then
84         task.notification_preset = {
85             font = "Monospace 10",
86             icon = helpers.icons_dir .. "/taskwarrior.png"
87         }
88     end
89
90     if widget then
91         widget:connect_signal("mouse::enter", function () task.show() end)
92         widget:connect_signal("mouse::leave", function () task.hide() end)
93     end
94 end
95
96 return task