wayland_bridge/
data_device_manager.rs

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
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::client::Client;
use crate::object::{NewObjectExt, ObjectRef, RequestReceiver};
use crate::seat::Seat;
use anyhow::Error;
use wayland_server_protocol::{
    WlDataDevice, WlDataDeviceManager, WlDataDeviceManagerRequest, WlDataDeviceRequest,
    WlDataSource, WlDataSourceRequest,
};

/// An implementation of the wl_data_device_manager global.
pub struct DataDeviceManager;

impl DataDeviceManager {
    /// Creates a new `DataDeviceManager`.
    pub fn new() -> Self {
        DataDeviceManager
    }
}

impl RequestReceiver<WlDataDeviceManager> for DataDeviceManager {
    fn receive(
        _this: ObjectRef<Self>,
        request: WlDataDeviceManagerRequest,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            WlDataDeviceManagerRequest::CreateDataSource { id } => {
                id.implement(client, DataSource)?;
            }
            WlDataDeviceManagerRequest::GetDataDevice { id, seat } => {
                id.implement(client, DataDevice { _object: seat.into() })?;
            }
        }
        Ok(())
    }
}

struct DataSource;

impl RequestReceiver<WlDataSource> for DataSource {
    fn receive(
        this: ObjectRef<Self>,
        request: WlDataSourceRequest,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            WlDataSourceRequest::Destroy => {
                client.delete_id(this.id())?;
            }
            WlDataSourceRequest::Offer { .. } => {}
            WlDataSourceRequest::SetActions { .. } => {}
        }
        Ok(())
    }
}

struct DataDevice {
    _object: ObjectRef<Seat>,
}

impl RequestReceiver<WlDataDevice> for DataDevice {
    fn receive(
        this: ObjectRef<Self>,
        request: WlDataDeviceRequest,
        client: &mut Client,
    ) -> Result<(), Error> {
        match request {
            WlDataDeviceRequest::Release => {
                client.delete_id(this.id())?;
            }
            WlDataDeviceRequest::StartDrag { .. } => {}
            WlDataDeviceRequest::SetSelection { .. } => {}
        }
        Ok(())
    }
}