diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua
index c3c9e85..415d267 100644
--- a/awesome/background_widget.lua
+++ b/awesome/background_widget.lua
@@ -3,22 +3,19 @@ naughty = require('naughty')
local wibox = require('wibox')
local awful = require('awful')
local gears = require('gears')
-local json = require('json')
+local json = require('jsonutils')
local home = os.getenv('HOME')
local todo_path = home .. '/.config/todo/todo.json'
-function read_all(file)
+local widget = nil
- return content
-end
+function todo_list_widget(index, todo)
-function todo_list_widget(todo, s)
-
- local text = '\n ' .. todo.title .. ' \n'
+ local text = '\n ' .. index .. '. ' .. todo.title .. ' \n'
for key, item in pairs(todo.items) do
- text = text .. ' - ' .. item .. ' \n'
+ text = text .. ' ' .. key .. '. ' .. item .. ' \n'
end
local text = wibox.widget {
@@ -35,54 +32,63 @@ function todo_list_widget(todo, s)
widget.shape_border_width = 1
widget.shape_border_color = "#ffffff"
- widget.point = { x = todo.x, y = todo.y }
return widget
end
-function add_background_widget(s)
+function update_background_widget(s)
- local f = io.open(todo_path, "rb")
+ local margin = 25
- if f ~= nil then
+ awful.spawn.easy_async_with_shell(":", function()
- local content = f:read("*all")
- f:close()
-
- todo = json.parse(content)
-
- local margin = 25
-
- local l = wibox.layout {
- homogeneous = false,
- spacing = margin,
- forced_num_cols = 3,
- layout = wibox.layout.grid,
- }
-
- l:set_orientation('horizontal')
-
- local widgets = {}
-
- for key, val in pairs(todo) do
- l:add(todo_list_widget(val, s))
+ if widget ~= nil then
+ widget:remove()
end
- background_widget = awful.wibar({
- screen = s,
- height = s.geometry.height,
- bg = "#00000000",
- })
+ local f = io.open(todo_path, "rb")
- background_widget:setup {
- wibox.container.margin(l, margin, margin, margin, margin),
- layout = wibox.layout.manual
- }
+ if f ~= nil then
- background_widget:struts({left=0, right=0, top=0, bottom=0})
+ local content = f:read("*all")
+ f:close()
- end
+ todo = json.parse(content)
+
+ local l = wibox.layout {
+ homogeneous = false,
+ spacing = margin,
+ forced_num_cols = 3,
+ layout = wibox.layout.grid,
+ }
+
+ l:set_orientation('horizontal')
+
+ local widgets = {}
+
+ for key, val in pairs(todo) do
+ l:add(todo_list_widget(key, val))
+ end
+
+ background_widget = awful.wibar({
+ screen = s,
+ height = s.geometry.height,
+ bg = "#00000000",
+ })
+
+ background_widget:setup {
+ wibox.container.margin(l, margin, margin, margin, margin),
+ layout = wibox.layout.manual
+ }
+
+ background_widget:struts({left=0, right=0, top=0, bottom=0})
+
+ widget = background_widget
+
+ end
+
+ end)
end
diff --git a/awesome/json.lua b/awesome/jsonutils.lua
similarity index 100%
rename from awesome/json.lua
rename to awesome/jsonutils.lua
diff --git a/awesome/rc.lua b/awesome/rc.lua
index e7d9e2d..f93c416 100644
--- a/awesome/rc.lua
+++ b/awesome/rc.lua
@@ -295,7 +295,7 @@ awful.screen.connect_for_each_screen(function(s)
},
}
- add_background_widget(s)
+ update_background_widget(s)
end)
-- }}}