OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/nix/xdg_util.h" | 5 #include "base/nix/xdg_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/environment.h" | 9 #include "base/environment.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 if (xdg_dir) { | 41 if (xdg_dir) { |
42 path = FilePath(xdg_dir); | 42 path = FilePath(xdg_dir); |
43 free(xdg_dir); | 43 free(xdg_dir); |
44 } else { | 44 } else { |
45 path = file_util::GetHomeDir().Append(fallback_dir); | 45 path = file_util::GetHomeDir().Append(fallback_dir); |
46 } | 46 } |
47 return path.StripTrailingSeparators(); | 47 return path.StripTrailingSeparators(); |
48 } | 48 } |
49 | 49 |
50 DesktopEnvironment GetDesktopEnvironment(Environment* env) { | 50 DesktopEnvironment GetDesktopEnvironment(Environment* env) { |
| 51 // XDG_CURRENT_DESKTOP is the newest standard circa 2012. |
| 52 std::string xdg_current_desktop; |
| 53 if (env->GetVar("XDG_CURRENT_DESKTOP", &xdg_current_desktop)) { |
| 54 // Not all desktop environments set this env var as of this writing. |
| 55 if (xdg_current_desktop == "Unity") |
| 56 return DESKTOP_ENVIRONMENT_UNITY; |
| 57 else if (xdg_current_desktop == "GNOME") |
| 58 return DESKTOP_ENVIRONMENT_GNOME; |
| 59 } |
| 60 |
| 61 // DESKTOP_SESSION was what everyone used in 2010. |
51 std::string desktop_session; | 62 std::string desktop_session; |
52 if (env->GetVar("DESKTOP_SESSION", &desktop_session)) { | 63 if (env->GetVar("DESKTOP_SESSION", &desktop_session)) { |
53 if (desktop_session == "gnome") { | 64 if (desktop_session == "gnome") { |
54 return DESKTOP_ENVIRONMENT_GNOME; | 65 return DESKTOP_ENVIRONMENT_GNOME; |
55 } else if (desktop_session == "kde4") { | 66 } else if (desktop_session == "kde4") { |
56 return DESKTOP_ENVIRONMENT_KDE4; | 67 return DESKTOP_ENVIRONMENT_KDE4; |
57 } else if (desktop_session == "kde") { | 68 } else if (desktop_session == "kde") { |
58 // This may mean KDE4 on newer systems, so we have to check. | 69 // This may mean KDE4 on newer systems, so we have to check. |
59 if (env->HasVar(kKDE4SessionEnvVar)) | 70 if (env->HasVar(kKDE4SessionEnvVar)) |
60 return DESKTOP_ENVIRONMENT_KDE4; | 71 return DESKTOP_ENVIRONMENT_KDE4; |
(...skipping 20 matching lines...) Expand all Loading... |
81 const char* GetDesktopEnvironmentName(DesktopEnvironment env) { | 92 const char* GetDesktopEnvironmentName(DesktopEnvironment env) { |
82 switch (env) { | 93 switch (env) { |
83 case DESKTOP_ENVIRONMENT_OTHER: | 94 case DESKTOP_ENVIRONMENT_OTHER: |
84 return NULL; | 95 return NULL; |
85 case DESKTOP_ENVIRONMENT_GNOME: | 96 case DESKTOP_ENVIRONMENT_GNOME: |
86 return "GNOME"; | 97 return "GNOME"; |
87 case DESKTOP_ENVIRONMENT_KDE3: | 98 case DESKTOP_ENVIRONMENT_KDE3: |
88 return "KDE3"; | 99 return "KDE3"; |
89 case DESKTOP_ENVIRONMENT_KDE4: | 100 case DESKTOP_ENVIRONMENT_KDE4: |
90 return "KDE4"; | 101 return "KDE4"; |
| 102 case DESKTOP_ENVIRONMENT_UNITY: |
| 103 return "UNITY"; |
91 case DESKTOP_ENVIRONMENT_XFCE: | 104 case DESKTOP_ENVIRONMENT_XFCE: |
92 return "XFCE"; | 105 return "XFCE"; |
93 } | 106 } |
94 return NULL; | 107 return NULL; |
95 } | 108 } |
96 | 109 |
97 const char* GetDesktopEnvironmentName(Environment* env) { | 110 const char* GetDesktopEnvironmentName(Environment* env) { |
98 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); | 111 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); |
99 } | 112 } |
100 | 113 |
101 } // namespace nix | 114 } // namespace nix |
102 } // namespace base | 115 } // namespace base |
OLD | NEW |