smithay_client_toolkit/primary_selection/
mod.rs1use crate::dispatch2::Dispatch2;
2use crate::globals::GlobalData;
3use crate::reexports::client::{
4 globals::{BindError, GlobalList},
5 protocol::wl_seat::WlSeat,
6 Dispatch, QueueHandle,
7};
8use crate::reexports::protocols::wp::primary_selection::zv1::client::{
9 zwp_primary_selection_device_manager_v1::ZwpPrimarySelectionDeviceManagerV1,
10 zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1,
11 zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1,
12};
13
14pub mod device;
15pub mod offer;
16pub mod selection;
17
18use self::device::{PrimarySelectionDevice, PrimarySelectionDeviceData};
19use selection::PrimarySelectionSource;
20
21#[derive(Debug)]
22pub struct PrimarySelectionManagerState {
23 manager: ZwpPrimarySelectionDeviceManagerV1,
24}
25
26impl PrimarySelectionManagerState {
27 pub fn bind<State>(globals: &GlobalList, qh: &QueueHandle<State>) -> Result<Self, BindError>
28 where
29 State: Dispatch<ZwpPrimarySelectionDeviceManagerV1, GlobalData, State> + 'static,
30 {
31 let manager = globals.bind(qh, 1..=1, GlobalData)?;
32 Ok(Self { manager })
33 }
34
35 pub fn primary_selection_manager(&self) -> &ZwpPrimarySelectionDeviceManagerV1 {
37 &self.manager
38 }
39
40 pub fn create_selection_source<State, I, T>(
42 &self,
43 qh: &QueueHandle<State>,
44 mime_types: I,
45 ) -> PrimarySelectionSource
46 where
47 State: Dispatch<ZwpPrimarySelectionSourceV1, GlobalData, State> + 'static,
48 I: IntoIterator<Item = T>,
49 T: ToString,
50 {
51 let source = self.manager.create_source(qh, GlobalData);
52
53 for mime_type in mime_types {
54 source.offer(mime_type.to_string());
55 }
56
57 PrimarySelectionSource::new(source)
58 }
59
60 pub fn get_selection_device<State>(
62 &self,
63 qh: &QueueHandle<State>,
64 seat: &WlSeat,
65 ) -> PrimarySelectionDevice
66 where
67 State: Dispatch<ZwpPrimarySelectionDeviceV1, PrimarySelectionDeviceData, State> + 'static,
68 {
69 PrimarySelectionDevice {
70 device: self.manager.get_device(
71 seat,
72 qh,
73 PrimarySelectionDeviceData::new(seat.clone()),
74 ),
75 }
76 }
77}
78
79impl Drop for PrimarySelectionManagerState {
80 fn drop(&mut self) {
81 self.manager.destroy();
82 }
83}
84
85impl<D> Dispatch2<ZwpPrimarySelectionDeviceManagerV1, D> for GlobalData {
86 fn event(
87 &self,
88 _: &mut D,
89 _: &ZwpPrimarySelectionDeviceManagerV1,
90 _: <ZwpPrimarySelectionDeviceManagerV1 as wayland_client::Proxy>::Event,
91 _: &wayland_client::Connection,
92 _: &QueueHandle<D>,
93 ) {
94 unreachable!("zwp_primary_selection_device_manager_v1 has no events")
95 }
96}