dotfiles/awesome/lain/widget/contrib/task.lua

97 lines
2.2 KiB
Lua
Raw Normal View History

2022-12-24 20:58:57 +00:00
--[[
Licensed under GNU General Public License v2
* (c) 2013, Jan Xie
--]]
2023-01-25 19:10:58 +00:00
local helpers = require('lain.helpers')
local markup = require('lain.util').markup
local awful = require('awful')
local naughty = require('naughty')
local mouse = mouse
2022-12-24 20:58:57 +00:00
-- Taskwarrior notification
-- lain.widget.contrib.task
local task = {}
function task.hide()
2023-01-25 19:10:58 +00:00
if not task.notification then
return
end
naughty.destroy(task.notification)
task.notification = nil
2022-12-24 20:58:57 +00:00
end
function task.show(scr)
2023-01-25 19:10:58 +00:00
task.notification_preset.screen = task.followtag and awful.screen.focused() or scr or 1
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
helpers.async({ awful.util.shell, '-c', task.show_cmd }, function(f)
local widget_focused = true
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
if mouse.current_widgets then
widget_focused = false
for _, v in ipairs(mouse.current_widgets) do
if task.widget == v then
widget_focused = true
break
end
end
end
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
if widget_focused then
task.hide()
task.notification = naughty.notify({
preset = task.notification_preset,
title = 'task next',
text = markup.font(task.notification_preset.font, awful.util.escape(f:gsub('\n*$', ''))),
})
end
end)
2022-12-24 20:58:57 +00:00
end
function task.prompt()
2023-01-25 19:10:58 +00:00
awful.prompt.run({
prompt = task.prompt_text,
textbox = awful.screen.focused().mypromptbox.widget,
exe_callback = function(t)
helpers.async(t, function(f)
naughty.notify({
preset = task.notification_preset,
title = t,
text = markup.font(task.notification_preset.font, awful.util.escape(f:gsub('\n*$', ''))),
})
end)
end,
history_path = awful.util.getdir('cache') .. '/history_task',
})
2022-12-24 20:58:57 +00:00
end
function task.attach(widget, args)
2023-01-25 19:10:58 +00:00
args = args or {}
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
task.show_cmd = args.show_cmd or 'task next'
task.prompt_text = args.prompt_text or 'Enter task command: '
task.followtag = args.followtag or false
task.notification_preset = args.notification_preset
task.widget = widget
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
if not task.notification_preset then
task.notification_preset = {
font = 'Monospace 10',
icon = helpers.icons_dir .. '/taskwarrior.png',
}
end
2022-12-24 20:58:57 +00:00
2023-01-25 19:10:58 +00:00
if widget then
widget:connect_signal('mouse::enter', function()
task.show()
end)
widget:connect_signal('mouse::leave', function()
task.hide()
end)
end
2022-12-24 20:58:57 +00:00
end
return task