Ctrl+V pastes files copied in a file manager; drop hint overlay; XWayland opt-in
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
0838c0ea61
commit
be52a05960
7 changed files with 83 additions and 1 deletions
12
src/app.rs
12
src/app.rs
|
|
@ -901,6 +901,7 @@ impl App {
|
|||
if i.consume_key(cs, Key::S) { act = Some("export_all"); }
|
||||
else if i.consume_key(c, Key::S) { act = Some("export"); }
|
||||
if i.consume_key(c, Key::H) { act = Some("toggle_shuffle"); }
|
||||
if !typing && i.consume_key(c, Key::V) { act = Some("paste_files"); }
|
||||
if i.consume_key(cs, Key::O) { act = Some("open_folder"); }
|
||||
else if i.consume_key(c, Key::O) { act = Some("open"); }
|
||||
if i.consume_key(Modifiers::COMMAND | Modifiers::ALT, Key::V) { act = Some("stop_after"); }
|
||||
|
|
@ -1007,6 +1008,17 @@ impl App {
|
|||
"shape" => { let v = !settings().get_bool("appearance/floating_shape"); settings().set("appearance/floating_shape", v); }
|
||||
"shape_morph" => {}
|
||||
"about" => self.dialog = Some(Dialog::About),
|
||||
"paste_files" => {
|
||||
let bus = self.bus.clone();
|
||||
std::thread::spawn(move || {
|
||||
let paths = util::clipboard_files();
|
||||
if paths.is_empty() {
|
||||
bus.toast("No files on the clipboard (copy them in your file manager first)");
|
||||
} else {
|
||||
bus.send(Msg::Picked { purpose: "paste_files".into(), paths });
|
||||
}
|
||||
});
|
||||
}
|
||||
"noop" => {}
|
||||
"selall" => {
|
||||
let pl = self.mgr.current_mut();
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ fn defaults() -> BTreeMap<&'static str, Value> {
|
|||
("appearance/font", json!("")),
|
||||
("appearance/notifications", json!(true)),
|
||||
("appearance/tray", json!(true)),
|
||||
("appearance/use_x11", json!(true)),
|
||||
("appearance/use_x11", json!(false)),
|
||||
("appearance/floating_shape", json!(true)),
|
||||
("appearance/max_fps", json!(30)),
|
||||
("lastfm/enabled", json!(false)),
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ fn main() -> eframe::Result {
|
|||
}
|
||||
// winit cannot receive file drops from file managers on Wayland; through XWayland it can
|
||||
if config::settings().get_bool("appearance/use_x11") && std::env::var_os("DISPLAY").is_some() && std::env::var_os("WAYLAND_DISPLAY").is_some() {
|
||||
if let Some(w) = std::env::var_os("WAYLAND_DISPLAY") {
|
||||
std::env::set_var("MULBERRY_WAYLAND_DISPLAY", w);
|
||||
}
|
||||
std::env::remove_var("WAYLAND_DISPLAY");
|
||||
}
|
||||
let viewport = egui::ViewportBuilder::default()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! Top-level window layout: menu bar, sidebar, hero, playlists, bottom bar and overlays.
|
||||
|
||||
use super::gfx::cr;
|
||||
use super::widgets::*;
|
||||
use super::{hero, menus, playlist_view, sidebar};
|
||||
use crate::app::App;
|
||||
|
|
@ -79,6 +80,15 @@ pub fn draw(app: &mut App, ui: &mut Ui) {
|
|||
}
|
||||
}
|
||||
|
||||
// ---- drop hint while a file is dragged over the window
|
||||
if ctx.input(|i| !i.raw.hovered_files.is_empty()) {
|
||||
let r = ctx.content_rect();
|
||||
let p = ctx.layer_painter(egui::LayerId::new(egui::Order::Foreground, Id::new("drop-hint")));
|
||||
p.rect_filled(r, 0.0, with_alpha(t.surface, 0.55));
|
||||
p.rect_stroke(r.shrink(10.0), cr(24.0), egui::Stroke::new(3.0, t.primary), egui::StrokeKind::Inside);
|
||||
p.text(r.center(), Align2::CENTER_CENTER, "Drop to add to the playlist", egui::FontId::proportional(24.0), t.primary);
|
||||
}
|
||||
|
||||
// ---- popups
|
||||
menus::show(app, &ctx);
|
||||
if app.area.drag.is_some() && ctx.input(|i| i.pointer.any_released()) {
|
||||
|
|
|
|||
|
|
@ -240,6 +240,7 @@ fn bar_menu(app: &mut App, ui: &mut Ui, i: usize, act: &mut Option<Act>) {
|
|||
}
|
||||
1 => {
|
||||
item(ui, g, act, Some("playlist_add"), "New playlist", "Ctrl+T", Act::Do("newpl"), None);
|
||||
item(ui, g, act, Some("content_copy"), "Paste files from file manager", "Ctrl+V", Act::Do("paste_files"), None);
|
||||
item(ui, g, act, Some("file_open"), "Import playlist…", "Ctrl+I", Act::Do("import"), None);
|
||||
item(ui, g, act, Some("save"), "Export playlist…", "Ctrl+S", Act::Do("export"), None);
|
||||
item(ui, g, act, Some("download"), "Export all playlists…", "Ctrl+Shift+S", Act::Do("export_all"), None);
|
||||
|
|
@ -746,6 +747,7 @@ impl App {
|
|||
pub fn on_picked(&mut self, purpose: &str, paths: Vec<String>) {
|
||||
match purpose {
|
||||
"open_files" => self.add_paths(paths, AddMode::Play),
|
||||
"paste_files" => self.add_paths(paths, AddMode::Append),
|
||||
"open_folder" => self.add_paths(paths, AddMode::Play),
|
||||
"add_library_folder" => {
|
||||
if let Some(d) = paths.first() {
|
||||
|
|
|
|||
43
src/util.rs
43
src/util.rs
|
|
@ -93,3 +93,46 @@ pub fn themed_icon(bg: eframe::egui::Color32, fg: eframe::egui::Color32, size: u
|
|||
}
|
||||
rgba
|
||||
}
|
||||
|
||||
/// Files copied in a file manager (Thunar, Dolphin, Nautilus…): read `text/uri-list` or
|
||||
/// `x-special/gnome-copied-files` from the clipboard with wl-paste / xclip.
|
||||
pub fn clipboard_files() -> Vec<String> {
|
||||
let wl = std::env::var_os("MULBERRY_WAYLAND_DISPLAY").or_else(|| std::env::var_os("WAYLAND_DISPLAY"));
|
||||
let run = |prog: &str, args: &[&str]| -> Option<String> {
|
||||
let mut c = std::process::Command::new(prog);
|
||||
c.args(args).stdin(std::process::Stdio::null()).stderr(std::process::Stdio::null());
|
||||
if let Some(w) = &wl {
|
||||
c.env("WAYLAND_DISPLAY", w);
|
||||
}
|
||||
let o = c.output().ok()?;
|
||||
o.status.success().then(|| String::from_utf8_lossy(&o.stdout).into_owned())
|
||||
};
|
||||
let mut text = String::new();
|
||||
if wl.is_some() {
|
||||
if let Some(types) = run("wl-paste", &["-l"]) {
|
||||
for ty in ["text/uri-list", "x-special/gnome-copied-files"] {
|
||||
if types.lines().any(|l| l.trim() == ty) {
|
||||
if let Some(t) = run("wl-paste", &["-t", ty]) {
|
||||
text = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if text.is_empty() {
|
||||
for ty in ["text/uri-list", "x-special/gnome-copied-files"] {
|
||||
if let Some(t) = run("xclip", &["-selection", "clipboard", "-t", ty, "-o"]) {
|
||||
if !t.trim().is_empty() {
|
||||
text = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
text.lines()
|
||||
.map(str::trim)
|
||||
.filter_map(|l| l.strip_prefix("file://"))
|
||||
.map(|p| crate::song::percent_decode(p))
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
12
tests/clip.rs
Normal file
12
tests/clip.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#[test]
|
||||
fn reads_copied_files_from_clipboard() {
|
||||
if std::env::var_os("WAYLAND_DISPLAY").is_none() || std::process::Command::new("wl-copy").arg("--version").output().is_err() {
|
||||
return;
|
||||
}
|
||||
let mut c = std::process::Command::new("wl-copy").args(["-t", "text/uri-list"]).stdin(std::process::Stdio::piped()).spawn().unwrap();
|
||||
use std::io::Write;
|
||||
c.stdin.take().unwrap().write_all(b"file:///tmp/a%20b.flac\r\nfile:///tmp/c.opus\r\n").unwrap();
|
||||
c.wait().unwrap();
|
||||
std::thread::sleep(std::time::Duration::from_millis(200));
|
||||
assert_eq!(mulberry::util::clipboard_files(), vec!["/tmp/a b.flac", "/tmp/c.opus"]);
|
||||
}
|
||||
Loading…
Reference in a new issue