x11_workspace_handler.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 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 UI_BASE_X_X11_WORKSPACE_HANDLER_H_
  5. #define UI_BASE_X_X11_WORKSPACE_HANDLER_H_
  6. #include <memory>
  7. #include "base/component_export.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "ui/gfx/x/connection.h"
  11. #include "ui/gfx/x/event.h"
  12. #include "ui/gfx/x/xproto.h"
  13. namespace x11 {
  14. class XScopedEventSelector;
  15. }
  16. namespace ui {
  17. // Listens for global workspace changes and notifies observers.
  18. class COMPONENT_EXPORT(UI_BASE_X) X11WorkspaceHandler
  19. : public x11::EventObserver {
  20. public:
  21. class Delegate {
  22. public:
  23. // Called when the workspace ID changes to|new_workspace|.
  24. virtual void OnCurrentWorkspaceChanged(
  25. const std::string& new_workspace) = 0;
  26. protected:
  27. virtual ~Delegate() = default;
  28. };
  29. explicit X11WorkspaceHandler(Delegate* delegate);
  30. ~X11WorkspaceHandler() override;
  31. X11WorkspaceHandler(const X11WorkspaceHandler&) = delete;
  32. X11WorkspaceHandler& operator=(const X11WorkspaceHandler&) = delete;
  33. // Gets the current workspace ID.
  34. std::string GetCurrentWorkspace();
  35. private:
  36. // x11::EventObserver
  37. void OnEvent(const x11::Event& event) override;
  38. void OnWorkspaceResponse(x11::GetPropertyResponse response);
  39. // The native root window.
  40. x11::Window x_root_window_;
  41. // Events selected on x_root_window_.
  42. std::unique_ptr<x11::XScopedEventSelector> x_root_window_events_;
  43. std::string workspace_;
  44. const raw_ptr<Delegate> delegate_;
  45. base::WeakPtrFactory<X11WorkspaceHandler> weak_factory_{this};
  46. };
  47. } // namespace ui
  48. #endif // UI_BASE_X_X11_WORKSPACE_HANDLER_H_