From 04a8ef58764553691ddf0942f41e31f581d77f21 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 14 Sep 2018 14:47:07 +0200 Subject: [PATCH] Todo stats to work --- awesome/background_widget.lua | 76 +++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index c43ac5c..a6e6429 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -1,26 +1,43 @@ +local os = require('os') +naughty = require('naughty') local wibox = require('wibox') local awful = require('awful') local gears = require('gears') +local json = require('json') -function todo_list_widget(s) +local home = os.getenv('HOME') +local todo_path = home .. '/.config/todo/todo.json' - local text = wibox.widget{ - markup = '\n TODO\n - Hello', +function read_all(file) + + return content +end + +function todo_list_widget(todo, s) + + local text = '\n ' .. todo.title .. '\n' + + for key, item in pairs(todo.items) do + text = text .. ' - ' .. item .. '\n' + end + + local text = wibox.widget { + markup = text, align = 'left', valign = 'top', - font = "Ubuntu 20", + font = "Ubuntu 18", widget = wibox.widget.textbox } - local widget = wibox.widget.background(text, "#000000aa", function(cr, width, height) + local widget = wibox.widget.background(text, todo.color, function(cr, width, height) gears.shape.rounded_rect(cr, width, height, 20) end) widget.shape_border_width = 1 widget.shape_border_color = "#ffffff" - widget.forced_width = 500 - widget.forced_height = 500 - widget.point = { x = 20, y = 30 } + widget.forced_width = todo.width + widget.forced_height = todo.height + widget.point = { x = todo.x, y = todo.y } return widget @@ -28,22 +45,39 @@ end function add_background_widget(s) - background_widget = awful.wibar({ - screen = s, - height = s.geometry.height, - bg = "#00000000", - }) + local f = io.open(todo_path, "rb") - local text = wibox.widget.textbox("Hello to you") - text.point = { x = 75, y = 200 } + if f ~= nil then - local w = todo_list_widget(s) + local content = f:read("*all") + f:close() - background_widget:setup { - layout = wibox.layout.manual, - w - } + todo = json.parse(content) - background_widget:struts({left=0, right=0, top=0, bottom=0}) + local l = wibox.layout { + layout = wibox.layout.manual + } + + local widgets = {} + + for key, val in pairs(todo) do + l:add(todo_list_widget(val, s)) + end + + background_widget = awful.wibar({ + screen = s, + height = s.geometry.height, + bg = "#00000000", + }) + + background_widget:setup { + l, + layout = wibox.layout.manual + } + + background_widget:struts({left=0, right=0, top=0, bottom=0}) + + end end +