--- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -88,7 +88,13 @@ #define BLENDER_USER_FORMAT "%s/Blender/%s" #define BLENDER_SYSTEM_FORMAT "%s/Blender/%s" #else + +#ifndef WITH_XDG_USER_DIRS #define BLENDER_USER_FORMAT "%s/.blender/%s" +#else +#define BLENDER_USER_FORMAT "%s/blender/%s" +#endif // WITH_XDG_USER_DIRS + #define BLENDER_SYSTEM_FORMAT "%s/blender/%s" #endif @@ -798,6 +804,13 @@ const char *BLI_getDefaultDocumentFolder(void) { #if !defined(WIN32) + + #ifdef WITH_XDG_USER_DIRS + const char *xdg_documents_dir = getenv("XDG_DOCUMENTS_DIR"); + if (xdg_documents_dir) + return xdg_documents_dir; + #endif + return getenv("HOME"); #else /* Windows */ --- a/intern/ghost/intern/GHOST_SystemPathsX11.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsX11.cpp @@ -41,6 +41,11 @@ #include // for fprintf only #include // for exit +#ifdef WITH_XDG_USER_DIRS +#include // for strncat only +#include // for get home without use getenv() +#endif + #ifdef PREFIX static const char *static_path= PREFIX "/share" ; #else @@ -63,7 +68,25 @@ const GHOST_TUns8* GHOST_SystemPathsX11::getUserDir() const { + #ifndef WITH_XDG_USER_DIRS return (const GHOST_TUns8 *)getenv("HOME"); + #else + const char *xdg_config_home = getenv("XDG_CONFIG_HOME"); + + if (xdg_config_home) + return (const GHOST_TUns8 *)xdg_config_home; + else { + char *home = NULL; + + if (getenv("HOME") != NULL) + home = strdup(getenv("HOME")); + else + home = getpwuid(getuid())->pw_dir; + + const char *xdg_config_fallback = strncat(home,"/.config",8); + return (const GHOST_TUns8 *)xdg_config_fallback; + } + #endif } const GHOST_TUns8* GHOST_SystemPathsX11::getBinaryDir() const +++ b/CMakeLists.txt @@ -146,6 +146,7 @@ option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON) mark_as_advanced(WITH_AUDASPACE) +option(WITH_XDG_USER_DIRS "Build with XDG Base Directory Specification (only config and documents for now)" OFF) # (unix defaults to OpenMP On) if(UNIX AND NOT APPLE) --- a/intern/ghost/CMakeLists.txt +++ b/intern/ghost/CMakeLists.txt @@ -281,5 +281,9 @@ endif() +if(WITH_XDG_USER_DIRS) + add_definitions(-DWITH_XDG_USER_DIRS) +endif() + blender_add_lib(bf_intern_ghost "${SRC}" "${INC}" "${INC_SYS}") --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -148,4 +148,8 @@ add_definitions(-DPARALLEL=1) endif() +if(WITH_XDG_USER_DIRS) + add_definitions(-DWITH_XDG_USER_DIRS) +endif() + blender_add_lib(bf_blenlib "${SRC}" "${INC}" "${INC_SYS}")