[gnome-panel/wip-geiger-dialog: 137/138] properties-dialog: add drag-and-drop to applet list
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip-geiger-dialog: 137/138] properties-dialog: add drag-and-drop to applet list
- Date: Fri, 14 May 2021 11:27:46 +0000 (UTC)
commit 434bd7e6e45fca79b9c37eb177dc6640a93aced9
Author: Sebastian Geiger <sbastig gmx net>
Date: Sun Apr 19 21:20:46 2020 +0200
properties-dialog: add drag-and-drop to applet list
Functionality to update applet position on panel is still missing.
data/theme/common.css | 4 ++
gnome-panel/gp-applet-list-row.c | 93 ++++++++++++++++++++++++++++++++--------
2 files changed, 78 insertions(+), 19 deletions(-)
---
diff --git a/data/theme/common.css b/data/theme/common.css
index c1f63c3de..2b2a1d075 100644
--- a/data/theme/common.css
+++ b/data/theme/common.css
@@ -111,3 +111,7 @@ gp-handle {
.context-row {
padding: 4px 10px;
}
+
+.applet-list-row-drag-icon {
+ background-color: #ffffff;
+}
diff --git a/gnome-panel/gp-applet-list-row.c b/gnome-panel/gp-applet-list-row.c
index 893f67c24..233cf9c70 100644
--- a/gnome-panel/gp-applet-list-row.c
+++ b/gnome-panel/gp-applet-list-row.c
@@ -53,6 +53,10 @@ enum
static GParamSpec *row_properties[LAST_PROP] = { NULL };
+static GtkTargetEntry entries[] = {
+ { (gchar *)"GTK_LIST_BOX_ROW", GTK_TARGET_SAME_APP, 0 }
+};
+
G_DEFINE_TYPE (GpAppletListRow, gp_applet_list_row, GTK_TYPE_LIST_BOX_ROW)
static void
@@ -139,41 +143,92 @@ drag_data_get_cb (GtkWidget *widget,
GpAppletListRow *self)
{
gtk_selection_data_set (data,
- gtk_selection_data_get_target (data),
+ gdk_atom_intern_static_string ("GTK_LIST_BOX_ROW"),
8,
- (const guchar *) self->iid,
- strlen (self->iid));
+ (const guchar *)&widget,
+ sizeof (gpointer));
}
static void
-setup_drag_source (GpAppletListRow *self)
+drag_data_received_cb (GtkWidget *target,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer user_data)
{
- GpAppletInfo *info;
- GdkModifierType modifiers;
- GdkDragAction actions;
- GtkTargetList *target_list;
- GdkAtom target;
+ gpointer handle;
+ GtkWidget *source;
+ GtkWidget *source_list;
+ GtkWidget *target_list;
+ int position;
- info = gp_module_get_applet_info (self->module, self->applet_id, NULL);
+ handle = *(gpointer*) gtk_selection_data_get_data (selection_data);
+ source = gtk_widget_get_ancestor (handle, GTK_TYPE_LIST_BOX_ROW);
- modifiers = GDK_BUTTON1_MASK | GDK_BUTTON2_MASK;
- actions = GDK_ACTION_COPY;
+ if (source == target)
+ return;
- gtk_drag_source_set (self->event_box, modifiers, NULL, 0, actions);
- gtk_drag_source_set_icon_name (self->event_box, info->icon_name);
+ source_list = gtk_widget_get_parent (source);
+ target_list = gtk_widget_get_parent (target);
+ position = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (target));
- target_list = gtk_target_list_new (NULL, 0);
+ g_object_ref (source);
+
+ gtk_container_remove (GTK_CONTAINER (source_list), source);
+ gtk_list_box_insert (GTK_LIST_BOX (target_list), source, position);
+ g_object_unref (source);
+}
+
+static void
+drag_begin (GtkWidget *widget,
+ GdkDragContext *context,
+ gpointer user_data)
+{
+ GtkWidget *row;
+ GtkAllocation alloc;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ GtkStyleContext *style_context;
- target = gdk_atom_intern_static_string ("application/x-panel-applet-iid");
- gtk_target_list_add (target_list, target, 0, 0);
+ row = gtk_widget_get_ancestor (widget, GTK_TYPE_LIST_BOX_ROW);
+ gtk_widget_get_allocation (row, &alloc);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ alloc.width, alloc.height);
- gtk_drag_source_set_target_list (self->event_box, target_list);
- gtk_target_list_unref (target_list);
+ cr = cairo_create (surface);
+
+ style_context = gtk_widget_get_style_context (row);
+ gtk_style_context_add_class (style_context, "applet-list-row-drag-icon");
+ gtk_widget_draw (row, cr);
+ gtk_style_context_remove_class (style_context, "applet-list-row-drag-icon");
+
+ gtk_drag_set_icon_surface (context, surface);
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+}
+
+static void
+setup_drag_source (GpAppletListRow *self)
+{
+ gtk_drag_source_set (self->event_box, GDK_BUTTON1_MASK, entries, 1, GDK_ACTION_MOVE);
+ gtk_drag_dest_set (GTK_WIDGET (self), GTK_DEST_DEFAULT_ALL, entries, 1, GDK_ACTION_MOVE);
g_signal_connect (self->event_box,
"drag-data-get",
G_CALLBACK (drag_data_get_cb),
self);
+
+ g_signal_connect (self,
+ "drag-data-received",
+ G_CALLBACK (drag_data_received_cb),
+ NULL);
+
+ g_signal_connect_after (self->event_box, "drag-begin",
+ G_CALLBACK (drag_begin), NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]