Use lgi to get icons directly from GTK
Rather than setting a path to the icons, use lgi to get the current GTK theme and then look up the icons. Then set the image as a cairo surface by using the GTK api directly. With this change, one can modify their GTK icon theme (e.g. with lxappearance), restart AwesomeWM and have the widget's icon automatically updated.
This commit is contained in:
parent
65e0f96115
commit
6f5d566ec0
18
README.md
18
README.md
|
@ -53,20 +53,16 @@ documentation of your display manager of choice for more information.
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
The widget displays power icons that are searched in the folders defined
|
The widget will display the battery icons defined in your GTK+ theme and it
|
||||||
in the table `beautiful.upower_icon_theme_dirs` with extensions defined
|
will resize them to fit in the available space. This means that you can switch
|
||||||
in the table `beautiful.upower_icon_extensions`.
|
your icon theme, for example using `lxappearance`, and update the widget by
|
||||||
The default is to look into `"/usr/share/icons/Adwaita/scalable/devices/"`
|
restarting AwesomeWM.
|
||||||
and `"/usr/share/icons/Adwaita/scalable/status/"`for
|
|
||||||
icons whose extension is `"svg"`. Note that the directory paths *must* end
|
|
||||||
with a slash and that the extensions *must not* contain a dot.
|
|
||||||
The icons are searched using Awesome's
|
|
||||||
[`awful.util.geticonpath` function](https://awesomewm.org/doc/api/modules/awful.util.html#geticonpath).
|
|
||||||
|
|
||||||
You can specify a GUI client to be launched when the widget is right-clicked.
|
You can specify a GUI client to be launched when the widget is right-clicked.
|
||||||
This can be done by changing the `gui_client` field of the widget. The default
|
This can be done by changing the `gui_client` field of the widget. The default
|
||||||
is to have no client. For example, you could use the [XFCE4 Power Manager](http://goodies.xfce.org/projects/applications/xfce4-power-manager)
|
is to have no client. For example, you could use the [XFCE4 Power
|
||||||
or the [GNOME one](https://projects.gnome.org/gnome-power-manager/).
|
Manager](http://goodies.xfce.org/projects/applications/xfce4-power-manager) or
|
||||||
|
the [GNOME one](https://projects.gnome.org/gnome-power-manager/).
|
||||||
|
|
||||||
You can set the critical battery percentage at which a warning will be
|
You can set the critical battery percentage at which a warning will be
|
||||||
displayed using the `critical_percentage` property (defaults to `5`).
|
displayed using the `critical_percentage` property (defaults to `5`).
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--[[
|
--[[
|
||||||
Copyright 2017 Stefano Mazzucco <stefano AT curso DOT re>
|
Copyright 2017-2019 Stefano Mazzucco <stefano AT curso DOT re>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -15,37 +15,41 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local beautiful = require("beautiful")
|
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
|
||||||
|
local lgi = require('lgi')
|
||||||
|
local icon_theme = lgi.Gtk.IconTheme.get_default()
|
||||||
|
local IconLookupFlags = lgi.Gtk.IconLookupFlags
|
||||||
|
|
||||||
local power = require("upower_dbus")
|
local power = require("upower_dbus")
|
||||||
local WarningLevel = power.enums.BatteryWarningLevel
|
local WarningLevel = power.enums.BatteryWarningLevel
|
||||||
|
|
||||||
local spawn_with_shell = awful.spawn.with_shell or awful.util.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/"}
|
|
||||||
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 widget = wibox.widget.imagebox()
|
local icon_size = 64
|
||||||
|
local icon_flags = {IconLookupFlags.GENERIC_FALLBACK}
|
||||||
|
|
||||||
|
local widget = wibox.widget {
|
||||||
|
resize = true,
|
||||||
|
widget = wibox.widget.imagebox
|
||||||
|
}
|
||||||
|
|
||||||
widget.critical_percentage = 5
|
widget.critical_percentage = 5
|
||||||
|
|
||||||
local function build_icon_path(device)
|
|
||||||
if device.IconName then
|
|
||||||
return awful.util.geticonpath(device.IconName, icon_theme_extensions, icon_theme_dirs)
|
|
||||||
end
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
function widget:update()
|
function widget:update()
|
||||||
self.device:update_mappings()
|
self.device:update_mappings()
|
||||||
|
|
||||||
self:set_image(build_icon_path(self.device))
|
local icon = icon_theme:lookup_icon(
|
||||||
|
self.device.IconName,
|
||||||
|
icon_size,
|
||||||
|
icon_flags
|
||||||
|
)
|
||||||
|
|
||||||
|
if icon then
|
||||||
|
self.image = icon:load_surface()
|
||||||
|
end
|
||||||
|
|
||||||
if self.device.IsPresent then
|
if self.device.IsPresent then
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue