From bf0d53403fc534ca3e2c4a7736e580213bf7ce32 Mon Sep 17 00:00:00 2001 From: astar76 Date: Sat, 24 Oct 2026 19:05:30 -0500 Subject: [PATCH] 2.0.1: file drops land where hovered, release notes Co-Authored-By: Claude Sonnet 5.5 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/app.rs | 5 +++- src/ui/playlist_view.rs | 12 +++++++- tests/reorder.rs | 28 ++++++++++++++++++- .../platform_impl/linux/wayland/seat/dnd.rs | 22 ++++++++++++--- 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 23c0557..aa83d1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2201,7 +2201,7 @@ dependencies = [ [[package]] name = "mulberry" -version = "2.0.0" +version = "2.0.1" dependencies = [ "base64 0.22.1", "chrono", diff --git a/Cargo.toml b/Cargo.toml index ece00db..2a87a7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mulberry" -version = "2.0.0" +version = "2.0.1" edition = "2021" description = "A Material You music player for Linux" license = "MIT" diff --git a/src/app.rs b/src/app.rs index 5366edb..1987930 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1044,8 +1044,11 @@ impl App { return; } let paths: Vec = dropped.iter().map(|f| f.path().to_string_lossy().into_owned()).filter(|p| !p.is_empty()).collect(); + // files land where they were hovered, like a row being reordered + let row = self.area.hover_dest.take(); if !paths.is_empty() { - self.add_paths(paths, AddMode::Append); + let job = AddJob { pl: self.mgr.current, row, play: false, replace: false }; + self.start_add(paths, job); } } diff --git a/src/ui/playlist_view.rs b/src/ui/playlist_view.rs index cc34ddb..543871b 100644 --- a/src/ui/playlist_view.rs +++ b/src/ui/playlist_view.rs @@ -22,6 +22,8 @@ pub enum DragPayload { } pub struct AreaState { + /// entry index where files dragged in from a file manager would be inserted + pub hover_dest: Option, pub order: Vec, pub widths: Vec, pub visible: Vec, @@ -39,6 +41,7 @@ impl AreaState { pub fn new() -> AreaState { let n = COLUMNS.len(); let mut s = AreaState { + hover_dest: None, order: (0..n).collect(), widths: COLUMNS.iter().map(|c| c.3).collect(), visible: COLUMNS.iter().map(|c| c.2).collect(), @@ -91,6 +94,7 @@ impl AreaState { fn new_default() -> AreaState { let n = COLUMNS.len(); AreaState { + hover_dest: None, order: (0..n).collect(), widths: COLUMNS.iter().map(|c| c.3).collect(), visible: COLUMNS.iter().map(|c| c.2).collect(), @@ -476,7 +480,8 @@ fn draw_list(app: &mut App, ui: &mut Ui) { app.area.scroll_request = None; } } - let dragging = app.area.drag.is_some(); + let ext_hover = ctx.input(|i| !i.raw.hovered_files.is_empty()); + let dragging = app.area.drag.is_some() || ext_hover; let pointer = ctx.pointer_latest_pos(); // keyboard on the list @@ -669,6 +674,11 @@ fn draw_list(app: &mut App, ui: &mut Ui) { } } app.area.drop_hint = drop_row; + if !ext_hover { + app.area.hover_dest = None; + } else { + app.area.hover_dest = drop_row.map(|vr| if vr >= visible.len() { app.mgr.current_pl().entries.len() } else { visible[vr] }); + } // ---- apply interactions let toks_empty = toks.is_empty(); diff --git a/tests/reorder.rs b/tests/reorder.rs index c90c800..d137cfa 100644 --- a/tests/reorder.rs +++ b/tests/reorder.rs @@ -42,5 +42,31 @@ fn dragging_rows_shows_the_insert_line_and_reorders() { h.input_mut().events.push(Event::PointerButton { pos: pos2(480.0, 575.0), button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE }); settle(&mut h, 4); eprintln!("after: {:?}", titles(&h)); - let _ = egui::Pos2::ZERO; + // a file dragged in from a file manager lands where it was hovered + let extra = music.join("99.flac"); + assert!(std::process::Command::new("ffmpeg").args(["-v", "quiet", "-y", "-f", "lavfi", "-i", "sine=frequency=550:duration=5", "-metadata", "title=Dropped"]).arg(&extra).status().unwrap().success()); + #[derive(Debug)] + struct F(std::path::PathBuf); + impl egui::DroppedFile for F { + fn path(&self) -> &std::path::Path { + &self.0 + } + fn bytes(&self) -> Result, String> { + Ok(vec![]) + } + } + h.input_mut().hovered_files.push(egui::HoveredFile { path: Some(extra.clone()), mime: String::new() }); + for y in [500.0, 540.0, 556.0] { + h.input_mut().events.push(Event::PointerMoved(pos2(480.0, y))); + h.step(); + h.step(); + } + h.render().unwrap().save(std::env::temp_dir().join("mulberry-filehover.png")).unwrap(); + h.input_mut().hovered_files.clear(); + h.input_mut().dropped_files.push(std::sync::Arc::new(F(extra))); + settle(&mut h, 20); + let t = titles(&h); + eprintln!("after file drop: {t:?}"); + assert_eq!(t[3], "Dropped", "inserted at the hovered position: {t:?}"); + assert_eq!(t.len(), 6); } diff --git a/vendor/winit/src/platform_impl/linux/wayland/seat/dnd.rs b/vendor/winit/src/platform_impl/linux/wayland/seat/dnd.rs index 3ce21f8..7b76172 100644 --- a/vendor/winit/src/platform_impl/linux/wayland/seat/dnd.rs +++ b/vendor/winit/src/platform_impl/linux/wayland/seat/dnd.rs @@ -16,9 +16,10 @@ use sctk::reexports::client::protocol::wl_data_source::WlDataSource; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Connection, QueueHandle}; +use crate::dpi::{LogicalPosition, PhysicalPosition}; use crate::event::WindowEvent; use crate::platform_impl::wayland::state::WinitState; -use crate::platform_impl::wayland::{make_wid, WindowId}; +use crate::platform_impl::wayland::{make_wid, DeviceId, WindowId}; const URI_LIST: &str = "text/uri-list"; @@ -41,6 +42,14 @@ fn parse_uri_list(text: &str) -> Vec { } impl WinitState { + /// While a drag is over the window the pointer is grabbed by the drag, so report its position ourselves. + fn dnd_cursor(&mut self, window: WindowId, x: f64, y: f64) { + let scale = self.windows.get_mut().get(&window).map(|w| w.lock().unwrap().scale_factor()).unwrap_or(1.0); + let position: PhysicalPosition = LogicalPosition::new(x, y).to_physical(scale); + let device_id = crate::event::DeviceId(crate::platform_impl::DeviceId::Wayland(DeviceId)); + self.dnd_event(WindowEvent::CursorMoved { device_id, position }, window); + } + fn dnd_event(&mut self, event: WindowEvent, window: WindowId) { self.events_sink.push_window_event(event, window); self.dispatched_events = true; @@ -53,8 +62,8 @@ impl DataDeviceHandler for WinitState { _: &Connection, _: &QueueHandle, device: &WlDataDevice, - _x: f64, - _y: f64, + x: f64, + y: f64, surface: &WlSurface, ) { let Some(offer) = drag_offer(device) else { return }; @@ -65,6 +74,7 @@ impl DataDeviceHandler for WinitState { let wid = make_wid(surface); self.dnd_window = Some(wid); self.dnd_event(WindowEvent::HoveredFile(PathBuf::from("/")), wid); + self.dnd_cursor(wid, x, y); } else { offer.accept_mime_type(offer.serial, None); } @@ -76,7 +86,11 @@ impl DataDeviceHandler for WinitState { } } - fn motion(&mut self, _: &Connection, _: &QueueHandle, _: &WlDataDevice, _x: f64, _y: f64) {} + fn motion(&mut self, _: &Connection, _: &QueueHandle, _: &WlDataDevice, x: f64, y: f64) { + if let Some(wid) = self.dnd_window { + self.dnd_cursor(wid, x, y); + } + } fn selection(&mut self, _: &Connection, _: &QueueHandle, _: &WlDataDevice) {}