Use /org/freedesktop/UPower/devices/DisplayDevice as self.device

DisplayDevice is a "special" device object that represent what a widget should
display, however it does *not* give information about Line Power. E.g. when a
laptop has no battery but is plugged on the mains, DisplayDevice says that no
device should be displayed and the icon is set to "battery-missing" (which is
in fact true).

However, if we are working, it means that we must be getting power from
somewhere, so let's display something in the tooltip anyway.

Command line example

$ upower -i /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         no
  updated:              Sun 05 Nov 2017 04:19:48 PM GMT (415 seconds ago)
  has history:          no
  has statistics:       no
  unknown
    warning-level:       none
    icon-name:          'battery-missing-symbolic'

See also https://upower.freedesktop.org/docs/UPower.html#UPower.GetDisplayDevice
This commit is contained in:
Stefano Mazzucco 2017-11-05 16:28:39 +00:00
parent 14f0f5a962
commit 388186cc28
2 changed files with 32 additions and 7 deletions

View File

@ -23,7 +23,6 @@ local naughty = require("naughty")
local power = require("upower_dbus")
local WarningLevel = power.enums.BatteryWarningLevel
local DeviceType = power.enums.DeviceType
local spawn_with_shell = awful.spawn.with_shell or awful.util.spawn_with_shell
local icon_theme_dirs = { -- The trailing slash is mandatory!
@ -44,9 +43,11 @@ end
function widget:update()
self.device:update_mappings()
self:set_image(build_icon_path(self.device))
if self.device.IsPresent then
local percentage = math.floor(self.device.Percentage)
local warning_level = self.device.warninglevel
@ -60,6 +61,7 @@ function widget:update()
text = percentage .. "% remaining"})
end
else
-- We don't know how we're powered, but we must be somehow!
self.tooltip:set_text("Plugged In")
end
end
@ -68,12 +70,8 @@ function widget:init()
local manager = power.Manager
self.manager = manager
local devices = {}
for _, d in ipairs(self.manager.devices) do
devices[d.type] = d
end
self.device = devices[DeviceType.Battery] or devices[DeviceType["Line Power"]]
-- https://upower.freedesktop.org/docs/UPower.html#UPower.GetDisplayDevice
self.device = power.create_device("/org/freedesktop/UPower/devices/DisplayDevice")
self.device:on_properties_changed(
function ()

View File

@ -0,0 +1,27 @@
package = "power_widget"
version = "0.3.3-1"
source = {
url = "git://github.com/stefano-m/awesome-power_widget",
tag = "v0.3.3"
}
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.3.0, < 0.4"
}
build = {
type = "builtin",
modules = {
power_widget = "power_widget.lua"
}
}