dragdrop

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dragdrop implements drag and drop over the wl_data_device protocol: the source side (data source + start_drag with an icon), the destination side (offer bookkeeping, accept/reject, payload transfer), and the routing of enter/motion/leave/drop to the target registered for the surface under the drag. It coexists with internal/clipboard, which handles the same device's selection events: offers are tracked per object, so a drag's offer never touches the selection.

Index

Constants

This section is empty.

Variables

View Source
var ErrDragActive = errors.New("dragdrop: a drag is already active")

ErrDragActive reports a start_drag while one is already running.

View Source
var ErrNoPayload = errors.New("dragdrop: no drag payload available")

ErrNoPayload reports a payload read with no accepted drag behind it.

View Source
var ErrUnavailable = errors.New("dragdrop: no data device")

ErrUnavailable reports that the session has no data device, so no drag can start.

Functions

This section is empty.

Types

type ActionTarget

type ActionTarget interface {
	DragAction(offered transfer.Action) transfer.Action
}

ActionTarget is a Target that picks the drop action from those the source offers (copy, move, ask); without it a drop prefers copy.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller owns the drag-and-drop half of the session's data device. Create one per session with New; bind every host surface that can take a drop; start drags with StartDrag when a gesture earns one. It is not safe for concurrent use.

func New

func New(sess *wlsession.Session, invoke func(func())) *Controller

New wires a controller to the session's data device and starts tracking advertised offers. Safe to call when the device is missing (compositor without wl_data_device_manager): every request then fails with ErrUnavailable. invoke runs a closure on the event loop, from any goroutine: it brings finished transfers back.

func (*Controller) Bind

func (c *Controller) Bind(surf *wl.Surface, t Target)

Bind registers t as the drop target of surf; t == nil unbinds. Mirrors wlsession.SetSurfaceInput for drops.

func (*Controller) CancelDrag

func (c *Controller) CancelDrag() bool

CancelDrag cancels this process's running drag from the source side (Esc during a drag, GTK's drag-cancel): destroying the data source ends the drag at the compositor, and OnDone hears ActionNone. Reports whether a drag was running.

func (*Controller) Dragging

func (c *Controller) Dragging() bool

Dragging reports whether a drag started by this process is running.

func (*Controller) HandleDataDeviceDataOffer

func (c *Controller) HandleDataDeviceDataOffer(ev wl.DataDeviceDataOfferEvent)

HandleDataDeviceDataOffer implements wl.DataDeviceDataOfferHandler: a new offer appears; start collecting its mime types. Drag and selection offers both pass here; each is tracked independently.

func (*Controller) HandleDataSourceAction

func (c *Controller) HandleDataSourceAction(ev wl.DataSourceActionEvent)

HandleDataSourceAction implements wl.DataSourceActionHandler: the compositor negotiated an action with the destination.

func (*Controller) HandleDataSourceCancelled

func (c *Controller) HandleDataSourceCancelled(wl.DataSourceCancelledEvent)

HandleDataSourceCancelled implements wl.DataSourceCancelledHandler: the compositor aborted the drag.

func (*Controller) HandleDataSourceDndDropPerformed

func (c *Controller) HandleDataSourceDndDropPerformed(wl.DataSourceDndDropPerformedEvent)

HandleDataSourceDndDropPerformed implements wl.DataSourceDndDropPerformedHandler: the pointer released; the icon goes away while the transfer may still run.

func (*Controller) HandleDataSourceDndFinished

func (c *Controller) HandleDataSourceDndFinished(wl.DataSourceDndFinishedEvent)

HandleDataSourceDndFinished implements wl.DataSourceDndFinishedHandler: the destination acknowledged the transfer.

func (*Controller) HandleDataSourceSend

func (c *Controller) HandleDataSourceSend(ev wl.DataSourceSendEvent)

HandleDataSourceSend implements wl.DataSourceSendHandler: a cross-process consumer asked for our data; write it off the loop, bounded by the deadline, and close so the reader sees EOF whatever the outcome. A failed write (EPIPE, deadline) leaves the consumer a short payload plus EOF, evidence the transfer broke.

func (*Controller) HandleDataSourceTarget

func (c *Controller) HandleDataSourceTarget(ev wl.DataSourceTargetEvent)

HandleDataSourceTarget implements wl.DataSourceTargetHandler: the destination under the pointer accepted a mime, or none.

func (*Controller) ReadPayload

func (c *Controller) ReadPayload(mime string, done func([]byte, error))

ReadPayload delivers the drop's bytes for mime to done on the loop goroutine, always on a later pass: the loop never waits for the peer, and the offer stays open for the transfer after the drop event ends. A drag that originated in this process short-circuits the wire: the content provider hands over the bytes directly, with no fd round-trip. Cross-process drops read through the offer pipe and, on version 3+, acknowledge with finish.

func (*Controller) StartDrag

func (c *Controller) StartDrag(cfg StartConfig) error

StartDrag claims the seat's drag-and-drop with the given content: the data source offers the mimes, and the compositor moves the icon until the drag drops or cancels. The grab serial is the pointer press that started the gesture.

func (*Controller) Stop

func (c *Controller) Stop()

Stop ends every running transfer and waits for them: an application stops its controller when its loop ends or its session goes.

type Icon

type Icon interface {
	Surface() *wl.Surface
	Destroy() error
}

Icon is a drag icon: the surface start_drag names, destroyed with everything it holds once the drag ends.

type StartConfig

type StartConfig struct {
	// Origin is the surface the implicit grab belongs to.
	Origin *wl.Surface
	// Icon is an optional drag icon; the compositor moves its surface
	// with the pointer. Nil shows a fallback cursor graphic.
	Icon Icon
	// GrabSerial is the pointer button-press serial of the gesture.
	GrabSerial uint32
	// Content is the offered payload with its actions and hooks.
	Content transfer.Drag
}

StartConfig describes one start_drag request.

type Target

type Target interface {
	DragEnter(mimes []string, x, y float64) string
	DragMotion(x, y float64) string
	DragLeave()
	Drop(x, y float64)
}

Target receives the drag-and-drop events for one bound surface, with coordinates in that surface's logical space. DragEnter and DragMotion return the accepted mime type, or "" to reject; mimes arrives in advertised (best-first) order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL