Skip to content

wl_data_device¤

wayland.wl_data_device ¤

Data transfer device

There is one wl_data_device per seat which can be obtained from the global wl_data_device_manager singleton.

A wl_data_device provides access to inter-client data transfer mechanisms such as copy-and-paste and drag-and-drop.

Methods:

error ¤

events

data_offer ¤

data_offer(id: wl_data_offer) -> None

Introduce a new wl_data_offer

The data_offer event introduces a new wl_data_offer object, which will subsequently be used in either the data_device.enter event (for drag-and-drop) or the data_device.selection event (for selections). Immediately following the data_device.data_offer event, the new data_offer object will send out data_offer.offer events to describe the mime types it offers.

Parameters:

enter ¤

enter(
    serial: int, surface: wl_surface, x: float, y: float, id: wl_data_offer
) -> None

Initiate drag-and-drop session

This event is sent when an active drag-and-drop pointer enters a surface owned by the client. The position of the pointer at enter time is provided by the x and y arguments, in surface-local coordinates.

Parameters:

  • serial ¤

    (int) –

    Serial number of the enter event

  • surface ¤

    (wl_surface) –

    Client surface entered

  • x ¤

    (float) –

    Surface-local x coordinate

  • y ¤

    (float) –

    Surface-local y coordinate

  • id ¤

    (wl_data_offer) –

    Source data_offer object

leave ¤

leave() -> None

End drag-and-drop session

This event is sent when the drag-and-drop pointer leaves the surface and the session ends. The client must destroy the wl_data_offer introduced at enter time at this point.

motion ¤

motion(time: int, x: float, y: float) -> None

Drag-and-drop session motion

This event is sent when the drag-and-drop pointer moves within the currently focused surface. The new position of the pointer is provided by the x and y arguments, in surface-local coordinates.

Parameters:

  • time ¤

    (int) –

    Timestamp with millisecond granularity

  • x ¤

    (float) –

    Surface-local x coordinate

  • y ¤

    (float) –

    Surface-local y coordinate

drop ¤

drop() -> None

End drag-and-drop session successfully

The event is sent when a drag-and-drop operation is ended because the implicit grab is removed.

The drag-and-drop destination is expected to honor the last action received through wl_data_offer.action, if the resulting action is "copy" or "move", the destination can still perform wl_data_offer.receive requests, and is expected to end all transfers with a wl_data_offer.finish request.

If the resulting action is "ask", the action will not be considered final. The drag-and-drop destination is expected to perform one last wl_data_offer.set_actions request, or wl_data_offer.destroy in order to cancel the operation.

selection ¤

selection(id: wl_data_offer) -> None

Advertise new selection

The selection event is sent out to notify the client of a new wl_data_offer for the selection for this device. The data_device.data_offer and the data_offer.offer events are sent out immediately before this event to introduce the data offer object. The selection event is sent to a client immediately before receiving keyboard focus and when a new selection is set while the client has keyboard focus. The data_offer is valid until a new data_offer or NULL is received or until the client loses keyboard focus. Switching surface with keyboard focus within the same client doesn't mean a new selection will be sent. The client must destroy the previous selection data_offer, if any, upon receiving this event.

Parameters:

start_drag ¤

Start drag-and-drop operation

This request asks the compositor to start a drag-and-drop operation on behalf of the client.

The source argument is the data source that provides the data for the eventual data transfer. If source is NULL, enter, leave and motion events are sent only to the client that initiated the drag and the client is expected to handle the data passing internally. If source is destroyed, the drag-and-drop session will be cancelled.

The origin surface is the surface where the drag originates and the client must have an active implicit grab that matches the serial.

The icon surface is an optional (can be NULL) surface that provides an icon to be moved around with the cursor. Initially, the top-left corner of the icon surface is placed at the cursor hotspot, but subsequent wl_surface.offset requests can move the relative position. Attach requests must be confirmed with wl_surface.commit as usual. The icon surface is given the role of a drag-and-drop icon. If the icon surface already has another role, it raises a protocol error.

The input region is ignored for wl_surfaces with the role of a drag-and-drop icon.

The given source may not be used in any further set_selection or start_drag requests. Attempting to reuse a previously-used source may send a used_source error.

Parameters:

  • source ¤

    (wl_data_source) –

    Data source for the eventual transfer

  • origin ¤

    (wl_surface) –

    Surface where the drag originates

  • icon ¤

    (wl_surface) –

    Drag-and-drop icon surface

  • serial ¤

    (int) –

    Serial number of the implicit grab on the origin

set_selection ¤

set_selection(source: wl_data_source, serial: int) -> None

Copy data to the selection

This request asks the compositor to set the selection to the data from the source on behalf of the client.

To unset the selection, set the source to NULL.

The given source may not be used in any further set_selection or start_drag requests. Attempting to reuse a previously-used source may send a used_source error.

Parameters:

  • source ¤

    (wl_data_source) –

    Data source for the selection

  • serial ¤

    (int) –

    Serial number of the event that triggered this request

release ¤

release() -> None

Destroy data device

This request destroys the data device.

on_data_offer ¤

on_data_offer(id: wl_data_offer) -> None

Introduce a new wl_data_offer.

Override to handle wayland.wl_data_device.events.data_offer.

on_enter ¤

on_enter(
    serial: int, surface: wl_surface, x: float, y: float, id: wl_data_offer
) -> None

Initiate drag-and-drop session.

Override to handle wayland.wl_data_device.events.enter.

on_leave ¤

on_leave() -> None

End drag-and-drop session.

Override to handle wayland.wl_data_device.events.leave.

on_motion ¤

on_motion(time: int, x: float, y: float) -> None

Drag-and-drop session motion.

Override to handle wayland.wl_data_device.events.motion.

on_drop ¤

on_drop() -> None

End drag-and-drop session successfully.

Override to handle wayland.wl_data_device.events.drop.

on_selection ¤

on_selection(id: wl_data_offer) -> None

Advertise new selection.

Override to handle wayland.wl_data_device.events.selection.