Move ShouldUseGlobalMenuBar to x_window_utils

This commit is contained in:
Cheng Zhao 2015-08-05 13:16:03 +08:00
parent 58b1172025
commit adbb909b39
3 changed files with 39 additions and 39 deletions

View 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