From 3299686041cd6ce1bae67b3812235dbe079e3d29 Mon Sep 17 00:00:00 2001 From: Julian Schacher Date: Mon, 24 Oct 2022 01:07:24 +0200 Subject: [PATCH] Update: Show drag icon when reordering `PrefsBoxOrderItemRow`s using DND The following code from GNOME/gnome-control-center was used as a reference to make this code work: - https://gitlab.gnome.org/GNOME/gnome-control-center/-/blob/ab7d752de959b26fc94d54cc67b11464be5dbe2f/panels/search/cc-search-panel-row.c#L96 - https://gitlab.gnome.org/GNOME/gnome-control-center/-/blob/ab7d752de959b26fc94d54cc67b11464be5dbe2f/panels/search/cc-search-panel-row.c#L84 --- src/prefsModules/PrefsBoxOrderItemRow.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/prefsModules/PrefsBoxOrderItemRow.js b/src/prefsModules/PrefsBoxOrderItemRow.js index f596ddc..8904d76 100644 --- a/src/prefsModules/PrefsBoxOrderItemRow.js +++ b/src/prefsModules/PrefsBoxOrderItemRow.js @@ -46,13 +46,28 @@ var PrefsBoxOrderItemRow = GObject.registerClass({ // `this`. let dragSource = new Gtk.DragSource(); dragSource.set_actions(Gdk.DragAction.MOVE); - dragSource.connect("prepare", () => { + dragSource.connect("prepare", (source, x, y) => { + this._drag_starting_point_x = x; + this._drag_starting_point_y = y; return Gdk.ContentProvider.new_for_value(this); }); // Stop all scrolling, which is due to this DND operation. dragSource.connect("drag-end", () => { scrollManager.stopScrollAll(); }); + dragSource.connect("drag-begin", (source, drag) => { + let dragWidget = new Gtk.ListBox(); + let allocation = this.get_allocation(); + dragWidget.set_size_request(allocation.width, allocation.height); + + let dragPrefsBoxOrderItemRow = new PrefsBoxOrderItemRow({}, null, this.item) + dragWidget.append(dragPrefsBoxOrderItemRow); + dragWidget.drag_highlight_row(dragPrefsBoxOrderItemRow); + + let currentDragIcon = Gtk.DragIcon.get_for_drag(drag); + currentDragIcon.set_child(dragWidget); + drag.set_hotspot(this._drag_starting_point_x, this._drag_starting_point_y); + }); this.add_controller(dragSource); /// Make `this` accept drops by creating a drop target and adding it to