zcr_remote_shell_impl.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. // Copyright 2021 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 COMPONENTS_EXO_WAYLAND_ZCR_REMOTE_SHELL_IMPL_H_
  5. #define COMPONENTS_EXO_WAYLAND_ZCR_REMOTE_SHELL_IMPL_H_
  6. #include <remote-shell-unstable-v1-server-protocol.h>
  7. #include <remote-shell-unstable-v2-server-protocol.h>
  8. #include "ash/wm/window_state.h"
  9. #include "components/exo/client_controlled_shell_surface.h"
  10. #include "components/exo/input_method_surface.h"
  11. #include "components/exo/notification_surface.h"
  12. #include "components/exo/seat.h"
  13. #include "components/exo/seat_observer.h"
  14. #include "components/exo/surface.h"
  15. #include "components/exo/toast_surface.h"
  16. #include "components/exo/wayland/wayland_display_observer.h"
  17. #include "components/exo/wayland/zcr_remote_shell.h"
  18. #include "components/exo/wayland/zcr_remote_shell_event_mapping.h"
  19. namespace exo {
  20. namespace wayland {
  21. using chromeos::WindowStateType;
  22. class WaylandRemoteOutput : public WaylandDisplayObserver {
  23. public:
  24. WaylandRemoteOutput(wl_resource* resource,
  25. WaylandRemoteOutputEventMapping event_mapping,
  26. WaylandDisplayHandler* display_handler);
  27. WaylandRemoteOutput(const WaylandRemoteOutput&) = delete;
  28. WaylandRemoteOutput& operator=(const WaylandRemoteOutput&) = delete;
  29. ~WaylandRemoteOutput() override;
  30. // Overridden from WaylandDisplayObserver:
  31. bool SendDisplayMetrics(const display::Display& display,
  32. uint32_t changed_metrics) override;
  33. void OnOutputDestroyed() override;
  34. private:
  35. wl_resource* const resource_;
  36. bool initial_config_sent_ = false;
  37. WaylandRemoteOutputEventMapping const event_mapping_;
  38. WaylandDisplayHandler* display_handler_;
  39. };
  40. // Implements remote shell interface and monitors workspace state needed
  41. // for the remote shell interface.
  42. class WaylandRemoteShell : public ash::TabletModeObserver,
  43. public display::DisplayObserver,
  44. public SeatObserver {
  45. public:
  46. using OutputResourceProvider = base::RepeatingCallback<wl_resource*(int64_t)>;
  47. WaylandRemoteShell(Display* display,
  48. wl_resource* remote_shell_resource,
  49. OutputResourceProvider output_provider,
  50. WaylandRemoteShellEventMapping event_mapping,
  51. bool use_default_scale_cancellation_default);
  52. WaylandRemoteShell(const WaylandRemoteShell&) = delete;
  53. WaylandRemoteShell& operator=(const WaylandRemoteShell&) = delete;
  54. ~WaylandRemoteShell() override;
  55. std::unique_ptr<ClientControlledShellSurface> CreateShellSurface(
  56. Surface* surface,
  57. int container,
  58. double default_device_scale_factor);
  59. std::unique_ptr<ClientControlledShellSurface::Delegate>
  60. CreateShellSurfaceDelegate(wl_resource* resource);
  61. std::unique_ptr<NotificationSurface> CreateNotificationSurface(
  62. Surface* surface,
  63. const std::string& notification_key);
  64. std::unique_ptr<InputMethodSurface> CreateInputMethodSurface(
  65. Surface* surface,
  66. double default_device_scale_factor);
  67. std::unique_ptr<ToastSurface> CreateToastSurface(
  68. Surface* surface,
  69. double default_device_scale_factor);
  70. void SetUseDefaultScaleCancellation(bool use_default_scale);
  71. void OnRemoteSurfaceDestroyed(wl_resource* resource);
  72. // Overridden from display::DisplayObserver:
  73. void OnWillProcessDisplayChanges() override;
  74. void OnDidProcessDisplayChanges() override;
  75. void OnDisplayAdded(const display::Display& new_display) override;
  76. void OnDisplayRemoved(const display::Display& old_display) override;
  77. void OnDisplayTabletStateChanged(display::TabletState state) override;
  78. void OnDisplayMetricsChanged(const display::Display& display,
  79. uint32_t changed_metrics) override;
  80. // Overridden from ash::TabletModeObserver:
  81. void OnTabletModeStarted() override;
  82. void OnTabletModeEnding() override;
  83. void OnTabletModeEnded() override;
  84. // Overridden from SeatObserver:
  85. void OnSurfaceFocused(Surface* gained_focus,
  86. Surface* lost_focus,
  87. bool has_focused_surface) override;
  88. WaylandRemoteShellEventMapping const event_mapping_;
  89. private:
  90. friend class WaylandRemoteShellTest;
  91. void ScheduleSendDisplayMetrics(int delay_ms);
  92. // Returns the transform that a display's output is currently adjusted for.
  93. wl_output_transform DisplayTransform(display::Display::Rotation rotation);
  94. void SendDisplayMetrics();
  95. void FocusedSurfaceChanged(Surface* gained_active_surface,
  96. Surface* lost_active_surface,
  97. bool has_focused_client);
  98. void OnRemoteSurfaceBoundsChanged(wl_resource* resource,
  99. WindowStateType current_state,
  100. WindowStateType requested_state,
  101. int64_t display_id,
  102. const gfx::Rect& bounds_in_display,
  103. bool resize,
  104. int bounds_change);
  105. void SendBoundsChanged(wl_resource* resource,
  106. int64_t display_id,
  107. const gfx::Rect& bounds_in_display,
  108. zcr_remote_surface_v1_bounds_change_reason reason);
  109. void OnRemoteSurfaceStateChanged(wl_resource* resource,
  110. WindowStateType old_state_type,
  111. WindowStateType new_state_type);
  112. void OnRemoteSurfaceChangeZoomLevel(wl_resource* resource, ZoomChange change);
  113. void OnRemoteSurfaceGeometryChanged(wl_resource* resource,
  114. const gfx::Rect& geometry);
  115. struct BoundsChangeData {
  116. int64_t display_id;
  117. gfx::Rect bounds_in_display;
  118. zcr_remote_surface_v1_bounds_change_reason reason;
  119. BoundsChangeData(int64_t display_id,
  120. const gfx::Rect& bounds,
  121. zcr_remote_surface_v1_bounds_change_reason reason)
  122. : display_id(display_id), bounds_in_display(bounds), reason(reason) {}
  123. };
  124. // The exo display instance. Not owned.
  125. Display* const display_;
  126. // The remote shell resource associated with observer.
  127. wl_resource* const remote_shell_resource_;
  128. // Callback to get the wl_output resource for a given display_id.
  129. OutputResourceProvider const output_provider_;
  130. // When true, the compositor should use the default_device_scale_factor to
  131. // undo the scaling on the client buffers. When false, the compositor should
  132. // use the device_scale_factor for the display for this scaling cancellation.
  133. // in v2 this is always false.
  134. bool use_default_scale_cancellation_;
  135. bool in_display_update_;
  136. bool needs_send_display_metrics_ = true;
  137. int layout_mode_ = ZCR_REMOTE_SHELL_V1_LAYOUT_MODE_WINDOWED;
  138. base::flat_map<wl_resource*, BoundsChangeData> pending_bounds_changes_;
  139. bool last_has_focused_client_ = false;
  140. display::ScopedDisplayObserver display_observer_{this};
  141. Seat* const seat_;
  142. base::WeakPtrFactory<WaylandRemoteShell> weak_ptr_factory_{this};
  143. friend class WaylandRemoteSurfaceDelegate;
  144. };
  145. class WaylandRemoteSurfaceDelegate
  146. : public ClientControlledShellSurface::Delegate {
  147. public:
  148. WaylandRemoteSurfaceDelegate(base::WeakPtr<WaylandRemoteShell> shell,
  149. wl_resource* resource,
  150. WaylandRemoteShellEventMapping event_mapping);
  151. ~WaylandRemoteSurfaceDelegate() override;
  152. WaylandRemoteSurfaceDelegate(const WaylandRemoteSurfaceDelegate&) = delete;
  153. WaylandRemoteSurfaceDelegate& operator=(const WaylandRemoteSurfaceDelegate&) =
  154. delete;
  155. private:
  156. // ClientControlledShellSurfaceDelegate:
  157. void OnGeometryChanged(const gfx::Rect& geometry) override;
  158. void OnStateChanged(chromeos::WindowStateType old_state_type,
  159. chromeos::WindowStateType new_state_type) override;
  160. void OnBoundsChanged(chromeos::WindowStateType current_state,
  161. chromeos::WindowStateType requested_state,
  162. int64_t display_id,
  163. const gfx::Rect& bounds_in_display,
  164. bool is_resize,
  165. int bounds_change) override;
  166. void OnDragStarted(int component) override;
  167. void OnDragFinished(int x, int y, bool canceled) override;
  168. void OnZoomLevelChanged(ZoomChange zoom_change) override;
  169. base::WeakPtr<WaylandRemoteShell> shell_;
  170. wl_resource* resource_;
  171. WaylandRemoteShellEventMapping const event_mapping_;
  172. };
  173. namespace zcr_remote_shell {
  174. double GetDefaultDeviceScaleFactor();
  175. gfx::Rect ScaleBoundsToPixelSnappedToParent(
  176. const gfx::Size& parent_size_in_pixel,
  177. const gfx::Size& parent_size,
  178. float device_scale_factor,
  179. const gfx::Rect& child_bounds);
  180. void remote_surface_destroy(wl_client* client, wl_resource* resource);
  181. void remote_surface_set_app_id(wl_client* client,
  182. wl_resource* resource,
  183. const char* app_id);
  184. void remote_surface_set_window_geometry(wl_client* client,
  185. wl_resource* resource,
  186. int32_t x,
  187. int32_t y,
  188. int32_t width,
  189. int32_t height);
  190. void remote_surface_set_orientation(wl_client* client,
  191. wl_resource* resource,
  192. int32_t orientation);
  193. void remote_surface_set_title(wl_client* client,
  194. wl_resource* resource,
  195. const char* title);
  196. void remote_surface_set_top_inset(wl_client* client,
  197. wl_resource* resource,
  198. int32_t height);
  199. void remote_surface_maximize(wl_client* client, wl_resource* resource);
  200. void remote_surface_minimize(wl_client* client, wl_resource* resource);
  201. void remote_surface_restore(wl_client* client, wl_resource* resource);
  202. void remote_surface_fullscreen(wl_client* client, wl_resource* resource);
  203. void remote_surface_pin(wl_client* client,
  204. wl_resource* resource,
  205. int32_t trusted);
  206. void remote_surface_unpin(wl_client* client, wl_resource* resource);
  207. void remote_surface_set_system_modal(wl_client* client, wl_resource* resource);
  208. void remote_surface_unset_system_modal(wl_client* client,
  209. wl_resource* resource);
  210. void remote_surface_set_rectangular_surface_shadow(wl_client* client,
  211. wl_resource* resource,
  212. int32_t x,
  213. int32_t y,
  214. int32_t width,
  215. int32_t height);
  216. void remote_surface_set_systemui_visibility(wl_client* client,
  217. wl_resource* resource,
  218. uint32_t visibility);
  219. void remote_surface_set_always_on_top(wl_client* client, wl_resource* resource);
  220. void remote_surface_unset_always_on_top(wl_client* client,
  221. wl_resource* resource);
  222. void remote_surface_start_move(wl_client* client,
  223. wl_resource* resource,
  224. int32_t x,
  225. int32_t y);
  226. void remote_surface_set_can_maximize(wl_client* client, wl_resource* resource);
  227. void remote_surface_unset_can_maximize(wl_client* client,
  228. wl_resource* resource);
  229. void remote_surface_set_min_size(wl_client* client,
  230. wl_resource* resource,
  231. int32_t width,
  232. int32_t height);
  233. void remote_surface_set_max_size(wl_client* client,
  234. wl_resource* resource,
  235. int32_t width,
  236. int32_t height);
  237. void remote_surface_set_aspect_ratio(wl_client* client,
  238. wl_resource* resource,
  239. int32_t aspect_ratio_width,
  240. int32_t aspect_ratio_height);
  241. void remote_surface_set_snapped_to_left(wl_client* client,
  242. wl_resource* resource);
  243. void remote_surface_set_snapped_to_right(wl_client* client,
  244. wl_resource* resource);
  245. void remote_surface_start_resize(wl_client* client,
  246. wl_resource* resource,
  247. uint32_t direction,
  248. int32_t x,
  249. int32_t y);
  250. void remote_surface_set_frame(wl_client* client,
  251. wl_resource* resource,
  252. uint32_t type);
  253. void remote_surface_set_frame_buttons(wl_client* client,
  254. wl_resource* resource,
  255. uint32_t visible_button_mask,
  256. uint32_t enabled_button_mask);
  257. void remote_surface_set_extra_title(wl_client* client,
  258. wl_resource* resource,
  259. const char* extra_title);
  260. void remote_surface_set_orientation_lock(wl_client* client,
  261. wl_resource* resource,
  262. uint32_t orientation_lock);
  263. void remote_surface_pip(wl_client* client, wl_resource* resource);
  264. void remote_surface_set_bounds(wl_client* client,
  265. wl_resource* resource,
  266. uint32_t display_id_hi,
  267. uint32_t display_id_lo,
  268. int32_t x,
  269. int32_t y,
  270. int32_t width,
  271. int32_t height);
  272. void remote_surface_set_accessibility_id(wl_client* client,
  273. wl_resource* resource,
  274. int32_t accessibility_id);
  275. void remote_surface_set_pip_original_window(wl_client* client,
  276. wl_resource* resource);
  277. void remote_surface_unset_pip_original_window(wl_client* client,
  278. wl_resource* resource);
  279. void remote_surface_set_system_gesture_exclusion(wl_client* client,
  280. wl_resource* resource,
  281. wl_resource* region_resource);
  282. void remote_surface_set_resize_lock(wl_client* client, wl_resource* resource);
  283. void remote_surface_unset_resize_lock(wl_client* client, wl_resource* resource);
  284. void remote_surface_set_bounds_in_output(wl_client* client,
  285. wl_resource* resource,
  286. wl_resource* output_resource,
  287. int32_t x,
  288. int32_t y,
  289. int32_t width,
  290. int32_t height);
  291. void remote_surface_set_resize_lock_type(wl_client* client,
  292. wl_resource* resource,
  293. uint32_t mode);
  294. void remote_surface_block_ime(wl_client* client, wl_resource* resource);
  295. void remote_surface_unblock_ime(wl_client* client, wl_resource* resource);
  296. void remote_surface_set_window_type(wl_client* client,
  297. wl_resource* resource,
  298. uint32_t type);
  299. void remote_surface_set_scale(wl_client* client,
  300. wl_resource* resource,
  301. wl_fixed_t scale);
  302. void remote_surface_activate(wl_client* client,
  303. wl_resource* resource,
  304. uint32_t serial);
  305. void remote_surface_unfullscreen(wl_client* client, wl_resource* resource);
  306. void remote_surface_fullscreen(wl_client* client, wl_resource* resource);
  307. void remote_surface_ack_configure_DEPRECATED(wl_client* client,
  308. wl_resource* resource,
  309. uint32_t serial);
  310. void remote_surface_move_DEPRECATED(wl_client* client, wl_resource* resource);
  311. void remote_surface_resize_DEPRECATED(wl_client* client, wl_resource* resource);
  312. void remote_surface_set_resize_outset_DEPRECATED(wl_client* client,
  313. wl_resource* resource,
  314. int32_t outset);
  315. void remote_surface_set_rectangular_shadow_DEPRECATED(wl_client* client,
  316. wl_resource* resource,
  317. int32_t x,
  318. int32_t y,
  319. int32_t width,
  320. int32_t height);
  321. void remote_surface_set_rectangular_shadow_background_opacity_DEPRECATED(
  322. wl_client* client,
  323. wl_resource* resource,
  324. wl_fixed_t opacity);
  325. ////////////////////////////////////////////////////////////////////////////////
  326. // notification_surface_interface:
  327. void notification_surface_set_app_id(wl_client* client,
  328. wl_resource* resource,
  329. const char* app_id);
  330. ////////////////////////////////////////////////////////////////////////////////
  331. // input_method_surface_interface:
  332. void input_method_surface_set_bounds_in_output(wl_client* client,
  333. wl_resource* resource,
  334. wl_resource* output_resource,
  335. int32_t x,
  336. int32_t y,
  337. int32_t width,
  338. int32_t height);
  339. void input_method_surface_set_bounds(wl_client* client,
  340. wl_resource* resource,
  341. uint32_t display_id_hi,
  342. uint32_t display_id_lo,
  343. int32_t x,
  344. int32_t y,
  345. int32_t width,
  346. int32_t height);
  347. ////////////////////////////////////////////////////////////////////////////////
  348. // toast_surface_interface:
  349. void toast_surface_set_bounds_in_output(wl_client* client,
  350. wl_resource* resource,
  351. wl_resource* output_resource,
  352. int32_t x,
  353. int32_t y,
  354. int32_t width,
  355. int32_t height);
  356. void toast_surface_set_position(wl_client* client,
  357. wl_resource* resource,
  358. uint32_t display_id_hi,
  359. uint32_t display_id_lo,
  360. int32_t x,
  361. int32_t y);
  362. void toast_surface_set_size(wl_client* client,
  363. wl_resource* resource,
  364. int32_t width,
  365. int32_t height);
  366. void toast_surface_set_bounds_in_output(wl_client* client,
  367. wl_resource* resource,
  368. wl_resource* output_resource,
  369. int32_t x,
  370. int32_t y,
  371. int32_t width,
  372. int32_t height);
  373. ////////////////////////////////////////////////////////////////////////////////
  374. // remote_shell_interface:
  375. void remote_shell_set_use_default_scale_cancellation(
  376. wl_client*,
  377. wl_resource* resource,
  378. int32_t use_default_scale_cancellation);
  379. } // namespace zcr_remote_shell
  380. } // namespace wayland
  381. } // namespace exo
  382. #endif // COMPONENTS_EXO_WAYLAND_ZCR_REMOTE_SHELL_IMPL_H_