Update widget to use upower_dbus 0.2 (with dbus_proxy)
This should allow more stability.
This commit is contained in:
parent
c6c22d4d53
commit
1a52e3a910
|
@ -0,0 +1,27 @@
|
|||
package = "power_widget"
|
||||
version = "0.2.0-1"
|
||||
source = {
|
||||
url = "git://github.com/stefano-m/awesome-power_widget",
|
||||
tag = "v0.2.0"
|
||||
}
|
||||
description = {
|
||||
summary = "A Power widget for the Awesome Window Manager",
|
||||
detailed = [[
|
||||
Monitor your power devices in Awesome with UPower and DBus.
|
||||
]],
|
||||
homepage = "https://github.com/stefano-m/awesome-power_widget",
|
||||
license = "GPL v3"
|
||||
}
|
||||
supported_platforms = {
|
||||
"linux"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1",
|
||||
"upower_dbus >= 0.2.0, < 0.3"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
power_widget = "power_widget.lua"
|
||||
}
|
||||
}
|
|
@ -21,12 +21,13 @@ local wibox = require("wibox")
|
|||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
|
||||
local GLib = require("lgi").GLib
|
||||
local power = require("upower_dbus")
|
||||
|
||||
-- Awesome DBus C API
|
||||
local cdbus = dbus -- luacheck: ignore
|
||||
|
||||
local spawn_with_shell = awful.spawn.with_shell or awful.util.spawn_with_shell or awful.spawn.with_shell
|
||||
local spawn_with_shell = awful.spawn.with_shell or awful.util.spawn_with_shell
|
||||
local icon_theme_dirs = { -- The trailing slash is mandatory!
|
||||
"/usr/share/icons/Adwaita/scalable/status/",
|
||||
"/usr/share/icons/Adwaita/scalable/devices/"}
|
||||
|
@ -34,6 +35,7 @@ local icon_theme_extensions = {"svg"}
|
|||
icon_theme_dirs = beautiful.upower_icon_theme_dirs or icon_theme_dirs
|
||||
icon_theme_extensions = beautiful.upower_icon_theme_extension or icon_theme_extensions
|
||||
|
||||
local ctx = GLib.MainLoop():get_context()
|
||||
local widget = wibox.widget.imagebox()
|
||||
|
||||
local function build_icon_path(device)
|
||||
|
@ -49,10 +51,10 @@ function widget:update()
|
|||
|
||||
if self.device.IsPresent then
|
||||
local percentage = math.floor(self.device.Percentage)
|
||||
local warning_level = self.device.WarningLevel
|
||||
local warning_level = self.device.warninglevel
|
||||
|
||||
self.tooltip:set_text(
|
||||
percentage .. "%" .. " - " .. self.device.State)
|
||||
percentage .. "%" .. " - " .. self.device.state)
|
||||
|
||||
if warning_level == "Low" or warning_level == "Critical" then
|
||||
naughty.notify({
|
||||
|
@ -75,7 +77,7 @@ local function setup_signals(wdg)
|
|||
",interface=org.freedesktop.DBus.Properties" ..
|
||||
",member=PropertiesChanged" ..
|
||||
",path=" ..
|
||||
wdg.device.dbus.path
|
||||
wdg.device.object_path
|
||||
)
|
||||
|
||||
cdbus.connect_signal("org.freedesktop.DBus.Properties",
|
||||
|
@ -84,14 +86,10 @@ local function setup_signals(wdg)
|
|||
-- ARRAY<STRING> invalidated_properties);
|
||||
function (info, interface, changed, _)
|
||||
if info.member == "PropertiesChanged"
|
||||
and interface == wdg.device.dbus.interface
|
||||
and info.path == wdg.device.dbus.path
|
||||
and interface == wdg.device.interface
|
||||
and info.path == wdg.device.object_path
|
||||
then
|
||||
for k, v in pairs(changed) do
|
||||
if wdg.device[k] then
|
||||
wdg.device[k] = v
|
||||
end
|
||||
end
|
||||
ctx:iteration()
|
||||
wdg:update()
|
||||
end
|
||||
end)
|
||||
|
@ -100,12 +98,11 @@ end
|
|||
|
||||
function widget:init()
|
||||
local manager = power.Manager
|
||||
manager:init()
|
||||
self.manager = manager
|
||||
|
||||
local devices = {}
|
||||
for _, d in ipairs(self.manager.devices) do
|
||||
devices[d.Type] = d
|
||||
devices[d.type] = d
|
||||
end
|
||||
self.device = devices["Battery"] or devices["Line Power"]
|
||||
|
||||
|
|
Loading…
Reference in New Issue