srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/crates/wayland/src/protocols/selection.rs
blob: fadb0cab9991916e7fac5b7b5c97796b149397f5 (plain) (blame)
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
//! Clipboard/primary-selection/drag-and-drop.
//!
//! All three selection protocols below (`wl_data_device_manager`,
//! `zwp_primary_selection_v1`, `zwlr_data_control_manager_v1`) share
//! smithay's single `SelectionHandler`. Every transfer here is
//! *client-to-client*: one client owns the selection and writes the bytes
//! itself, and smithay wires the two ends together without the data passing
//! through us. `send_selection` is only ever called for a
//! **compositor-provided** selection (one this WM set itself via
//! `set_data_device_selection`), which srdwm never does - so it is
//! deliberately left unimplemented rather than faked.

use smithay::wayland::selection::data_device::{ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler};
use smithay::wayland::selection::primary_selection::{PrimarySelectionHandler, PrimarySelectionState};
use smithay::wayland::selection::wlr_data_control::{DataControlHandler, DataControlState};
use smithay::wayland::selection::SelectionHandler;

use crate::state::CompState;

impl SelectionHandler for CompState {
    type SelectionUserData = ();
}

impl DataDeviceHandler for CompState {
    fn data_device_state(&self) -> &DataDeviceState {
        &self.data_device_state
    }
}

// Drag-and-drop: the default trait methods already do the right thing for a
// compositor that doesn't draw its own drag icon or offer server-side drag
// sources - smithay runs the pointer grab and the offer/accept negotiation
// internally. Both are implemented empty (rather than skipped) because
// `DataDeviceHandler` requires them as supertraits.
impl ClientDndGrabHandler for CompState {}
impl ServerDndGrabHandler for CompState {}

impl PrimarySelectionHandler for CompState {
    fn primary_selection_state(&self) -> &PrimarySelectionState {
        &self.primary_selection_state
    }
}

/// `zwlr_data_control_manager_v1`: lets a client read/watch the selection
/// without ever holding keyboard focus. This is what `wl-paste --watch`
/// (and thus `cliphist store`, which the user's session autostarts) needs
/// - a focus-following clipboard manager is impossible without it.
impl DataControlHandler for CompState {
    fn data_control_state(&self) -> &DataControlState {
        &self.data_control_state
    }
}