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

task widget: Check if mouse is still over attached widget in aync show
[etc/awesome.git] / widget / 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 mouse   = mouse
14 local string  = { format = string.format, gsub = string.gsub }
15
16 -- Taskwarrior notification
17 -- lain.widget.contrib.task
18 local task = {}
19
20 function task.hide()
21     if not task.notification then return end
22     naughty.destroy(task.notification)
23     task.notification = nil
24 end
25
26 function task.show(scr)
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({ awful.util.shell, "-c", task.show_cmd }, function(f)
35         local widget_focused = true
36
37         if mouse.current_widgets then
38             widget_focused = false
39             for _,v in ipairs(mouse.current_widgets) do
40                 if task.widget == v then
41                     widget_focused = true
42                     break
43                 end
44             end
45         end
46
47         if widget_focused then
48             task.hide()
49             task.notification = naughty.notify({
50                     preset = task.notification_preset,
51                     title  = "task next",
52                     text   = markup.font(task.notification_preset.font,
53                         awful.util.escape(f:gsub("\n*$", "")))
54                 })
55         end
56     end)
57 end
58
59 function task.prompt()
60     awful.prompt.run {
61         prompt       = task.prompt_text,
62         textbox      = awful.screen.focused().mypromptbox.widget,
63         exe_callback = function(t)
64             helpers.async(t, function(f)
65                 naughty.notify {
66                     preset = task.notification_preset,
67                     title  = t,
68                     text   = markup.font(task.notification_preset.font,
69                              awful.util.escape(f:gsub("\n*$", "")))
70                 }
71             end)
72         end,
73         history_path = awful.util.getdir("cache") .. "/history_task"
74     }
75 end
76
77 function task.attach(widget, args)
78     local args               = args or {}
79     task.show_cmd            = args.show_cmd or "task next"
80     task.prompt_text         = args.prompt_text or "Enter task command: "
81     task.followtag           = args.followtag or false
82     task.notification_preset = args.notification_preset
83     task.widget              = widget
84
85     if not task.notification_preset then
86         task.notification_preset = {
87             font = "Monospace 10",
88             icon = helpers.icons_dir .. "/taskwarrior.png"
89         }
90     end
91
92     if widget then
93         widget:connect_signal("mouse::enter", function () task.show() end)
94         widget:connect_signal("mouse::leave", function () task.hide() end)
95     end
96 end
97
98 return task