]> khamidou — GitHub mirrors - electron.git/commitdiff
linux: Only use global menu bar under Unity.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 6 Aug 2014 15:34:16 +0000 (23:34 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 6 Aug 2014 15:34:16 +0000 (23:34 +0800)
Fixes atom/atom#3182.

atom/browser/native_window_views.cc

index 93ff0f3855c12ba4e0111fd8667d772f131c1b69..4153ae1a411a8b262e1c01d070df466ba86a8926 100644 (file)
@@ -39,6 +39,8 @@
 #if defined(USE_X11)
 #include "atom/browser/ui/views/global_menu_bar_x11.h"
 #include "atom/browser/ui/views/frameless_view.h"
+#include "base/environment.h"
+#include "base/nix/xdg_util.h"
 #include "chrome/browser/ui/libgtk2ui/unity_service.h"
 #include "ui/gfx/x/x11_types.h"
 #include "ui/views/window/native_frame_view.h"
@@ -59,6 +61,16 @@ const int kMenuBarHeight = 20;
 const int kMenuBarHeight = 25;
 #endif
 
+#if defined(USE_X11)
+bool ShouldUseGlobalMenuBar() {
+  // Some DE would pretend to be Unity but don't have global application menu,
+  // so we can not trust unity::IsRunning().
+  scoped_ptr<base::Environment> env(base::Environment::Create());
+  return unity::IsRunning() && (base::nix::GetDesktopEnvironment(env.get()) ==
+      base::nix::DESKTOP_ENVIRONMENT_UNITY);
+}
+#endif
+
 class NativeWindowClientView : public views::ClientView {
  public:
   NativeWindowClientView(views::Widget* widget,
@@ -355,7 +367,7 @@ void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
   RegisterAccelerators(menu_model);
 
 #if defined(USE_X11)
-  if (unity::IsRunning() && !global_menu_bar_)
+  if (!global_menu_bar_ && ShouldUseGlobalMenuBar())
     global_menu_bar_.reset(new GlobalMenuBarX11(this));
 
   // Use global application menu bar when possible.