Check the rest on real hardware; fix quit crash, repaint hang and console

Checked on the real GPU and niri: hardware decoding, fullscreen, the minimum
window, menus at the edges, colours from the video, mpv's console, screensaver
inhibit, the portal file dialog and Wayland drag and drop.

- Unset mpv's wakeup callback before libmpv2 frees it (segfault on quit).
- mpv callbacks post to a small thread instead of locking egui (hang on quit).
- Hide the controls while mpv's console is open; don't double typed spaces.
- Any pointer move shows the controls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-26 18:41:57 -06:00
commit 997dc3a262
4 changed files with 63 additions and 17 deletions

View file

@ -10,10 +10,24 @@ Version 0.1.0, first build (2026-11-26).
- Playlist and Adjust sheets; Settings dialog (Appearance, Playback, Languages, mpv, Keyboard, About); Open link dialog.
- Light and dark themes; idle: no frames about a second after pausing.
## Not checked yet
- Real GPU (only llvmpipe so far), hardware decoding on real hardware, Wayland drag and drop from a file manager.
- File dialogs (portal), screensaver inhibit, colours from the video, keys passed to mpv's console.
- Window at the minimum size (480x360), fullscreen, menus near the window edges.
## Checked on real hardware and a real compositor (niri, 2026-11-26)
- Real GPU: plays on the user's Wayland session; hardware decoding is on (`vaapi`, shown in the top bar).
- Fullscreen (F) fills the screen with the controls on top; F again restores the window.
- Window at the minimum size (480x360): top bar and dock fit, the title elides; menus opened at the bottom-right
and top-left corners flip and stay inside the window.
- Colours from the video: an orange clip turns the theme orange (primary `#FFB28B`).
- mpv's console (`): typed commands run; the controls hide while it is open so its command line stays visible,
and come back when it closes.
- Screensaver inhibit: the ScreenSaver Inhibit call is answered on niri while a video plays.
- File dialogs: Ctrl+O opens the portal's "Open videos" picker (xdg-desktop-portal-gtk); it closes with the app.
- Wayland drag and drop: a file dragged from another app (GTK drag source, real pointer drag in a nested niri)
opens and plays.
## Fixed while checking
- A crash on quit: mpv could call its wakeup callback after libmpv2 had freed it. The callback is now unset first.
- A hang (10 s, then abort): mpv's callbacks asked egui for a repaint while holding mpv's lock. They now post to a
small thread that does the asking.
- The dock covered mpv's console; a space typed in the console came out twice.
## Missing
- A `--gallery` page of every control in every state (the /material skill asks for one).

View file

@ -573,7 +573,9 @@ impl App {
match e {
egui::Event::Key { key, pressed: true, modifiers, repeat, .. } => {
if console {
if let Some(k) = non_text_key(*key, *modifiers) {
// a plain space also arrives as typed text, which is forwarded below
let plain_space = *key == Key::Space && !modifiers.ctrl && !modifiers.alt && !modifiers.command;
if !plain_space && let Some(k) = non_text_key(*key, *modifiers) {
forward.push(k);
}
continue;
@ -865,7 +867,7 @@ impl eframe::App for App {
let mut acts = self.keyboard(&ctx);
let screen = ctx.content_rect();
let moved = ctx.input(|i| i.pointer.delta().length_sq() > 0.0 || i.pointer.any_pressed() || !i.events.is_empty() && i.events.iter().any(|e| matches!(e, egui::Event::Key { .. } | egui::Event::MouseWheel { .. })));
let moved = ctx.input(|i| i.pointer.delta().length_sq() > 0.0 || i.pointer.any_pressed() || !i.events.is_empty() && i.events.iter().any(|e| matches!(e, egui::Event::Key { .. } | egui::Event::MouseWheel { .. } | egui::Event::PointerMoved(_))));
if moved || self.last_move == 0.0 {
self.last_move = now;
}
@ -874,7 +876,9 @@ impl eframe::App for App {
let over_chrome = ctx.pointer_hover_pos().is_some_and(|p| self.chrome_rects.iter().any(|r| r.contains(p)));
let hold = !playing || self.menu.is_some() || self.sheet != Sheet::None || self.dialog != Dialog::None || over_chrome || self.seek_dragging;
let left = self.settings.hide_after as f64 - (now - self.last_move);
let show = hold || left > 0.0;
// mpv's console types at the bottom of the picture; keep the controls out of its way
let console = self.player.as_ref().is_some_and(|p| p.mpv.get_property::<bool>("user-data/mpv/console/open").unwrap_or(false));
let show = !console && (hold || left > 0.0);
if !hold && left > 0.0 {
ctx.request_repaint_after(std::time::Duration::from_secs_f64(left + 0.02));
}

View file

@ -370,8 +370,30 @@ fn ctx_free(_id: eframe::egui::TextureId) {
}
unsafe extern "C" fn on_update(ctx: *mut c_void) {
let egui = unsafe { &*(ctx as *const eframe::egui::Context) };
egui.request_repaint();
let wake = unsafe { &*(ctx as *const Waker) };
wake.wake();
}
/// mpv calls back from its own threads, sometimes while holding its core lock. Asking egui for a repaint there
/// could wait on egui's lock while the UI thread, inside egui, waits on mpv. So callbacks only post a note and
/// a small thread of ours does the asking.
#[derive(Clone)]
struct Waker(std::sync::mpsc::SyncSender<()>);
impl Waker {
fn new(egui: eframe::egui::Context) -> Waker {
let (tx, rx) = std::sync::mpsc::sync_channel::<()>(1);
let _ = std::thread::Builder::new().name("mpv-wake".into()).spawn(move || {
while rx.recv().is_ok() {
egui.request_repaint();
}
});
Waker(tx)
}
fn wake(&self) {
let _ = self.0.try_send(());
}
}
/// Display pointers mpv needs for hardware decoding interop.
@ -433,8 +455,9 @@ impl Player {
for (n, (name, fmt)) in PROPS.iter().enumerate() {
let _ = mpv.observe_property(name, *fmt, n as u64);
}
let wake = egui.clone();
mpv.set_wakeup_callback(move || wake.request_repaint());
let waker = Waker::new(egui);
let wake = waker.clone();
mpv.set_wakeup_callback(move || wake.wake());
let get_proc = Box::new(get_proc_address);
let mut init_params = sys::mpv_opengl_init_params {
@ -456,8 +479,8 @@ impl Player {
if err < 0 {
return Err(format!("Couldn't set up video output: {}", sys::mpv_error_str(err)));
}
// The context lives as long as the app (we leak one clone of it on purpose).
let ctx_ptr = Box::into_raw(Box::new(egui)) as *mut c_void;
// The waker lives as long as the app (we leak one clone of it on purpose).
let ctx_ptr = Box::into_raw(Box::new(waker)) as *mut c_void;
unsafe { sys::mpv_render_context_set_update_callback(render, Some(on_update), ctx_ptr) };
Ok(Player { mpv, state: State { idle: true, speed: 1.0, volume: 100.0, sub_visible: true, sub_scale: 1.0, sub_pos: 100.0, zoom: 0.0, ..State::default() }, render, _get_proc: get_proc, fbo: None, dirty: true })
}
@ -583,6 +606,9 @@ impl Player {
impl Drop for Player {
fn drop(&mut self) {
// libmpv2 frees our wakeup closure before destroying mpv, which may still call it in between.
// Unsetting it here waits for a call in flight (mpv holds the same lock) and stops later ones.
unsafe { sys::mpv_set_wakeup_callback(self.mpv.ctx.as_ptr(), None, std::ptr::null_mut()) };
if !self.render.is_null() {
unsafe { sys::mpv_render_context_free(self.render) };
}

View file

@ -1,17 +1,19 @@
#!/bin/bash
# Hidden smoke run: Quince in a nested niri on Xvfb (tools/nested-session.sh), software GL, a throwaway config,
# driven by a QUINCE_SCRIPT (see src/script.rs). Nothing shows on the user's screen.
# SMOKE_VISIBLE=1 runs it on the user's own Wayland display instead (real GPU), still with a throwaway config.
# tools/smoke.sh <script.txt> <outdir> [files...]
set -u
root=$(cd "$(dirname "$0")/.." && pwd)
script=$(realpath "$1"); out=$2; shift 2
mkdir -p "$out"; out=$(cd "$out" && pwd)
bin=${SMOKE_BIN:-$root/target/debug/quince}
"$root/tools/nested-session.sh" start "$out/session" "${SMOKE_SIZE:-1280x800}" || exit 1
( set -a; . "$out/session/env"; set +a
visible=${SMOKE_VISIBLE:-}
[ -z "$visible" ] && { "$root/tools/nested-session.sh" start "$out/session" "${SMOKE_SIZE:-1280x800}" || exit 1; }
( [ -z "$visible" ] && { set -a; . "$out/session/env"; set +a; export LIBGL_ALWAYS_SOFTWARE=1; }
HOME_CFG=$out/home; mkdir -p "$HOME_CFG"
QUINCE_CONFIG=${QUINCE_CONFIG:-$out/settings.json} QUINCE_SCRIPT=$script QUINCE_SHOTS=$out QUINCE_STATUS=$out/status.json \
LIBGL_ALWAYS_SOFTWARE=1 RUST_BACKTRACE=1 timeout "${SMOKE_TIMEOUT:-90}" "$bin" "$@" >"$out/quince.log" 2>&1
RUST_BACKTRACE=1 timeout "${SMOKE_TIMEOUT:-90}" "$bin" "$@" >"$out/quince.log" 2>&1
echo "exit $?" >>"$out/quince.log" )
"$root/tools/nested-session.sh" stop "$out/session"
[ -z "$visible" ] && "$root/tools/nested-session.sh" stop "$out/session"
tail -3 "$out/quince.log"