Merge branch 'master' of https://github.com/streetturtle/awesome-wm-widgets
This commit is contained in:
commit
9e2b5087ba
|
@ -1,29 +1,63 @@
|
||||||
local wibox = require("wibox")
|
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local watch = require("awful.widget.watch")
|
local watch = require("awful.widget.watch")
|
||||||
|
local wibox = require("wibox")
|
||||||
|
|
||||||
-- acpi sample outputs
|
-- acpi sample outputs
|
||||||
-- Battery 0: Discharging, 75%, 01:51:38 remaining
|
-- Battery 0: Discharging, 75%, 01:51:38 remaining
|
||||||
-- Battery 0: Charging, 53%, 00:57:43 until charged
|
-- Battery 0: Charging, 53%, 00:57:43 until charged
|
||||||
|
|
||||||
local PATH_TO_ICONS = "/usr/share/icons/Arc/status/symbolic/"
|
local PATH_TO_ICONS = "/usr/share/icons/Arc/status/symbolic/"
|
||||||
local USERNAME = os.getenv("USER")
|
local HOME = os.getenv("HOME")
|
||||||
|
|
||||||
battery_widget = wibox.widget {
|
local battery_widget = wibox.widget {
|
||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
resize = false
|
resize = false
|
||||||
},
|
},
|
||||||
layout = wibox.container.margin(_, 0, 0, 3),
|
layout = wibox.container.margin(_, 0, 0, 3)
|
||||||
set_image = function(self, path)
|
|
||||||
self.icon.image = path
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
-- Popup with battery info
|
||||||
"acpi", 10,
|
-- One way of creating a pop-up notification - naughty.notify
|
||||||
|
local notification
|
||||||
|
local function show_battery_status()
|
||||||
|
awful.spawn.easy_async([[bash -c 'acpi']],
|
||||||
|
function(stdout, _, _, _)
|
||||||
|
notification = naughty.notify{
|
||||||
|
text = stdout,
|
||||||
|
title = "Battery status",
|
||||||
|
timeout = 5, hover_timeout = 0.5,
|
||||||
|
width = 200,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Alternative to naughty.notify - tooltip. You can compare both and choose the preferred one
|
||||||
|
--battery_popup = awful.tooltip({objects = {battery_widget}})
|
||||||
|
|
||||||
|
-- To use colors from beautiful theme put
|
||||||
|
-- following lines in rc.lua before require("battery"):
|
||||||
|
-- beautiful.tooltip_fg = beautiful.fg_normal
|
||||||
|
-- beautiful.tooltip_bg = beautiful.bg_normal
|
||||||
|
|
||||||
|
local function show_battery_warning()
|
||||||
|
naughty.notify{
|
||||||
|
icon = HOME .. "/.config/awesome/nichosi.png",
|
||||||
|
icon_size=100,
|
||||||
|
text = "Huston, we have a problem",
|
||||||
|
title = "Battery is dying",
|
||||||
|
timeout = 5, hover_timeout = 0.5,
|
||||||
|
position = "bottom_right",
|
||||||
|
bg = "#F06060",
|
||||||
|
fg = "#EEE9EF",
|
||||||
|
width = 300,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
watch("acpi", 10,
|
||||||
function(widget, stdout, stderr, exitreason, exitcode)
|
function(widget, stdout, stderr, exitreason, exitcode)
|
||||||
local batteryType
|
local batteryType
|
||||||
local _, status, charge_str, time = string.match(stdout, '(.+): (%a+), (%d?%d%d)%%,? ?.*')
|
local _, status, charge_str, time = string.match(stdout, '(.+): (%a+), (%d?%d%d)%%,? ?.*')
|
||||||
|
@ -43,53 +77,14 @@ watch(
|
||||||
else
|
else
|
||||||
batteryType = string.format(batteryType, '')
|
batteryType = string.format(batteryType, '')
|
||||||
end
|
end
|
||||||
widget.image = PATH_TO_ICONS .. batteryType .. ".svg"
|
widget.icon:set_image(PATH_TO_ICONS .. batteryType .. ".svg")
|
||||||
|
|
||||||
-- Update popup text
|
-- Update popup text
|
||||||
-- TODO: Filter long lines
|
|
||||||
-- battery_popup.text = string.gsub(stdout, "\n$", "")
|
-- battery_popup.text = string.gsub(stdout, "\n$", "")
|
||||||
end,
|
end,
|
||||||
battery_widget
|
battery_widget)
|
||||||
)
|
|
||||||
|
|
||||||
-- Popup with battery info
|
|
||||||
-- One way of creating a pop-up notification - naughty.notify
|
|
||||||
local notification
|
|
||||||
function show_battery_status()
|
|
||||||
awful.spawn.easy_async([[bash -c 'acpi']],
|
|
||||||
function(stdout, _, _, _)
|
|
||||||
notification = naughty.notify{
|
|
||||||
text = stdout,
|
|
||||||
title = "Battery status",
|
|
||||||
timeout = 5, hover_timeout = 0.5,
|
|
||||||
width = 200,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
battery_widget:connect_signal("mouse::enter", function() show_battery_status() end)
|
battery_widget:connect_signal("mouse::enter", function() show_battery_status() end)
|
||||||
battery_widget:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
|
battery_widget:connect_signal("mouse::leave", function() naughty.destroy(notification) end)
|
||||||
|
|
||||||
-- Alternative to naughty.notify - tooltip. You can compare both and choose the preferred one
|
return battery_widget
|
||||||
|
|
||||||
--battery_popup = awful.tooltip({objects = {battery_widget}})
|
|
||||||
|
|
||||||
-- To use colors from beautiful theme put
|
|
||||||
-- following lines in rc.lua before require("battery"):
|
|
||||||
-- beautiful.tooltip_fg = beautiful.fg_normal
|
|
||||||
-- beautiful.tooltip_bg = beautiful.bg_normal
|
|
||||||
|
|
||||||
--[[ Show warning notification ]]
|
|
||||||
function show_battery_warning()
|
|
||||||
naughty.notify{
|
|
||||||
icon = "/home/" .. USERNAME .. "/.config/awesome/nichosi.png",
|
|
||||||
icon_size=100,
|
|
||||||
text = "Huston, we have a problem",
|
|
||||||
title = "Battery is dying",
|
|
||||||
timeout = 5, hover_timeout = 0.5,
|
|
||||||
position = "bottom_right",
|
|
||||||
bg = "#F06060",
|
|
||||||
fg = "#EEE9EF",
|
|
||||||
width = 300,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue