1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_NIX_XDG_UTIL_H_ 6 #define BASE_NIX_XDG_UTIL_H_ 7 8 // XDG refers to http://en.wikipedia.org/wiki/Freedesktop.org . 9 // This file contains utilities found across free desktop environments. 10 11 #include <vector> 12 13 #include "base/base_export.h" 14 15 namespace base { 16 17 class Environment; 18 class FilePath; 19 20 namespace nix { 21 22 enum DesktopEnvironment { 23 DESKTOP_ENVIRONMENT_OTHER = 0, 24 DESKTOP_ENVIRONMENT_CINNAMON = 1, 25 DESKTOP_ENVIRONMENT_DEEPIN = 2, 26 DESKTOP_ENVIRONMENT_GNOME = 3, 27 // KDE{3,4,5,6} are sufficiently different that we count 28 // them as different desktop environments here. 29 DESKTOP_ENVIRONMENT_KDE3 = 4, 30 DESKTOP_ENVIRONMENT_KDE4 = 5, 31 DESKTOP_ENVIRONMENT_KDE5 = 6, 32 DESKTOP_ENVIRONMENT_KDE6 = 12, 33 DESKTOP_ENVIRONMENT_PANTHEON = 7, 34 DESKTOP_ENVIRONMENT_UKUI = 8, 35 DESKTOP_ENVIRONMENT_UNITY = 9, 36 DESKTOP_ENVIRONMENT_XFCE = 10, 37 DESKTOP_ENVIRONMENT_LXQT = 11, 38 }; 39 40 // Values based on valid types indicated in: 41 // https://www.freedesktop.org/software/systemd/man/pam_systemd.html; though 42 // "Unset" and "Other" are provided by us to distinguish between the potentially 43 // valid "Unspecified" and other cases where we may not be able to find the 44 // value. 45 enum class SessionType { 46 kUnset = 0, 47 kOther = 1, 48 kUnspecified = 2, 49 kTty = 3, 50 kX11 = 4, 51 kWayland = 5, 52 kMir = 6, 53 }; 54 55 // The default XDG config directory name. 56 BASE_EXPORT extern const char kDotConfigDir[]; 57 58 // The XDG config directory environment variable. 59 BASE_EXPORT extern const char kXdgConfigHomeEnvVar[]; 60 61 // The XDG current desktop environment variable. 62 BASE_EXPORT extern const char kXdgCurrentDesktopEnvVar[]; 63 64 // The XDG session type environment variable. 65 BASE_EXPORT extern const char kXdgSessionTypeEnvVar[]; 66 67 // Utility function for getting XDG directories. 68 // |env_name| is the name of an environment variable that we want to use to get 69 // a directory path. |fallback_dir| is the directory relative to $HOME that we 70 // use if |env_name| cannot be found or is empty. |fallback_dir| may be NULL. 71 // Examples of |env_name| are XDG_CONFIG_HOME and XDG_DATA_HOME. 72 BASE_EXPORT FilePath GetXDGDirectory(Environment* env, const char* env_name, 73 const char* fallback_dir); 74 75 // Wrapper around xdg_user_dir_lookup() from src/base/third_party/xdg-user-dirs 76 // This looks up "well known" user directories like the desktop and music 77 // folder. Examples of |dir_name| are DESKTOP and MUSIC. 78 BASE_EXPORT FilePath GetXDGUserDirectory(const char* dir_name, 79 const char* fallback_dir); 80 81 // Get the path to write user-specific application data files to, as specified 82 // in the XDG Base Directory Specification: 83 // http://standards.freedesktop.org/basedir-spec/latest/ 84 BASE_EXPORT FilePath GetXDGDataWriteLocation(Environment* env); 85 86 // Get the list of paths to search for application data files, in order of 87 // preference, as specified in the XDG Base Directory Specification: 88 // http://standards.freedesktop.org/basedir-spec/latest/ 89 // Called on the FILE thread. 90 BASE_EXPORT std::vector<FilePath> GetXDGDataSearchLocations(Environment* env); 91 92 // Return an entry from the DesktopEnvironment enum with a best guess 93 // of which desktop environment we're using. We use this to know when 94 // to attempt to use preferences from the desktop environment -- 95 // proxy settings, password manager, etc. 96 BASE_EXPORT DesktopEnvironment GetDesktopEnvironment(Environment* env); 97 98 // Return a string representation of the given desktop environment. 99 // May return NULL in the case of DESKTOP_ENVIRONMENT_OTHER. 100 BASE_EXPORT const char* GetDesktopEnvironmentName(DesktopEnvironment env); 101 // Convenience wrapper that calls GetDesktopEnvironment() first. 102 BASE_EXPORT const char* GetDesktopEnvironmentName(Environment* env); 103 104 // Return an entry from the SessionType enum with a best guess 105 // of which session type we're using. 106 BASE_EXPORT SessionType GetSessionType(Environment& env); 107 108 } // namespace nix 109 } // namespace base 110 111 #endif // BASE_NIX_XDG_UTIL_H_ 112