From 3aaad9993a30b77bcb66c381f506397ee6874300 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 14 Sep 2018 21:21:58 +0200 Subject: [PATCH 1/6] Removed useless func --- awesome/background_widget.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index 3977df4..c46e3c9 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -8,11 +8,6 @@ local json = require('json') local home = os.getenv('HOME') local todo_path = home .. '/.config/todo/todo.json' -function read_all(file) - - return content -end - function todo_list_widget(todo, s) local text = '\n ' .. todo.title .. ' \n' From df6c67baacc416f98784ca60bff276e3de03ec4a Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 14 Sep 2018 21:23:14 +0200 Subject: [PATCH 2/6] Remove point --- awesome/background_widget.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index c46e3c9..c1d8e4d 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -30,7 +30,6 @@ function todo_list_widget(todo, s) widget.shape_border_width = 1 widget.shape_border_color = "#ffffff" - widget.point = { x = todo.x, y = todo.y } return widget From c339ead2124118691f1d890e5cfb74f9b2e60147 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 14 Sep 2018 21:32:18 +0200 Subject: [PATCH 3/6] Rename json to jsonutils to avoid conflict --- awesome/background_widget.lua | 2 +- awesome/{json.lua => jsonutils.lua} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename awesome/{json.lua => jsonutils.lua} (100%) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index c1d8e4d..62bede1 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -3,7 +3,7 @@ naughty = require('naughty') local wibox = require('wibox') local awful = require('awful') local gears = require('gears') -local json = require('json') +local json = require('jsonutils') local home = os.getenv('HOME') local todo_path = home .. '/.config/todo/todo.json' diff --git a/awesome/json.lua b/awesome/jsonutils.lua similarity index 100% rename from awesome/json.lua rename to awesome/jsonutils.lua From 37ecf108e053deade76250226ad8594a6494ef48 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sat, 15 Sep 2018 10:55:51 +0200 Subject: [PATCH 4/6] Async --- awesome/background_widget.lua | 64 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index 62bede1..dfd5b10 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -37,46 +37,50 @@ end function add_background_widget(s) - local f = io.open(todo_path, "rb") + awful.spawn.easy_async_with_shell(":", function() - if f ~= nil then + local f = io.open(todo_path, "rb") - local content = f:read("*all") - f:close() + if f ~= nil then - todo = json.parse(content) + local content = f:read("*all") + f:close() - local margin = 25 + todo = json.parse(content) - local l = wibox.layout { - homogeneous = true, - spacing = margin, - forced_num_cols = 3, - layout = wibox.layout.grid, - } + local margin = 25 - l:set_orientation('horizontal') + local l = wibox.layout { + homogeneous = true, + spacing = margin, + forced_num_cols = 3, + layout = wibox.layout.grid, + } - local widgets = {} + 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}) - 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) end From b67b5c5f43c3eb567b09ca9d59ef42a71b538848 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sun, 16 Sep 2018 13:09:47 +0200 Subject: [PATCH 5/6] Added indices --- awesome/background_widget.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index dfd5b10..4e3b1bc 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -8,12 +8,12 @@ local json = require('jsonutils') local home = os.getenv('HOME') local todo_path = home .. '/.config/todo/todo.json' -function todo_list_widget(todo, s) +function todo_list_widget(index, todo, s) - local text = '\n ' .. todo.title .. ' \n' + local text = '\n ' .. index .. '. ' .. todo.title .. ' \n' for key, item in pairs(todo.items) do - text = text .. ' - ' .. item .. ' \n' + text = text .. ' ' .. key .. '. ' .. item .. ' \n' end local text = wibox.widget { @@ -62,7 +62,7 @@ function add_background_widget(s) local widgets = {} for key, val in pairs(todo) do - l:add(todo_list_widget(val, s)) + l:add(todo_list_widget(key, val, s)) end background_widget = awful.wibar({ From 7c70080bbe7bb90600edc350412b7662629808df Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sun, 16 Sep 2018 15:18:46 +0200 Subject: [PATCH 6/6] Update widget --- awesome/background_widget.lua | 14 +++++++++++--- awesome/rc.lua | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/awesome/background_widget.lua b/awesome/background_widget.lua index 4e3b1bc..593fe4d 100644 --- a/awesome/background_widget.lua +++ b/awesome/background_widget.lua @@ -8,7 +8,9 @@ local json = require('jsonutils') local home = os.getenv('HOME') local todo_path = home .. '/.config/todo/todo.json' -function todo_list_widget(index, todo, s) +local widget = nil + +function todo_list_widget(index, todo) local text = '\n ' .. index .. '. ' .. todo.title .. ' \n' @@ -35,10 +37,14 @@ function todo_list_widget(index, todo, s) end -function add_background_widget(s) +function update_background_widget(s) awful.spawn.easy_async_with_shell(":", function() + if widget ~= nil then + widget:remove() + end + local f = io.open(todo_path, "rb") if f ~= nil then @@ -62,7 +68,7 @@ function add_background_widget(s) local widgets = {} for key, val in pairs(todo) do - l:add(todo_list_widget(key, val, s)) + l:add(todo_list_widget(key, val)) end background_widget = awful.wibar({ @@ -78,6 +84,8 @@ function add_background_widget(s) background_widget:struts({left=0, right=0, top=0, bottom=0}) + widget = background_widget + end end) diff --git a/awesome/rc.lua b/awesome/rc.lua index e7d9e2d..f93c416 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -295,7 +295,7 @@ awful.screen.connect_for_each_screen(function(s) }, } - add_background_widget(s) + update_background_widget(s) end) -- }}}