diff --git a/src/ui/play_queue.vala b/src/ui/play_queue.vala index d5d2d3f..07e8976 100644 --- a/src/ui/play_queue.vala +++ b/src/ui/play_queue.vala @@ -1,3 +1,5 @@ +// song widget+drag behavior taken from gnome music + [GtkTemplate (ui = "/eu/callcc/audrey/ui/play_queue_song.ui")] class Ui.PlayQueueSong : Gtk.ListBoxRow { public bool draggable { get; set; default = false; } @@ -57,12 +59,46 @@ class Ui.PlayQueueSong : Gtk.ListBoxRow { return starred == null ? "non-starred" : "starred"; } + private double drag_x; + private double drag_y; + [GtkCallback] private Gdk.ContentProvider? on_drag_prepare (double x, double y) { - if (this.draggable) return new Gdk.ContentProvider.for_value (this); + if (this.draggable) { + this.drag_x = x; + this.drag_y = y; + return new Gdk.ContentProvider.for_value (this); + } else return null; } + private Gtk.ListBox? drag_widget; + + [GtkCallback] private void on_drag_begin (Gtk.DragSource source, Gdk.Drag drag) { + this.drag_widget = new Gtk.ListBox (); + this.drag_widget.set_size_request (this.get_width (), this.get_height ()); + + var drag_row = new PlayQueueSong (this.playbin); + drag_row.draggable = false; + drag_row.show_artist = this.show_artist; + drag_row.show_album = this.show_album; + drag_row.current = false; + drag_row.displayed_position = this.displayed_position; + drag_row.song = this.song; + drag_row.play_icon_name = this.play_icon_name; + + this.drag_widget.append (drag_row); + this.drag_widget.drag_highlight_row (drag_row); + + var drag_icon = Gtk.DragIcon.get_for_drag (drag); + drag_icon.set("child", this.drag_widget); + drag.set_hotspot ((int) this.drag_x, (int) this.drag_y); + } + [GtkCallback] private bool on_drop (Value value, double x, double y) { + this.drag_widget = null; + this.drag_x = 0.0; + this.drag_y = 0.0; + var source = value as PlayQueueSong; debug ("dropped %u on %u", source.displayed_position, this.displayed_position); this.playbin.move_track (source.displayed_position-1, this.displayed_position-1); diff --git a/src/ui/play_queue_song.blp b/src/ui/play_queue_song.blp index b3969b7..0a008dc 100644 --- a/src/ui/play_queue_song.blp +++ b/src/ui/play_queue_song.blp @@ -124,6 +124,7 @@ template $UiPlayQueueSong: ListBoxRow { propagation-phase: capture; prepare => $on_drag_prepare (); + drag-begin => $on_drag_begin (); } DropTarget {