commit
ad68d3bf5b
|
@ -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.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../icons/awesome
|
|
@ -0,0 +1 @@
|
||||||
|
../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../../../icons/awesome16.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../../../icons/awesome16.png
|
|
@ -0,0 +1 @@
|
||||||
|
awesome.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../64x64/apps/awesome.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -0,0 +1 @@
|
||||||
|
../../../icons/fallback.png
|
|
@ -4,6 +4,8 @@
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
local utils = require("menubar.utils")
|
local utils = require("menubar.utils")
|
||||||
|
local theme = require("beautiful")
|
||||||
|
local glib = require("lgi").GLib
|
||||||
|
|
||||||
describe("menubar.utils unescape", function()
|
describe("menubar.utils unescape", function()
|
||||||
local single_strings = {
|
local single_strings = {
|
||||||
|
@ -50,4 +52,64 @@ describe("menubar.utils unescape", function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("menubar.utils lookup_icon_uncached", function()
|
||||||
|
local shimmed = {}
|
||||||
|
local icon_theme
|
||||||
|
|
||||||
|
local function assert_found_in_path(icon, path)
|
||||||
|
assert.matches(path .. '$', utils.lookup_icon_uncached(icon) or '')
|
||||||
|
end
|
||||||
|
|
||||||
|
setup(function()
|
||||||
|
local root = (os.getenv("SOURCE_DIRECTORY") or '.') .. "/spec/menubar"
|
||||||
|
|
||||||
|
local function shim(name, retval)
|
||||||
|
shimmed[name] = glib[name]
|
||||||
|
glib[name] = function() return retval end
|
||||||
|
end
|
||||||
|
|
||||||
|
shim('get_home_dir', root .. "/home")
|
||||||
|
shim('get_user_data_dir', root .. "/home/.local/share")
|
||||||
|
shim('get_system_data_dirs', {
|
||||||
|
root .. "/usr/local/share",
|
||||||
|
root .. "/usr/share"
|
||||||
|
})
|
||||||
|
|
||||||
|
icon_theme = theme.icon_theme
|
||||||
|
theme.icon_theme = 'awesome'
|
||||||
|
end)
|
||||||
|
|
||||||
|
teardown(function()
|
||||||
|
for name, func in pairs(shimmed) do
|
||||||
|
glib[name] = func
|
||||||
|
end
|
||||||
|
theme.icon_theme = icon_theme
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('finds icons in icon base directories, in correct order', function()
|
||||||
|
|
||||||
|
-- Shimmed icon base directories contain the following icons:
|
||||||
|
--
|
||||||
|
-- usr/share/pixmaps/icon[1-5].png
|
||||||
|
-- usr/share/icons/icon[2-5].png
|
||||||
|
-- usr/local/share/icons/icon[3-5].png
|
||||||
|
-- .local/share/icons/icon[4-5].png
|
||||||
|
-- .icons/icon5.png
|
||||||
|
|
||||||
|
assert_found_in_path('icon1', '/usr/share/pixmaps/icon1.png')
|
||||||
|
assert_found_in_path('icon2', '/usr/share/icons/icon2.png')
|
||||||
|
assert_found_in_path('icon3', '/usr/local/share/icons/icon3.png')
|
||||||
|
assert_found_in_path('icon4', '/.local/share/icons/icon4.png')
|
||||||
|
assert_found_in_path('icon5', '/.icons/icon5.png')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('finds icons in $HOME/.icons/<theme>/<size>/apps/', function()
|
||||||
|
|
||||||
|
-- Theme 'awesome' in shimmed $HOME/.icons:
|
||||||
|
|
||||||
|
assert_found_in_path('awesome', '/.icons/awesome/64x64/apps/awesome.png')
|
||||||
|
assert_found_in_path('awesome2', '/.icons/awesome/scalable/apps/awesome2.png')
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue