diff --git a/src/application.rs b/src/application.rs index 4ec016d..1a376e5 100644 --- a/src/application.rs +++ b/src/application.rs @@ -6,6 +6,7 @@ mod imp { #[derive(Default)] pub struct Application { + // FIXME: move somewhere else mpv: Rc, } @@ -91,6 +92,13 @@ mod imp { impl AdwApplicationImpl for Application {} impl Application {} + + impl Drop for Application { + fn drop(&mut self) { + println!("dropping AudreyApplication"); + self.mpv.command(["quit"]).unwrap(); + } + } } use gtk::{gio, glib}; diff --git a/src/mpv.rs b/src/mpv.rs index 87ba7ee..0df45a9 100644 --- a/src/mpv.rs +++ b/src/mpv.rs @@ -1,6 +1,6 @@ mod ffi; -use std::ffi::{c_int, c_void, CStr, CString}; +use std::ffi::{c_char, c_int, c_void, CStr, CString}; #[link(name = "mpv")] extern "C" {} @@ -114,6 +114,25 @@ impl Handle { }) } + pub fn command<'a>(&self, args: impl IntoIterator) -> Result<(), Error> { + // add zero terminators to Everything + let args: Vec = args + .into_iter() + .map(CString::new) + .map(Result::unwrap) + .collect(); + let mut args: Vec<*const c_char> = args + .iter() + .map(CString::as_c_str) + .map(CStr::as_ptr) + .collect(); + // must be null terminated + args.push(std::ptr::null_mut()); + let args: *mut *const c_char = args.as_mut_ptr(); + + Error::from_return_code(unsafe { ffi::mpv_command(self.inner.as_ptr(), args) }) + } + // TODO: return None on SHUTDOWN possibly? pub fn tick(&self) -> Option { // take listener before we drain the event queue, so we don't miss any notifications