/* * Copyright © Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef MIR_FRONTEND_WAYLAND_CONNECTOR_H_ #define MIR_FRONTEND_WAYLAND_CONNECTOR_H_ #include #include "wayland_wrapper.h" #include "input_trigger_registry.h" #include #include #include #include #include #include #include #include #include #include namespace mir { class Executor; class MainLoop; template class ObserverRegistrar; class DecorationStrategy; namespace compositor { class ScreenShooterFactory; } namespace input { class InputDeviceHub; class InputDeviceRegistry; class Seat; class CursorObserverMultiplexer; class CompositeEventFilter; class KeyboardObserver; } namespace graphics { class GraphicBufferAllocator; class DisplayConfigurationObserver; class RenderingPlatform; } namespace shell { class Shell; class AccessibilityManager; } namespace scene { class Clipboard; class IdleHub; class Surface; class TextInputHub; class SessionLock; class SessionCoordinator; } namespace time { class Clock; } namespace frontend { class OutputManager; class PointerInputDispatcher; class SessionAuthorizer; class SurfaceStack; class WlApplication; class WlCompositor; class WlDataDeviceManager; class WlSeat; class WlShm; class WlSubcompositor; class WlSurface; class WpViewporter; class LinuxDRMSyncobjManager; class DesktopFileManager; class SurfaceRegistry; class InputTriggerRegistry; class KeyboardStateTracker; class WaylandExtensions { public: /// The resources needed to init Wayland extensions struct Context { wl_display* display; std::shared_ptr wayland_executor; std::shared_ptr shell; std::shared_ptr session_authorizer; std::shared_ptr main_clipboard; std::shared_ptr primary_selection_clipboard; std::shared_ptr text_input_hub; std::shared_ptr idle_hub; WlSeat* seat; OutputManager* output_manager; std::shared_ptr surface_stack; std::shared_ptr input_device_registry; std::shared_ptr composite_event_filter; std::shared_ptr graphic_buffer_allocator; std::shared_ptr screen_shooter_factory; std::shared_ptr main_loop; std::shared_ptr desktop_file_manager; std::shared_ptr session_lock; std::shared_ptr decoration_strategy; std::shared_ptr session_coordinator; std::shared_ptr> keyboard_observer_registrar; std::shared_ptr token_authority; std::shared_ptr surface_registry; std::shared_ptr clock; std::shared_ptr cursor_observer_multiplexer; std::shared_ptr action_group_manager; std::shared_ptr input_trigger_registry; std::shared_ptr keyboard_state_tracker; }; WaylandExtensions() = default; virtual ~WaylandExtensions() = default; WaylandExtensions(WaylandExtensions const&) = delete; WaylandExtensions& operator=(WaylandExtensions const&) = delete; virtual void run_builders(wl_display* display, std::function&& work)> const& run_on_wayland_mainloop); void init(Context const& context); auto get_extension(std::string const& name) const -> std::shared_ptr; protected: void add_extension(std::string const name, std::shared_ptr implementation); virtual void custom_extensions(Context const& context); private: std::unordered_map> extension_protocols; }; class WaylandConnector : public Connector, public WaylandTools { public: using WaylandProtocolExtensionFilter = std::function const&, char const*)>; WaylandConnector( std::shared_ptr const& shell, std::shared_ptr const& clock, std::shared_ptr const& input_hub, std::shared_ptr const& seat, std::shared_ptr> const& keyboard_observer_registrar, std::shared_ptr const& input_device_registry, std::shared_ptr const& composite_event_filter, std::shared_ptr drag_icon_controller, std::shared_ptr pointer_input_dispatcher, std::shared_ptr const& allocator, std::shared_ptr const& session_authorizer, std::shared_ptr const& surface_stack, std::shared_ptr> const& display_config_registrar, std::shared_ptr const& main_clipboard, std::shared_ptr const& primary_selection_clipboard, std::shared_ptr const& text_input_hub, std::shared_ptr const& idle_hub, std::shared_ptr const& screen_shooter_factory, std::shared_ptr const& main_loop, bool arw_socket, std::unique_ptr extensions, WaylandProtocolExtensionFilter const& extension_filter, std::shared_ptr const& accessibility_manager, std::shared_ptr const& session_lock, std::shared_ptr const& decoration_strategy, std::shared_ptr const& session_coordinator, std::shared_ptr const& token_authority, std::vector> const& render_platforms, std::shared_ptr const& cursor_observer_multiplexer); ~WaylandConnector() override; void start() override; void stop() override; int client_socket_fd() const override; int client_socket_fd( std::function const& session)> const& connect_handler) const override; void run_on_wayland_display(std::function const& functor); /// Runs callback the first time a wl_surface with the given id is created, or immediately if one currently exists /// Callback is never called if a wl_surface with the id is never created void on_surface_created(wl_client* client, uint32_t id, std::function const& callback); auto socket_name() const -> std::optional override; auto get_extension(std::string const& name) const -> std::shared_ptr; private: struct ServerWrapper; void for_each_output_binding( wayland::Client* client, graphics::DisplayConfigurationOutputId output, std::function const& callback) override; bool wl_display_global_filter_func(wl_client const* client, wl_global const* global) const; static bool wl_display_global_filter_func_thunk(wl_client const* client, wl_global const* global, void* data); /* The wayland global filter is called during wl_global_remove * (libwayland needs to know if it should broadcast the removal) * * This means the filter needs to outlive any extension object * that provides a wl_global (which is all of them). * * For safety, just ensure it outlives the wl_display. libwayland * cannot *possibly* call it after then :) */ WaylandProtocolExtensionFilter const extension_filter; std::unique_ptr const display; std::unique_ptr server_wrapper; mir::Fd const pause_signal; std::unique_ptr compositor_global; std::unique_ptr subcompositor_global; std::unique_ptr seat_global; std::unique_ptr output_manager; std::shared_ptr desktop_file_manager; std::unique_ptr data_device_manager_global; std::unique_ptr shm_global; std::unique_ptr viewporter; std::unique_ptr drm_syncobj; std::shared_ptr const executor; std::shared_ptr const allocator; std::shared_ptr const shell; std::unique_ptr const extensions; std::shared_ptr session_lock_; std::thread dispatch_thread; wl_event_source* pause_source; std::string wayland_display; // Only accessed on event loop std::unordered_map const& session)>> mutable connect_handlers; }; } } #endif // MIR_FRONTEND_WAYLAND_CONNECTOR_H_