2018-09-14 13:47:07 +01:00
|
|
|
local os = require('os')
|
|
|
|
naughty = require('naughty')
|
2018-09-13 15:54:24 +01:00
|
|
|
local wibox = require('wibox')
|
|
|
|
local awful = require('awful')
|
2018-09-13 16:23:13 +01:00
|
|
|
local gears = require('gears')
|
2018-09-14 20:32:18 +01:00
|
|
|
local json = require('jsonutils')
|
2018-09-13 16:23:13 +01:00
|
|
|
|
2018-09-14 13:47:07 +01:00
|
|
|
local home = os.getenv('HOME')
|
|
|
|
local todo_path = home .. '/.config/todo/todo.json'
|
2018-09-13 16:23:13 +01:00
|
|
|
|
2018-09-16 14:18:46 +01:00
|
|
|
local widget = nil
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-16 14:18:46 +01:00
|
|
|
function todo_list_widget(index, todo)
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-16 12:09:47 +01:00
|
|
|
local text = '\n <b>' .. index .. '. ' .. todo.title .. '</b> \n'
|
2018-09-14 13:47:07 +01:00
|
|
|
|
|
|
|
for key, item in pairs(todo.items) do
|
2018-09-16 12:09:47 +01:00
|
|
|
text = text .. ' ' .. key .. '. ' .. item .. ' \n'
|
2018-09-14 13:47:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local text = wibox.widget {
|
|
|
|
markup = text,
|
2018-09-13 16:23:13 +01:00
|
|
|
align = 'left',
|
|
|
|
valign = 'top',
|
2018-09-14 13:47:07 +01:00
|
|
|
font = "Ubuntu 18",
|
2018-09-13 16:23:13 +01:00
|
|
|
widget = wibox.widget.textbox
|
|
|
|
}
|
|
|
|
|
2018-09-14 13:47:07 +01:00
|
|
|
local widget = wibox.widget.background(text, todo.color, function(cr, width, height)
|
2018-09-13 16:23:13 +01:00
|
|
|
gears.shape.rounded_rect(cr, width, height, 20)
|
|
|
|
end)
|
|
|
|
|
|
|
|
widget.shape_border_width = 1
|
|
|
|
widget.shape_border_color = "#ffffff"
|
|
|
|
|
|
|
|
return widget
|
|
|
|
|
|
|
|
end
|
2018-09-13 15:54:24 +01:00
|
|
|
|
2018-09-16 14:18:46 +01:00
|
|
|
function update_background_widget(s)
|
2018-09-13 15:54:24 +01:00
|
|
|
|
2018-09-17 08:16:27 +01:00
|
|
|
local margin = 25
|
2018-09-13 15:54:24 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
awful.spawn.easy_async_with_shell(":", function()
|
2018-09-13 15:54:24 +01:00
|
|
|
|
2018-09-17 08:20:54 +01:00
|
|
|
if s.widget ~= nil then
|
|
|
|
s.widget:remove()
|
2018-09-16 14:18:46 +01:00
|
|
|
end
|
2018-09-13 15:54:24 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
local f = io.open(todo_path, "rb")
|
2018-09-13 16:23:13 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
if f ~= nil then
|
2018-09-13 15:54:24 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
local content = f:read("*all")
|
|
|
|
f:close()
|
2018-09-14 14:06:13 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
todo = json.parse(content)
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
local l = wibox.layout {
|
2018-09-17 08:16:27 +01:00
|
|
|
homogeneous = false,
|
2018-09-15 09:55:51 +01:00
|
|
|
spacing = margin,
|
|
|
|
forced_num_cols = 3,
|
|
|
|
layout = wibox.layout.grid,
|
|
|
|
}
|
2018-09-14 14:06:13 +01:00
|
|
|
|
2018-09-19 09:56:48 +01:00
|
|
|
-- l:set_orientation('horizontal')
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
local widgets = {}
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
for key, val in pairs(todo) do
|
2018-09-16 14:18:46 +01:00
|
|
|
l:add(todo_list_widget(key, val))
|
2018-09-15 09:55:51 +01:00
|
|
|
end
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
background_widget = awful.wibar({
|
|
|
|
screen = s,
|
|
|
|
height = s.geometry.height,
|
|
|
|
bg = "#00000000",
|
|
|
|
})
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
background_widget:setup {
|
|
|
|
wibox.container.margin(l, margin, margin, margin, margin),
|
|
|
|
layout = wibox.layout.manual
|
|
|
|
}
|
2018-09-14 13:47:07 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
background_widget:struts({left=0, right=0, top=0, bottom=0})
|
|
|
|
|
2018-09-17 08:20:54 +01:00
|
|
|
s.widget = background_widget
|
2018-09-16 14:18:46 +01:00
|
|
|
|
2018-09-15 09:55:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end)
|
2018-09-13 15:54:24 +01:00
|
|
|
|
|
|
|
end
|
2018-09-14 13:47:07 +01:00
|
|
|
|