Expand description

Utilities for manipulating the data devices

The data device is wayland’s abstraction to represent both selection (copy/paste) and drag’n’drop actions. This module provides logic to handle this part of the protocol. Selection and drag’n’drop are per-seat notions.

This module provides 2 main freestanding functions:

  • init_data_device: this function must be called during the compositor startup to initialize the data device logic
  • set_data_device_focus: 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)

Using these two functions is enough for your clients to be able to interact with each other using the data devices.

The module also provides additionnal mechanisms allowing your compositor to see and interact with the contents of the data device:

  • You can provide a callback closure to init_data_device to peek into the the actions of your clients
  • the freestanding function set_data_device_selection allows you to set the contents of the selection for your clients
  • the freestanding function start_dnd allows you to initiate a drag’n’drop event from the compositor itself and receive interactions of clients with it via an other dedicated callback.

The module also defines the DnDIconRole that you need to insert into your compositor roles enum, to represent surfaces that are used as a DnD icon.

Initialization

use smithay::wayland::data_device::{init_data_device, default_action_chooser, DnDIconRole};

// You need to insert the `DndIconRole` into your roles, to handle requests from clients
// to set a surface as a dnd icon
define_roles!(Roles => [DnDIcon, DnDIconRole]);

// init the data device:
init_data_device(
    &mut display,            // the display
    |dnd_event| { /* a callback to react to client DnD/selection actions */ },
    default_action_chooser,  // a closure to choose the DnD action depending on clients
                             // negociation
    compositor_token.clone(), // a compositor token
    None                     // insert a logger here
);

Structs

The role applied to surfaces used as DnD icons
The metadata describing a data source

Enums

Events that are generated by interactions of the clients with the data device
Event generated by the interactions of clients with a server initiated drag’n’drop

Functions

A simple action chooser for DnD negociation
Initialize the data device global
Set the data device focus to a certain client for a given seat
Set a compositor-provided selection for this seat
Start a drag’n’drop from a ressource controlled by the compositor
Access the metadata of a data source