diff options
author | streetturtle <streetturtle@gmail.com> | 2020-11-23 17:12:30 -0500 |
---|---|---|
committer | streetturtle <streetturtle@gmail.com> | 2020-11-23 17:12:30 -0500 |
commit | 33339666fd9e7b9caec9d0abc7194a319d6974b5 (patch) | |
tree | ac680022348d4f165c93b586b6975223a5f1dd51 | |
parent | 19805d24124e5ddc3c63f14abb500b990222c22c (diff) |
[docker] add a delete button
-rw-r--r-- | docker-widget/docker.lua | 118 | ||||
-rw-r--r-- | docker-widget/icons/trash-btn.svg | 1 |
2 files changed, 100 insertions, 19 deletions
diff --git a/docker-widget/docker.lua b/docker-widget/docker.lua index 6e04d8a..5bd5746 100644 --- a/docker-widget/docker.lua +++ b/docker-widget/docker.lua @@ -62,7 +62,6 @@ local parse_container = function(line) else actual_status = status end how_long = how_long:gsub('%s?%(.*%)%s?', '') - -- if how_long:find('seconds') then how_long = 'less than a minute ago' end local container = { name = name, @@ -122,20 +121,36 @@ local function worker(args) if container.is_up() or container.is_exited() then start_stop_button = wibox.widget { { - id = 'icon', - image = ICONS_DIR .. (container:is_up() and 'stop-btn.svg' or 'play-btn.svg'), - opacity = 0.4, - resize = false, - widget = wibox.widget.imagebox + { + id = 'icon', + image = ICONS_DIR .. (container:is_up() and 'stop-btn.svg' or 'play-btn.svg'), + opacity = 0.4, + resize = false, + widget = wibox.widget.imagebox + }, + left = 2, + right = 2, + layout = wibox.container.margin }, - left = 2, - right = 2, - layout = wibox.container.margin + shape = gears.shape.circle, + bg = '#00000000', + widget = wibox.container.background } + local old_cursor, old_wibox start_stop_button:connect_signal("mouse::enter", function(c) + c:set_bg('#3B4252') + + local wb = mouse.current_wibox + old_cursor, old_wibox = wb.cursor, wb + wb.cursor = "hand1" c:get_children_by_id("icon")[1]:set_opacity(1) c:get_children_by_id("icon")[1]:emit_signal('widget::redraw_needed') end) start_stop_button:connect_signal("mouse::leave", function(c) + c:set_bg('#00000000') + if old_wibox then + old_wibox.cursor = old_cursor + old_wibox = nil + end c:get_children_by_id("icon")[1]:set_opacity(0.4) c:get_children_by_id("icon")[1]:emit_signal('widget::redraw_needed') end) @@ -148,7 +163,7 @@ local function worker(args) status_icon:set_opacity(0.2) status_icon:emit_signal('widget::redraw_needed') - awful.spawn.easy_async('docker ' .. command .. ' ' .. container['name'], function(stdout, stderr) + spawn.easy_async('docker ' .. command .. ' ' .. container['name'], function(stdout, stderr) if stderr ~= '' then show_warning(stderr) end spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers), function(stdout, stderr) rebuild_widget(stdout, stderr) end) @@ -163,21 +178,36 @@ local function worker(args) if container.is_up() then pause_unpause_button = wibox.widget { { - id = 'icon', - image = ICONS_DIR .. (container:is_paused() and 'unpause-btn.svg' or 'pause-btn.svg'), - opacity = 0.4, - resize = false, - widget = wibox.widget.imagebox + { + id = 'icon', + image = ICONS_DIR .. (container:is_paused() and 'unpause-btn.svg' or 'pause-btn.svg'), + opacity = 0.4, + resize = false, + widget = wibox.widget.imagebox + }, + left = 2, + right = 2, + layout = wibox.container.margin }, - left = 2, - right = 2, - layout = wibox.container.margin + shape = gears.shape.circle, + bg = '#00000000', + widget = wibox.container.background } + local old_cursor, old_wibox pause_unpause_button:connect_signal("mouse::enter", function(c) + c:set_bg('#3B4252') + local wb = mouse.current_wibox + old_cursor, old_wibox = wb.cursor, wb + wb.cursor = "hand1" c:get_children_by_id("icon")[1]:set_opacity(1) c:get_children_by_id("icon")[1]:emit_signal('widget::redraw_needed') end) pause_unpause_button:connect_signal("mouse::leave", function(c) + c:set_bg('#00000000') + if old_wibox then + old_wibox.cursor = old_cursor + old_wibox = nil + end c:get_children_by_id("icon")[1]:set_opacity(0.4) c:get_children_by_id("icon")[1]:emit_signal('widget::redraw_needed') end) @@ -200,6 +230,55 @@ local function worker(args) pause_unpause_button = nil end + local delete_button + if not container.is_up() then + delete_button = wibox.widget { + { + { + id = 'icon', + image = ICONS_DIR .. 'trash-btn.svg', + opacity = 0.4, + resize = false, + widget = wibox.widget.imagebox + }, + margins = 4, + layout = wibox.container.margin + }, + shape = gears.shape.circle, + bg = '#00000000', + widget = wibox.container.background + } + delete_button:buttons( + awful.util.table.join( awful.button({}, 1, function() + awful.spawn.easy_async('docker rm ' .. container['name'], function(stdout, stderr) + if stderr ~= '' then show_warning(stderr) end + spawn.easy_async(string.format(LIST_CONTAINERS_CMD, number_of_containers), function(stdout, stderr) + rebuild_widget(stdout, stderr) end) + end) + end))) + + local old_cursor, old_wibox + delete_button:connect_signal("mouse::enter", function(c) + c:set_bg('#3B4252') + local wb = mouse.current_wibox + old_cursor, old_wibox = wb.cursor, wb + wb.cursor = "hand1" + c:get_children_by_id("icon")[1]:set_opacity(1) + c:get_children_by_id("icon")[1]:emit_signal('widget::redraw_needed') + end) + delete_button:connect_signal("mouse::leave", function(c) + c:set_bg('#00000000') + if old_wibox then + old_wibox.cursor = old_cursor + old_wibox = nil + end + c:get_children_by_id("icon")[1]:set_opacity(0.4) + c:get_children_by_id("icon")[1]:emit_signal('widget::redraw_needed') + end) + else + delete_button = nil + end + local row = wibox.widget { { @@ -237,9 +316,10 @@ local function worker(args) { start_stop_button, pause_unpause_button, + delete_button, layout = wibox.layout.align.horizontal }, - forced_width = 60, + forced_width = 90, valign = 'center', haligh = 'center', layout = wibox.container.place, diff --git a/docker-widget/icons/trash-btn.svg b/docker-widget/icons/trash-btn.svg new file mode 100644 index 0000000..78d8035 --- /dev/null +++ b/docker-widget/icons/trash-btn.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#BF616A" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-trash-2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
\ No newline at end of file |