From 3db87c693abb4dfa35c09ea01050f8763f43fa95 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 21 Feb 2016 16:53:46 +0100 Subject: [PATCH] menubar.icon_theme: Don't require("awful") This avoids having to mock half the C API just because all of awful is loaded needlessly in this unit test and is generally a good idea. Signed-off-by: Uli Schlachter --- lib/menubar/icon_theme.lua | 20 ++++++++++---------- spec/menubar/icon_theme_spec.lua | 23 ----------------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/lib/menubar/icon_theme.lua b/lib/menubar/icon_theme.lua index 768db7c7..6ffb9e51 100644 --- a/lib/menubar/icon_theme.lua +++ b/lib/menubar/icon_theme.lua @@ -12,7 +12,7 @@ -- http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-0.12.html local beautiful = require("beautiful") -local awful = require("awful") +local awful_util = require("awful.util") local GLib = require("lgi").GLib local index_theme = require("menubar.index_theme") @@ -26,18 +26,18 @@ local get_pragmatic_base_directories = function() local dirs = {} local dir = GLib.build_filenamev({GLib.get_home_dir(), ".icons"}) - if awful.util.dir_readable(dir) then + if awful_util.dir_readable(dir) then table.insert(dirs, dir) end dir = GLib.build_filenamev({GLib.get_user_data_dir(), "icons"}) - if awful.util.dir_readable(dir) then + if awful_util.dir_readable(dir) then table.insert(dirs, dir) end for _, v in ipairs(GLib.get_system_data_dirs()) do dir = GLib.build_filenamev({v, "icons"}) - if awful.util.dir_readable(dir) then + if awful_util.dir_readable(dir) then table.insert(dirs, dir) end end @@ -45,7 +45,7 @@ local get_pragmatic_base_directories = function() local need_usr_share_pixmaps = true for _, v in ipairs(GLib.get_system_data_dirs()) do dir = GLib.build_filenamev({v, "pixmaps"}) - if awful.util.dir_readable(dir) then + if awful_util.dir_readable(dir) then table.insert(dirs, dir) end if dir == "/usr/share/pixmaps" then @@ -54,7 +54,7 @@ local get_pragmatic_base_directories = function() end dir = "/usr/share/pixmaps" - if need_usr_share_pixmaps and awful.util.dir_readable(dir) then + if need_usr_share_pixmaps and awful_util.dir_readable(dir) then table.insert(dirs, dir) end @@ -66,7 +66,7 @@ local get_default_icon_theme_name = function() for _, dir in ipairs(get_pragmatic_base_directories()) do for _, icon_theme_name in ipairs(icon_theme_names) do local filename = string.format("%s/%s/index.theme", dir, icon_theme_name) - if awful.util.file_readable(filename) then + if awful_util.file_readable(filename) then return icon_theme_name end end @@ -153,7 +153,7 @@ local lookup_icon = function(self, icon_name, icon_size) local filename = string.format("%s/%s/%s/%s.%s", basedir, self.icon_theme_name, subdir, icon_name, ext) - if awful.util.file_readable(filename) then + if awful_util.file_readable(filename) then return filename else checked_already[filename] = true @@ -174,7 +174,7 @@ local lookup_icon = function(self, icon_name, icon_size) basedir, self.icon_theme_name, subdir, icon_name, ext) if not checked_already[filename] then - if awful.util.file_readable(filename) then + if awful_util.file_readable(filename) then closest_filename = filename minimal_size = dist end @@ -210,7 +210,7 @@ local lookup_fallback_icon = function(self, icon_name) local filename = string.format("%s/%s.%s", dir, icon_name, ext) - if awful.util.file_readable(filename) then + if awful_util.file_readable(filename) then return filename end end diff --git a/spec/menubar/icon_theme_spec.lua b/spec/menubar/icon_theme_spec.lua index 8588d3a2..ff937a47 100644 --- a/spec/menubar/icon_theme_spec.lua +++ b/spec/menubar/icon_theme_spec.lua @@ -3,29 +3,6 @@ -- @copyright 2015 Kazunobu Kuriyama --------------------------------------------------------------------------- --- Hack so that beautiful can be loaded -_G.awesome = { - xrdb_get_value = function() end, - connect_signal = function() end, - register_xproperty = function() end -} --- Additional hacks to load menubar -_G.screen = { - add_signal = function() end, - count = function() return 0 end -} -_G.client = { - connect_signal = function() end, - add_signal = function() end -} -_G.tag = { - connect_signal = function() end, - add_signal = function() end -} -_G.root = { - cursor = function() end -} - local os = os local string = string local icon_theme = require("menubar.icon_theme")