Fix icon path resolution in menubar.utils

Issue #2152

Rewrites get_icon_lookup_path to find icons and themes in
$HOME/.icons. Also adds 'scalable' as the top priority icon size.
This commit is contained in:
get 2018-01-15 22:35:41 +01:00
parent c9bd787fd6
commit a65079b104
1 changed files with 53 additions and 36 deletions

View File

@ -20,6 +20,7 @@ local w_textbox = require("wibox.widget.textbox")
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
local protected_call = require("gears.protected_call") local protected_call = require("gears.protected_call")
local gstring = require("gears.string") local gstring = require("gears.string")
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
local utils = {} local utils = {}
@ -123,7 +124,8 @@ do
end end
local all_icon_sizes = { local all_icon_sizes = {
'128x128' , 'scalable',
'128x128',
'96x96', '96x96',
'72x72', '72x72',
'64x64', '64x64',
@ -154,48 +156,63 @@ local icon_lookup_path = nil
--- Get a list of icon lookup paths. --- Get a list of icon lookup paths.
-- @treturn table A list of directories, without trailing slash. -- @treturn table A list of directories, without trailing slash.
local function get_icon_lookup_path() local function get_icon_lookup_path()
if not icon_lookup_path then if icon_lookup_path then return icon_lookup_path end
local add_if_readable = function(t, path)
local function ensure_args(t, paths)
if type(paths) == 'string' then paths = { paths } end
return t or {}, paths
end
local function add_if_readable(t, paths)
t, paths = ensure_args(t, paths)
for _, path in ipairs(paths) do
if gfs.dir_readable(path) then if gfs.dir_readable(path) then
table.insert(t, path) table.insert(t, path)
end end
end end
icon_lookup_path = {} return t
local icon_theme_paths = {} end
local icon_theme = theme.icon_theme
local paths = glib.get_system_data_dirs() local function add_with_dir(t, paths, dir)
table.insert(paths, 1, glib.get_user_data_dir()) t, paths = ensure_args(t, paths)
table.insert(paths, 1, glib.build_filenamev({glib.get_home_dir(), dir = { nil, dir }
'.icons'}))
for _,dir in ipairs(paths) do for _, path in ipairs(paths) do
local icons_dir = glib.build_filenamev({dir, 'icons'}) dir[1] = path
if gfs.dir_readable(icons_dir) then table.insert(t, glib.build_filenamev(dir))
if icon_theme then
add_if_readable(icon_theme_paths,
glib.build_filenamev({icons_dir,
icon_theme}))
end
-- Fallback theme.
add_if_readable(icon_theme_paths,
glib.build_filenamev({icons_dir, 'hicolor'}))
end
end end
for _, icon_theme_directory in ipairs(icon_theme_paths) do return t
for _, size in ipairs(all_icon_sizes) do end
add_if_readable(icon_lookup_path,
glib.build_filenamev({icon_theme_directory, icon_lookup_path = {}
size, 'apps'})) local theme_priority = { 'hicolor' }
end if theme.icon_theme then table.insert(theme_priority, 1, theme.icon_theme) end
end
for _,dir in ipairs(paths)do local paths = add_with_dir({}, glib.get_home_dir(), '.icons')
-- lowest priority fallbacks add_with_dir(paths, {
add_if_readable(icon_lookup_path, glib.get_user_data_dir(), -- $XDG_DATA_HOME, typically $HOME/.local/share
glib.build_filenamev({dir, 'pixmaps'})) unpack(glib.get_system_data_dirs()) -- $XDG_DATA_DIRS, typically /usr/{,local/}share
add_if_readable(icon_lookup_path, }, 'icons')
glib.build_filenamev({dir, 'icons'})) add_with_dir(paths, glib.get_system_data_dirs(), 'pixmaps')
local icon_theme_paths = {}
for _, theme_dir in ipairs(theme_priority) do
add_if_readable(icon_theme_paths,
add_with_dir({}, paths, theme_dir))
end
local app_in_theme_paths = {}
for _, icon_theme_directory in ipairs(icon_theme_paths) do
for _, size in ipairs(all_icon_sizes) do
table.insert(app_in_theme_paths,
glib.build_filenamev({ icon_theme_directory,
size, 'apps' }))
end end
end end
return icon_lookup_path add_if_readable(icon_lookup_path, app_in_theme_paths)
return add_if_readable(icon_lookup_path, paths)
end end
--- Remove CR newline from the end of the string. --- Remove CR newline from the end of the string.