2.0.1: file drops land where hovered, release notes

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
astar76 2026-10-24 19:05:30 -05:00
commit bf0d53403f
6 changed files with 62 additions and 9 deletions

2
Cargo.lock generated
View file

@ -2201,7 +2201,7 @@ dependencies = [
[[package]]
name = "mulberry"
version = "2.0.0"
version = "2.0.1"
dependencies = [
"base64 0.22.1",
"chrono",

View file

@ -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"

View file

@ -1044,8 +1044,11 @@ impl App {
return;
}
let paths: Vec<String> = 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);
}
}

View file

@ -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<usize>,
pub order: Vec<usize>,
pub widths: Vec<f32>,
pub visible: Vec<bool>,
@ -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();

View file

@ -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<Vec<u8>, 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);
}

View file

@ -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<PathBuf> {
}
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<f64> = 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<Self>,
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<Self>, _: &WlDataDevice, _x: f64, _y: f64) {}
fn motion(&mut self, _: &Connection, _: &QueueHandle<Self>, _: &WlDataDevice, x: f64, y: f64) {
if let Some(wid) = self.dnd_window {
self.dnd_cursor(wid, x, y);
}
}
fn selection(&mut self, _: &Connection, _: &QueueHandle<Self>, _: &WlDataDevice) {}