File: zcr_remote_shell_v2.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (311 lines) | stat: -rw-r--r-- 13,473 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <aura-shell-server-protocol.h>

#include "ash/wm/desks/desks_util.h"
#include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/zcr_remote_shell_impl.h"
#include "components/exo/wm_helper.h"

namespace exo::wayland {
namespace {

int RemoteSurfaceContainerV2(uint32_t container) {
  switch (container) {
    case ZCR_REMOTE_SHELL_V2_CONTAINER_DEFAULT:
      return ash::desks_util::GetActiveDeskContainerId();
    case ZCR_REMOTE_SHELL_V2_CONTAINER_OVERLAY:
      return ash::kShellWindowId_SystemModalContainer;
    default:
      DLOG(WARNING) << "Unsupported container: " << container;
      return ash::desks_util::GetActiveDeskContainerId();
  }
}

const struct WaylandRemoteOutputEventMapping remote_output_event_mapping_v2 = {
    zcr_remote_output_v2_send_identification_data,
    // deprecated but not removed due to lack of alternative for stable
    // identifier for wl_resource required on the ARC side.
    zcr_remote_output_v2_send_display_id,
    zcr_remote_output_v2_send_port,
    zcr_remote_output_v2_send_insets,
    zcr_remote_output_v2_send_stable_insets,
    zcr_remote_output_v2_send_systemui_behavior,
    ZCR_REMOTE_OUTPUT_V2_SYSTEMUI_BEHAVIOR_SINCE_VERSION,
    ZCR_REMOTE_OUTPUT_V2_STABLE_INSETS_SINCE_VERSION,
};

const WaylandRemoteShellEventMapping wayland_remote_shell_event_mapping_v2 = {
    zcr_remote_surface_v2_send_window_geometry_changed,
    zcr_remote_surface_v2_send_change_zoom_level,
    zcr_remote_surface_v2_send_state_type_changed,
    zcr_remote_surface_v2_send_bounds_changed_in_output,
    zcr_remote_surface_v2_send_bounds_changed,
    nullptr,  // moved to zaura-shell protocol
    zcr_remote_shell_v2_send_desktop_focus_state_changed,
    nullptr,  // event removed in v2
    zcr_remote_surface_v2_send_drag_finished,
    zcr_remote_surface_v2_send_drag_started,
    zcr_remote_shell_v2_send_layout_mode,
    zcr_remote_shell_v2_send_default_device_scale_factor,
    nullptr,  // event removed in v2
    ZCR_REMOTE_SURFACE_V2_BOUNDS_CHANGED_IN_OUTPUT_SINCE_VERSION,
    ZCR_REMOTE_SHELL_V2_DESKTOP_FOCUS_STATE_CHANGED_SINCE_VERSION,
    ZCR_REMOTE_SHELL_V2_LAYOUT_MODE_SINCE_VERSION,
    ZCR_REMOTE_SHELL_V2_DEFAULT_DEVICE_SCALE_FACTOR_SINCE_VERSION,
    1,
    1,
    1,
    /*has_bounds_change_reason_float=*/true,
};

const struct zcr_remote_surface_v2_interface remote_surface_implementation_v2 =
    {
        +[](wl_client* client, wl_resource* resource) {
          wl_resource_destroy(resource);
        },
        zcr_remote_shell::remote_surface_set_app_id,
        zcr_remote_shell::remote_surface_set_title,
        zcr_remote_shell::remote_surface_set_top_inset,
        zcr_remote_shell::remote_surface_maximize,
        zcr_remote_shell::remote_surface_minimize,
        zcr_remote_shell::remote_surface_restore,
        zcr_remote_shell::remote_surface_fullscreen,
        zcr_remote_shell::remote_surface_pin,
        zcr_remote_shell::remote_surface_unpin,
        zcr_remote_shell::remote_surface_set_system_modal,
        zcr_remote_shell::remote_surface_unset_system_modal,
        zcr_remote_shell::remote_surface_set_rectangular_surface_shadow,
        zcr_remote_shell::remote_surface_set_systemui_visibility,
        zcr_remote_shell::remote_surface_set_always_on_top,
        zcr_remote_shell::remote_surface_unset_always_on_top,
        zcr_remote_shell::remote_surface_set_orientation,
        zcr_remote_shell::remote_surface_start_move,
        zcr_remote_shell::remote_surface_set_can_maximize,
        zcr_remote_shell::remote_surface_unset_can_maximize,
        zcr_remote_shell::remote_surface_set_min_size,
        zcr_remote_shell::remote_surface_set_max_size,
        zcr_remote_shell::remote_surface_set_snapped_to_left,
        zcr_remote_shell::remote_surface_set_snapped_to_right,
        zcr_remote_shell::remote_surface_start_resize,
        zcr_remote_shell::remote_surface_set_frame,
        zcr_remote_shell::remote_surface_set_frame_buttons,
        zcr_remote_shell::remote_surface_set_extra_title,
        zcr_remote_shell::remote_surface_set_orientation_lock,
        zcr_remote_shell::remote_surface_pip,
        zcr_remote_shell::remote_surface_set_aspect_ratio,
        zcr_remote_shell::remote_surface_set_accessibility_id_DEPRECATED,
        zcr_remote_shell::remote_surface_set_pip_original_window,
        zcr_remote_shell::remote_surface_unset_pip_original_window,
        zcr_remote_shell::remote_surface_set_system_gesture_exclusion,
        zcr_remote_shell::remote_surface_set_resize_lock,
        zcr_remote_shell::remote_surface_unset_resize_lock,
        zcr_remote_shell::remote_surface_set_bounds_in_output,
        zcr_remote_shell::remote_surface_set_resize_lock_type,
        zcr_remote_shell::remote_surface_set_float,
        zcr_remote_shell::remote_surface_set_scale_factor,
        zcr_remote_shell::remote_surface_set_window_corner_radii,
        zcr_remote_shell::remote_surface_set_shadow_corner_radii
};

const struct zcr_notification_surface_v2_interface
    notification_surface_implementation_v2 = {
        +[](wl_client* client, wl_resource* resource) {
          wl_resource_destroy(resource);
        },
        zcr_remote_shell::notification_surface_set_app_id,
};

const struct zcr_input_method_surface_v2_interface
    input_method_surface_implementation_v2 = {
        +[](wl_client* client, wl_resource* resource) {
          wl_resource_destroy(resource);
        },
        zcr_remote_shell::input_method_surface_set_bounds_in_output,
};

const struct zcr_toast_surface_v2_interface toast_surface_implementation_v2 = {
    +[](wl_client* client, wl_resource* resource) {
      wl_resource_destroy(resource);
    },
    zcr_remote_shell::toast_surface_set_bounds_in_output,
    zcr_remote_shell::toast_surface_set_scale_factor,
};

const struct zcr_remote_output_v2_interface remote_output_implementation_v2 = {
    +[](wl_client* client, wl_resource* resource) {
      wl_resource_destroy(resource);
    },
};

void HandleRemoteSurfaceCloseCallbackV2(wl_resource* resource) {
  zcr_remote_surface_v2_send_close(resource);
  wl_client_flush(wl_resource_get_client(resource));
}

void remote_shell_get_remote_surface_v2(wl_client* client,
                                        wl_resource* resource,
                                        uint32_t id,
                                        wl_resource* surface,
                                        uint32_t container) {
  WaylandRemoteShell* shell = GetUserDataAs<WaylandRemoteShell>(resource);
  std::unique_ptr<ClientControlledShellSurface> shell_surface =
      shell->CreateShellSurface(GetUserDataAs<Surface>(surface),
                                RemoteSurfaceContainerV2(container));
  if (!shell_surface) {
    wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V2_ERROR_ROLE,
                           "surface has already been assigned a role");
    return;
  }

  wl_resource* remote_surface_resource =
      wl_resource_create(client, &zcr_remote_surface_v2_interface,
                         wl_resource_get_version(resource), id);

  shell_surface->SetSecurityDelegate(GetSecurityDelegate(client));

  shell_surface->set_delegate(
      shell->CreateShellSurfaceDelegate(remote_surface_resource));
  shell_surface->set_close_callback(
      base::BindRepeating(&HandleRemoteSurfaceCloseCallbackV2,
                          base::Unretained(remote_surface_resource)));
  shell_surface->set_surface_destroyed_callback(base::BindOnce(
      &wl_resource_destroy, base::Unretained(remote_surface_resource)));

  SetImplementation(remote_surface_resource, &remote_surface_implementation_v2,
                    std::move(shell_surface));
}

void remote_shell_get_notification_surface_v2(wl_client* client,
                                              wl_resource* resource,
                                              uint32_t id,
                                              wl_resource* surface,
                                              const char* notification_key) {
  if (GetUserDataAs<Surface>(surface)->HasSurfaceDelegate()) {
    wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V2_ERROR_ROLE,
                           "surface has already been assigned a role");
    return;
  }

  std::unique_ptr<NotificationSurface> notification_surface =
      GetUserDataAs<WaylandRemoteShell>(resource)->CreateNotificationSurface(
          GetUserDataAs<Surface>(surface), std::string(notification_key));
  if (!notification_surface) {
    wl_resource_post_error(resource,
                           ZCR_REMOTE_SHELL_V2_ERROR_INVALID_NOTIFICATION_KEY,
                           "invalid notification key");
    return;
  }

  wl_resource* notification_surface_resource =
      wl_resource_create(client, &zcr_notification_surface_v2_interface,
                         wl_resource_get_version(resource), id);
  SetImplementation(notification_surface_resource,
                    &notification_surface_implementation_v2,
                    std::move(notification_surface));
}

void remote_shell_get_input_method_surface_v2(wl_client* client,
                                              wl_resource* resource,
                                              uint32_t id,
                                              wl_resource* surface) {
  if (GetUserDataAs<Surface>(surface)->HasSurfaceDelegate()) {
    wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V2_ERROR_ROLE,
                           "surface has already been assigned a role");
    return;
  }

  std::unique_ptr<ClientControlledShellSurface> input_method_surface =
      GetUserDataAs<WaylandRemoteShell>(resource)->CreateInputMethodSurface(
          GetUserDataAs<Surface>(surface));
  if (!input_method_surface) {
    wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V2_ERROR_ROLE,
                           "Cannot create an IME surface");
    return;
  }

  wl_resource* input_method_surface_resource =
      wl_resource_create(client, &zcr_input_method_surface_v2_interface,
                         wl_resource_get_version(resource), id);
  SetImplementation(input_method_surface_resource,
                    &input_method_surface_implementation_v2,
                    std::move(input_method_surface));
}

void remote_shell_get_toast_surface_v2(wl_client* client,
                                       wl_resource* resource,
                                       uint32_t id,
                                       wl_resource* surface) {
  if (GetUserDataAs<Surface>(surface)->HasSurfaceDelegate()) {
    wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V2_ERROR_ROLE,
                           "surface has already been assigned a role");
    return;
  }

  std::unique_ptr<ClientControlledShellSurface> toast_surface =
      GetUserDataAs<WaylandRemoteShell>(resource)->CreateToastSurface(
          GetUserDataAs<Surface>(surface));
  if (!toast_surface) {
    wl_resource_post_error(resource, ZCR_REMOTE_SHELL_V2_ERROR_ROLE,
                           "Cannot create an toast surface");
    return;
  }

  wl_resource* toast_surface_resource =
      wl_resource_create(client, &zcr_toast_surface_v2_interface,
                         wl_resource_get_version(resource), id);
  SetImplementation(toast_surface_resource, &toast_surface_implementation_v2,
                    std::move(toast_surface));
}

void remote_shell_get_remote_output_v2(wl_client* client,
                                       wl_resource* resource,
                                       uint32_t id,
                                       wl_resource* output_resource) {
  WaylandDisplayHandler* display_handler =
      GetUserDataAs<WaylandDisplayHandler>(output_resource);

  wl_resource* remote_output_resource =
      wl_resource_create(client, &zcr_remote_output_v2_interface,
                         wl_resource_get_version(resource), id);

  auto remote_output = std::make_unique<WaylandRemoteOutput>(
      remote_output_resource, remote_output_event_mapping_v2, display_handler);

  SetImplementation(remote_output_resource, &remote_output_implementation_v2,
                    std::move(remote_output));
}

const struct zcr_remote_shell_v2_interface remote_shell_implementation_v2 = {
    +[](wl_client* client, wl_resource* resource) {
      // Nothing to do here.
    },
    remote_shell_get_remote_surface_v2,
    remote_shell_get_notification_surface_v2,
    remote_shell_get_input_method_surface_v2,
    remote_shell_get_toast_surface_v2,
    remote_shell_get_remote_output_v2};

}  // namespace

void bind_remote_shell_v2(wl_client* client,
                          void* data,
                          uint32_t version,
                          uint32_t id) {
  wl_resource* resource = wl_resource_create(
      client, &zcr_remote_shell_v2_interface,
      std::min<uint32_t>(version, zcr_remote_shell_v2_interface.version), id);

  auto* remote_shell_data = static_cast<WaylandRemoteShellData*>(data);
  SetImplementation(
      resource, &remote_shell_implementation_v2,
      std::make_unique<WaylandRemoteShell>(
          remote_shell_data->display, resource,
          base::BindRepeating(remote_shell_data->output_provider, client),
          wayland_remote_shell_event_mapping_v2,
          /*use_default_scale_cancellation_default=*/false));
}

}  // namespace exo::wayland