This commit is contained in:
Ospald, Julian 2017-06-29 12:51:28 +02:00
parent 62ec3d6eb0
commit d83209e67f
2 changed files with 23 additions and 30 deletions

View File

@ -129,19 +129,21 @@ pub fn watch_poll_descriptors(
mixer: RefCell<Mixer>, mixer: RefCell<Mixer>,
) -> Vec<c_uint> { ) -> Vec<c_uint> {
let mut watch_ids: Vec<c_uint> = vec![]; let mut watch_ids: Vec<c_uint> = vec![];
let mixer = unsafe { let mixer = mixer.into_inner();
mem::transmute::<Mixer, *mut alsa_sys::snd_mixer_t>(mixer.into_inner()) let mixer_ptr = unsafe {
mem::transmute::<Mixer, *mut alsa_sys::snd_mixer_t>(mixer)
}; };
for poll in polls { for poll in polls {
unsafe { unsafe {
let gioc: *mut glib_sys::GIOChannel = glib_sys::g_io_channel_unix_new(poll.fd); let gioc: *mut glib_sys::GIOChannel =
glib_sys::g_io_channel_unix_new(poll.fd);
watch_ids.push(glib_sys::g_io_add_watch( watch_ids.push(glib_sys::g_io_add_watch(
gioc, gioc,
glib_sys::GIOCondition::from_bits( glib_sys::GIOCondition::from_bits(
glib_sys::G_IO_IN.bits() | glib_sys::G_IO_ERR.bits(), glib_sys::G_IO_IN.bits() | glib_sys::G_IO_ERR.bits(),
).unwrap(), ).unwrap(),
Some(watch_cb), Some(watch_cb),
mixer as glib_sys::gpointer, mixer_ptr as glib_sys::gpointer,
)); ));
} }
} }
@ -149,15 +151,12 @@ pub fn watch_poll_descriptors(
return watch_ids; return watch_ids;
} }
extern "C" fn watch_cb( extern fn watch_cb(
chan: *mut glib_sys::GIOChannel, chan: *mut glib_sys::GIOChannel,
cond: glib_sys::GIOCondition, cond: glib_sys::GIOCondition,
data: glib_sys::gpointer, data: glib_sys::gpointer,
) -> glib_sys::gboolean { ) -> glib_sys::gboolean {
// println!("Blah");
// println!("GIOC: {:?}", chan);
let mixer = data as *mut alsa_sys::snd_mixer_t; let mixer = data as *mut alsa_sys::snd_mixer_t;
unsafe { unsafe {
@ -168,28 +167,28 @@ extern "C" fn watch_cb(
return false as glib_sys::gboolean; return false as glib_sys::gboolean;
} }
// println!("GIOC (later): {:?}", chan); let mut sread: size_t = 1;
let mut sread: usize = 1;
let mut buf: u8 = 0; let mut buf: u8 = 0;
while sread > 0 { while sread > 0 {
let stat = unsafe { glib_sys::g_io_channel_read_chars(chan, let stat: glib_sys::GIOStatus = unsafe {
&mut buf as *mut u8, glib_sys::g_io_channel_read_chars(
250, chan,
&mut sread as *mut size_t, &mut buf as *mut u8,
ptr::null_mut()) 256,
&mut sread as *mut size_t,
ptr::null_mut(),
)
}; };
match stat { match stat {
glib_sys::G_IO_STATUS_AGAIN => continue, glib_sys::G_IO_STATUS_AGAIN => continue,
glib_sys::G_IO_STATUS_NORMAL => (), glib_sys::G_IO_STATUS_NORMAL => println!("G_IO_STATUS_NORMAL"),
glib_sys::G_IO_STATUS_ERROR => (), glib_sys::G_IO_STATUS_ERROR => println!("G_IO_STATUS_ERROR"),
glib_sys::G_IO_STATUS_EOF => (), glib_sys::G_IO_STATUS_EOF => println!("G_IO_STATUS_EOF"),
_ => (),
} }
return true as glib_sys::gboolean; return true as glib_sys::gboolean;
}; }
return true as glib_sys::gboolean; return true as glib_sys::gboolean;
} }

View File

@ -1,3 +1,5 @@
#![feature(alloc_system)]
extern crate alloc_system;
extern crate flexi_logger; extern crate flexi_logger;
#[macro_use] #[macro_use]
@ -34,11 +36,6 @@ mod app_state;
fn main() { fn main() {
gtk::init().unwrap(); gtk::init().unwrap();
let x = 4 / 0;
println!("Zero: {}", x);
let ref apps = AppS { let ref apps = AppS {
status_icon: gtk::StatusIcon::new_from_icon_name("pnmixer"), status_icon: gtk::StatusIcon::new_from_icon_name("pnmixer"),
builder_popup: gtk::Builder::new_from_string( builder_popup: gtk::Builder::new_from_string(
@ -47,10 +44,7 @@ fn main() {
}; };
let acard = Rc::new(RefCell::new( let acard = Rc::new(RefCell::new(
AlsaCard::new( AlsaCard::new(None, Some(String::from("Master"))).unwrap(),
None,
Some(String::from("Master")),
).unwrap(),
)); ));
flexi_logger::LogOptions::new() flexi_logger::LogOptions::new()