dnd: Add a GdkDrag::action property

This lets us drop the ::action-changed signal for the
property change notification. But, can just as well move
the signal class handers which just update the cursor
to the ::action setter. No need to do this in the backends.
This commit is contained in:
Matthias Clasen 2018-07-03 01:16:47 +02:00
parent 63ab523146
commit db0b9f61ae
5 changed files with 55 additions and 74 deletions

View File

@ -64,6 +64,7 @@ enum {
PROP_DEVICE,
PROP_DISPLAY,
PROP_FORMATS,
PROP_ACTION,
N_PROPERTIES
};
@ -71,7 +72,6 @@ enum {
CANCEL,
DROP_PERFORMED,
DND_FINISHED,
ACTION_CHANGED,
N_SIGNALS
};
@ -260,6 +260,13 @@ gdk_drag_set_property (GObject *gobject,
}
break;
case PROP_ACTION:
{
GdkDragAction action = g_value_get_flags (value);
gdk_drag_set_action (drag, action);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -293,6 +300,10 @@ gdk_drag_get_property (GObject *gobject,
g_value_set_boxed (value, priv->formats);
break;
case PROP_ACTION:
g_value_set_flags (value, drag->action);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
@ -384,6 +395,16 @@ gdk_drag_class_init (GdkDragClass *klass)
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_ACTION] =
g_param_spec_flags ("action",
"Action",
"The currently selected action",
GDK_TYPE_DRAG_ACTION,
0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* GdkDrag::cancel:
* @drag: The object on which the signal is emitted
@ -432,22 +453,6 @@ gdk_drag_class_init (GdkDragClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GdkDrag::action-changed:
* @drag: The object on which the signal is emitted
* @action: The action currently chosen
*
* A new action is being chosen for the drag operation.
*/
signals[ACTION_CHANGED] =
g_signal_new (g_intern_static_string ("action-changed"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GdkDragClass, action_changed),
NULL, NULL,
g_cclosure_marshal_VOID__FLAGS,
G_TYPE_NONE, 1, GDK_TYPE_DRAG_ACTION);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
@ -617,6 +622,23 @@ gdk_drag_set_actions (GdkDrag *drag,
priv->suggested_action = suggested_action;
}
void
gdk_drag_set_action (GdkDrag *drag,
GdkDragAction action)
{
GdkCursor *cursor;
if (drag->action == action)
return;
drag->action = action;
cursor = gdk_drag_get_cursor (drag, action);
gdk_drag_set_cursor (drag, cursor);
g_object_notify_by_pspec (G_OBJECT (drag), properties[PROP_ACTION]);
}
/**
* gdk_drag_get_drag_surface:
* @drag: a #GdkDrag

View File

@ -54,8 +54,6 @@ struct _GdkDragClass {
gboolean (*handle_event) (GdkDrag *drag,
const GdkEvent *event);
void (*action_changed) (GdkDrag *drag,
GdkDragAction action);
};
struct _GdkDrag {
@ -76,6 +74,8 @@ void gdk_drag_set_cursor (GdkDrag *drag,
void gdk_drag_set_actions (GdkDrag *drag,
GdkDragAction actions,
GdkDragAction suggested_action);
void gdk_drag_set_action (GdkDrag *drag,
GdkDragAction action);
void gdk_drag_cancel (GdkDrag *drag,
GdkDragCancelReason reason);

View File

@ -124,7 +124,7 @@ gdk_wayland_drag_init (GdkWaylandDrag *drag_wayland)
drag = GDK_DRAG (drag_wayland);
drags = g_list_prepend (drags, drag);
drag->action = GDK_ACTION_COPY;
gdk_drag_set_action (drag, GDK_ACTION_COPY);
}
static GdkSurface *
@ -160,17 +160,8 @@ gdk_wayland_drag_set_cursor (GdkDrag *drag,
{
GdkDevice *device = gdk_drag_get_device (drag);
gdk_wayland_seat_set_global_cursor (gdk_device_get_seat (device), cursor);
}
static void
gdk_wayland_drag_action_changed (GdkDrag *drag,
GdkDragAction action)
{
GdkCursor *cursor;
cursor = gdk_drag_get_cursor (drag, action);
gdk_drag_set_cursor (drag, cursor);
if (device != NULL)
gdk_wayland_seat_set_global_cursor (gdk_device_get_seat (device), cursor);
}
static void
@ -217,7 +208,6 @@ gdk_wayland_drag_class_init (GdkWaylandDragClass *klass)
drag_class->set_hotspot = gdk_wayland_drag_set_hotspot;
drag_class->drop_done = gdk_wayland_drag_drop_done;
drag_class->set_cursor = gdk_wayland_drag_set_cursor;
drag_class->action_changed = gdk_wayland_drag_action_changed;
drag_class->drop_performed = gdk_wayland_drag_drop_performed;
drag_class->cancel = gdk_wayland_drag_cancel;
}
@ -345,8 +335,7 @@ data_source_action (void *data,
g_message ("data source action, source = %p action=%x",
source, action));
drag->action = _wl_to_gdk_actions (action);
g_signal_emit_by_name (drag, "action-changed", drag->action);
gdk_drag_set_action (drag, _wl_to_gdk_actions (action));
}
static const struct wl_data_source_listener data_source_listener = {

View File

@ -1072,7 +1072,7 @@ maybe_emit_action_changed (GdkWin32Drag *drag_win32,
if (actions != drag_win32->current_action)
{
drag_win32->current_action = actions;
g_signal_emit_by_name (GDK_DRAG (drag_win32), "action-changed", actions);
gdk_drag_set_action (GDK_DRAG (drag_win32), actions);
}
}

View File

@ -170,8 +170,6 @@ static void gdk_surface_cache_unref (GdkSurfaceCache *cache);
gboolean gdk_x11_drag_handle_event (GdkDrag *drag,
const GdkEvent *event);
void gdk_x11_drag_action_changed (GdkDrag *drag,
GdkDragAction action);
static GList *drags;
static GSList *window_caches;
@ -232,7 +230,6 @@ gdk_x11_drag_class_init (GdkX11DragClass *klass)
drag_class->cancel = gdk_x11_drag_cancel;
drag_class->drop_performed = gdk_x11_drag_drop_performed;
drag_class->handle_event = gdk_x11_drag_handle_event;
drag_class->action_changed = gdk_x11_drag_action_changed;
}
static void
@ -882,13 +879,8 @@ gdk_x11_drag_handle_status (GdkDisplay *display,
action = 0;
}
drag->action = xdnd_action_from_atom (display, action);
if (drag->action != drag_x11->current_action)
{
drag_x11->current_action = drag->action;
g_signal_emit_by_name (drag, "action-changed", drag->action);
}
gdk_drag_set_action (drag, xdnd_action_from_atom (display, action));
drag_x11->current_action = action;
}
}
@ -1010,12 +1002,8 @@ send_client_message_async_cb (Window window,
window == drag_x11->proxy_xid)
{
drag_x11->proxy_xid = None;
drag->action = 0;
if (drag->action != drag_x11->current_action)
{
drag_x11->current_action = 0;
g_signal_emit_by_name (drag, "action-changed", 0);
}
gdk_drag_set_action (drag, 0);
drag_x11->current_action = 0;
drag_x11->drag_status = GDK_DRAG_STATUS_DRAG;
}
@ -1558,17 +1546,13 @@ gdk_x11_drag_drag_motion (GdkDrag *drag,
{
drag_x11->proxy_xid = None;
drag_x11->drop_xid = None;
drag->action = 0;
gdk_drag_set_action (drag, 0);
}
/* Push a status event, to let the client know that
* the drag changed
*/
if (drag->action != drag_x11->current_action)
{
drag_x11->current_action = drag->action;
g_signal_emit_by_name (drag, "action-changed", drag->action);
}
drag_x11->current_action = gdk_drag_get_selected_action (drag);
}
/* Send a drag-motion event */
@ -1597,15 +1581,11 @@ gdk_x11_drag_drag_motion (GdkDrag *drag,
*/
if (gdk_content_formats_contain_mime_type (formats, "application/x-rootwindow-drop") ||
gdk_content_formats_contain_mime_type (formats, "application/x-rootwin-drop"))
drag->action = gdk_drag_get_suggested_action (drag);
gdk_drag_set_action (drag, gdk_drag_get_suggested_action (drag));
else
drag->action = 0;
gdk_drag_set_action (drag, 0);
if (drag->action != drag_x11->current_action)
{
drag_x11->current_action = drag->action;
g_signal_emit_by_name (drag, "action-changed", drag->action);
}
drag_x11->current_action = gdk_drag_get_selected_action (drag);
}
break;
case GDK_DRAG_PROTO_NONE:
@ -2448,13 +2428,3 @@ gdk_x11_drag_handle_event (GdkDrag *drag,
return FALSE;
}
void
gdk_x11_drag_action_changed (GdkDrag *drag,
GdkDragAction action)
{
GdkCursor *cursor;
cursor = gdk_drag_get_cursor (drag, action);
gdk_drag_set_cursor (drag, cursor);
}