Mir
wayland_extensions.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2018-2019 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 or 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef MIRAL_WAYLAND_EXTENSIONS_H
18 #define MIRAL_WAYLAND_EXTENSIONS_H
19 
20 #include "application.h"
21 
22 #include <functional>
23 #include <memory>
24 #include <string>
25 #include <optional>
26 #include <set>
27 
28 struct wl_display;
29 struct wl_client;
30 struct wl_resource;
31 
32 namespace mir { class Server; }
33 
34 namespace miral
35 {
36 class Window;
37 
47 {
48 public:
51 
52  void operator()(mir::Server& server) const;
53 
57 
62  auto all_supported() const -> std::set<std::string>;
63 
66  class Context
67  {
68  public:
69  virtual auto display() const -> wl_display* = 0;
70  virtual void run_on_wayland_mainloop(std::function<void()>&& work) const = 0;
71 
72  protected:
73  Context() = default;
74  virtual ~Context() = default;
75  Context(Context const&) = delete;
76  Context& operator=(Context const&) = delete;
77  };
78 
81  struct Builder
82  {
84  std::string name;
85 
91  std::function<std::shared_ptr<void>(Context const* context)> build;
92  };
93 
96  class EnableInfo
97  {
98  public:
100  auto app() const -> Application const&;
102  auto name() const -> const char*;
104  auto user_preference() const -> std::optional<bool>;
105 
106  private:
107  friend WaylandExtensions;
108  EnableInfo(Application const& app, const char* name, std::optional<bool> user_preference);
109  struct Self;
110  std::unique_ptr<Self> const self;
111  };
112 
114  using Filter = std::function<bool(Application const& app, char const* protocol)>;
115 
117  using EnableCallback = std::function<bool(EnableInfo const& info)>;
118 
123  [[deprecated("use conditionally_enable() instead")]]
124  void set_filter(Filter const& extension_filter);
125 
136  static char const* const zwlr_layer_shell_v1;
137 
140  static char const* const zxdg_output_manager_v1;
141 
146  static char const* const zwlr_foreign_toplevel_manager_v1;
147 
152  static char const* const zwp_virtual_keyboard_manager_v1;
153 
159  static char const* const zwp_input_method_manager_v2;
160 
164  static char const* const zwlr_screencopy_manager_v1;
165 
170  [[deprecated("use zwp_virtual_keyboard_manager_v1 instead")]]
171  static char const* const zwp_virtual_keyboard_v1;
172  [[deprecated("use zwp_input_method_manager_v2 instead")]]
173  static char const* const zwp_input_method_v2;
179  void add_extension(Builder const& builder);
180 
184 
188  static auto recommended() -> std::set<std::string>;
189 
194  static auto supported() -> std::set<std::string>;
195 
200  auto enable(std::string name) -> WaylandExtensions&;
201 
206  auto disable(std::string name) -> WaylandExtensions&;
207 
212  auto conditionally_enable(std::string name, EnableCallback const& callback) -> WaylandExtensions&;
213 
214 private:
215  struct Self;
216  std::shared_ptr<Self> self;
217 };
218 
222 auto application_for(wl_client* client) -> Application;
223 
227 auto application_for(wl_resource* resource) -> Application;
228 
236 auto window_for(wl_resource* surface) -> Window;
237 }
238 
239 #endif //MIRAL_WAYLAND_EXTENSIONS_H
Context information useful for implementing Wayland extensions.
Definition: wayland_extensions.h:67
virtual auto display() const -> wl_display *=0
Information that can be used to determine if to enable a conditionally enabled extension.
Definition: wayland_extensions.h:97
auto app() const -> Application const &
The application that is being given access to this extension.
auto name() const -> const char *
The name of the extension/global, always the same as given to conditionally_enable()
auto user_preference() const -> std::optional< bool >
If the user has enabled or disabled this extension one of the wayland extension Mir options.
Enable configuration of the Wayland extensions enabled at runtime.
Definition: wayland_extensions.h:47
static char const *const zwlr_layer_shell_v1
Supported wayland extensions that are not enabled by default.
Definition: wayland_extensions.h:136
std::function< bool(EnableInfo const &info)> EnableCallback
Definition: wayland_extensions.h:117
static auto supported() -> std::set< std::string >
The set of Wayland extensions that core Mir supports. Does not include bespoke extensions A superset ...
void add_extension_disabled_by_default(Builder const &builder)
Add a bespoke Wayland extension both to "supported" but not "enabled by default".
static char const *const zwp_virtual_keyboard_manager_v1
Allows clients to act as a virtual keyboard, useful for on-screen keyboards. Clients are not required...
Definition: wayland_extensions.h:152
static char const *const zwp_input_method_manager_v2
Allows clients (such as on-screen keyboards) to intercept physical key events and act as a source of ...
Definition: wayland_extensions.h:159
void add_extension(Builder const &builder)
Add a bespoke Wayland extension both to "supported" and "enabled by default".
static auto recommended() -> std::set< std::string >
The set of Wayland extensions that Mir recommends. Also the set that is enabled by default upon const...
static char const *const zwp_input_method_v2
Definition: wayland_extensions.h:173
static char const *const zwp_virtual_keyboard_v1
Definition: wayland_extensions.h:171
auto operator=(WaylandExtensions const &) -> WaylandExtensions &
WaylandExtensions(WaylandExtensions const &)
static char const *const zxdg_output_manager_v1
Allows clients to retrieve additional information about outputs.
Definition: wayland_extensions.h:140
void operator()(mir::Server &server) const
auto enable(std::string name) -> WaylandExtensions &
Enable a Wayland extension by default. The user can still disable it with the drop-wayland-extensions...
std::function< bool(Application const &app, char const *protocol)> Filter
Definition: wayland_extensions.h:114
auto disable(std::string name) -> WaylandExtensions &
Disable a Wayland extension by default. The user can still enable it with the add-wayland-extensions ...
auto all_supported() const -> std::set< std::string >
All Wayland extensions supported. This includes both the supported() provided by Mir and any extensio...
static char const *const zwlr_foreign_toplevel_manager_v1
Allows a client to get information and gain control over all toplevels of all clients Useful for task...
Definition: wayland_extensions.h:146
static char const *const zwlr_screencopy_manager_v1
Allows clients to take screenshots and record the screen. Only enable for clients that are trusted to...
Definition: wayland_extensions.h:164
void set_filter(Filter const &extension_filter)
Set an extension filter callback to control the extensions available to specific clients....
auto conditionally_enable(std::string name, EnableCallback const &callback) -> WaylandExtensions &
Enable a Wayland extension only when the callback returns true. The callback can use info....
WaylandExtensions()
Default to enabling the extensions recommended by Mir.
Handle class to manage a Mir surface. It may be null (e.g. default initialized)
Definition: window.h:36
Definition: splash_session.h:22
Mir Abstraction Layer.
Definition: floating_window_manager.h:29
std::shared_ptr< mir::scene::Session > Application
Definition: application.h:32
auto application_for(wl_client *client) -> Application
Get the MirAL application for a wl_client.
auto window_for(wl_resource *surface) -> Window
Get the MirAL Window for a Wayland Surface, XdgSurface, etc. Note that there may not be a correspondi...
A Builder creates and registers an extension protocol.
Definition: wayland_extensions.h:82
std::function< std::shared_ptr< void >Context const *context)> build
Functor that creates and registers an extension protocol.
Definition: wayland_extensions.h:91
std::string name
Name of the protocol extension's Wayland global.
Definition: wayland_extensions.h:84

Copyright © 2012-2022 Canonical Ltd.
Generated on śro, 1 cze 2022, 16:52:55 UTC
This documentation is licensed under the GPL version 2 or 3.