dotfiles/awesome/background_widget.lua

89 lines
1.9 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)
2018-09-14 15:06:13 +02:00
local text = '\n <b>' .. todo.title .. '</b> \n'
2018-09-14 14:47:07 +02:00
for key, item in pairs(todo.items) do
2018-09-14 15:06:13 +02:00
text = text .. ' - ' .. item .. ' \n'
2018-09-14 14:47:07 +02:00
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.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 15:06:13 +02:00
local margin = 25
2018-09-14 14:47:07 +02:00
local l = wibox.layout {
2018-09-17 09:14:49 +02:00
homogeneous = false,
2018-09-14 15:06:13 +02:00
spacing = margin,
forced_num_cols = 3,
layout = wibox.layout.grid,
2018-09-14 14:47:07 +02:00
}
2018-09-14 15:06:13 +02:00
l:set_orientation('horizontal')
2018-09-14 14:47:07 +02:00
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 {
2018-09-14 15:06:13 +02:00
wibox.container.margin(l, margin, margin, margin, margin),
2018-09-14 14:47:07 +02:00
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