scene_management/
pointerinjector_config.rs

1// Copyright 2021 The Fuchsia 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
5use async_utils::hanging_get::server as hanging_get;
6use {
7    fidl_fuchsia_ui_pointerinjector as ui_pointerinjector,
8    fidl_fuchsia_ui_pointerinjector_configuration as ui_pointerinjector_config,
9};
10
11/// Minimal spec that can be used to generate a fuchsia.ui.pointerinjector.Viewport,
12/// for the purposes of implementing fuchsia.ui.pointerinjector.configuration.Setup API.
13#[derive(Copy, Clone)]
14pub struct InjectorViewportSpec {
15    pub width: f32,
16    pub height: f32,
17    pub scale: f32,
18    pub x_offset: f32,
19    pub y_offset: f32,
20}
21
22/// Conversion from InjectorViewportSpec -> fuchsia.ui.pointerinjector.Viewport.
23impl std::convert::From<InjectorViewportSpec> for ui_pointerinjector::Viewport {
24    fn from(spec: InjectorViewportSpec) -> Self {
25        ui_pointerinjector::Viewport {
26            extents: Some([[0.0, 0.0], [spec.width, spec.height]]),
27            viewport_to_context_transform: Some([
28                // Same transform as: https://cs.opensource.google/fuchsia/fuchsia/+/main:src/ui/input/lib/injector/injector.cc;drc=af2ffe6ce432b6e6f050a7c2d62e9e5fc2b3e3f2;l=315
29                spec.scale,
30                0.,
31                0.,
32                0.,
33                spec.scale,
34                0.,
35                spec.x_offset,
36                spec.y_offset,
37                1.,
38            ]),
39            ..Default::default()
40        }
41    }
42}
43
44/// Used to implement fuchsia.ui.pointerinjector.configuration.Setup.WatchViewport().
45pub type InjectorViewportChangeFn = Box<
46    dyn Fn(&InjectorViewportSpec, ui_pointerinjector_config::SetupWatchViewportResponder) -> bool
47        + Send
48        + Sync,
49>;
50
51/// Used to implement fuchsia.ui.pointerinjector.configuration.Setup.WatchViewport().
52pub type InjectorViewportHangingGet = hanging_get::HangingGet<
53    InjectorViewportSpec,
54    ui_pointerinjector_config::SetupWatchViewportResponder,
55    InjectorViewportChangeFn,
56>;
57
58/// Used to implement fuchsia.ui.pointerinjector.configuration.Setup.WatchViewport().
59pub type InjectorViewportPublisher = hanging_get::Publisher<
60    InjectorViewportSpec,
61    ui_pointerinjector_config::SetupWatchViewportResponder,
62    InjectorViewportChangeFn,
63>;
64
65/// Used to implement fuchsia.ui.pointerinjector.configuration.Setup.WatchViewport().
66pub type InjectorViewportSubscriber = hanging_get::Subscriber<
67    InjectorViewportSpec,
68    ui_pointerinjector_config::SetupWatchViewportResponder,
69    InjectorViewportChangeFn,
70>;