This commit is contained in:
Erica Z 2024-11-13 19:55:23 +01:00
parent 2e0a0ef40f
commit cd43f50fdb

View file

@ -15,9 +15,9 @@ mod imp {
pub(super) enum State { pub(super) enum State {
Idle, Idle,
FileLoading, FileLoading,
FileLoaded, // internal? FileLoaded, // internal
Active, Active,
FileEnded, // internal? FileEnded, // internal
Seeking, Seeking,
} }
@ -105,7 +105,7 @@ mod imp {
// "Useful to drain property changes before a new file is loaded." // "Useful to drain property changes before a new file is loaded."
mpv.add_hook(0, "on_before_start_file", 0).unwrap(); mpv.add_hook(0, "on_before_start_file", 0).unwrap();
// "Useful to drain property changes after a file has finished." // "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 { Self {
state: Cell::new(State::Idle), state: Cell::new(State::Idle),
@ -265,40 +265,69 @@ mod imp {
let mpv_event_loop_handle = glib::spawn_future_local(async move { let mpv_event_loop_handle = glib::spawn_future_local(async move {
loop { loop {
let window = window.upgrade().unwrap(); let window = window.upgrade().unwrap();
let listener = window.imp().mpv.wakeup_listener();
// only send property change notifications after the event queue is drained // only send property change notifications after the event queue is drained
let freeze_notify = window.freeze_notify(); 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) { let listener = loop {
use crate::mpv::Event; let listener = window.imp().mpv.wakeup_listener();
match event { while let Some(event) = window.imp().mpv.wait_event(0.0) {
Event::PropertyChange(event) => window.imp().on_property_change(event), use crate::mpv::Event;
Event::Hook(event) => window.imp().on_hook(event),
Event::LogMessage(event) => window.imp().on_log_message(event),
Event::StartFile(_) => window.imp().on_start_file(), match event {
Event::FileLoaded => window.imp().on_file_loaded(), Event::PropertyChange(event) => {
Event::PlaybackRestart => window.imp().on_playback_restart(), window.imp().on_property_change(event)
Event::Seek => window.imp().on_seek(), }
Event::EndFile(event) => window.imp().on_end_file(event), Event::Hook(event) => window.imp().on_hook(event),
Event::LogMessage(event) => window.imp().on_log_message(event),
Event::Unknown(_) => { Event::StartFile(_) => window.imp().on_start_file(),
// either deprecated or future, ignore 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 // send property change notifications now
drop(freeze_notify); drop(freeze_notify);
event!(
Level::TRACE,
"after event loop, state is {:?}",
window.imp().state.get()
);
drop(window); drop(window);
listener.await; listener.await;
} }