awesome-wm-widgets/run-shell/run-shell.lua

170 lines
5.4 KiB
Lua
Raw Normal View History

2018-11-05 23:04:47 +01:00
-------------------------------------------------
2018-11-09 17:29:35 +01:00
-- Run Shell for Awesome Window Manager
2018-11-05 23:04:47 +01:00
-- More details could be found here:
2018-11-09 17:29:35 +01:00
-- https://github.com/streetturtle/awesome-wm-widgets/tree/master/run-shell
2018-11-05 23:04:47 +01:00
-- @author Pavel Makhov
2019-02-05 02:38:56 +01:00
-- @copyright 2019 Pavel Makhov
2018-11-05 23:04:47 +01:00
-------------------------------------------------
local awful = require("awful")
local gfs = require("gears.filesystem")
local wibox = require("wibox")
local gears = require("gears")
local completion = require("awful.completion")
2019-03-29 22:08:45 +01:00
local naughty = require("naughty")
2018-11-05 23:04:47 +01:00
2019-03-30 23:29:01 +01:00
local HOME = os.getenv("HOME")
2018-11-06 22:35:29 +01:00
local run_shell = awful.widget.prompt()
2018-11-05 23:04:47 +01:00
2018-12-20 04:39:53 +01:00
local widget = {}
function widget.new()
2019-03-21 14:36:24 +01:00
2018-12-20 04:39:53 +01:00
local widget_instance = {
2019-03-09 02:55:16 +01:00
_cached_wiboxes = {}
2018-12-20 04:39:53 +01:00
}
function widget_instance:_create_wibox()
local w = wibox {
visible = false,
ontop = true,
2020-04-29 02:46:06 +02:00
height = mouse.screen.geometry.height,
width = mouse.screen.geometry.width,
2019-03-21 14:36:24 +01:00
opacity = 0.9,
2020-04-29 02:46:06 +02:00
bg = 'radial:'.. mouse.screen.geometry.width/2 .. ','
.. mouse.screen.geometry.height/2 .. ',20:'
.. mouse.screen.geometry.width/2 .. ','
.. mouse.screen.geometry.height/2
.. ',700:0,#2E344022:0.2,#4C566A88:1,#2E3440ff'
2018-12-20 04:39:53 +01:00
}
2019-03-29 22:08:45 +01:00
local suspend_button = wibox.widget {
image = '/usr/share/icons/Arc/actions/symbolic/system-shutdown-symbolic.svg',
widget = wibox.widget.imagebox,
resize = false,
2019-03-30 23:29:01 +01:00
opacity = 0.2,
2020-12-06 02:57:04 +01:00
--luacheck:ignore 432
2019-03-29 22:08:45 +01:00
set_hover = function(self, opacity)
self.opacity = opacity
self.image = '/usr/share/icons/Arc/actions/symbolic/system-shutdown-symbolic.svg'
end
}
2019-03-30 23:29:01 +01:00
local turnoff_notification
2019-03-29 22:08:45 +01:00
suspend_button:connect_signal("mouse::enter", function()
2019-03-30 23:29:01 +01:00
turnoff_notification = naughty.notify{
icon = HOME .. "/.config/awesome/nichosi.png",
icon_size=100,
title = "Huston, we have a problem",
text = "You're about to turn off your computer",
timeout = 5, hover_timeout = 0.5,
position = "bottom_right",
bg = "#F06060",
fg = "#EEE9EF",
width = 300,
}
2019-03-29 22:08:45 +01:00
suspend_button:set_hover(1)
end)
suspend_button:connect_signal("mouse::leave", function()
2019-03-30 23:29:01 +01:00
naughty.destroy(turnoff_notification)
2019-03-29 22:08:45 +01:00
suspend_button:set_hover(0.2)
end)
2019-03-30 23:29:01 +01:00
suspend_button:connect_signal("button::press", function(_,_,_,button)
if (button == 1) then
awful.spawn("shutdown now")
end
end)
2018-12-20 04:39:53 +01:00
w:setup {
2018-11-06 22:35:29 +01:00
{
{
2018-12-20 04:39:53 +01:00
{
{
2019-03-29 22:08:45 +01:00
{
markup = '<span font="awesomewm-font 14" color="#ffffff">a</span>',
widget = wibox.widget.textbox,
},
id = 'icon',
left = 10,
layout = wibox.container.margin
},
{
run_shell,
left = 10,
layout = wibox.container.margin,
2018-12-20 04:39:53 +01:00
},
2019-03-29 22:08:45 +01:00
id = 'left',
layout = wibox.layout.fixed.horizontal
},
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,
widget = wibox.container.background
},
valign = 'center',
layout = wibox.container.place
},
{
{
suspend_button,
2018-12-20 04:39:53 +01:00
layout = wibox.layout.fixed.horizontal
2018-11-06 22:35:29 +01:00
},
2019-03-29 22:08:45 +01:00
valign = 'bottom',
layout = wibox.container.place,
2018-11-06 22:35:29 +01:00
},
2019-03-29 22:08:45 +01:00
layout = wibox.layout.stack
2018-12-20 04:39:53 +01:00
}
2018-11-05 23:04:47 +01:00
2018-12-20 04:39:53 +01:00
return w
end
2019-03-09 02:55:16 +01:00
function widget_instance:launch()
local s = mouse.screen
2018-12-20 04:39:53 +01:00
if not self._cached_wiboxes[s] then
self._cached_wiboxes[s] = {}
end
if not self._cached_wiboxes[s][1] then
self._cached_wiboxes[s][1] = self:_create_wibox()
end
local w = self._cached_wiboxes[s][1]
2019-03-09 02:55:16 +01:00
w.visible = true
awful.placement.top(w, { margins = { top = 20 }, parent = awful.screen.focused() })
awful.prompt.run {
prompt = 'Run: ',
bg_cursor = '#74aeab',
textbox = run_shell.widget,
completion_callback = completion.shell,
exe_callback = function(...)
run_shell:spawn_and_handle_error(...)
2018-12-20 04:39:53 +01:00
end,
2019-03-09 02:55:16 +01:00
history_path = gfs.get_cache_dir() .. "/history",
done_callback = function() w.visible = false end
}
2018-12-20 04:39:53 +01:00
end
return widget_instance
2018-12-24 16:05:15 +01:00
end
2018-12-20 04:39:53 +01:00
local function get_default_widget()
if not widget.default_widget then
widget.default_widget = widget.new()
end
return widget.default_widget
2018-11-05 23:04:47 +01:00
end
2018-12-20 04:39:53 +01:00
function widget.launch(...)
return get_default_widget():launch(...)
end
return widget