GdkDrop: drop the priv struct

Its not needed.
This commit is contained in:
Matthias Clasen 2018-07-04 00:59:18 +02:00
parent 59c2efbcd6
commit d927c3bee0
2 changed files with 48 additions and 77 deletions

View File

@ -34,16 +34,6 @@
#include "gdkpipeiostreamprivate.h" #include "gdkpipeiostreamprivate.h"
#include "gdksurface.h" #include "gdksurface.h"
typedef struct _GdkDropPrivate GdkDropPrivate;
struct _GdkDropPrivate {
GdkDevice *device;
GdkDrag *drag;
GdkContentFormats *formats;
GdkSurface *surface;
GdkDragAction actions;
};
enum { enum {
PROP_0, PROP_0,
PROP_ACTIONS, PROP_ACTIONS,
@ -57,7 +47,7 @@ enum {
static GParamSpec *properties[N_PROPERTIES] = { NULL, }; static GParamSpec *properties[N_PROPERTIES] = { NULL, };
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkDrop, gdk_drop, G_TYPE_OBJECT) G_DEFINE_ABSTRACT_TYPE (GdkDrop, gdk_drop, G_TYPE_OBJECT)
/** /**
* GdkDrop: * GdkDrop:
@ -94,7 +84,6 @@ gdk_drop_read_local_async (GdkDrop *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
GdkContentFormats *content_formats; GdkContentFormats *content_formats;
const char *mime_type; const char *mime_type;
GTask *task; GTask *task;
@ -103,7 +92,7 @@ gdk_drop_read_local_async (GdkDrop *self,
g_task_set_priority (task, io_priority); g_task_set_priority (task, io_priority);
g_task_set_source_tag (task, gdk_drop_read_local_async); g_task_set_source_tag (task, gdk_drop_read_local_async);
if (priv->drag == NULL) if (self->drag == NULL)
{ {
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
_("Drag'n'drop from other applications is not supported.")); _("Drag'n'drop from other applications is not supported."));
@ -111,7 +100,7 @@ gdk_drop_read_local_async (GdkDrop *self,
return; return;
} }
content_formats = gdk_content_provider_ref_formats (priv->drag->content); content_formats = gdk_content_provider_ref_formats (self->drag->content);
content_formats = gdk_content_formats_union_serialize_mime_types (content_formats); content_formats = gdk_content_formats_union_serialize_mime_types (content_formats);
mime_type = gdk_content_formats_match_mime_type (content_formats, formats); mime_type = gdk_content_formats_match_mime_type (content_formats, formats);
@ -122,7 +111,7 @@ gdk_drop_read_local_async (GdkDrop *self,
stream = gdk_pipe_io_stream_new (); stream = gdk_pipe_io_stream_new ();
output_stream = g_io_stream_get_output_stream (stream); output_stream = g_io_stream_get_output_stream (stream);
gdk_drag_write_async (priv->drag, gdk_drag_write_async (self->drag,
mime_type, mime_type,
output_stream, output_stream,
io_priority, io_priority,
@ -166,7 +155,6 @@ gdk_drop_set_property (GObject *gobject,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GdkDrop *self = GDK_DROP (gobject); GdkDrop *self = GDK_DROP (gobject);
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
switch (prop_id) switch (prop_id)
{ {
@ -175,26 +163,26 @@ gdk_drop_set_property (GObject *gobject,
break; break;
case PROP_DEVICE: case PROP_DEVICE:
priv->device = g_value_dup_object (value); self->device = g_value_dup_object (value);
g_assert (priv->device != NULL); g_assert (self->device != NULL);
if (priv->surface) if (self->surface)
g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device)); g_assert (gdk_surface_get_display (self->surface) == gdk_device_get_display (self->device));
break; break;
case PROP_DRAG: case PROP_DRAG:
priv->drag = g_value_dup_object (value); self->drag = g_value_dup_object (value);
break; break;
case PROP_FORMATS: case PROP_FORMATS:
priv->formats = g_value_dup_boxed (value); self->formats = g_value_dup_boxed (value);
g_assert (priv->formats != NULL); g_assert (self->formats != NULL);
break; break;
case PROP_SURFACE: case PROP_SURFACE:
priv->surface = g_value_dup_object (value); self->surface = g_value_dup_object (value);
g_assert (priv->surface != NULL); g_assert (self->surface != NULL);
if (priv->device) if (self->device)
g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device)); g_assert (gdk_surface_get_display (self->surface) == gdk_device_get_display (self->device));
break; break;
default: default:
@ -210,32 +198,31 @@ gdk_drop_get_property (GObject *gobject,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GdkDrop *self = GDK_DROP (gobject); GdkDrop *self = GDK_DROP (gobject);
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
switch (prop_id) switch (prop_id)
{ {
case PROP_ACTIONS: case PROP_ACTIONS:
g_value_set_flags (value, priv->actions); g_value_set_flags (value, self->actions);
break; break;
case PROP_DEVICE: case PROP_DEVICE:
g_value_set_object (value, priv->device); g_value_set_object (value, self->device);
break; break;
case PROP_DISPLAY: case PROP_DISPLAY:
g_value_set_object (value, gdk_device_get_display (priv->device)); g_value_set_object (value, gdk_device_get_display (self->device));
break; break;
case PROP_DRAG: case PROP_DRAG:
g_value_set_object (value, priv->drag); g_value_set_object (value, self->drag);
break; break;
case PROP_FORMATS: case PROP_FORMATS:
g_value_set_boxed (value, priv->formats); g_value_set_boxed (value, self->formats);
break; break;
case PROP_SURFACE: case PROP_SURFACE:
g_value_set_object (value, priv->surface); g_value_set_object (value, self->surface);
break; break;
default: default:
@ -248,10 +235,9 @@ static void
gdk_drop_finalize (GObject *object) gdk_drop_finalize (GObject *object)
{ {
GdkDrop *self = GDK_DROP (object); GdkDrop *self = GDK_DROP (object);
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_clear_object (&priv->device); g_clear_object (&self->device);
g_clear_object (&priv->drag); g_clear_object (&self->drag);
G_OBJECT_CLASS (gdk_drop_parent_class)->finalize (object); G_OBJECT_CLASS (gdk_drop_parent_class)->finalize (object);
} }
@ -376,11 +362,9 @@ gdk_drop_init (GdkDrop *self)
GdkDisplay * GdkDisplay *
gdk_drop_get_display (GdkDrop *self) gdk_drop_get_display (GdkDrop *self)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), NULL); g_return_val_if_fail (GDK_IS_DROP (self), NULL);
return gdk_device_get_display (priv->device); return gdk_device_get_display (self->device);
} }
/** /**
@ -394,11 +378,9 @@ gdk_drop_get_display (GdkDrop *self)
GdkDevice * GdkDevice *
gdk_drop_get_device (GdkDrop *self) gdk_drop_get_device (GdkDrop *self)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), NULL); g_return_val_if_fail (GDK_IS_DROP (self), NULL);
return priv->device; return self->device;
} }
/** /**
@ -413,11 +395,9 @@ gdk_drop_get_device (GdkDrop *self)
GdkContentFormats * GdkContentFormats *
gdk_drop_get_formats (GdkDrop *self) gdk_drop_get_formats (GdkDrop *self)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), NULL); g_return_val_if_fail (GDK_IS_DROP (self), NULL);
return priv->formats; return self->formats;
} }
/** /**
@ -431,11 +411,9 @@ gdk_drop_get_formats (GdkDrop *self)
GdkSurface * GdkSurface *
gdk_drop_get_surface (GdkDrop *self) gdk_drop_get_surface (GdkDrop *self)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), NULL); g_return_val_if_fail (GDK_IS_DROP (self), NULL);
return priv->surface; return self->surface;
} }
/** /**
@ -457,26 +435,22 @@ gdk_drop_get_surface (GdkDrop *self)
GdkDragAction GdkDragAction
gdk_drop_get_actions (GdkDrop *self) gdk_drop_get_actions (GdkDrop *self)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), 0); g_return_val_if_fail (GDK_IS_DROP (self), 0);
return priv->actions; return self->actions;
} }
void void
gdk_drop_set_actions (GdkDrop *self, gdk_drop_set_actions (GdkDrop *self,
GdkDragAction actions) GdkDragAction actions)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_if_fail (GDK_IS_DROP (self)); g_return_if_fail (GDK_IS_DROP (self));
g_return_if_fail ((actions & GDK_ACTION_ASK) == 0); g_return_if_fail ((actions & GDK_ACTION_ASK) == 0);
if (priv->actions == actions) if (self->actions == actions)
return; return;
priv->actions = actions; self->actions = actions;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]);
} }
@ -495,11 +469,9 @@ gdk_drop_set_actions (GdkDrop *self,
GdkDrag * GdkDrag *
gdk_drop_get_drag (GdkDrop *self) gdk_drop_get_drag (GdkDrop *self)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
g_return_val_if_fail (GDK_IS_DROP (self), 0); g_return_val_if_fail (GDK_IS_DROP (self), 0);
return priv->drag; return self->drag;
} }
/** /**
@ -557,9 +529,7 @@ gdk_drop_read_internal (GdkDrop *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self); if (self->drag)
if (priv->drag)
{ {
gdk_drop_read_local_async (self, gdk_drop_read_local_async (self,
formats, formats,
@ -708,7 +678,6 @@ gdk_drop_read_value_internal (GdkDrop *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
GdkContentFormatsBuilder *builder; GdkContentFormatsBuilder *builder;
GdkContentFormats *formats; GdkContentFormats *formats;
GValue *value; GValue *value;
@ -721,11 +690,11 @@ gdk_drop_read_value_internal (GdkDrop *self,
g_value_init (value, type); g_value_init (value, type);
g_task_set_task_data (task, value, free_value); g_task_set_task_data (task, value, free_value);
if (priv->drag) if (self->drag)
{ {
GError *error = NULL; GError *error = NULL;
if (gdk_content_provider_get_value (priv->drag->content, value, &error)) if (gdk_content_provider_get_value (self->drag->content, value, &error))
{ {
g_task_return_pointer (task, value, NULL); g_task_return_pointer (task, value, NULL);
g_object_unref (task); g_object_unref (task);
@ -906,14 +875,13 @@ gdk_drop_emit_enter_event (GdkDrop *self,
gboolean dont_queue, gboolean dont_queue,
guint32 time) guint32 time)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
GdkEvent *event; GdkEvent *event;
event = gdk_event_new (GDK_DRAG_ENTER); event = gdk_event_new (GDK_DRAG_ENTER);
event->any.surface = g_object_ref (priv->surface); event->any.surface = g_object_ref (self->surface);
event->dnd.drop = g_object_ref (self); event->dnd.drop = g_object_ref (self);
event->dnd.time = time; event->dnd.time = time;
gdk_event_set_device (event, priv->device); gdk_event_set_device (event, self->device);
gdk_drop_do_emit_event (event, dont_queue); gdk_drop_do_emit_event (event, dont_queue);
} }
@ -925,16 +893,15 @@ gdk_drop_emit_motion_event (GdkDrop *self,
double y_root, double y_root,
guint32 time) guint32 time)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
GdkEvent *event; GdkEvent *event;
event = gdk_event_new (GDK_DRAG_MOTION); event = gdk_event_new (GDK_DRAG_MOTION);
event->any.surface = g_object_ref (priv->surface); event->any.surface = g_object_ref (self->surface);
event->dnd.drop = g_object_ref (self); event->dnd.drop = g_object_ref (self);
event->dnd.time = time; event->dnd.time = time;
event->dnd.x_root = x_root; event->dnd.x_root = x_root;
event->dnd.y_root = y_root; event->dnd.y_root = y_root;
gdk_event_set_device (event, priv->device); gdk_event_set_device (event, self->device);
gdk_drop_do_emit_event (event, dont_queue); gdk_drop_do_emit_event (event, dont_queue);
} }
@ -944,14 +911,13 @@ gdk_drop_emit_leave_event (GdkDrop *self,
gboolean dont_queue, gboolean dont_queue,
guint32 time) guint32 time)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
GdkEvent *event; GdkEvent *event;
event = gdk_event_new (GDK_DRAG_LEAVE); event = gdk_event_new (GDK_DRAG_LEAVE);
event->any.surface = g_object_ref (priv->surface); event->any.surface = g_object_ref (self->surface);
event->dnd.drop = g_object_ref (self); event->dnd.drop = g_object_ref (self);
event->dnd.time = time; event->dnd.time = time;
gdk_event_set_device (event, priv->device); gdk_event_set_device (event, self->device);
gdk_drop_do_emit_event (event, dont_queue); gdk_drop_do_emit_event (event, dont_queue);
} }
@ -963,16 +929,15 @@ gdk_drop_emit_drop_event (GdkDrop *self,
double y_root, double y_root,
guint32 time) guint32 time)
{ {
GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
GdkEvent *event; GdkEvent *event;
event = gdk_event_new (GDK_DROP_START); event = gdk_event_new (GDK_DROP_START);
event->any.surface = g_object_ref (priv->surface); event->any.surface = g_object_ref (self->surface);
event->dnd.drop = g_object_ref (self); event->dnd.drop = g_object_ref (self);
event->dnd.time = time; event->dnd.time = time;
event->dnd.x_root = x_root; event->dnd.x_root = x_root;
event->dnd.y_root = y_root; event->dnd.y_root = y_root;
gdk_event_set_device (event, priv->device); gdk_event_set_device (event, self->device);
gdk_drop_do_emit_event (event, dont_queue); gdk_drop_do_emit_event (event, dont_queue);
} }

View File

@ -34,6 +34,12 @@ typedef struct _GdkDropClass GdkDropClass;
struct _GdkDrop { struct _GdkDrop {
GObject parent_instance; GObject parent_instance;
GdkDevice *device;
GdkDrag *drag;
GdkContentFormats *formats;
GdkSurface *surface;
GdkDragAction actions;
}; };
struct _GdkDropClass { struct _GdkDropClass {