diff --git a/src/ui/window.rs b/src/ui/window.rs index c42ec48..6bb713e 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -15,9 +15,9 @@ mod imp { pub(super) enum State { Idle, FileLoading, - FileLoaded, // internal? + FileLoaded, // internal Active, - FileEnded, // internal? + FileEnded, // internal Seeking, } @@ -105,7 +105,7 @@ mod imp { // "Useful to drain property changes before a new file is loaded." mpv.add_hook(0, "on_before_start_file", 0).unwrap(); // "Useful to drain property changes after a file has finished." - mpv.add_hook(0, "o_after_start_file", 0).unwrap(); + mpv.add_hook(0, "on_after_end_file", 0).unwrap(); Self { state: Cell::new(State::Idle), @@ -265,40 +265,69 @@ mod imp { let mpv_event_loop_handle = glib::spawn_future_local(async move { loop { let window = window.upgrade().unwrap(); - let listener = window.imp().mpv.wakeup_listener(); // only send property change notifications after the event queue is drained let freeze_notify = window.freeze_notify(); + event!( + Level::TRACE, + "before event loop, state is {:?}", + window.imp().state.get() + ); - while let Some(event) = window.imp().mpv.wait_event(0.0) { - use crate::mpv::Event; + let listener = loop { + let listener = window.imp().mpv.wakeup_listener(); - match event { - Event::PropertyChange(event) => window.imp().on_property_change(event), - Event::Hook(event) => window.imp().on_hook(event), - Event::LogMessage(event) => window.imp().on_log_message(event), + while let Some(event) = window.imp().mpv.wait_event(0.0) { + use crate::mpv::Event; - Event::StartFile(_) => window.imp().on_start_file(), - Event::FileLoaded => window.imp().on_file_loaded(), - Event::PlaybackRestart => window.imp().on_playback_restart(), - Event::Seek => window.imp().on_seek(), - Event::EndFile(event) => window.imp().on_end_file(event), + match event { + Event::PropertyChange(event) => { + window.imp().on_property_change(event) + } + Event::Hook(event) => window.imp().on_hook(event), + Event::LogMessage(event) => window.imp().on_log_message(event), - Event::Unknown(_) => { - // either deprecated or future, ignore + Event::StartFile(_) => window.imp().on_start_file(), + Event::FileLoaded => window.imp().on_file_loaded(), + Event::PlaybackRestart => window.imp().on_playback_restart(), + Event::Seek => window.imp().on_seek(), + Event::EndFile(event) => window.imp().on_end_file(event), + + Event::Unknown(_) => { + // either deprecated or future, ignore + } + + Event::AudioReconfig => { + // "This is relatively uninteresting, because there is no such thing as audio output embedding." + // ^ ignore + } + + _ => event!(Level::DEBUG, "unhandled {event:?}"), } - - Event::AudioReconfig => { - // "This is relatively uninteresting, because there is no such thing as audio output embedding." - // ^ ignore - } - - _ => event!(Level::DEBUG, "unhandled {event:?}"), } - } + + match window.imp().state.get() { + State::FileLoaded | State::FileEnded => { + // really annoying intermediary states we're not really interested + // in seeing outside of this loop + // just block until it's done lol + use event_listener::Listener; + event!(Level::INFO, "blocking"); + listener.wait(); + } + + _ => break listener, + } + }; // send property change notifications now drop(freeze_notify); + event!( + Level::TRACE, + "after event loop, state is {:?}", + window.imp().state.get() + ); + drop(window); listener.await; }