This commit is contained in:
Julian Ospald 2017-06-30 22:08:08 +02:00
parent f2fcdd3cd7
commit f3fc6aca23
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
4 changed files with 25 additions and 63 deletions

View File

@ -89,6 +89,8 @@ impl AlsaCard {
*rc = glib::get_monotonic_time();
}
// TODO invoke handlers, make use of user
debug!("Setting vol to {:?} by user {:?}", new_vol, user);
return set_vol(&self.selem(), new_vol);
}
@ -107,6 +109,7 @@ impl AlsaCard {
let mut rc = self.last_action_timestamp.borrow_mut();
*rc = glib::get_monotonic_time();
// TODO invoke handlers, make use of user
debug!("Setting mute to {} by user {:?}", mute, user);
return set_mute(&self.selem(), mute);
}
@ -118,29 +121,32 @@ impl AlsaCard {
let now: i64 = glib::get_monotonic_time();
let delay: i64 = now - last;
if delay < 1000000 {
info!("Delay: {}", delay);
return;
}
debug!("Discarding last time stamp, too old");
*self.last_action_timestamp.borrow_mut() = 0;
}
/* external change */
match alsa_event {
// TODO: invoke handlers with AudioUserUnknown
AlsaEvent::AlsaCardError => info!("AlsaCardError"),
AlsaEvent::AlsaCardDiconnected => info!("AlsaCardDiconnected"),
AlsaEvent::AlsaCardError => debug!("AlsaCardError"),
AlsaEvent::AlsaCardDiconnected => debug!("AlsaCardDiconnected"),
AlsaEvent::AlsaCardValuesChanged => {
info!("AlsaCardValuesChanged");
debug!("AlsaCardValuesChanged");
self.invoke_handlers(self::AudioSignal::AudioValuesChanged,
self::AudioUser::AudioUserUnknown);
}
e => warn!("Unhandled alsa event: {:?}", e),
}
}
fn invoke_handlers(&self, signal: AudioSignal, user: AudioUser) {
debug!("Invoking handlers for signal {:?} by user {:?}",
signal,
user);
let handlers = self.handlers.borrow();
let x: &Vec<Box<Fn(&AlsaCard, AudioSignal, AudioUser)>> = &*handlers;
for handler in x {
@ -157,7 +163,7 @@ impl AlsaCard {
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum AudioUser {
AudioUserUnknown,
AudioUserPopup,
@ -166,7 +172,7 @@ pub enum AudioUser {
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum AudioSignal {
AudioNoCard,
AudioCardInitialized,
@ -177,7 +183,7 @@ pub enum AudioSignal {
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub enum AlsaEvent {
AlsaCardError,
AlsaCardDiconnected,
@ -220,17 +226,11 @@ extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
let acard =
unsafe { mem::transmute::<glib_sys::gpointer, &AlsaCard>(data) };
{
unsafe {
let mixer_ptr =
unsafe {
mem::transmute::<&Mixer,
&*mut alsa_sys::snd_mixer_t>(&acard.mixer)
};
unsafe {
alsa_sys::snd_mixer_handle_events(*mixer_ptr);
}
}
mem::transmute::<&Mixer, &*mut alsa_sys::snd_mixer_t>(&acard.mixer);
alsa_sys::snd_mixer_handle_events(*mixer_ptr);
};
if cond == glib_sys::G_IO_ERR {
return false as glib_sys::gboolean;
@ -251,12 +251,12 @@ extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
match stat {
glib_sys::G_IO_STATUS_AGAIN => {
info!("G_IO_STATUS_AGAIN");
debug!("G_IO_STATUS_AGAIN");
continue;
}
glib_sys::G_IO_STATUS_NORMAL => info!("G_IO_STATUS_NORMAL"),
glib_sys::G_IO_STATUS_ERROR => info!("G_IO_STATUS_ERROR"),
glib_sys::G_IO_STATUS_EOF => info!("G_IO_STATUS_EOF"),
glib_sys::G_IO_STATUS_NORMAL => debug!("G_IO_STATUS_NORMAL"),
glib_sys::G_IO_STATUS_ERROR => debug!("G_IO_STATUS_ERROR"),
glib_sys::G_IO_STATUS_EOF => debug!("G_IO_STATUS_EOF"),
}
return true as glib_sys::gboolean;
}

View File

@ -44,7 +44,7 @@ fn main() {
flexi_logger::LogOptions::new()
.log_to_file(false)
// ... your configuration options go here ...
.init(Some("info".to_string()))
.init(Some("pnmixer=debug".to_string()))
.unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));
ui_entry::init(apps);

View File

@ -14,10 +14,10 @@ pub fn init(appstate: Rc<AppS>) {
match (s, u) {
(AudioSignal::AudioValuesChanged,
AudioUser::AudioUserUnknown) => {
println!("External volume change!");
debug!("External volume change!");
}
_ => println!("Nix"),
_ => debug!("Nix"),
}
}));
}

View File

@ -6,13 +6,8 @@ use gdk::{GrabOwnership, GrabStatus, BUTTON_PRESS_MASK, KEY_PRESS_MASK};
use gdk;
use gdk_sys::{GDK_KEY_Escape, GDK_CURRENT_TIME};
use glib;
use glib_sys;
use gobject_sys::{G_SIGNAL_MATCH_ID, G_SIGNAL_MATCH_DATA};
use gobject_sys;
use gtk::prelude::*;
use gtk;
use std::mem;
use std::ptr;
use std::rc::Rc;
@ -146,29 +141,8 @@ pub fn update_mute_check(appstate: &AppS,
toggle_signal: u64,
muted: Result<bool>) {
let check_button = &appstate.gui.popup_window.mute_check;
// let check_button_ptr = unsafe {
// mem::transmute::<&gtk::CheckButton, &*mut gobject_sys::GObject>(
// check_button,
// )
// };
// g_signal_handlers_block_matched() doesn't work in gtk-rs
glib::signal_handler_block(check_button, toggle_signal);
// let n_blocked = unsafe {
// gobject_sys::g_signal_handlers_block_matched(
// *check_button_ptr,
// G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA,
// toggle_signal as u32,
// 0,
// ptr::null_mut(),
// ptr::null_mut(),
// ptr::null_mut(),
// )
// };
// if n_blocked != 1 {
// error!("Wrong number of blocked handlers: {}", n_blocked);
// }
match muted {
Ok(val) => {
@ -184,18 +158,6 @@ pub fn update_mute_check(appstate: &AppS,
}
glib::signal_handler_unblock(check_button, toggle_signal);
// unsafe {
// gobject_sys::g_signal_handlers_unblock_matched(
// *check_button_ptr,
// G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA,
// toggle_signal as u32,
// 0,
// ptr::null_mut(),
// ptr::null_mut(),
// ptr::null_mut(),
// );
// }
}