5b63e20e3004b9b1434cb30d7e02b46982fc2228
[AGL/meta-agl-devel.git] /
1 From 7f3f913ec5bea1d94c04f8a029db659c33e56dbf Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <mv0@users.noreply.github.com>
3 Date: Sun, 24 Jul 2022 21:15:54 +0300
4 Subject: [PATCH 1/3] Allow the embedder to run as a regular/normal application
5  (#71)
6
7 * shell: Do not issue always the ready request
8
9 Rather than sending the ready request always, just do it when we've
10 found at least a background type of surface.
11
12 This way we can have a flutter instance as a regular application but
13 also as a shell client.
14
15 This is a work-around for the time being, a much more suitable approach
16 would be to have a mechanism that tells us when the client has finished
17 loading or has it's first frame swapped (or something similar to that).
18
19 Note that we need at least a background surface so not finding one
20 assumes that we're a regular application (WINDOW_NORMAL).
21
22 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
23
24 * shell: Do not attempt always bind to agl-shell interface
25
26 This helps up running as a regular application in
27 situations where we already have a client bound to the agl-shell
28 interface.
29
30 We can't really accept more than one client to bind to the interface and
31 without a change in the protocol to avoid racy situations, it seems more
32 natural for the embedder to infer if it actually needs to do that.
33
34 When the protocol has been updated to include additional events to let
35 clients that they've lost the race, we can remove this change.
36
37 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
38
39 Co-authored-by: Marius Vlad <marius.vlad@collabora.com>
40 ---
41  shell/app.cc             | 13 +++++++++++--
42  shell/wayland/display.cc | 18 +++++++++++++++---
43  shell/wayland/display.h  |  8 +++++++-
44  shell/wayland/window.h   |  2 +-
45  4 files changed, 34 insertions(+), 7 deletions(-)
46
47 diff --git a/shell/app.cc b/shell/app.cc
48 index 03c33ff..3ca183b 100644
49 --- a/shell/app.cc
50 +++ b/shell/app.cc
51 @@ -25,8 +25,10 @@
52  
53  App::App(const std::vector<Configuration::Config>& configs)
54      : m_wayland_display(std::make_shared<Display>(!configs[0].disable_cursor,
55 -                                                  configs[0].cursor_theme)) {
56 +                                                  configs[0].cursor_theme,
57 +                                                  configs)) {
58    FML_DLOG(INFO) << "+App::App";
59 +  bool found_view_with_bg = false;
60  
61    size_t index = 0;
62    m_views.reserve(configs.size());
63 @@ -35,9 +37,16 @@ App::App(const std::vector<Configuration::Config>& configs)
64      view->Initialize();
65      m_views.emplace_back(std::move(view));
66      index++;
67 +
68 +    if (WaylandWindow::get_window_type(cfg.view.window_type) ==
69 +        WaylandWindow::WINDOW_BG)
70 +      found_view_with_bg = true;
71    }
72  
73 -  m_wayland_display->AglShellDoReady();
74 +  // check that if we had a BG type and issue a ready() request for it,
75 +  // otherwise we're going to assume that this is a NORMAL/REGULAR application.
76 +  if (found_view_with_bg)
77 +    m_wayland_display->AglShellDoReady();
78  
79    FML_DLOG(INFO) << "-App::App";
80  }
81 diff --git a/shell/wayland/display.cc b/shell/wayland/display.cc
82 index 06eba8c..5d78471 100644
83 --- a/shell/wayland/display.cc
84 +++ b/shell/wayland/display.cc
85 @@ -27,7 +27,9 @@
86  #include "constants.h"
87  #include "engine.h"
88  
89 -Display::Display(bool enable_cursor, std::string cursor_theme_name)
90 +Display::Display(bool enable_cursor,
91 +                 std::string cursor_theme_name,
92 +                 const std::vector<Configuration::Config>& configs)
93      : m_xkb_context(xkb_context_new(XKB_CONTEXT_NO_FLAGS)),
94        m_buffer_scale(1),
95        m_last_buffer_scale(m_buffer_scale),
96 @@ -35,6 +37,15 @@ Display::Display(bool enable_cursor, std::string cursor_theme_name)
97        m_cursor_theme_name(std::move(cursor_theme_name)) {
98    FML_DLOG(INFO) << "+ Display()";
99  
100 +  for (auto const& cfg : configs) {
101 +    // check if we actually need to bind to agl-shell
102 +    auto window_type = WaylandWindow::get_window_type(cfg.view.window_type);
103 +    if (window_type != WaylandWindow::WINDOW_NORMAL) {
104 +      m_bind_to_agl_shell = true;
105 +      break;
106 +    }
107 +  }
108 +
109    m_display = wl_display_connect(nullptr);
110    if (m_display == nullptr) {
111      FML_LOG(ERROR) << "Failed to connect to Wayland display. "
112 @@ -46,7 +57,7 @@ Display::Display(bool enable_cursor, std::string cursor_theme_name)
113    wl_registry_add_listener(m_registry, &registry_listener, this);
114    wl_display_dispatch(m_display);
115  
116 -  if (!m_agl_shell) {
117 +  if (!m_agl_shell && m_bind_to_agl_shell) {
118      FML_LOG(INFO) << "agl_shell extension not present";
119    }
120  
121 @@ -152,7 +163,8 @@ void Display::registry_handle_global(void* data,
122          wl_registry_bind(registry, name, &wl_seat_interface,
123                           std::min(static_cast<uint32_t>(5), version)));
124      wl_seat_add_listener(d->m_seat, &seat_listener, d);
125 -  } else if (strcmp(interface, agl_shell_interface.name) == 0) {
126 +  } else if (strcmp(interface, agl_shell_interface.name) == 0 &&
127 +             d->m_bind_to_agl_shell) {
128      d->m_agl_shell = static_cast<struct agl_shell*>(
129          wl_registry_bind(registry, name, &agl_shell_interface,
130                           std::min(static_cast<uint32_t>(1), version)));
131 diff --git a/shell/wayland/display.h b/shell/wayland/display.h
132 index af3d460..bf05b27 100644
133 --- a/shell/wayland/display.h
134 +++ b/shell/wayland/display.h
135 @@ -32,11 +32,15 @@
136  #include "static_plugins/text_input/text_input.h"
137  #include "xdg-shell-client-protocol.h"
138  
139 +#include "configuration/configuration.h"
140 +
141  class Engine;
142  
143  class Display {
144   public:
145 -  explicit Display(bool enable_cursor, std::string cursor_theme_name);
146 +  explicit Display(bool enable_cursor,
147 +                   std::string cursor_theme_name,
148 +                   const std::vector<Configuration::Config>& configs);
149  
150    ~Display();
151  
152 @@ -96,6 +100,8 @@ class Display {
153    struct wl_shm* m_shm{};
154    struct wl_surface* m_base_surface{};
155  
156 +  bool m_bind_to_agl_shell = false;
157 +
158    std::map<wl_surface*, Engine*> m_surface_engine_map;
159    wl_surface* m_active_surface{};
160    Engine* m_active_engine{};
161 diff --git a/shell/wayland/window.h b/shell/wayland/window.h
162 index c4fe5e6..4b5c726 100644
163 --- a/shell/wayland/window.h
164 +++ b/shell/wayland/window.h
165 @@ -79,6 +79,7 @@ class WaylandWindow {
166    wl_surface* GetBaseSurface() { return m_base_surface; }
167  
168    uint32_t m_fps_counter;
169 +  static window_type get_window_type(const std::string& type);
170  
171   private:
172    struct shm_buffer {
173 @@ -157,5 +158,4 @@ class WaylandWindow {
174  
175    static const struct wl_callback_listener frame_listener;
176  
177 -  static window_type get_window_type(const std::string& type);
178  };
179 -- 
180 2.35.3
181