yes, I'm very commit lazy
This commit is contained in:
@@ -3,20 +3,23 @@
|
||||
--------------------------------
|
||||
|
||||
-- Awesome Libs
|
||||
local awful = require("awful")
|
||||
local dpi = require("beautiful").xresources.apply_dpi
|
||||
local gears = require("gears")
|
||||
local lgi = require("lgi")
|
||||
local naughty = require("naughty")
|
||||
local upower_glib = lgi.require("UPowerGlib")
|
||||
local wibox = require("wibox")
|
||||
local awful = require('awful')
|
||||
local dpi = require('beautiful').xresources.apply_dpi
|
||||
local gears = require('gears')
|
||||
local lgi = require('lgi')
|
||||
local naughty = require('naughty')
|
||||
local upower_glib = lgi.require('UPowerGlib')
|
||||
local wibox = require('wibox')
|
||||
|
||||
-- Local libs
|
||||
local hover = require('src.tools.hover')
|
||||
|
||||
local capi = {
|
||||
awesome = awesome,
|
||||
}
|
||||
|
||||
-- Icon directory path
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. "src/assets/icons/battery/"
|
||||
local icondir = gears.filesystem.get_configuration_dir() .. 'src/assets/icons/battery/'
|
||||
|
||||
---Returns the battery widget
|
||||
---@return wibox.widget
|
||||
@@ -29,46 +32,46 @@ return function(battery_kind)
|
||||
{
|
||||
{
|
||||
{
|
||||
id = "icon",
|
||||
image = gears.color.recolor_image(icondir .. "battery-unknown.svg", Theme_config.battery.fg),
|
||||
id = 'icon',
|
||||
image = gears.color.recolor_image(icondir .. 'battery-unknown.svg', Theme_config.battery.fg),
|
||||
widget = wibox.widget.imagebox,
|
||||
valign = "center",
|
||||
halign = "center",
|
||||
resize = false
|
||||
valign = 'center',
|
||||
halign = 'center',
|
||||
resize = false,
|
||||
},
|
||||
id = "icon_layout",
|
||||
widget = wibox.container.place
|
||||
id = 'icon_layout',
|
||||
widget = wibox.container.place,
|
||||
},
|
||||
id = "icon_margin",
|
||||
id = 'icon_margin',
|
||||
top = dpi(2),
|
||||
widget = wibox.container.margin
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
spacing = dpi(10),
|
||||
{
|
||||
visible = false,
|
||||
align = 'center',
|
||||
valign = 'center',
|
||||
id = "label",
|
||||
widget = wibox.widget.textbox
|
||||
id = 'label',
|
||||
widget = wibox.widget.textbox,
|
||||
},
|
||||
id = "battery_layout",
|
||||
layout = wibox.layout.fixed.horizontal
|
||||
id = 'battery_layout',
|
||||
layout = wibox.layout.fixed.horizontal,
|
||||
},
|
||||
id = "container",
|
||||
id = 'container',
|
||||
left = dpi(8),
|
||||
right = dpi(8),
|
||||
widget = wibox.container.margin
|
||||
widget = wibox.container.margin,
|
||||
},
|
||||
bg = Theme_config.battery.bg,
|
||||
fg = Theme_config.battery.fg,
|
||||
shape = function(cr, width, height)
|
||||
gears.shape.rounded_rect(cr, width, height, dpi(6))
|
||||
end,
|
||||
widget = wibox.container.background
|
||||
widget = wibox.container.background,
|
||||
}
|
||||
|
||||
-- Color change on mouse over
|
||||
Hover_signal(battery_widget)
|
||||
hover.bg_hover { widget = battery_widget }
|
||||
|
||||
-- Open an energy manager on click
|
||||
battery_widget:connect_signal(
|
||||
@@ -105,9 +108,9 @@ return function(battery_kind)
|
||||
|
||||
local tooltip = awful.tooltip {
|
||||
objects = { battery_widget },
|
||||
mode = "inside",
|
||||
preferred_alignments = "middle",
|
||||
margins = dpi(10)
|
||||
mode = 'inside',
|
||||
preferred_alignments = 'middle',
|
||||
margins = dpi(10),
|
||||
}
|
||||
|
||||
---Sets the battery information for the widget
|
||||
@@ -125,50 +128,50 @@ return function(battery_kind)
|
||||
battery_time = device.time_to_full
|
||||
end
|
||||
|
||||
local battery_string = math.floor(battery_time / 3600) .. "h, " .. math.floor((battery_time / 60) % 60) .. "m"
|
||||
local battery_string = math.floor(battery_time / 3600) .. 'h, ' .. math.floor((battery_time / 60) % 60) .. 'm'
|
||||
|
||||
if battery_temp == 0.0 then
|
||||
battery_temp = "NaN"
|
||||
battery_temp = 'NaN'
|
||||
else
|
||||
battery_temp = math.floor(battery_temp + 0.5) .. "°C"
|
||||
battery_temp = math.floor(battery_temp + 0.5) .. '°C'
|
||||
end
|
||||
|
||||
if not battery_percentage then
|
||||
return
|
||||
end
|
||||
|
||||
battery_widget:get_children_by_id("battery_layout")[1].spacing = dpi(5)
|
||||
battery_widget:get_children_by_id("label")[1].visible = true
|
||||
battery_widget:get_children_by_id("label")[1].text = battery_percentage .. '%'
|
||||
battery_widget:get_children_by_id('battery_layout')[1].spacing = dpi(5)
|
||||
battery_widget:get_children_by_id('label')[1].visible = true
|
||||
battery_widget:get_children_by_id('label')[1].text = battery_percentage .. '%'
|
||||
|
||||
tooltip.markup = "<span foreground='#64ffda'>Battery Status:</span> <span foreground='#90caf9'>"
|
||||
.. battery_status .. "</span>\n<span foreground='#64ffda'>Remaining time:</span> <span foreground='#90caf9'>"
|
||||
.. battery_string .. "</span>\n<span foreground='#64ffda'>Temperature:</span> <span foreground='#90caf9'>"
|
||||
.. battery_temp .. "</span>"
|
||||
.. battery_temp .. '</span>'
|
||||
|
||||
local icon = 'battery'
|
||||
|
||||
if battery_status == 'fully-charged' or battery_status == 'charging' and battery_percentage == 100 then
|
||||
icon = icon .. '-' .. 'charging.svg'
|
||||
naughty.notification {
|
||||
title = "Battery notification",
|
||||
message = "Battery is fully charged",
|
||||
title = 'Battery notification',
|
||||
message = 'Battery is fully charged',
|
||||
icon = icondir .. icon,
|
||||
timeout = 5
|
||||
timeout = 5,
|
||||
}
|
||||
battery_widget:get_children_by_id("icon")[1].image = gears.surface.load_uncached(gears.color.recolor_image(icondir
|
||||
battery_widget:get_children_by_id('icon')[1].image = gears.surface.load_uncached(gears.color.recolor_image(icondir
|
||||
.. icon, Theme_config.battery.fg))
|
||||
return
|
||||
elseif battery_percentage > 0 and battery_percentage < 10 and battery_status == 'discharging' then
|
||||
icon = icon .. '-' .. 'alert.svg'
|
||||
naughty.notification {
|
||||
title = "Battery warning",
|
||||
message = "Battery is running low!\n" .. battery_percentage .. "% left",
|
||||
urgency = "critical",
|
||||
title = 'Battery warning',
|
||||
message = 'Battery is running low!\n' .. battery_percentage .. '% left',
|
||||
urgency = 'critical',
|
||||
icon = icondir .. icon,
|
||||
timeout = 60
|
||||
timeout = 60,
|
||||
}
|
||||
battery_widget:get_children_by_id("icon")[1].image = gears.surface.load_uncached(gears.color.recolor_image(icondir
|
||||
battery_widget:get_children_by_id('icon')[1].image = gears.surface.load_uncached(gears.color.recolor_image(icondir
|
||||
.. icon, Theme_config.battery.fg))
|
||||
return
|
||||
end
|
||||
@@ -195,9 +198,9 @@ return function(battery_kind)
|
||||
icon = icon .. '-' .. battery_status .. '-' .. '90'
|
||||
end
|
||||
|
||||
battery_widget:get_children_by_id("icon")[1].image = gears.surface.load_uncached(gears.color.recolor_image(icondir ..
|
||||
battery_widget:get_children_by_id('icon')[1].image = gears.surface.load_uncached(gears.color.recolor_image(icondir ..
|
||||
icon .. '.svg', Theme_config.battery.fg))
|
||||
capi.awesome.emit_signal("update::battery_widget", battery_percentage, icondir .. icon .. ".svg")
|
||||
capi.awesome.emit_signal('update::battery_widget', battery_percentage, icondir .. icon .. '.svg')
|
||||
|
||||
end
|
||||
|
||||
@@ -208,12 +211,12 @@ return function(battery_kind)
|
||||
---Will report to the bluetooth widget.
|
||||
---@param path string device path /org/freedesktop/...
|
||||
local function attach_to_device(path)
|
||||
local device_path = User_config.battery_path or path or ""
|
||||
local device_path = User_config.battery_path or path or ''
|
||||
|
||||
battery_widget.device = get_device_from_path(device_path) or upower_glib.Client():get_display_device()
|
||||
|
||||
battery_widget.device.on_notify = function(device)
|
||||
battery_widget:emit_signal("upower::update", device)
|
||||
battery_widget:emit_signal('upower::update', device)
|
||||
end
|
||||
|
||||
-- Check which device kind the user wants to display
|
||||
@@ -223,7 +226,7 @@ return function(battery_kind)
|
||||
end
|
||||
|
||||
-- The delayed call will fire every time awesome finishes its main event loop
|
||||
gears.timer.delayed_call(battery_widget.emit_signal, battery_widget, "upower::update", battery_widget.device)
|
||||
gears.timer.delayed_call(battery_widget.emit_signal, battery_widget, 'upower::update', battery_widget.device)
|
||||
end
|
||||
|
||||
for _, device in ipairs(get_device_path()) do
|
||||
@@ -231,7 +234,7 @@ return function(battery_kind)
|
||||
end
|
||||
|
||||
battery_widget:connect_signal(
|
||||
"upower::update",
|
||||
'upower::update',
|
||||
function(_, device)
|
||||
if upower_glib.DeviceKind[battery_widget.device.kind] == battery_kind then
|
||||
set_battery(device)
|
||||
|
||||
Reference in New Issue
Block a user