Module primary_selection

Module primary_selection 

Source
Available on crate feature wayland_frontend only.
Expand description

Utilities for manipulating the primary selection

The primary selection is an additional protocol modeled after the data device to represent and additional selection (copy/paste), a concept taken from the X11 Server. This primary selection is a shortcut to the common clipboard selection, where text just needs to be selected in order to allow copying it elsewhere The de facto way to perform this action is the middle mouse button, although it is not limited to this one.

This module provides the freestanding set_primary_focus function: This function sets the data device focus for a given seat; you’d typically call it whenever the keyboard focus changes, to follow it (for example in the focus hook of your keyboards).

The module also provides an additional mechanism allowing your compositor to see and interact with the contents of the primary selection:

§Initialization

To initialize this implementation, create the PrimarySelectionState, store it inside your State struct and implement the PrimarySelectionHandler and SelectionHandler, as shown in this example:

use smithay::delegate_primary_selection;
use smithay::wayland::selection::SelectionHandler;
use smithay::wayland::selection::primary_selection::{PrimarySelectionState, PrimarySelectionHandler};

// Create the primary_selection state
let primary_selection_state = PrimarySelectionState::new::<State>(
    &display.handle(),
);

// insert the PrimarySelectionState into your state
// ..

// implement the necessary traits
impl SelectionHandler for State {
    type SelectionUserData = ();
}
impl PrimarySelectionHandler for State {
    fn primary_selection_state(&mut self) -> &mut PrimarySelectionState { &mut self.primary_selection_state }
    // ... override default implementations here to customize handling ...
}
delegate_primary_selection!(State);

// You're now ready to go!

Structs§

PrimarySelectionState
State of the primary selection.
SourceMetadata
The metadata describing a data source

Enums§

SelectionRequestError
Errors happening when requesting selection contents

Traits§

PrimarySelectionHandler
Access the primary selection state.

Functions§

clear_primary_selection
Clear the current selection for this seat
current_primary_selection_userdata
Gets the user_data for the currently active selection, if set by the compositor
request_primary_client_selection
Request the current primary selection of the given seat to be written to the provided file descriptor with the given mime type.
set_primary_focus
Set the primary selection focus to a certain client for a given seat
set_primary_selection
Set a compositor-provided primary selection for this seat