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