Fix clipboard shortcuts, menu alignment, shape button and lyrics editor
- Enable eframe's clipboard feature so Ctrl+C/X/V work in text fields - Playlist/player shortcuts no longer fire while typing in a text box - Remove "Paste files from file manager" menu item; Ctrl+V still adds copied file:// paths when no text field has focus - Submenu rows use the same font/icon metrics as other rows, and all menu rows span the full menu width - "Change shape" in the floating shape menu now morphs the shape - Edit lyrics opens with the currently active lyrics from any source Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
a505cdb89d
commit
3a241d4d17
6 changed files with 142 additions and 34 deletions
100
Cargo.lock
generated
100
Cargo.lock
generated
|
|
@ -552,18 +552,42 @@ dependencies = [
|
|||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop"
|
||||
version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43b32313e937c8721c9d17ee9bf60699a6402b4b7c2cb6ac1bee0ffcaa4b4e5e"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"polling",
|
||||
"rustix 1.1.5",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20"
|
||||
dependencies = [
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"rustix 0.38.44",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa"
|
||||
dependencies = [
|
||||
"calloop 0.14.5",
|
||||
"rustix 1.1.5",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.10.0"
|
||||
|
|
@ -1000,6 +1024,7 @@ dependencies = [
|
|||
"objc2-ui-kit 0.3.2",
|
||||
"profiling",
|
||||
"raw-window-handle",
|
||||
"smithay-clipboard",
|
||||
"web-time",
|
||||
"windows-sys 0.61.2",
|
||||
"winit",
|
||||
|
|
@ -3655,8 +3680,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"calloop",
|
||||
"calloop-wayland-source",
|
||||
"calloop 0.13.0",
|
||||
"calloop-wayland-source 0.3.0",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
|
|
@ -3673,6 +3698,44 @@ dependencies = [
|
|||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-client-toolkit"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"calloop 0.14.5",
|
||||
"calloop-wayland-source 0.4.1",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix 1.1.5",
|
||||
"thiserror 2.0.21",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
"wayland-cursor",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-experimental",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
"wayland-scanner",
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-clipboard"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"smithay-client-toolkit 0.20.0",
|
||||
"wayland-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.2.2"
|
||||
|
|
@ -3995,6 +4058,7 @@ version = "0.1.44"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
|
|
@ -4386,6 +4450,32 @@ dependencies = [
|
|||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-experimental"
|
||||
version = "20250721.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-misc"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e9567599ef23e09b8dad6e429e5738d4509dfc46b3b21f32841a304d16b29c8"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-plasma"
|
||||
version = "0.3.12"
|
||||
|
|
@ -4873,7 +4963,7 @@ dependencies = [
|
|||
"bitflags 2.13.2",
|
||||
"block2 0.5.1",
|
||||
"bytemuck",
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"cfg_aliases",
|
||||
"concurrent-queue",
|
||||
"core-foundation",
|
||||
|
|
@ -4894,7 +4984,7 @@ dependencies = [
|
|||
"raw-window-handle",
|
||||
"redox_syscall 0.4.1",
|
||||
"rustix 0.38.44",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"smol_str",
|
||||
"tracing",
|
||||
"unicode-segmentation",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ description = "A Material You music player for Linux"
|
|||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
eframe = { version = "0.37", default-features = false, features = ["glow", "wayland", "x11", "default_fonts", "system_fonts"] }
|
||||
eframe = { version = "0.37", default-features = false, features = ["glow", "wayland", "x11", "clipboard", "default_fonts", "system_fonts"] }
|
||||
rusqlite = { version = "0.41", features = ["bundled"] }
|
||||
lofty = "0.25"
|
||||
libmpv2 = "6"
|
||||
|
|
|
|||
42
src/app.rs
42
src/app.rs
|
|
@ -229,6 +229,9 @@ impl App {
|
|||
if token == self.np.lyr_token || source == "loading" {
|
||||
self.hero.on_lyrics(&text, &source, self.np.song.as_ref().map(|s| s.is_stream()).unwrap_or(false));
|
||||
if source != "loading" {
|
||||
// the editor opens on whatever lyrics are active, whichever source they came from
|
||||
self.np.lyrics = text.clone();
|
||||
self.np.lyrics_source = source.clone();
|
||||
let pos = self.player.pos();
|
||||
self.hero.lyrics.set_position(pos);
|
||||
}
|
||||
|
|
@ -881,27 +884,28 @@ impl App {
|
|||
let c = Modifiers::COMMAND;
|
||||
let cs = Modifiers::COMMAND | Modifiers::SHIFT;
|
||||
if i.consume_key(Modifiers::NONE, Key::F11) { act = Some("focus"); }
|
||||
if i.consume_key(c, Key::ArrowRight) { act = Some("next"); }
|
||||
if i.consume_key(c, Key::ArrowLeft) { act = Some("prev"); }
|
||||
if i.consume_key(Modifiers::ALT, Key::ArrowRight) { act = Some("seek+"); }
|
||||
if i.consume_key(Modifiers::ALT, Key::ArrowLeft) { act = Some("seek-"); }
|
||||
if i.consume_key(c, Key::ArrowUp) { act = Some("vol+"); }
|
||||
if i.consume_key(c, Key::ArrowDown) { act = Some("vol-"); }
|
||||
if i.consume_key(c, Key::M) { act = Some("mute"); }
|
||||
if i.consume_key(c, Key::T) { act = Some("newpl"); }
|
||||
if i.consume_key(c, Key::W) { act = Some("closepl"); }
|
||||
if i.consume_key(c, Key::J) { act = Some("jump"); }
|
||||
if i.consume_key(c, Key::D) { act = Some("queue"); }
|
||||
if i.consume_key(c, Key::E) { act = Some("tags"); }
|
||||
if !typing && i.consume_key(c, Key::ArrowRight) { act = Some("next"); }
|
||||
if !typing && i.consume_key(c, Key::ArrowLeft) { act = Some("prev"); }
|
||||
if !typing && i.consume_key(Modifiers::ALT, Key::ArrowRight) { act = Some("seek+"); }
|
||||
if !typing && i.consume_key(Modifiers::ALT, Key::ArrowLeft) { act = Some("seek-"); }
|
||||
if !typing && i.consume_key(c, Key::ArrowUp) { act = Some("vol+"); }
|
||||
if !typing && i.consume_key(c, Key::ArrowDown) { act = Some("vol-"); }
|
||||
if !typing && i.consume_key(c, Key::M) { act = Some("mute"); }
|
||||
if !typing && i.consume_key(c, Key::T) { act = Some("newpl"); }
|
||||
if !typing && i.consume_key(c, Key::W) { act = Some("closepl"); }
|
||||
if !typing && i.consume_key(c, Key::J) { act = Some("jump"); }
|
||||
if !typing && i.consume_key(c, Key::D) { act = Some("queue"); }
|
||||
if !typing && i.consume_key(c, Key::E) { act = Some("tags"); }
|
||||
if i.consume_key(c, Key::F) { act = Some("filter"); }
|
||||
if i.consume_key(c, Key::L) { act = Some("love"); }
|
||||
if i.consume_key(c, Key::U) { act = Some("url"); }
|
||||
if i.consume_key(cs, Key::Z) { act = Some("redo"); }
|
||||
else if i.consume_key(c, Key::Z) { act = Some("undo"); }
|
||||
if !typing && i.consume_key(c, Key::L) { act = Some("love"); }
|
||||
if !typing && i.consume_key(c, Key::U) { act = Some("url"); }
|
||||
if !typing && i.consume_key(cs, Key::Z) { act = Some("redo"); }
|
||||
else if !typing && i.consume_key(c, Key::Z) { act = Some("undo"); }
|
||||
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 !typing && i.consume_key(c, Key::H) { act = Some("toggle_shuffle"); }
|
||||
// egui-winit turns Ctrl+V into Event::Paste(text); files copied in a file manager arrive as file:// lines
|
||||
if !typing && i.events.iter().any(|e| matches!(e, egui::Event::Paste(t) if t.lines().next().is_some_and(|l| l.starts_with("file://")))) { 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"); }
|
||||
|
|
@ -1006,7 +1010,7 @@ impl App {
|
|||
"equalizer" => self.dialog = Some(Dialog::Equalizer),
|
||||
"analyzer" => { let v = !settings().get_bool("appearance/analyzer"); settings().set("appearance/analyzer", v); }
|
||||
"shape" => { let v = !settings().get_bool("appearance/floating_shape"); settings().set("appearance/floating_shape", v); }
|
||||
"shape_morph" => {}
|
||||
"shape_morph" => { let App { shape, g, .. } = self; shape.morph_to(g); }
|
||||
"about" => self.dialog = Some(Dialog::About),
|
||||
"paste_files" => {
|
||||
let bus = self.bus.clone();
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ pub fn show(app: &mut App, ctx: &Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
menu_width_store(ui);
|
||||
});
|
||||
});
|
||||
let rect = inner.response.rect;
|
||||
|
|
@ -240,7 +241,6 @@ 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);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ impl ShapeState {
|
|||
}
|
||||
}
|
||||
|
||||
fn morph_to(&mut self, g: &Gfx) {
|
||||
pub fn morph_to(&mut self, g: &Gfx) {
|
||||
let mut rng = rand::rng();
|
||||
let choices: Vec<usize> = (0..self.all.len()).filter(|i| *i != self.cur).collect();
|
||||
let n = *choices.choose(&mut rng).unwrap();
|
||||
|
|
|
|||
|
|
@ -340,8 +340,19 @@ pub fn menu_frame(g: &Gfx) -> egui::Frame {
|
|||
.inner_margin(egui::Margin::symmetric(0, 5))
|
||||
}
|
||||
|
||||
/// Width the menu had last frame, so every row (also those above the widest one) spans the whole menu.
|
||||
fn menu_width(ui: &Ui) -> f32 {
|
||||
ui.ctx().data(|d| d.get_temp::<f32>(ui.id().with("menu-w"))).unwrap_or(0.0)
|
||||
}
|
||||
|
||||
/// Remember the menu's width for next frame's `menu_width`; call at the end of the menu body.
|
||||
pub fn menu_width_store(ui: &Ui) {
|
||||
let w = ui.min_rect().width();
|
||||
ui.ctx().data_mut(|d| d.insert_temp(ui.id().with("menu-w"), w));
|
||||
}
|
||||
|
||||
pub fn menu_sep(ui: &mut Ui, g: &Gfx) {
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.min_size().x.max(180.0), 9.0), Sense::hover());
|
||||
let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.min_size().x.max(180.0).max(menu_width(ui)), 9.0), Sense::hover());
|
||||
ui.painter().line_segment([Pos2::new(rect.left() + 14.0, rect.center().y), Pos2::new(rect.right() - 14.0, rect.center().y)], Stroke::new(1.0, g.theme.outline_variant));
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +367,7 @@ pub fn menu_item_h(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, hin
|
|||
let tw = ui.painter().layout_no_wrap(text.to_string(), fnt.clone(), Color32::WHITE).size().x;
|
||||
let hw = if hint.is_empty() { 0.0 } else { ui.painter().layout_no_wrap(hint.to_string(), font(12.5), Color32::WHITE).size().x + 28.0 };
|
||||
let want = (tw + 40.0 + 30.0 + hw).max(190.0);
|
||||
let want = want.max(ui.min_size().x);
|
||||
let want = want.max(ui.min_size().x).max(menu_width(ui));
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(want, 30.0), Sense::click());
|
||||
let t = &g.theme;
|
||||
let row = rect.shrink2(Vec2::new(6.0, 0.0));
|
||||
|
|
@ -385,8 +396,9 @@ pub fn menu_item_h(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, hin
|
|||
|
||||
/// Submenu row; returns the response of the row (the submenu body is shown by egui).
|
||||
pub fn submenu<R>(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, add: impl FnOnce(&mut Ui, &mut Gfx) -> R) {
|
||||
let fnt = font(14.0);
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new(ui.min_size().x.max(190.0), 30.0), Sense::click());
|
||||
let fnt = font(13.5);
|
||||
let tw = ui.painter().layout_no_wrap(text.to_string(), fnt.clone(), Color32::WHITE).size().x;
|
||||
let (rect, resp) = ui.allocate_exact_size(Vec2::new((tw + 40.0 + 30.0).max(190.0).max(ui.min_size().x).max(menu_width(ui)), 30.0), Sense::click());
|
||||
let row = rect.shrink2(Vec2::new(6.0, 0.0));
|
||||
let open_id = resp.id.with("open");
|
||||
let is_open = ui.ctx().data(|d| d.get_temp::<bool>(open_id)).unwrap_or(false);
|
||||
|
|
@ -394,10 +406,10 @@ pub fn submenu<R>(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, add:
|
|||
ui.painter().rect_filled(row, cr(10.0), with_alpha(g.theme.on_surface, 0.08));
|
||||
}
|
||||
if let Some(name) = icon {
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.left() + 24.0, row.center().y), Vec2::splat(20.0)), name, g.theme.on_surface_variant);
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.left() + 22.0, row.center().y), Vec2::splat(18.0)), name, g.theme.on_surface_variant);
|
||||
}
|
||||
ui.painter().text(Pos2::new(row.left() + 40.0, row.center().y), Align2::LEFT_CENTER, text, fnt, g.theme.on_surface);
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.right() - 20.0, row.center().y), Vec2::splat(20.0)), "chevron_right", g.theme.on_surface_variant);
|
||||
g.icon(ui.painter(), Rect::from_center_size(Pos2::new(row.right() - 22.0, row.center().y), Vec2::splat(18.0)), "chevron_right", g.theme.on_surface_variant);
|
||||
// open on hover/click, stay open while the pointer is over the row or the submenu
|
||||
let sub_id = resp.id.with("sub");
|
||||
let sub_rect: Option<Rect> = ui.ctx().data(|d| d.get_temp(sub_id));
|
||||
|
|
@ -419,7 +431,9 @@ pub fn submenu<R>(ui: &mut Ui, g: &mut Gfx, icon: Option<&str>, text: &str, add:
|
|||
frame.show(ui, |ui| {
|
||||
ui.set_min_width(220.0);
|
||||
ui.spacing_mut().item_spacing = Vec2::ZERO;
|
||||
add(ui, g)
|
||||
let r = add(ui, g);
|
||||
menu_width_store(ui);
|
||||
r
|
||||
});
|
||||
});
|
||||
ui.ctx().data_mut(|d| d.insert_temp(sub_id, inner.response.rect));
|
||||
|
|
|
|||
Loading…
Reference in a new issue