Skip to main content

wl_clipboard_rs/
seat_data.rs

1use crate::data_control::{Device, Offer};
2
3#[derive(Default)]
4pub struct SeatData {
5    /// The name of this seat, if any.
6    pub name: Option<String>,
7
8    /// The data device of this seat, if any.
9    pub device: Option<Device>,
10
11    /// The data offer of this seat, if any.
12    pub offer: Option<Offer>,
13
14    /// The primary-selection data offer of this seat, if any.
15    pub primary_offer: Option<Offer>,
16}
17
18impl SeatData {
19    /// Sets this seat's name.
20    pub fn set_name(&mut self, name: String) {
21        self.name = Some(name)
22    }
23
24    /// Sets this seat's device.
25    ///
26    /// Destroys the old one, if any.
27    pub fn set_device(&mut self, device: Option<Device>) {
28        let old_device = self.device.take();
29        self.device = device;
30
31        if let Some(device) = old_device {
32            device.destroy();
33        }
34    }
35
36    /// Sets this seat's data offer.
37    ///
38    /// Destroys the old one, if any.
39    pub fn set_offer(&mut self, new_offer: Option<Offer>) {
40        let old_offer = self.offer.take();
41        self.offer = new_offer;
42
43        if let Some(offer) = old_offer {
44            offer.destroy();
45        }
46    }
47
48    /// Sets this seat's primary-selection data offer.
49    ///
50    /// Destroys the old one, if any.
51    pub fn set_primary_offer(&mut self, new_offer: Option<Offer>) {
52        let old_offer = self.primary_offer.take();
53        self.primary_offer = new_offer;
54
55        if let Some(offer) = old_offer {
56            offer.destroy();
57        }
58    }
59}