Merge branch 'menubar-icons'
Closes: https://github.com/awesomeWM/awesome/pull/100
This commit is contained in:
commit
2d54ee271d
|
@ -11,6 +11,7 @@ local ipairs = ipairs
|
|||
local string = string
|
||||
local awful_util = require("awful.util")
|
||||
local theme = require("beautiful")
|
||||
local glib = require("lgi").GLib
|
||||
|
||||
-- Utility module for menubar
|
||||
-- menubar.utils
|
||||
|
@ -48,9 +49,8 @@ local all_icon_sizes = {
|
|||
'16x16'
|
||||
}
|
||||
|
||||
-- List of supported icon formats. Ignore SVG because Awesome doesn't
|
||||
-- support it.
|
||||
local icon_formats = { "png", "xpm" }
|
||||
-- List of supported icon formats.
|
||||
local icon_formats = { "png", "xpm", "svg" }
|
||||
|
||||
-- Check whether the icon format is supported.
|
||||
-- @param icon_file Filename of the icon.
|
||||
|
@ -64,6 +64,35 @@ local function is_format_supported(icon_file)
|
|||
return false
|
||||
end
|
||||
|
||||
local icon_lookup_path = nil
|
||||
local function get_icon_lookup_path()
|
||||
if not icon_lookup_path then
|
||||
icon_lookup_path = {}
|
||||
local icon_theme_paths = {}
|
||||
local icon_theme = theme.icon_theme
|
||||
local paths = glib.get_system_data_dirs()
|
||||
table.insert(paths, 1, glib.get_user_data_dir())
|
||||
table.insert(paths, 1, glib.get_home_dir() .. '/.icons')
|
||||
for k,dir in ipairs(paths)do
|
||||
if icon_theme then
|
||||
table.insert(icon_theme_paths, dir..'/icons/' .. icon_theme .. '/')
|
||||
end
|
||||
table.insert(icon_theme_paths, dir..'/icons/hicolor/') -- fallback theme
|
||||
end
|
||||
for i, icon_theme_directory in ipairs(icon_theme_paths) do
|
||||
for j, size in ipairs(all_icon_sizes) do
|
||||
table.insert(icon_lookup_path, icon_theme_directory .. size .. '/apps/')
|
||||
end
|
||||
end
|
||||
for k,dir in ipairs(paths)do
|
||||
-- lowest priority fallbacks
|
||||
table.insert(icon_lookup_path, dir..'/pixmaps/')
|
||||
table.insert(icon_lookup_path, dir..'/icons/')
|
||||
end
|
||||
end
|
||||
return icon_lookup_path
|
||||
end
|
||||
|
||||
--- Lookup an icon in different folders of the filesystem.
|
||||
-- @param icon_file Short or full name of the icon.
|
||||
-- @return full name of the icon.
|
||||
|
@ -75,32 +104,9 @@ function utils.lookup_icon(icon_file)
|
|||
if icon_file:sub(1, 1) == '/' and is_format_supported(icon_file) then
|
||||
-- If the path to the icon is absolute and its format is
|
||||
-- supported, do not perform a lookup.
|
||||
return icon_file
|
||||
return awful_util.file_readable(icon_file) and icon_file or nil
|
||||
else
|
||||
local icon_path = {}
|
||||
local icon_theme_paths = {}
|
||||
local icon_theme = theme.icon_theme
|
||||
if icon_theme then
|
||||
table.insert(icon_theme_paths, '/usr/share/icons/' .. icon_theme .. '/')
|
||||
-- TODO also look in parent icon themes, as in freedesktop.org specification
|
||||
end
|
||||
table.insert(icon_theme_paths, '/usr/share/icons/hicolor/') -- fallback theme
|
||||
|
||||
for i, icon_theme_directory in ipairs(icon_theme_paths) do
|
||||
for j, size in ipairs(all_icon_sizes) do
|
||||
table.insert(icon_path, icon_theme_directory .. size .. '/apps/')
|
||||
table.insert(icon_path, icon_theme_directory .. size .. '/actions/')
|
||||
table.insert(icon_path, icon_theme_directory .. size .. '/devices/')
|
||||
table.insert(icon_path, icon_theme_directory .. size .. '/places/')
|
||||
table.insert(icon_path, icon_theme_directory .. size .. '/categories/')
|
||||
table.insert(icon_path, icon_theme_directory .. size .. '/status/')
|
||||
end
|
||||
end
|
||||
-- lowest priority fallbacks
|
||||
table.insert(icon_path, '/usr/share/pixmaps/')
|
||||
table.insert(icon_path, '/usr/share/icons/')
|
||||
|
||||
for i, directory in ipairs(icon_path) do
|
||||
for i, directory in ipairs(get_icon_lookup_path()) do
|
||||
if is_format_supported(icon_file) and awful_util.file_readable(directory .. icon_file) then
|
||||
return directory .. icon_file
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue