allow relative path for background images in style files
Mark Tiefenbruck mark@fluxbox.org
4 files changed,
28 insertions(+),
19 deletions(-)
M
src/FbTk/Image.cc
→
src/FbTk/Image.cc
@@ -21,6 +21,7 @@ // DEALINGS IN THE SOFTWARE.
#include "Image.hh" #include "StringUtil.hh" +#include "FileUtil.hh" #ifdef HAVE_CONFIG_H #include "config.h"@@ -94,25 +95,26 @@ // valid handle?
if (s_image_map.find(extension) == s_image_map.end()) return false; - // load file - PixmapWithMask *pm = s_image_map[extension]->load(filename, screen_num); - // failed?, try different search paths - if (pm == 0 && s_search_paths.size()) { - // first we need to get basename of current filename - string base_filename = StringUtil::basename(filename); - string path = ""; - // append each search path and try to load - StringList::iterator it = s_search_paths.begin(); - StringList::iterator it_end = s_search_paths.end(); - for (; it != it_end && pm == 0; ++it) { - // append search path and try load it - path = StringUtil::expandFilename(*it); - pm = s_image_map[extension]->load(path + "/" + base_filename, screen_num); - } + string path = locateFile(filename); + if (!path.empty()) + return s_image_map[extension]->load(path, screen_num); + + return 0; +} +string Image::locateFile(const string &filename) { + string path = StringUtil::expandFilename(filename); + if (FileUtil::isRegularFile(path.c_str())) + return path; + string base = StringUtil::basename(filename); + StringList::iterator it = s_search_paths.begin(); + StringList::iterator it_end = s_search_paths.end(); + for (; it != it_end; ++it) { + path = StringUtil::expandFilename(*it) + "/" + base; + if (FileUtil::isRegularFile(path.c_str())) + return path; } - - return pm; + return ""; } bool Image::registerType(const string &type, ImageBase &base) {
M
src/FbTk/Image.hh
→
src/FbTk/Image.hh
@@ -55,6 +55,8 @@ /// removes a path to search images from
static void removeSearchPath(const std::string &search_path); /// adds a path to search images from static void removeAllSearchPaths(); + /// locates an image in the search path + static std::string locateFile(const std::string &filename); private: typedef std::map<std::string, ImageBase *> ImageMap; typedef std::list<std::string> StringList;
M
src/RootTheme.cc
→
src/RootTheme.cc
@@ -28,6 +28,7 @@ #include "Screen.hh"
#include "FbTk/App.hh" #include "FbTk/Font.hh" +#include "FbTk/Image.hh" #include "FbTk/ImageControl.hh" #include "FbTk/Resource.hh" #include "FbTk/FileUtil.hh"@@ -197,6 +198,7 @@
// if background argument is a file then // parse image options and call image setting // command specified in the resources + std::string img_path = FbTk::Image::locateFile(filename); filename = FbTk::StringUtil::expandFilename(filename); std::string cmd = realProgramName("fbsetbg") + (m_first ? " -z " : " -Z ");@@ -204,7 +206,7 @@ // style doesn't wish to change the background
if (strstr(m_background->options().c_str(), "none") != 0) { if (!m_first) return; - } else if (FbTk::FileUtil::isRegularFile(filename.c_str())) { + } else if (!img_path.empty()) { // parse options if (strstr(m_background->options().c_str(), "tiled") != 0) cmd += "-t ";@@ -215,7 +217,7 @@ cmd += "-a ";
else cmd += "-f "; - cmd += filename; + cmd += img_path; } else if (FbTk::FileUtil::isDirectory(filename.c_str()) && strstr(m_background->options().c_str(), "random") != 0) { cmd += "-r " + filename;