first attempt to make it leakless

This commit is contained in:
streetturtle 2018-12-19 22:39:53 -05:00
parent 855677d667
commit 29118150a9
1 changed files with 119 additions and 70 deletions

View File

@ -7,6 +7,10 @@
-- @copyright 2018 Pavel Makhov -- @copyright 2018 Pavel Makhov
------------------------------------------------- -------------------------------------------------
local capi = {
screen = screen,
client = client,
}
local awful = require("awful") local awful = require("awful")
local gfs = require("gears.filesystem") local gfs = require("gears.filesystem")
local wibox = require("wibox") local wibox = require("wibox")
@ -16,24 +20,38 @@ local completion = require("awful.completion")
local run_shell = awful.widget.prompt() local run_shell = awful.widget.prompt()
local w = wibox {
local function get_screen(s)
return s and capi.screen[s]
end
local widget = {}
function widget.new()
local widget_instance = {
_cached_wiboxes = {},
}
function widget_instance:_create_wibox()
local w = wibox {
visible = false, visible = false,
ontop = true, ontop = true,
height = 1060, height = 1060,
width = 1920 width = 1920
} }
w:setup { w:setup {
{ {
{ {
{ {
{ {
text = '', text = 'a',
font = 'Play 18', font = 'awesomewm-font 13',
widget = wibox.widget.textbox, widget = wibox.widget.textbox,
}, },
id = 'icon', id = 'icon',
top = 9,
left = 10, left = 10,
layout = wibox.container.margin layout = wibox.container.margin
}, },
@ -56,9 +74,25 @@ w:setup {
forced_height = 50 forced_height = 50
}, },
layout = wibox.container.place layout = wibox.container.place
} }
local function launch(s) return w
end
function widget_instance:launch(s, c)
-- c = c or capi.client.focus
-- s = s or (c and c.screen or awful.screen.focused())
s = 1
naughty.notify{text = 'screen ' .. s}
if not self._cached_wiboxes[s] then
self._cached_wiboxes[s] = {}
naughty.notify{text = 'nope'}
end
if not self._cached_wiboxes[s][1] then
self._cached_wiboxes[s][1] = self:_create_wibox()
naughty.notify{text = 'nope'}
end
local w = self._cached_wiboxes[s][1]
awful.spawn.with_line_callback(os.getenv("HOME") .. "/.config/awesome/awesome-wm-widgets/run-shell/scratch_6.sh " .. tostring(awful.screen.focused().geometry.x), { awful.spawn.with_line_callback(os.getenv("HOME") .. "/.config/awesome/awesome-wm-widgets/run-shell/scratch_6.sh " .. tostring(awful.screen.focused().geometry.x), {
stdout = function(line) stdout = function(line)
w.visible = true w.visible = true
@ -76,6 +110,7 @@ local function launch(s)
done_callback = function() done_callback = function()
-- w.bgimage='' -- w.bgimage=''
w.visible = false w.visible = false
w.bgimage = ''
awful.spawn([[bash -c 'rm -f /tmp/i3lock*']]) awful.spawn([[bash -c 'rm -f /tmp/i3lock*']])
end end
} }
@ -84,8 +119,22 @@ local function launch(s)
naughty.notify { text = "ERR:" .. line } naughty.notify { text = "ERR:" .. line }
end, end,
}) })
end
return widget_instance
end
local function get_default_widget()
if not widget.default_widget then
widget.default_widget = widget.new()
end
return widget.default_widget
end end
return { function widget.launch(...)
launch = launch return get_default_widget():launch(...)
} end
return widget