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>,
) -> Vec<c_uint> {
let mut watch_ids: Vec<c_uint> = vec![];
let mixer = unsafe {
mem::transmute::<Mixer, *mut alsa_sys::snd_mixer_t>(mixer.into_inner())
let mixer = mixer.into_inner();
let mixer_ptr = unsafe {
mem::transmute::<Mixer, *mut alsa_sys::snd_mixer_t>(mixer)
};
for poll in polls {
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(
gioc,
glib_sys::GIOCondition::from_bits(
glib_sys::G_IO_IN.bits() | glib_sys::G_IO_ERR.bits(),
).unwrap(),
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;
}
extern "C" fn watch_cb(
extern fn watch_cb(
chan: *mut glib_sys::GIOChannel,
cond: glib_sys::GIOCondition,
data: glib_sys::gpointer,
) -> glib_sys::gboolean {
// println!("Blah");
// println!("GIOC: {:?}", chan);
let mixer = data as *mut alsa_sys::snd_mixer_t;
unsafe {
@ -168,28 +167,28 @@ extern "C" fn watch_cb(
return false as glib_sys::gboolean;
}
// println!("GIOC (later): {:?}", chan);
let mut sread: usize = 1;
let mut sread: size_t = 1;
let mut buf: u8 = 0;
while sread > 0 {
let stat = unsafe { glib_sys::g_io_channel_read_chars(chan,
&mut buf as *mut u8,
250,
&mut sread as *mut size_t,
ptr::null_mut())
let stat: glib_sys::GIOStatus = unsafe {
glib_sys::g_io_channel_read_chars(
chan,
&mut buf as *mut u8,
256,
&mut sread as *mut size_t,
ptr::null_mut(),
)
};
match stat {
glib_sys::G_IO_STATUS_AGAIN => continue,
glib_sys::G_IO_STATUS_NORMAL => (),
glib_sys::G_IO_STATUS_ERROR => (),
glib_sys::G_IO_STATUS_EOF => (),
_ => (),
glib_sys::G_IO_STATUS_NORMAL => println!("G_IO_STATUS_NORMAL"),
glib_sys::G_IO_STATUS_ERROR => println!("G_IO_STATUS_ERROR"),
glib_sys::G_IO_STATUS_EOF => println!("G_IO_STATUS_EOF"),
}
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;
#[macro_use]
@ -34,11 +36,6 @@ mod app_state;
fn main() {
gtk::init().unwrap();
let x = 4 / 0;
println!("Zero: {}", x);
let ref apps = AppS {
status_icon: gtk::StatusIcon::new_from_icon_name("pnmixer"),
builder_popup: gtk::Builder::new_from_string(
@ -47,10 +44,7 @@ fn main() {
};
let acard = Rc::new(RefCell::new(
AlsaCard::new(
None,
Some(String::from("Master")),
).unwrap(),
AlsaCard::new(None, Some(String::from("Master"))).unwrap(),
));
flexi_logger::LogOptions::new()