all repos — fluxbox @ dda95bf106079fdfd12a690de0ce79a88279505f

custom fork of the fluxbox windowmanager

allow relative path for background images in style files
Mark Tiefenbruck mark@fluxbox.org
commit

dda95bf106079fdfd12a690de0ce79a88279505f

parent

c033c201c4254c11804713dc427d22940da05438

4 files changed, 28 insertions(+), 19 deletions(-)

jump to
M ChangeLogChangeLog

@@ -1,5 +1,8 @@

(Format: Year/Month/Day) Changes for 1.1.2 +*08/10/07: + * Allow relative paths for background images in style files (Mark) + RootTheme.cc FbTk/Image.cc/hh *08/10/05: * Remove menu modes (Mark) Screen.cc/hh ScreenResources.cc FbTk/MenuTheme.cc/hh FbTk/Menu.cc
M src/FbTk/Image.ccsrc/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.hhsrc/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.ccsrc/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;