Page MenuHome

blender_add_xdg_base_directory_support_ideasman42.patch

blender_add_xdg_base_directory_support_ideasman42.patch

Index: intern/ghost/intern/GHOST_SystemPathsX11.cpp
===================================================================
--- intern/ghost/intern/GHOST_SystemPathsX11.cpp (revision 41458)
+++ intern/ghost/intern/GHOST_SystemPathsX11.cpp (working copy)
@@ -41,6 +41,11 @@
#include <stdio.h> // for fprintf only
#include <cstdlib> // for exit
+#ifdef WITH_XDG_USER_DIRS
+# include <pwd.h> // for get home without use getenv()
+# include <limits.h> // for PATH_MAX
+#endif
+
#ifdef PREFIX
static const char *static_path= PREFIX "/share" ;
#else
@@ -63,7 +68,27 @@
const GHOST_TUns8* GHOST_SystemPathsX11::getUserDir() const
{
+#ifndef WITH_XDG_USER_DIRS
return (const GHOST_TUns8 *)getenv("HOME");
+#else /* WITH_XDG_USER_DIRS */
+ const char *home= getenv("XDG_CONFIG_HOME");
+
+ if (home) {
+ return (const GHOST_TUns8 *)home;
+ }
+ else {
+ static char user_path[PATH_MAX];
+
+ home= getenv("HOME");
+
+ if (home == NULL) {
+ home= getpwuid(getuid())->pw_dir;
+ }
+
+ snprintf(user_path, sizeof(user_path), "%s/.config", home);
+ return (const GHOST_TUns8 *)user_path;
+ }
+#endif /* WITH_XDG_USER_DIRS */
}
const GHOST_TUns8* GHOST_SystemPathsX11::getBinaryDir() const
Index: intern/ghost/CMakeLists.txt
===================================================================
--- intern/ghost/CMakeLists.txt (revision 41458)
+++ intern/ghost/CMakeLists.txt (working copy)
@@ -108,6 +108,10 @@
)
endif()
+if(WITH_XDG_USER_DIRS)
+ add_definitions(-DWITH_XDG_USER_DIRS)
+endif()
+
if(WITH_HEADLESS OR WITH_GHOST_SDL)
if(WITH_HEADLESS)
list(APPEND SRC
Index: source/blender/blenlib/CMakeLists.txt
===================================================================
--- source/blender/blenlib/CMakeLists.txt (revision 41458)
+++ source/blender/blenlib/CMakeLists.txt (working copy)
@@ -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}")
Index: source/blender/blenlib/intern/path_util.c
===================================================================
--- source/blender/blenlib/intern/path_util.c (revision 41458)
+++ source/blender/blenlib/intern/path_util.c (working copy)
@@ -82,14 +82,18 @@
/* standard paths */
#ifdef WIN32
-#define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s"
-#define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s"
+# define BLENDER_USER_FORMAT "%s\\Blender Foundation\\Blender\\%s"
+# define BLENDER_SYSTEM_FORMAT "%s\\Blender Foundation\\Blender\\%s"
#elif defined(__APPLE__)
-#define BLENDER_USER_FORMAT "%s/Blender/%s"
-#define BLENDER_SYSTEM_FORMAT "%s/Blender/%s"
-#else
-#define BLENDER_USER_FORMAT "%s/.blender/%s"
-#define BLENDER_SYSTEM_FORMAT "%s/blender/%s"
+# define BLENDER_USER_FORMAT "%s/Blender/%s"
+# define BLENDER_SYSTEM_FORMAT "%s/Blender/%s"
+#else /* UNIX */
+# 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
/* local */
@@ -797,10 +801,18 @@
as default location to save documents */
const char *BLI_getDefaultDocumentFolder(void)
{
- #if !defined(WIN32)
+#ifndef 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 */
+#else /* Windows */
const char * ret;
static char documentfolder[MAXPATHLEN];
HRESULT hResult;
@@ -825,7 +837,7 @@
}
return NULL;
- #endif
+#endif /* WIN32 */
}
/* NEW stuff, to be cleaned up when fully migrated */
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 41458)
+++ CMakeLists.txt (working copy)
@@ -157,6 +157,8 @@
if(UNIX AND NOT APPLE)
option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)" ON)
option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
+ option(WITH_XDG_USER_DIRS "Build with XDG Base Directory Specification (only config and documents for now)" OFF)
+ mark_as_advanced(WITH_XDG_USER_DIRS)
else()
# not an option for other OS's
set(WITH_BUILTIN_GLEW ON)

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8b/75/94f11f01b31137ebb1b42eccc21d

Event Timeline