Cleanup
This commit is contained in:
parent
f2fcdd3cd7
commit
f3fc6aca23
44
src/audio.rs
44
src/audio.rs
@ -89,6 +89,8 @@ impl AlsaCard {
|
|||||||
*rc = glib::get_monotonic_time();
|
*rc = glib::get_monotonic_time();
|
||||||
}
|
}
|
||||||
// TODO invoke handlers, make use of user
|
// TODO invoke handlers, make use of user
|
||||||
|
|
||||||
|
debug!("Setting vol to {:?} by user {:?}", new_vol, user);
|
||||||
return set_vol(&self.selem(), new_vol);
|
return set_vol(&self.selem(), new_vol);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +109,7 @@ impl AlsaCard {
|
|||||||
let mut rc = self.last_action_timestamp.borrow_mut();
|
let mut rc = self.last_action_timestamp.borrow_mut();
|
||||||
*rc = glib::get_monotonic_time();
|
*rc = glib::get_monotonic_time();
|
||||||
// TODO invoke handlers, make use of user
|
// TODO invoke handlers, make use of user
|
||||||
|
debug!("Setting mute to {} by user {:?}", mute, user);
|
||||||
return set_mute(&self.selem(), mute);
|
return set_mute(&self.selem(), mute);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,29 +121,32 @@ impl AlsaCard {
|
|||||||
let now: i64 = glib::get_monotonic_time();
|
let now: i64 = glib::get_monotonic_time();
|
||||||
let delay: i64 = now - last;
|
let delay: i64 = now - last;
|
||||||
if delay < 1000000 {
|
if delay < 1000000 {
|
||||||
info!("Delay: {}", delay);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
debug!("Discarding last time stamp, too old");
|
||||||
*self.last_action_timestamp.borrow_mut() = 0;
|
*self.last_action_timestamp.borrow_mut() = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* external change */
|
/* external change */
|
||||||
match alsa_event {
|
match alsa_event {
|
||||||
// TODO: invoke handlers with AudioUserUnknown
|
// TODO: invoke handlers with AudioUserUnknown
|
||||||
AlsaEvent::AlsaCardError => info!("AlsaCardError"),
|
AlsaEvent::AlsaCardError => debug!("AlsaCardError"),
|
||||||
AlsaEvent::AlsaCardDiconnected => info!("AlsaCardDiconnected"),
|
AlsaEvent::AlsaCardDiconnected => debug!("AlsaCardDiconnected"),
|
||||||
AlsaEvent::AlsaCardValuesChanged => {
|
AlsaEvent::AlsaCardValuesChanged => {
|
||||||
info!("AlsaCardValuesChanged");
|
debug!("AlsaCardValuesChanged");
|
||||||
self.invoke_handlers(self::AudioSignal::AudioValuesChanged,
|
self.invoke_handlers(self::AudioSignal::AudioValuesChanged,
|
||||||
self::AudioUser::AudioUserUnknown);
|
self::AudioUser::AudioUserUnknown);
|
||||||
}
|
}
|
||||||
|
e => warn!("Unhandled alsa event: {:?}", e),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn invoke_handlers(&self, signal: AudioSignal, user: AudioUser) {
|
fn invoke_handlers(&self, signal: AudioSignal, user: AudioUser) {
|
||||||
|
debug!("Invoking handlers for signal {:?} by user {:?}",
|
||||||
|
signal,
|
||||||
|
user);
|
||||||
let handlers = self.handlers.borrow();
|
let handlers = self.handlers.borrow();
|
||||||
let x: &Vec<Box<Fn(&AlsaCard, AudioSignal, AudioUser)>> = &*handlers;
|
let x: &Vec<Box<Fn(&AlsaCard, AudioSignal, AudioUser)>> = &*handlers;
|
||||||
for handler in x {
|
for handler in x {
|
||||||
@ -157,7 +163,7 @@ impl AlsaCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum AudioUser {
|
pub enum AudioUser {
|
||||||
AudioUserUnknown,
|
AudioUserUnknown,
|
||||||
AudioUserPopup,
|
AudioUserPopup,
|
||||||
@ -166,7 +172,7 @@ pub enum AudioUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum AudioSignal {
|
pub enum AudioSignal {
|
||||||
AudioNoCard,
|
AudioNoCard,
|
||||||
AudioCardInitialized,
|
AudioCardInitialized,
|
||||||
@ -177,7 +183,7 @@ pub enum AudioSignal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum AlsaEvent {
|
pub enum AlsaEvent {
|
||||||
AlsaCardError,
|
AlsaCardError,
|
||||||
AlsaCardDiconnected,
|
AlsaCardDiconnected,
|
||||||
@ -220,17 +226,11 @@ extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
|
|||||||
let acard =
|
let acard =
|
||||||
unsafe { mem::transmute::<glib_sys::gpointer, &AlsaCard>(data) };
|
unsafe { mem::transmute::<glib_sys::gpointer, &AlsaCard>(data) };
|
||||||
|
|
||||||
{
|
unsafe {
|
||||||
let mixer_ptr =
|
let mixer_ptr =
|
||||||
unsafe {
|
mem::transmute::<&Mixer, &*mut alsa_sys::snd_mixer_t>(&acard.mixer);
|
||||||
mem::transmute::<&Mixer,
|
alsa_sys::snd_mixer_handle_events(*mixer_ptr);
|
||||||
&*mut alsa_sys::snd_mixer_t>(&acard.mixer)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
alsa_sys::snd_mixer_handle_events(*mixer_ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if cond == glib_sys::G_IO_ERR {
|
if cond == glib_sys::G_IO_ERR {
|
||||||
return false as glib_sys::gboolean;
|
return false as glib_sys::gboolean;
|
||||||
@ -251,12 +251,12 @@ extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
|
|||||||
|
|
||||||
match stat {
|
match stat {
|
||||||
glib_sys::G_IO_STATUS_AGAIN => {
|
glib_sys::G_IO_STATUS_AGAIN => {
|
||||||
info!("G_IO_STATUS_AGAIN");
|
debug!("G_IO_STATUS_AGAIN");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
glib_sys::G_IO_STATUS_NORMAL => info!("G_IO_STATUS_NORMAL"),
|
glib_sys::G_IO_STATUS_NORMAL => debug!("G_IO_STATUS_NORMAL"),
|
||||||
glib_sys::G_IO_STATUS_ERROR => info!("G_IO_STATUS_ERROR"),
|
glib_sys::G_IO_STATUS_ERROR => debug!("G_IO_STATUS_ERROR"),
|
||||||
glib_sys::G_IO_STATUS_EOF => info!("G_IO_STATUS_EOF"),
|
glib_sys::G_IO_STATUS_EOF => debug!("G_IO_STATUS_EOF"),
|
||||||
}
|
}
|
||||||
return true as glib_sys::gboolean;
|
return true as glib_sys::gboolean;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
|||||||
flexi_logger::LogOptions::new()
|
flexi_logger::LogOptions::new()
|
||||||
.log_to_file(false)
|
.log_to_file(false)
|
||||||
// ... your configuration options go here ...
|
// ... 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));
|
.unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));
|
||||||
|
|
||||||
ui_entry::init(apps);
|
ui_entry::init(apps);
|
||||||
|
@ -14,10 +14,10 @@ pub fn init(appstate: Rc<AppS>) {
|
|||||||
match (s, u) {
|
match (s, u) {
|
||||||
(AudioSignal::AudioValuesChanged,
|
(AudioSignal::AudioValuesChanged,
|
||||||
AudioUser::AudioUserUnknown) => {
|
AudioUser::AudioUserUnknown) => {
|
||||||
println!("External volume change!");
|
debug!("External volume change!");
|
||||||
|
|
||||||
}
|
}
|
||||||
_ => println!("Nix"),
|
_ => debug!("Nix"),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,8 @@ use gdk::{GrabOwnership, GrabStatus, BUTTON_PRESS_MASK, KEY_PRESS_MASK};
|
|||||||
use gdk;
|
use gdk;
|
||||||
use gdk_sys::{GDK_KEY_Escape, GDK_CURRENT_TIME};
|
use gdk_sys::{GDK_KEY_Escape, GDK_CURRENT_TIME};
|
||||||
use glib;
|
use glib;
|
||||||
use glib_sys;
|
|
||||||
use gobject_sys::{G_SIGNAL_MATCH_ID, G_SIGNAL_MATCH_DATA};
|
|
||||||
use gobject_sys;
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk;
|
use gtk;
|
||||||
use std::mem;
|
|
||||||
use std::ptr;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
||||||
@ -146,29 +141,8 @@ pub fn update_mute_check(appstate: &AppS,
|
|||||||
toggle_signal: u64,
|
toggle_signal: u64,
|
||||||
muted: Result<bool>) {
|
muted: Result<bool>) {
|
||||||
let check_button = &appstate.gui.popup_window.mute_check;
|
let check_button = &appstate.gui.popup_window.mute_check;
|
||||||
// let check_button_ptr = unsafe {
|
|
||||||
// mem::transmute::<>k::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);
|
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 {
|
match muted {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
@ -184,18 +158,6 @@ pub fn update_mute_check(appstate: &AppS,
|
|||||||
}
|
}
|
||||||
|
|
||||||
glib::signal_handler_unblock(check_button, toggle_signal);
|
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(),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user