Drag And Drop

Drag And Drop — Functions for controlling drag and drop handling

Functions

Signals

void action-changed Run Last
void cancel Run Last
void dnd-finished Run Last
void drop-performed Run Last

Types and Values

Object Hierarchy

    GObject
    ╰── CdkDragContext

Includes

#include <cdk/cdk.h>

Description

These functions provide a low level interface for drag and drop. The X backend of CDK supports both the Xdnd and Motif drag and drop protocols transparently, the Win32 backend supports the WM_DROPFILES protocol.

CTK+ provides a higher level abstraction based on top of these functions, and so they are not normally needed in CTK+ applications. See the Drag and Drop section of the CTK+ documentation for more information.

Functions

cdk_drag_get_selection ()

CdkAtom
cdk_drag_get_selection (CdkDragContext *context);

Returns the selection atom for the current source window.

Parameters

context

a CdkDragContext.

 

Returns

the selection atom, or CDK_NONE.

[transfer none]


cdk_drag_abort ()

void
cdk_drag_abort (CdkDragContext *context,
                guint32 time_);

Aborts a drag without dropping.

This function is called by the drag source.

This function does not need to be called in managed drag and drop operations. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

a CdkDragContext

 

time_

the timestamp for this operation

 

cdk_drop_reply ()

void
cdk_drop_reply (CdkDragContext *context,
                gboolean accepted,
                guint32 time_);

Accepts or rejects a drop.

This function is called by the drag destination in response to a drop initiated by the drag source.

Parameters

context

a CdkDragContext

 

accepted

TRUE if the drop is accepted

 

time_

the timestamp for this operation

 

cdk_drag_drop ()

void
cdk_drag_drop (CdkDragContext *context,
               guint32 time_);

Drops on the current destination.

This function is called by the drag source.

This function does not need to be called in managed drag and drop operations. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

a CdkDragContext

 

time_

the timestamp for this operation

 

cdk_drag_drop_done ()

void
cdk_drag_drop_done (CdkDragContext *context,
                    gboolean success);

Inform CDK if the drop ended successfully. Passing FALSE for success may trigger a drag cancellation animation.

This function is called by the drag source, and should be the last call before dropping the reference to the context .

The CdkDragContext will only take the first cdk_drag_drop_done() call as effective, if this function is called multiple times, all subsequent calls will be ignored.

Parameters

context

a CdkDragContext

 

success

whether the drag was ultimatively successful

 

Since: 3.20


cdk_drag_find_window_for_screen ()

void
cdk_drag_find_window_for_screen (CdkDragContext *context,
                                 CdkWindow *drag_window,
                                 CdkScreen *screen,
                                 gint x_root,
                                 gint y_root,
                                 CdkWindow **dest_window,
                                 CdkDragProtocol *protocol);

Finds the destination window and DND protocol to use at the given pointer position.

This function is called by the drag source to obtain the dest_window and protocol parameters for cdk_drag_motion().

Parameters

context

a CdkDragContext

 

drag_window

a window which may be at the pointer position, but should be ignored, since it is put up by the drag source as an icon

 

screen

the screen where the destination window is sought

 

x_root

the x position of the pointer in root coordinates

 

y_root

the y position of the pointer in root coordinates

 

dest_window

location to store the destination window in.

[out]

protocol

location to store the DND protocol in.

[out]

Since: 2.2


cdk_drag_begin ()

CdkDragContext *
cdk_drag_begin (CdkWindow *window,
                GList *targets);

Starts a drag and creates a new drag context for it. This function assumes that the drag is controlled by the client pointer device, use cdk_drag_begin_for_device() to begin a drag with a different device.

This function is called by the drag source.

Parameters

window

the source window for this drag.

 

targets

the offered targets, as list of CdkAtoms.

[transfer none][element-type CdkAtom]

Returns

a newly created CdkDragContext.

[transfer full]


cdk_drag_begin_for_device ()

CdkDragContext *
cdk_drag_begin_for_device (CdkWindow *window,
                           CdkDevice *device,
                           GList *targets);

Starts a drag and creates a new drag context for it.

This function is called by the drag source.

Parameters

window

the source window for this drag

 

device

the device that controls this drag

 

targets

the offered targets, as list of CdkAtoms.

[transfer none][element-type CdkAtom]

Returns

a newly created CdkDragContext.

[transfer full]


cdk_drag_begin_from_point ()

CdkDragContext *
cdk_drag_begin_from_point (CdkWindow *window,
                           CdkDevice *device,
                           GList *targets,
                           gint x_root,
                           gint y_root);

Starts a drag and creates a new drag context for it.

This function is called by the drag source.

Parameters

window

the source window for this drag

 

device

the device that controls this drag

 

targets

the offered targets, as list of CdkAtoms.

[transfer none][element-type CdkAtom]

x_root

the x coordinate where the drag nominally started

 

y_root

the y coordinate where the drag nominally started

 

Returns

a newly created CdkDragContext.

[transfer full]

Since: 3.20


cdk_drag_motion ()

gboolean
cdk_drag_motion (CdkDragContext *context,
                 CdkWindow *dest_window,
                 CdkDragProtocol protocol,
                 gint x_root,
                 gint y_root,
                 CdkDragAction suggested_action,
                 CdkDragAction possible_actions,
                 guint32 time_);

Updates the drag context when the pointer moves or the set of actions changes.

This function is called by the drag source.

This function does not need to be called in managed drag and drop operations. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

a CdkDragContext

 

dest_window

the new destination window, obtained by cdk_drag_find_window()

 

protocol

the DND protocol in use, obtained by cdk_drag_find_window()

 

x_root

the x position of the pointer in root coordinates

 

y_root

the y position of the pointer in root coordinates

 

suggested_action

the suggested action

 

possible_actions

the possible actions

 

time_

the timestamp for this operation

 

Returns

TRUE if the update of drag context was successful.


cdk_drop_finish ()

void
cdk_drop_finish (CdkDragContext *context,
                 gboolean success,
                 guint32 time_);

Ends the drag operation after a drop.

This function is called by the drag destination.

Parameters

context

a CdkDragContext

 

success

TRUE if the data was successfully received

 

time_

the timestamp for this operation

 

cdk_drag_status ()

void
cdk_drag_status (CdkDragContext *context,
                 CdkDragAction action,
                 guint32 time_);

Selects one of the actions offered by the drag source.

This function is called by the drag destination in response to cdk_drag_motion() called by the drag source.

Parameters

context

a CdkDragContext

 

action

the selected action which will be taken when a drop happens, or 0 to indicate that a drop will not be accepted

 

time_

the timestamp for this operation

 

cdk_drag_drop_succeeded ()

gboolean
cdk_drag_drop_succeeded (CdkDragContext *context);

Returns whether the dropped data has been successfully transferred. This function is intended to be used while handling a CDK_DROP_FINISHED event, its return value is meaningless at other times.

Parameters

context

a CdkDragContext

 

Returns

TRUE if the drop was successful.

Since: 2.6


cdk_window_get_drag_protocol ()

CdkDragProtocol
cdk_window_get_drag_protocol (CdkWindow *window,
                              CdkWindow **target);

Finds out the DND protocol supported by a window.

Parameters

window

the destination window

 

target

location of the window where the drop should happen. This may be window or a proxy window, or NULL if window does not support Drag and Drop.

[out][allow-none][transfer full]

Returns

the supported DND protocol.

Since: 3.0


cdk_drag_context_get_actions ()

CdkDragAction
cdk_drag_context_get_actions (CdkDragContext *context);

Determines the bitmask of actions proposed by the source if cdk_drag_context_get_suggested_action() returns CDK_ACTION_ASK.

Parameters

context

a CdkDragContext

 

Returns

the CdkDragAction flags

Since: 2.22


cdk_drag_context_get_suggested_action ()

CdkDragAction
cdk_drag_context_get_suggested_action (CdkDragContext *context);

Determines the suggested drag action of the context.

Parameters

context

a CdkDragContext

 

Returns

a CdkDragAction value

Since: 2.22


cdk_drag_context_get_selected_action ()

CdkDragAction
cdk_drag_context_get_selected_action (CdkDragContext *context);

Determines the action chosen by the drag destination.

Parameters

context

a CdkDragContext

 

Returns

a CdkDragAction value

Since: 2.22


cdk_drag_context_list_targets ()

GList *
cdk_drag_context_list_targets (CdkDragContext *context);

Retrieves the list of targets of the context.

Parameters

context

a CdkDragContext

 

Returns

a GList of targets.

[transfer none][element-type CdkAtom]

Since: 2.22


cdk_drag_context_get_device ()

CdkDevice *
cdk_drag_context_get_device (CdkDragContext *context);

Returns the CdkDevice associated to the drag context.

Parameters

context

a CdkDragContext

 

Returns

The CdkDevice associated to context .

[transfer none]


cdk_drag_context_set_device ()

void
cdk_drag_context_set_device (CdkDragContext *context,
                             CdkDevice *device);

Associates a CdkDevice to context , so all Drag and Drop events for context are emitted as if they came from this device.

Parameters

context

a CdkDragContext

 

device

a CdkDevice

 

cdk_drag_context_get_source_window ()

CdkWindow *
cdk_drag_context_get_source_window (CdkDragContext *context);

Returns the CdkWindow where the DND operation started.

Parameters

context

a CdkDragContext

 

Returns

a CdkWindow.

[transfer none]

Since: 2.22


cdk_drag_context_get_dest_window ()

CdkWindow *
cdk_drag_context_get_dest_window (CdkDragContext *context);

Returns the destination window for the DND operation.

Parameters

context

a CdkDragContext

 

Returns

a CdkWindow.

[transfer none]

Since: 3.0


cdk_drag_context_get_protocol ()

CdkDragProtocol
cdk_drag_context_get_protocol (CdkDragContext *context);

Returns the drag protocol that is used by this context.

Parameters

context

a CdkDragContext

 

Returns

the drag protocol

Since: 3.0


cdk_drag_context_get_drag_window ()

CdkWindow *
cdk_drag_context_get_drag_window (CdkDragContext *context);

Returns the window on which the drag icon should be rendered during the drag operation. Note that the window may not be available until the drag operation has begun. CDK will move the window in accordance with the ongoing drag operation. The window is owned by context and will be destroyed when the drag operation is over.

Parameters

context

a CdkDragContext

 

Returns

the drag window, or NULL.

[nullable][transfer none]

Since: 3.20


cdk_drag_context_set_hotspot ()

void
cdk_drag_context_set_hotspot (CdkDragContext *context,
                              gint hot_x,
                              gint hot_y);

Sets the position of the drag window that will be kept under the cursor hotspot. Initially, the hotspot is at the top left corner of the drag window.

Parameters

context

a CdkDragContext

 

hot_x

x coordinate of the drag window hotspot

 

hot_y

y coordinate of the drag window hotspot

 

Since: 3.20


cdk_drag_context_manage_dnd ()

gboolean
cdk_drag_context_manage_dnd (CdkDragContext *context,
                             CdkWindow *ipc_window,
                             CdkDragAction actions);

Requests the drag and drop operation to be managed by context . When a drag and drop operation becomes managed, the CdkDragContext will internally handle all input and source-side CdkEventDND events as required by the windowing system.

Once the drag and drop operation is managed, the drag context will emit the following signals:

  • The “action-changed” signal whenever the final action to be performed by the drag and drop operation changes.

  • The “drop-performed” signal after the user performs the drag and drop gesture (typically by releasing the mouse button).

  • The “dnd-finished” signal after the drag and drop operation concludes (after all CdkSelection transfers happen).

  • The “cancel” signal if the drag and drop operation is finished but doesn't happen over an accepting destination, or is cancelled through other means.

Parameters

context

a CdkDragContext

 

ipc_window

Window to use for IPC messaging/events

 

actions

the actions supported by the drag source

 

Returns

TRUE if the drag and drop operation is managed.

Since: 3.20

Types and Values

CdkDragContext

typedef struct _CdkDragContext CdkDragContext;

enum CdkDragCancelReason

Used in CdkDragContext to the reason of a cancelled DND operation.

Members

CDK_DRAG_CANCEL_NO_TARGET

There is no suitable drop target.

 

CDK_DRAG_CANCEL_USER_CANCELLED

Drag cancelled by the user

 

CDK_DRAG_CANCEL_ERROR

Unspecified error.

 

Since: 3.20


enum CdkDragProtocol

Used in CdkDragContext to indicate the protocol according to which DND is done.

Members

CDK_DRAG_PROTO_NONE

no protocol.

 

CDK_DRAG_PROTO_MOTIF

The Motif DND protocol. No longer supported

 

CDK_DRAG_PROTO_XDND

The Xdnd protocol.

 

CDK_DRAG_PROTO_ROOTWIN

An extension to the Xdnd protocol for unclaimed root window drops.

 

CDK_DRAG_PROTO_WIN32_DROPFILES

The simple WM_DROPFILES protocol.

 

CDK_DRAG_PROTO_OLE2

The complex OLE2 DND protocol (not implemented).

 

CDK_DRAG_PROTO_LOCAL

Intra-application DND.

 

CDK_DRAG_PROTO_WAYLAND

Wayland DND protocol.

 

enum CdkDragAction

Used in CdkDragContext to indicate what the destination should do with the dropped data.

Members

CDK_ACTION_DEFAULT

Means nothing, and should not be used.

 

CDK_ACTION_COPY

Copy the data.

 

CDK_ACTION_MOVE

Move the data, i.e. first copy it, then delete it from the source using the DELETE target of the X selection protocol.

 

CDK_ACTION_LINK

Add a link to the data. Note that this is only useful if source and destination agree on what it means.

 

CDK_ACTION_PRIVATE

Special action which tells the source that the destination will do something that the source doesn’t understand.

 

CDK_ACTION_ASK

Ask the user what to do with the data.

 

Signal Details

The “action-changed” signal

void
user_function (CdkDragContext *context,
               CdkDragAction   action,
               gpointer        user_data)

A new action is being chosen for the drag and drop operation.

This signal will only be emitted if the CdkDragContext manages the drag and drop operation. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

The object on which the signal is emitted

 

action

The action currently chosen

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last

Since: 3.20


The “cancel” signal

void
user_function (CdkDragContext     *context,
               CdkDragCancelReason reason,
               gpointer            user_data)

The drag and drop operation was cancelled.

This signal will only be emitted if the CdkDragContext manages the drag and drop operation. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

The object on which the signal is emitted

 

reason

The reason the context was cancelled

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last

Since: 3.20


The “dnd-finished” signal

void
user_function (CdkDragContext *context,
               gpointer        user_data)

The drag and drop operation was finished, the drag destination finished reading all data. The drag source can now free all miscellaneous data.

This signal will only be emitted if the CdkDragContext manages the drag and drop operation. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

The object on which the signal is emitted

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last

Since: 3.20


The “drop-performed” signal

void
user_function (CdkDragContext *context,
               int             time,
               gpointer        user_data)

The drag and drop operation was performed on an accepting client.

This signal will only be emitted if the CdkDragContext manages the drag and drop operation. See cdk_drag_context_manage_dnd() for more information.

Parameters

context

The object on which the signal is emitted

 

time

the time at which the drop happened.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last

Since: 3.20