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

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