summaryrefslogtreecommitdiff
path: root/run-shell
diff options
context:
space:
mode:
authorstreetturtle <streetturtle@gmail.com>2018-12-19 22:39:53 -0500
committerstreetturtle <streetturtle@gmail.com>2018-12-19 22:39:53 -0500
commit29118150a9208321532ec90fa6a75d15180bf3ec (patch)
tree94a72182e6bdb9305a3c7237e81a14ebe544f6a5 /run-shell
parent855677d667875e301fc519e77bf998964f6db4a3 (diff)
first attempt to make it leakless
Diffstat (limited to 'run-shell')
-rw-r--r--run-shell/run-shell.lua179
1 files changed, 114 insertions, 65 deletions
diff --git a/run-shell/run-shell.lua b/run-shell/run-shell.lua
index e46d5a9..06fdd23 100644
--- a/run-shell/run-shell.lua
+++ b/run-shell/run-shell.lua
@@ -7,6 +7,10 @@
-- @copyright 2018 Pavel Makhov
-------------------------------------------------
+local capi = {
+ screen = screen,
+ client = client,
+}
local awful = require("awful")
local gfs = require("gears.filesystem")
local wibox = require("wibox")
@@ -16,76 +20,121 @@ local completion = require("awful.completion")
local run_shell = awful.widget.prompt()
-local w = wibox {
- visible = false,
- ontop = true,
- height = 1060,
- width = 1920
-}
-w:setup {
- {
- {
+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,
+ ontop = true,
+ height = 1060,
+ width = 1920
+ }
+
+ w:setup {
{
{
- text = '',
- font = 'Play 18',
- widget = wibox.widget.textbox,
+ {
+ {
+ text = 'a',
+ font = 'awesomewm-font 13',
+ widget = wibox.widget.textbox,
+ },
+ id = 'icon',
+ left = 10,
+ layout = wibox.container.margin
+ },
+ {
+ run_shell,
+ left = 10,
+ layout = wibox.container.margin,
+ },
+ id = 'left',
+ layout = wibox.layout.fixed.horizontal
},
- id = 'icon',
- top = 9,
- left = 10,
- layout = wibox.container.margin
- },
- {
- run_shell,
- left = 10,
- layout = wibox.container.margin,
+ widget = wibox.container.background,
+ bg = '#333333',
+ shape = function(cr, width, height)
+ gears.shape.rounded_rect(cr, width, height, 3)
+ end,
+ shape_border_color = '#74aeab',
+ shape_border_width = 1,
+ forced_width = 200,
+ forced_height = 50
},
- id = 'left',
- layout = wibox.layout.fixed.horizontal
- },
- widget = wibox.container.background,
- bg = '#333333',
- shape = function(cr, width, height)
- gears.shape.rounded_rect(cr, width, height, 3)
- end,
- shape_border_color = '#74aeab',
- shape_border_width = 1,
- forced_width = 200,
- forced_height = 50
- },
- layout = wibox.container.place
-}
+ layout = wibox.container.place
+ }
-local function launch(s)
- 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)
- w.visible = true
- w.bgimage = '/tmp/i3lock-' .. line .. '.png'
- awful.placement.top(w, { margins = { top = 20 }, parent = awful.screen.focused() })
- awful.prompt.run {
- prompt = "<b>Run</b>: ",
- bg_cursor = '#74aeab',
- textbox = run_shell.widget,
- completion_callback = completion.shell,
- exe_callback = function(...)
- run_shell:spawn_and_handle_error(...)
- end,
- history_path = gfs.get_cache_dir() .. "/history",
- done_callback = function()
- -- w.bgimage=''
- w.visible = false
- awful.spawn([[bash -c 'rm -f /tmp/i3lock*']])
- end
- }
- end,
- stderr = function(line)
- naughty.notify { text = "ERR:" .. line }
- end,
- })
+ 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), {
+ stdout = function(line)
+ w.visible = true
+ w.bgimage = '/tmp/i3lock-' .. line .. '.png'
+ awful.placement.top(w, { margins = { top = 20 }, parent = awful.screen.focused() })
+ awful.prompt.run {
+ prompt = "<b>Run</b>: ",
+ bg_cursor = '#74aeab',
+ textbox = run_shell.widget,
+ completion_callback = completion.shell,
+ exe_callback = function(...)
+ run_shell:spawn_and_handle_error(...)
+ end,
+ history_path = gfs.get_cache_dir() .. "/history",
+ done_callback = function()
+ -- w.bgimage=''
+ w.visible = false
+ w.bgimage = ''
+ awful.spawn([[bash -c 'rm -f /tmp/i3lock*']])
+ end
+ }
+ end,
+ stderr = function(line)
+ naughty.notify { text = "ERR:" .. line }
+ 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
-return {
- launch = launch
-}
+function widget.launch(...)
+ return get_default_widget():launch(...)
+end
+
+
+return widget