2023-02-14 02:58:08 +01:00
|
|
|
-------------------------------------------
|
|
|
|
-- @author https://github.com/Kasper24
|
|
|
|
-- @copyright 2021-2022 Kasper24
|
|
|
|
-------------------------------------------
|
2022-05-11 17:28:32 +02:00
|
|
|
local lgi = require("lgi")
|
|
|
|
local Gio = lgi.Gio
|
2023-02-14 01:26:18 +01:00
|
|
|
local DesktopAppInfo = Gio.DesktopAppInfo
|
2023-02-14 04:07:59 +01:00
|
|
|
local AppInfo = Gio.DesktopAppInfo
|
2022-05-11 17:28:32 +02:00
|
|
|
local Gtk = lgi.require("Gtk", "3.0")
|
2023-02-14 04:07:59 +01:00
|
|
|
local string = string
|
|
|
|
local ipairs = ipairs
|
2021-11-03 22:38:36 +01:00
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
local ICON_SIZE = 48
|
|
|
|
local GTK_THEME = Gtk.IconTheme.get_default()
|
2021-11-03 22:38:36 +01:00
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
local _icon_theme = {}
|
2022-05-11 17:28:32 +02:00
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
function _icon_theme.choose_icon(icons_names, icon_theme, icon_size)
|
|
|
|
if icon_theme then
|
|
|
|
GTK_THEME = Gtk.IconTheme.new()
|
|
|
|
Gtk.IconTheme.set_custom_theme(GTK_THEME, icon_theme);
|
|
|
|
end
|
|
|
|
if icon_size then
|
|
|
|
ICON_SIZE = icon_size
|
2021-11-03 22:38:36 +01:00
|
|
|
end
|
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
local icon_info = GTK_THEME:choose_icon(icons_names, ICON_SIZE, 0);
|
2021-11-05 04:38:54 +01:00
|
|
|
if icon_info then
|
2022-05-11 17:28:32 +02:00
|
|
|
local icon_path = icon_info:get_filename()
|
2021-11-05 04:38:54 +01:00
|
|
|
if icon_path then
|
|
|
|
return icon_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
function _icon_theme.get_gicon_path(gicon, icon_theme, icon_size)
|
2021-11-03 22:38:36 +01:00
|
|
|
if gicon == nil then
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
if icon_theme then
|
|
|
|
GTK_THEME = Gtk.IconTheme.new()
|
|
|
|
Gtk.IconTheme.set_custom_theme(GTK_THEME, icon_theme);
|
|
|
|
end
|
|
|
|
if icon_size then
|
|
|
|
ICON_SIZE = icon_size
|
|
|
|
end
|
|
|
|
|
|
|
|
local icon_info = GTK_THEME:lookup_by_gicon(gicon, ICON_SIZE, 0);
|
2021-11-03 22:38:36 +01:00
|
|
|
if icon_info then
|
2022-05-11 17:28:32 +02:00
|
|
|
local icon_path = icon_info:get_filename()
|
2021-11-03 22:38:36 +01:00
|
|
|
if icon_path then
|
|
|
|
return icon_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
function _icon_theme.get_icon_path(icon_name, icon_theme, icon_size)
|
|
|
|
if icon_theme then
|
|
|
|
GTK_THEME = Gtk.IconTheme.new()
|
|
|
|
Gtk.IconTheme.set_custom_theme(GTK_THEME, icon_theme);
|
|
|
|
end
|
|
|
|
if icon_size then
|
|
|
|
ICON_SIZE = icon_size
|
|
|
|
end
|
|
|
|
|
|
|
|
local icon_info = GTK_THEME:lookup_icon(icon_name, ICON_SIZE, 0)
|
2021-11-03 22:38:36 +01:00
|
|
|
if icon_info then
|
2022-05-11 17:28:32 +02:00
|
|
|
local icon_path = icon_info:get_filename()
|
2021-11-03 22:38:36 +01:00
|
|
|
if icon_path then
|
|
|
|
return icon_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2023-02-14 04:07:59 +01:00
|
|
|
function _icon_theme.get_client_icon_path(client, icon_theme, icon_size)
|
|
|
|
local app_list = AppInfo.get_all()
|
|
|
|
|
|
|
|
local class = string.lower(client.class)
|
|
|
|
local name = string.lower(client.name)
|
|
|
|
|
|
|
|
for _, app in ipairs(app_list) do
|
|
|
|
local id = app:get_id()
|
|
|
|
local desktop_app_info = DesktopAppInfo.new(id)
|
|
|
|
if desktop_app_info then
|
|
|
|
local props = {
|
|
|
|
string.lower(desktop_app_info:get_string("Name") or ""),
|
|
|
|
string.lower(desktop_app_info:get_filename() or ""),
|
|
|
|
string.lower(desktop_app_info:get_startup_wm_class() or ""),
|
|
|
|
string.lower(desktop_app_info:get_string("Icon") or ""),
|
|
|
|
string.lower(desktop_app_info:get_string("Exec") or ""),
|
|
|
|
string.lower(desktop_app_info:get_string("Keywords") or "")
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, prop in ipairs(props) do
|
|
|
|
if prop ~= "" and (prop == class or prop == name) then
|
|
|
|
local icon = desktop_app_info:get_string("Icon")
|
|
|
|
return _icon_theme.get_icon_path(icon, icon_theme, icon_size)
|
2023-02-14 02:40:16 +01:00
|
|
|
end
|
2023-02-14 02:34:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-14 04:07:59 +01:00
|
|
|
return _icon_theme.choose_icon({"window", "window-manager", "xfwm4-default", "window_list"}, icon_theme, icon_size)
|
2023-02-14 02:34:41 +01:00
|
|
|
end
|
|
|
|
|
2023-02-14 01:26:18 +01:00
|
|
|
return _icon_theme
|