global_menu_bar_registrar_x11.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_REGISTRAR_X11_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_REGISTRAR_X11_H_
  6. #include <gio/gio.h>
  7. #include <set>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/singleton.h"
  10. #include "ui/base/glib/scoped_gsignal.h"
  11. #include "ui/gfx/x/xproto.h"
  12. // Advertises our menu bars to Unity.
  13. //
  14. // GlobalMenuBarX11 is responsible for managing the DbusmenuServer for each
  15. // x11::Window. We need a separate object to own the dbus channel to
  16. // com.canonical.AppMenu.Registrar and to register/unregister the mapping
  17. // between a x11::Window and the DbusmenuServer instance we are offering.
  18. class GlobalMenuBarRegistrarX11 {
  19. public:
  20. static GlobalMenuBarRegistrarX11* GetInstance();
  21. void OnWindowMapped(x11::Window window);
  22. void OnWindowUnmapped(x11::Window window);
  23. private:
  24. friend struct base::DefaultSingletonTraits<GlobalMenuBarRegistrarX11>;
  25. GlobalMenuBarRegistrarX11();
  26. ~GlobalMenuBarRegistrarX11();
  27. // disable copy
  28. GlobalMenuBarRegistrarX11(const GlobalMenuBarRegistrarX11&) = delete;
  29. GlobalMenuBarRegistrarX11& operator=(const GlobalMenuBarRegistrarX11&) =
  30. delete;
  31. // Sends the actual message.
  32. void RegisterXWindow(x11::Window window);
  33. void UnregisterXWindow(x11::Window window);
  34. static void OnProxyCreated(GObject* source,
  35. GAsyncResult* result,
  36. gpointer user_data);
  37. void OnNameOwnerChanged(GDBusProxy* /* ignored */, GParamSpec* /* ignored */);
  38. void SetRegistrarProxy(GDBusProxy* proxy);
  39. raw_ptr<GDBusProxy> registrar_proxy_ = nullptr;
  40. // x11::Window which want to be registered, but haven't yet been because
  41. // we're waiting for the proxy to become available.
  42. std::set<x11::Window> live_windows_;
  43. ScopedGSignal signal_;
  44. };
  45. #endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_GLOBAL_MENU_BAR_REGISTRAR_X11_H_