summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorErkin Bahceci <erkinbah@gmail.com>2009-08-07 21:26:14 -0500
committerErkin Bahceci <erkinbah@gmail.com>2009-08-07 21:26:14 -0500
commit682c30d5c4b574ee47ded28f6b864725a8cb79a4 (patch)
tree9f5a4fecddf7951ec2a21be6638ea8c62acd04d0 /plugins
parentc49a8742241ba09739d0e07efed068f9b3d786ff (diff)
downloadcompiz-with-glib-mainloop-682c30d5c4b574ee47ded28f6b864725a8cb79a4.tar.gz
compiz-with-glib-mainloop-682c30d5c4b574ee47ded28f6b864725a8cb79a4.tar.bz2
compiztoolbox: Add function to get XDG user dirs.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h19
-rw-r--r--plugins/compiztoolbox/src/compiztoolbox.cpp71
2 files changed, 89 insertions, 1 deletions
diff --git a/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h b/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h
index cea3fe8..bf14888 100644
--- a/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h
+++ b/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h
@@ -36,8 +36,25 @@
#include <X11/Xatom.h>
#include <X11/extensions/Xrender.h>
+#include <fstream>
-typedef enum {
+typedef enum
+{
+ XDGUserDirDesktop = 0,
+ XDGUserDirDownload,
+ XDGUserDirTemplates,
+ XDGUserDirPublicshare,
+ XDGUserDirDocuments,
+ XDGUserDirMusic,
+ XDGUserDirPictures,
+ XDGUserDirVideos
+} XDGUserDir;
+
+CompString getXDGUserDir (XDGUserDir userDir);
+
+
+typedef enum
+{
CurrentViewport = 0,
AllViewports,
Panels,
diff --git a/plugins/compiztoolbox/src/compiztoolbox.cpp b/plugins/compiztoolbox/src/compiztoolbox.cpp
index d12a523..41aa64e 100644
--- a/plugins/compiztoolbox/src/compiztoolbox.cpp
+++ b/plugins/compiztoolbox/src/compiztoolbox.cpp
@@ -27,6 +27,77 @@
#include <compiztoolbox/compiztoolbox.h>
+CompString
+getXDGUserDir (XDGUserDir userDir)
+{
+ std::ifstream userDirsFile;
+ CompString userDirsFilePath;
+ const char *userDirsPathSuffix = "/user-dirs.dirs";
+ const char *varNames[8] =
+ {
+ "XDG_DESKTOP_DIR",
+ "XDG_DOWNLOAD_DIR",
+ "XDG_TEMPLATES_DIR",
+ "XDG_PUBLICSHARE_DIR",
+ "XDG_DOCUMENTS_DIR",
+ "XDG_MUSIC_DIR",
+ "XDG_PICTURES_DIR",
+ "XDG_VIDEOS_DIR"
+ };
+ const char *varName = varNames[userDir];
+ size_t varLength = strlen (varName);
+
+ char *home = getenv ("HOME");
+ if (!(home && strlen (home)))
+ return "";
+
+ char *configHome = getenv ("XDG_CONFIG_HOME");
+ if (configHome && strlen (configHome))
+ {
+ userDirsFilePath = configHome;
+ userDirsFilePath += userDirsPathSuffix;
+ }
+ else
+ {
+ userDirsFilePath = home;
+ userDirsFilePath =
+ userDirsFilePath + "/.config" + userDirsPathSuffix;
+ }
+ userDirsFile.open (userDirsFilePath.c_str (), std::ifstream::in);
+ if (!userDirsFile.is_open ())
+ return "";
+
+ // The user-dirs file has lines like:
+ // XDG_DESKTOP_DIR="$HOME/Desktop"
+ // Read it line by line until the desired directory is found.
+ while (!userDirsFile.eof())
+ {
+ CompString line;
+ getline (userDirsFile, line);
+
+ size_t varPos = line.find (varName);
+ if (varPos != CompString::npos) // if found
+ {
+ userDirsFile.close ();
+
+ // Skip the =" part
+ size_t valueStartPos = varPos + varLength + 2;
+
+ // Ignore the " at the end
+ CompString value = line.substr (valueStartPos,
+ line.length () - valueStartPos - 1);
+
+ if (value.substr (0, 5) == "$HOME")
+ return CompString (home) + value.substr (5);
+ else if (value.substr (0, 7) == "${HOME}")
+ return CompString (home) + value.substr (7);
+ else
+ return value;
+ }
+ }
+ return "";
+}
+
void
BaseSwitchScreen::setSelectedWindowHint ()