Move ShouldUseGlobalMenuBar to x_window_utils
authorCheng Zhao <zcbenz@gmail.com>
Wed, 5 Aug 2015 05:16:03 +0000 (13:16 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 5 Aug 2015 05:16:03 +0000 (13:16 +0800)
atom/browser/native_window_views.cc
atom/browser/ui/x/x_window_utils.cc
atom/browser/ui/x/x_window_utils.h

index cb28f2d..6386711 100644 (file)
@@ -43,9 +43,6 @@
 #include "base/nix/xdg_util.h"
 #include "base/strings/string_util.h"
 #include "chrome/browser/ui/libgtk2ui/unity_service.h"
-#include "dbus/bus.h"
-#include "dbus/object_proxy.h"
-#include "dbus/message.h"
 #include "ui/base/x/x11_util.h"
 #include "ui/gfx/x/x11_types.h"
 #include "ui/views/window/native_frame_view.h"
@@ -70,42 +67,6 @@ const int kMenuBarHeight = 20;
 const int kMenuBarHeight = 25;
 #endif
 
-#if defined(USE_X11)
-// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available.
-bool ShouldUseGlobalMenuBar() {
-  dbus::Bus::Options options;
-  scoped_refptr<dbus::Bus> bus(new dbus::Bus(options));
-
-  dbus::ObjectProxy* object_proxy =
-      bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS));
-  dbus::MethodCall method_call(DBUS_INTERFACE_DBUS, "ListNames");
-  scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
-      &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
-  if (!response) {
-    bus->ShutdownAndBlock();
-    return false;
-  }
-
-  dbus::MessageReader reader(response.get());
-  dbus::MessageReader array_reader(NULL);
-  if (!reader.PopArray(&array_reader)) {
-    bus->ShutdownAndBlock();
-    return false;
-  }
-  while (array_reader.HasMoreData()) {
-    std::string name;
-    if (array_reader.PopString(&name) &&
-        name == "com.canonical.AppMenu.Registrar") {
-      bus->ShutdownAndBlock();
-      return true;
-    }
-  }
-
-  bus->ShutdownAndBlock();
-  return false;
-}
-#endif
-
 bool IsAltKey(const content::NativeWebKeyboardEvent& event) {
 #if defined(USE_X11)
   // 164 and 165 represent VK_LALT and VK_RALT.
index eaef547..a15affb 100644 (file)
@@ -7,6 +7,9 @@
 #include <X11/Xatom.h>
 
 #include "base/strings/string_util.h"
+#include "dbus/bus.h"
+#include "dbus/object_proxy.h"
+#include "dbus/message.h"
 #include "ui/base/x/x11_util.h"
 
 namespace atom {
@@ -46,4 +49,37 @@ void SetWindowType(::Window xwindow, const std::string& type) {
                   reinterpret_cast<unsigned char*>(&window_type), 1);
 }
 
+bool ShouldUseGlobalMenuBar() {
+  dbus::Bus::Options options;
+  scoped_refptr<dbus::Bus> bus(new dbus::Bus(options));
+
+  dbus::ObjectProxy* object_proxy =
+      bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS));
+  dbus::MethodCall method_call(DBUS_INTERFACE_DBUS, "ListNames");
+  scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
+      &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
+  if (!response) {
+    bus->ShutdownAndBlock();
+    return false;
+  }
+
+  dbus::MessageReader reader(response.get());
+  dbus::MessageReader array_reader(NULL);
+  if (!reader.PopArray(&array_reader)) {
+    bus->ShutdownAndBlock();
+    return false;
+  }
+  while (array_reader.HasMoreData()) {
+    std::string name;
+    if (array_reader.PopString(&name) &&
+        name == "com.canonical.AppMenu.Registrar") {
+      bus->ShutdownAndBlock();
+      return true;
+    }
+  }
+
+  bus->ShutdownAndBlock();
+  return false;
+}
+
 }  // namespace atom
index ccf56d1..16f3dda 100644 (file)
@@ -22,6 +22,9 @@ void SetWMSpecState(::Window xwindow, bool enabled, ::Atom state);
 // Sets the _NET_WM_WINDOW_TYPE of window.
 void SetWindowType(::Window xwindow, const std::string& type);
 
+// Returns true if the bus name "com.canonical.AppMenu.Registrar" is available.
+bool ShouldUseGlobalMenuBar();
+
 }  // namespace atom
 
 #endif  // ATOM_BROWSER_UI_X_X_WINDOW_UTILS_H_