wayland_bridge/
aura_shell.rs

1// Copyright 2019 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 crate::client::Client;
6use crate::compositor::Surface;
7use crate::object::{NewObjectExt, ObjectRef, RequestReceiver};
8use crate::output::Output;
9use anyhow::Error;
10use fidl_fuchsia_ui_gfx::DisplayInfo;
11use fuchsia_wayland_core as wl;
12use zaura_shell_server_protocol::{
13    zaura_output, ZauraOutput, ZauraOutputRequest, ZauraShell, ZauraShellRequest, ZauraSurface,
14    ZauraSurfaceRequest,
15};
16
17/// An implementation of the zaura_shell global.
18pub struct AuraShell;
19
20impl AuraShell {
21    /// Creates a new `AuraShell`.
22    pub fn new() -> Self {
23        Self
24    }
25}
26
27impl RequestReceiver<ZauraShell> for AuraShell {
28    fn receive(
29        _this: ObjectRef<Self>,
30        request: ZauraShellRequest,
31        client: &mut Client,
32    ) -> Result<(), Error> {
33        match request {
34            ZauraShellRequest::GetAuraSurface { id, surface } => {
35                id.implement(client, AuraSurface::new(surface))?;
36            }
37            ZauraShellRequest::GetAuraOutput { id, output } => {
38                let aura_output = AuraOutput::new();
39                let aura_output_ref = id.implement(client, aura_output)?;
40                let output: ObjectRef<Output> = output.into();
41                output.get_mut(client)?.set_aura_output(aura_output_ref);
42                let display_info = client.display().display_info();
43                Output::post_display_info(output, client, &display_info)?;
44            }
45        }
46        Ok(())
47    }
48}
49
50struct AuraSurface {
51    surface_ref: ObjectRef<Surface>,
52}
53
54impl AuraSurface {
55    pub fn new(surface: wl::ObjectId) -> Self {
56        Self { surface_ref: surface.into() }
57    }
58}
59
60impl RequestReceiver<ZauraSurface> for AuraSurface {
61    fn receive(
62        this: ObjectRef<Self>,
63        request: ZauraSurfaceRequest,
64        client: &mut Client,
65    ) -> Result<(), Error> {
66        match request {
67            ZauraSurfaceRequest::SetFrame { .. } => {}
68            ZauraSurfaceRequest::SetParent { parent, x, y } => {
69                let maybe_parent_ref = if parent != 0 {
70                    let parent_ref: ObjectRef<AuraSurface> = parent.into();
71                    Some(parent_ref.get(client)?.surface_ref)
72                } else {
73                    None
74                };
75                let surface_ref = this.get(client)?.surface_ref;
76                let surface = surface_ref.get_mut(client)?;
77                surface.set_parent_and_offset(maybe_parent_ref, x, y);
78            }
79            ZauraSurfaceRequest::SetFrameColors { .. } => {}
80            ZauraSurfaceRequest::SetStartupId { startup_id } => {
81                let surface_id = this.get(client)?.surface_ref.id();
82                println!("startup_id for surface {} = '{}'", surface_id, startup_id);
83            }
84            ZauraSurfaceRequest::SetApplicationId { application_id } => {
85                let surface_id = this.get(client)?.surface_ref.id();
86                println!("application_id for surface {} = '{}'", surface_id, application_id);
87            }
88            ZauraSurfaceRequest::SetClientSurfaceId { .. } => {}
89            ZauraSurfaceRequest::SetOcclusionTracking => {}
90            ZauraSurfaceRequest::UnsetOcclusionTracking { .. } => {}
91        }
92        Ok(())
93    }
94}
95
96pub struct AuraOutput;
97
98impl AuraOutput {
99    pub fn new() -> Self {
100        Self
101    }
102
103    pub fn post_display_info(
104        this: ObjectRef<Self>,
105        client: &Client,
106        _display_info: &DisplayInfo,
107    ) -> Result<(), Error> {
108        client.event_queue().post(
109            this.id(),
110            zaura_output::Event::Scale {
111                flags: zaura_output::ScaleProperty::Current
112                    | zaura_output::ScaleProperty::Preferred,
113                // Use scale factor 1.0.
114                scale: zaura_output::ScaleFactor::_1000,
115            },
116        )?;
117        client.event_queue().post(
118            this.id(),
119            zaura_output::Event::Connection { connection: zaura_output::ConnectionType::Internal },
120        )?;
121        client.event_queue().post(
122            this.id(),
123            zaura_output::Event::DeviceScaleFactor { scale: zaura_output::ScaleFactor::_1000 },
124        )?;
125        Ok(())
126    }
127}
128
129impl RequestReceiver<ZauraOutput> for AuraOutput {
130    fn receive(
131        _this: ObjectRef<Self>,
132        request: ZauraOutputRequest,
133        _client: &mut Client,
134    ) -> Result<(), Error> {
135        match request {}
136    }
137}