From c315687dadaddd6573bc2701908cb52e2f1c6157 Mon Sep 17 00:00:00 2001 From: salorium Date: Thu, 5 Feb 2015 19:42:49 +0100 Subject: [PATCH 1/4] menubar: improve path icon behavior This adds $XDG_DATA_DIRS and HOME/.icons for icon lookups. --- lib/menubar/utils.lua.in | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/menubar/utils.lua.in b/lib/menubar/utils.lua.in index 8cd0b1690..0da1b8245 100644 --- a/lib/menubar/utils.lua.in +++ b/lib/menubar/utils.lua.in @@ -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 @@ -80,12 +81,15 @@ function utils.lookup_icon(icon_file) 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 + 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 - 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/') @@ -96,10 +100,11 @@ function utils.lookup_icon(icon_file) 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 k,dir in ipairs(paths)do + -- lowest priority fallbacks + table.insert(icon_path, dir..'/pixmaps/') + table.insert(icon_path, dir..'/icons/') + end for i, directory in ipairs(icon_path) do if is_format_supported(icon_file) and awful_util.file_readable(directory .. icon_file) then return directory .. icon_file From d25e15001fa2bb68d32a6b8bb8f587ec4f4b03b3 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 9 Feb 2015 19:23:42 +0100 Subject: [PATCH 2/4] Move building of icon lookup path into get_icon_lookup_path --- lib/menubar/utils.lua.in | 65 ++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/lib/menubar/utils.lua.in b/lib/menubar/utils.lua.in index 0da1b8245..3fb8a3f22 100644 --- a/lib/menubar/utils.lua.in +++ b/lib/menubar/utils.lua.in @@ -65,6 +65,40 @@ 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/') + table.insert(icon_lookup_path, icon_theme_directory .. size .. '/actions/') + table.insert(icon_lookup_path, icon_theme_directory .. size .. '/devices/') + table.insert(icon_lookup_path, icon_theme_directory .. size .. '/places/') + table.insert(icon_lookup_path, icon_theme_directory .. size .. '/categories/') + table.insert(icon_lookup_path, icon_theme_directory .. size .. '/status/') + 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. @@ -76,36 +110,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 - 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_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 - for k,dir in ipairs(paths)do - -- lowest priority fallbacks - table.insert(icon_path, dir..'/pixmaps/') - table.insert(icon_path, dir..'/icons/') - end - 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 From dc41e62f9a58faf723c3eefba729b1e2362f2b2f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 9 Feb 2015 19:49:01 +0100 Subject: [PATCH 3/4] menubar: icon_formats: svg is supported --- lib/menubar/utils.lua.in | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/menubar/utils.lua.in b/lib/menubar/utils.lua.in index 3fb8a3f22..3361a5879 100644 --- a/lib/menubar/utils.lua.in +++ b/lib/menubar/utils.lua.in @@ -49,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. From 60e04d3ae3606e815c7e8599ba4485fe4891ac04 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 9 Feb 2015 20:06:19 +0100 Subject: [PATCH 4/4] menubar: get_icon_lookup_path: only look in apps/ with icon_themes Ref: https://github.com/awesomeWM/awesome/pull/100#issuecomment-73559676 --- lib/menubar/utils.lua.in | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/menubar/utils.lua.in b/lib/menubar/utils.lua.in index 3361a5879..eac831b0e 100644 --- a/lib/menubar/utils.lua.in +++ b/lib/menubar/utils.lua.in @@ -82,11 +82,6 @@ local function get_icon_lookup_path() 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/') - table.insert(icon_lookup_path, icon_theme_directory .. size .. '/actions/') - table.insert(icon_lookup_path, icon_theme_directory .. size .. '/devices/') - table.insert(icon_lookup_path, icon_theme_directory .. size .. '/places/') - table.insert(icon_lookup_path, icon_theme_directory .. size .. '/categories/') - table.insert(icon_lookup_path, icon_theme_directory .. size .. '/status/') end end for k,dir in ipairs(paths)do