Switch completely to Gio for icons and it fixed the startup/lookup time for icons. Now works with every icon theme. Taglist/Tasklist/Window switcher still rely on WM_CLASS and WM_NAME to match the icon name, this probably can't be fixed in a sane way
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
-- Initialising, order is important!
|
-- Initialising, order is important!
|
||||||
require("src.theme.user_config")
|
require("src.theme.user_config")
|
||||||
require("src.theme.theme_config")
|
require("src.theme.theme_config")
|
||||||
require("src.tools.icon_theme")
|
require("src.tools.gio_icon_lookup")
|
||||||
require("src.theme.init")
|
require("src.theme.init")
|
||||||
require("src.core.error_handling")
|
require("src.core.error_handling")
|
||||||
require("src.core.signals")
|
require("src.core.signals")
|
||||||
@@ -20,5 +20,5 @@ require("src.bindings.bind_to_tags")
|
|||||||
require("src.modules.init")
|
require("src.modules.init")
|
||||||
require("src.tools.helpers.init")
|
require("src.tools.helpers.init")
|
||||||
require("src.tools.hex_to_rgba")
|
require("src.tools.hex_to_rgba")
|
||||||
require("src.tools.auto_starter")(User_config.autostart)
|
--require("src.tools.auto_starter")(User_config.autostart)
|
||||||
require("src.tools.dbus.bluetooth_dbus")()
|
require("src.tools.dbus.bluetooth_dbus")()
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ return function()
|
|||||||
{ -- Icon
|
{ -- Icon
|
||||||
valign = "center",
|
valign = "center",
|
||||||
halign = "center",
|
halign = "center",
|
||||||
--[[ image = xdg_icon_lookup:find_icon(Gio.DesktopAppInfo.get_string(desktop_app_info, "Icon"), 64) or
|
|
||||||
awful.util.getdir("config") .. "src/assets/icons/fallback.svg", -- fallback icon ]]
|
|
||||||
image = Get_gicon_path(app_info.get_icon(app)),
|
image = Get_gicon_path(app_info.get_icon(app)),
|
||||||
resize = true,
|
resize = true,
|
||||||
widget = wibox.widget.imagebox
|
widget = wibox.widget.imagebox
|
||||||
|
|||||||
@@ -4,11 +4,10 @@
|
|||||||
-- Awesome Libs
|
-- Awesome Libs
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
local dpi = require("beautiful").xresources.apply_dpi
|
local dpi = require("beautiful").xresources.apply_dpi
|
||||||
|
local Gio = require("lgi").Gio
|
||||||
local gears = require("gears")
|
local gears = require("gears")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local desktop_parser = require("src.tools.desktop_parser")
|
|
||||||
|
|
||||||
return function(screen, programs)
|
return function(screen, programs)
|
||||||
|
|
||||||
local function create_dock_element(program, size)
|
local function create_dock_element(program, size)
|
||||||
@@ -16,6 +15,15 @@ return function(screen, programs)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local desktop_app_info = Gio.DesktopAppInfo.new_from_filename(program)
|
||||||
|
if not desktop_app_info then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local gicon = Gio.Icon.new_for_string(Gio.DesktopAppInfo.get_string(desktop_app_info, "Icon"))
|
||||||
|
if not gicon then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local dock_element = wibox.widget {
|
local dock_element = wibox.widget {
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@@ -23,6 +31,7 @@ return function(screen, programs)
|
|||||||
{
|
{
|
||||||
resize = true,
|
resize = true,
|
||||||
widget = wibox.widget.imagebox,
|
widget = wibox.widget.imagebox,
|
||||||
|
image = Get_gicon_path(gicon) or "",
|
||||||
valign = "center",
|
valign = "center",
|
||||||
halign = "center",
|
halign = "center",
|
||||||
id = "icon",
|
id = "icon",
|
||||||
@@ -50,8 +59,6 @@ return function(screen, programs)
|
|||||||
widget = wibox.container.margin
|
widget = wibox.container.margin
|
||||||
}
|
}
|
||||||
|
|
||||||
dock_element.background.margin.icon_container.icon.image = xdg_icon_lookup:find_icon(program["Icon"], 64)
|
|
||||||
|
|
||||||
for _, c in ipairs(client.get()) do
|
for _, c in ipairs(client.get()) do
|
||||||
if string.lower(c.class):match(program["Icon"]) and c == client.focus then
|
if string.lower(c.class):match(program["Icon"]) and c == client.focus then
|
||||||
dock_element.background.bg = Theme_config.dock.element_focused_bg
|
dock_element.background.bg = Theme_config.dock.element_focused_bg
|
||||||
@@ -71,7 +78,7 @@ return function(screen, programs)
|
|||||||
|
|
||||||
awful.tooltip {
|
awful.tooltip {
|
||||||
objects = { dock_element },
|
objects = { dock_element },
|
||||||
text = program["Name"],
|
text = Gio.DesktopAppInfo.get_string(desktop_app_info, "Name"),
|
||||||
mode = "outside",
|
mode = "outside",
|
||||||
preferred_alignments = "middle",
|
preferred_alignments = "middle",
|
||||||
margins = dpi(10)
|
margins = dpi(10)
|
||||||
@@ -110,7 +117,7 @@ return function(screen, programs)
|
|||||||
local dock_elements = { layout = wibox.layout.fixed.horizontal }
|
local dock_elements = { layout = wibox.layout.fixed.horizontal }
|
||||||
|
|
||||||
for i, p in ipairs(pr) do
|
for i, p in ipairs(pr) do
|
||||||
dock_elements[i] = create_dock_element(desktop_parser.Get_desktop_values(p), User_config.dock_icon_size)
|
dock_elements[i] = create_dock_element(Get_desktop_values(p), User_config.dock_icon_size)
|
||||||
end
|
end
|
||||||
|
|
||||||
return dock_elements
|
return dock_elements
|
||||||
@@ -140,7 +147,7 @@ return function(screen, programs)
|
|||||||
local indicators = { layout = wibox.layout.flex.horizontal, spacing = dpi(5) }
|
local indicators = { layout = wibox.layout.flex.horizontal, spacing = dpi(5) }
|
||||||
local col = Theme_config.dock.indicator_bg
|
local col = Theme_config.dock.indicator_bg
|
||||||
for i, c in ipairs(clients) do
|
for i, c in ipairs(clients) do
|
||||||
local icon = desktop_parser.Get_desktop_values(pr)
|
local icon = Get_desktop_values(pr)
|
||||||
if icon then
|
if icon then
|
||||||
local icon_name = string.lower(icon["Icon"] or "")
|
local icon_name = string.lower(icon["Icon"] or "")
|
||||||
if icon_name:match(string.lower(c.class or c.name)) then
|
if icon_name:match(string.lower(c.class or c.name)) then
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
--------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
return function(s)
|
return function(s)
|
||||||
xdg_icon_lookup = require("src.tools.xdg_icon_lookup")()
|
|
||||||
|
|
||||||
---Lookup function to return the widget from its easy name string
|
---Lookup function to return the widget from its easy name string
|
||||||
---@param widgets table
|
---@param widgets table
|
||||||
---@return widget
|
---@return widget
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ return function()
|
|||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
--!ADD FALLBACK ICON!--
|
--!ADD FALLBACK ICON!--
|
||||||
image = xdg_icon_lookup:find_icon(client.class, 64) or client.icon,
|
image = Get_icon(client.class, client.name) or client.icon,
|
||||||
valign = "center",
|
valign = "center",
|
||||||
halign = "center",
|
halign = "center",
|
||||||
widget = wibox.widget.imagebox
|
widget = wibox.widget.imagebox
|
||||||
|
|||||||
83
awesome/src/tools/gio_icon_lookup.lua
Normal file
83
awesome/src/tools/gio_icon_lookup.lua
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
-- Libraries
|
||||||
|
local lgi = require("lgi")
|
||||||
|
local Gtk = lgi.require("Gtk", "3.0")
|
||||||
|
local Gio = lgi.Gio
|
||||||
|
local gears = require("gears")
|
||||||
|
local GLib = require("lgi").GLib
|
||||||
|
|
||||||
|
-- Get all .desktop files as gobjects
|
||||||
|
local app_info = Gio.AppInfo
|
||||||
|
local app_list = app_info.get_all()
|
||||||
|
|
||||||
|
-- Init a new Gtk theme from the users string
|
||||||
|
local gtk_theme = Gtk.IconTheme.new()
|
||||||
|
Gtk.IconTheme.set_custom_theme(gtk_theme, User_config.icon_theme)
|
||||||
|
|
||||||
|
---Gets the icon path from an AppInfo gicon.
|
||||||
|
---@param app Gio.AppInfo
|
||||||
|
---@return string path
|
||||||
|
function Get_gicon_path(app)
|
||||||
|
local icon_info = gtk_theme:lookup_by_gicon(app, 64, 0)
|
||||||
|
if icon_info then
|
||||||
|
local path = icon_info:get_filename()
|
||||||
|
if path then
|
||||||
|
return path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
---Takes a class and name string and tries to match it to an icon.
|
||||||
|
---@param class string
|
||||||
|
---@param name string
|
||||||
|
---@return string | nil icon_path
|
||||||
|
function Get_icon(class, name)
|
||||||
|
class = string.lower(class) or ""
|
||||||
|
name = string.lower(name) or ""
|
||||||
|
for _, app in ipairs(app_list) do
|
||||||
|
local desktop_app_info = Gio.DesktopAppInfo.new(app_info.get_id(app))
|
||||||
|
local icon_string = Gio.DesktopAppInfo.get_string(desktop_app_info, "Icon")
|
||||||
|
if icon_string then
|
||||||
|
icon_string = string.lower(icon_string)
|
||||||
|
if icon_string:match(class) or class:match(icon_string) then
|
||||||
|
return Get_gicon_path(app_info.get_icon(app))
|
||||||
|
elseif icon_string:match(name) or name:match(icon_string) then
|
||||||
|
return Get_gicon_path(app_info.get_icon(app))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
---Will return every $XDG_DATA_DIRS
|
||||||
|
---@return table
|
||||||
|
local function get_paths()
|
||||||
|
local dirs = {}
|
||||||
|
|
||||||
|
local dir
|
||||||
|
for _, value in ipairs(GLib.get_system_data_dirs()) do
|
||||||
|
dir = GLib.build_filenamev({ value, "applications" })
|
||||||
|
if gears.filesystem.dir_readable(dir) then table.insert(dirs, dir) end
|
||||||
|
end
|
||||||
|
|
||||||
|
dir = GLib.build_filenamev({ GLib.get_user_data_dir(), "applications" })
|
||||||
|
if gears.filesystem.dir_readable(dir) then table.insert(dirs, dir) end
|
||||||
|
|
||||||
|
return dirs
|
||||||
|
end
|
||||||
|
|
||||||
|
---Returns every .desktop file into a table
|
||||||
|
---@param file string .desktop files
|
||||||
|
---@return string | nil path
|
||||||
|
function Get_desktop_values(file)
|
||||||
|
|
||||||
|
if not file or file == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, dir in ipairs(get_paths()) do
|
||||||
|
if gears.filesystem.file_readable(dir .. "/" .. file, "r") then
|
||||||
|
return dir .. "/" .. file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -82,7 +82,7 @@ local list_update = function(widget, buttons, _, _, objects)
|
|||||||
id = "icon_container",
|
id = "icon_container",
|
||||||
{
|
{
|
||||||
id = "icon",
|
id = "icon",
|
||||||
image = client.icon,
|
image = Get_icon(client.class, client.name) or client.icon,
|
||||||
resize = true,
|
resize = true,
|
||||||
valign = "center",
|
valign = "center",
|
||||||
halign = "center",
|
halign = "center",
|
||||||
@@ -95,8 +95,6 @@ local list_update = function(widget, buttons, _, _, objects)
|
|||||||
widget = wibox.container.margin
|
widget = wibox.container.margin
|
||||||
}
|
}
|
||||||
|
|
||||||
icon.icon_container.icon:set_image(xdg_icon_lookup:find_icon(client.class, 64) or client.icon)
|
|
||||||
|
|
||||||
tag_widget.container:setup({
|
tag_widget.container:setup({
|
||||||
icon,
|
icon,
|
||||||
strategy = "exact",
|
strategy = "exact",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ local list_update = function(widget, buttons, label, _, objects)
|
|||||||
valign = "center",
|
valign = "center",
|
||||||
halign = "center",
|
halign = "center",
|
||||||
resize = true,
|
resize = true,
|
||||||
image = object.icon,
|
image = Get_icon(object.class, object.name) or object.icon,
|
||||||
widget = wibox.widget.imagebox
|
widget = wibox.widget.imagebox
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
@@ -114,8 +114,7 @@ local list_update = function(widget, buttons, label, _, objects)
|
|||||||
task_widget:set_bg(Theme_config.tasklist.bg)
|
task_widget:set_bg(Theme_config.tasklist.bg)
|
||||||
task_widget.container.layout_it.title:set_text('')
|
task_widget.container.layout_it.title:set_text('')
|
||||||
end
|
end
|
||||||
task_widget:get_children_by_id("icon")[1]:set_image(xdg_icon_lookup:find_icon(object.class, 64) or
|
|
||||||
object.icon)
|
|
||||||
widget:add(task_widget)
|
widget:add(task_widget)
|
||||||
widget:set_spacing(dpi(6))
|
widget:set_spacing(dpi(6))
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
-- @supermodule wibox.widget.base
|
-- @supermodule wibox.widget.base
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: deprecated
|
||||||
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
local base = require("wibox.widget.base")
|
local base = require("wibox.widget.base")
|
||||||
local table = table
|
local table = table
|
||||||
|
|||||||
Reference in New Issue
Block a user