dotfiles/awesome/background_widget.lua

87 lines
2.0 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')
local json = require('jsonutils')
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 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"
return widget
end
2018-09-13 16:54:24 +02:00
function add_background_widget(s)
2018-09-15 10:55:51 +02:00
awful.spawn.easy_async_with_shell(":", function()
2018-09-13 16:54:24 +02:00
2018-09-15 10:55:51 +02:00
local f = io.open(todo_path, "rb")
2018-09-13 16:54:24 +02:00
2018-09-15 10:55:51 +02:00
if f ~= nil then
2018-09-13 17:23:13 +02:00
2018-09-15 10:55:51 +02:00
local content = f:read("*all")
f:close()
2018-09-13 16:54:24 +02:00
2018-09-15 10:55:51 +02:00
todo = json.parse(content)
2018-09-14 15:06:13 +02:00
2018-09-15 10:55:51 +02:00
local margin = 25
2018-09-14 14:47:07 +02:00
2018-09-15 10:55:51 +02:00
local l = wibox.layout {
homogeneous = true,
spacing = margin,
forced_num_cols = 3,
layout = wibox.layout.grid,
}
2018-09-14 15:06:13 +02:00
2018-09-15 10:55:51 +02:00
l:set_orientation('horizontal')
2018-09-14 14:47:07 +02:00
2018-09-15 10:55:51 +02:00
local widgets = {}
2018-09-14 14:47:07 +02:00
2018-09-15 10:55:51 +02:00
for key, val in pairs(todo) do
l:add(todo_list_widget(val, s))
end
2018-09-14 14:47:07 +02:00
2018-09-15 10:55:51 +02:00
background_widget = awful.wibar({
screen = s,
height = s.geometry.height,
bg = "#00000000",
})
2018-09-14 14:47:07 +02:00
2018-09-15 10:55:51 +02:00
background_widget:setup {
wibox.container.margin(l, margin, margin, margin, margin),
layout = wibox.layout.manual
}
2018-09-14 14:47:07 +02:00
2018-09-15 10:55:51 +02:00
background_widget:struts({left=0, right=0, top=0, bottom=0})
end
end)
2018-09-13 16:54:24 +02:00
end
2018-09-14 14:47:07 +02:00