dotfiles/awesome/background_widget.lua

84 lines
1.8 KiB
Lua
Raw Normal View History

2018-09-14 14:47:07 +02:00
local os = require('os')
naughty = require('naughty')
2018-09-13 16:54:24 +02:00
local wibox = require('wibox')
local awful = require('awful')
2018-09-13 17:23:13 +02:00
local gears = require('gears')
2018-09-14 14:47:07 +02:00
local json = require('json')
2018-09-13 17:23:13 +02:00
2018-09-14 14:47:07 +02:00
local home = os.getenv('HOME')
local todo_path = home .. '/.config/todo/todo.json'
2018-09-13 17:23:13 +02:00
2018-09-14 14:47:07 +02:00
function read_all(file)
return content
end
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,
2018-09-13 17:23:13 +02:00
align = 'left',
valign = 'top',
2018-09-14 14:47:07 +02:00
font = "Ubuntu 18",
2018-09-13 17:23:13 +02:00
widget = wibox.widget.textbox
}
2018-09-14 14:47:07 +02:00
local widget = wibox.widget.background(text, todo.color, function(cr, width, height)
2018-09-13 17:23:13 +02:00
gears.shape.rounded_rect(cr, width, height, 20)
end)
widget.shape_border_width = 1
widget.shape_border_color = "#ffffff"
2018-09-14 14:47:07 +02:00
widget.forced_width = todo.width
widget.forced_height = todo.height
widget.point = { x = todo.x, y = todo.y }
2018-09-13 17:23:13 +02:00
return widget
end
2018-09-13 16:54:24 +02:00
function add_background_widget(s)
2018-09-14 14:47:07 +02:00
local f = io.open(todo_path, "rb")
2018-09-13 16:54:24 +02:00
2018-09-14 14:47:07 +02:00
if f ~= nil then
2018-09-13 16:54:24 +02:00
2018-09-14 14:47:07 +02:00
local content = f:read("*all")
f:close()
2018-09-13 17:23:13 +02:00
2018-09-14 14:47:07 +02:00
todo = json.parse(content)
2018-09-13 16:54:24 +02:00
2018-09-14 14:47:07 +02:00
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
2018-09-13 16:54:24 +02:00
end
2018-09-14 14:47:07 +02:00