dotfiles/awesome/background_widget.lua

84 lines
1.9 KiB
Lua

local os = require('os')
naughty = require('naughty')
local wibox = require('wibox')
local awful = require('awful')
local gears = require('gears')
local json = require('json')
local home = os.getenv('HOME')
local todo_path = home .. '/.config/todo/todo.json'
function todo_list_widget(todo, s)
local text = '\n <b>' .. todo.title .. '</b> \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 18",
widget = wibox.widget.textbox
}
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.point = { x = todo.x, y = todo.y }
return widget
end
function add_background_widget(s)
local f = io.open(todo_path, "rb")
if f ~= nil then
local content = f:read("*all")
f:close()
todo = json.parse(content)
local margin = 25
local l = wibox.layout {
homogeneous = true,
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))
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})
end
end