diff --git a/Cargo.toml b/Cargo.toml index 78a85a3ec..bfed3a539 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ error-chain = { path = "3rdparty/error-chain" } toml = "^0.4.2" serde_derive = "^1.0.9" serde = "^1.0.9" +xdg = "*" [dependencies.gtk] git = "https://github.com/gtk-rs/gtk.git" diff --git a/src/alsa_card.rs b/src/alsa_card.rs index 93dc3ea66..f55bf374e 100644 --- a/src/alsa_card.rs +++ b/src/alsa_card.rs @@ -36,11 +36,10 @@ pub struct AlsaCard { impl AlsaCard { - pub fn new( - card_name: Option, - elem_name: Option, - cb: Rc, - ) -> Result> { + pub fn new(card_name: Option, + elem_name: Option, + cb: Rc) + -> Result> { let card = { match card_name { Some(name) => get_alsa_card_by_name(name)?, @@ -51,26 +50,26 @@ impl AlsaCard { let vec_pollfd = PollDescriptors::get(&mixer)?; - let selem_id = get_selem_by_name( - &mixer, - elem_name.unwrap_or(String::from("Master")), - ).unwrap() - .get_id(); + let selem_id = + get_selem_by_name(&mixer, + elem_name.unwrap_or(String::from("Master"))) + .unwrap() + .get_id(); let acard = Box::new(AlsaCard { - _cannot_construct: (), - card: card, - mixer: mixer, - selem_id: selem_id, - watch_ids: Cell::new(vec![]), - cb: cb, - }); + _cannot_construct: (), + card: card, + mixer: mixer, + selem_id: selem_id, + watch_ids: Cell::new(vec![]), + cb: cb, + }); /* TODO: callback is registered here, which must be unregistered * when the card is destroyed!! * poll descriptors must be unwatched too */ - let watch_ids = - AlsaCard::watch_poll_descriptors(vec_pollfd, acard.as_ref()); + let watch_ids = AlsaCard::watch_poll_descriptors(vec_pollfd, + acard.as_ref()); acard.watch_ids.set(watch_ids); return Ok(acard); @@ -83,7 +82,9 @@ impl AlsaCard { pub fn chan_name(&self) -> Result { - let n = self.selem_id.get_name().map(|y| String::from(y))?; + let n = self.selem_id + .get_name() + .map(|y| String::from(y))?; return Ok(n); } @@ -112,9 +113,7 @@ impl AlsaCard { } let range = selem.get_playback_volume_range(); - selem.set_playback_volume_all( - percent_to_vol(new_vol, range), - )?; + selem.set_playback_volume_all(percent_to_vol(new_vol, range))?; return Ok(()); } @@ -141,10 +140,9 @@ impl AlsaCard { } - fn watch_poll_descriptors( - polls: Vec, - acard: &AlsaCard, - ) -> Vec { + fn watch_poll_descriptors(polls: Vec, + acard: &AlsaCard) + -> Vec { let mut watch_ids: Vec = vec![]; let acard_ptr = unsafe { mem::transmute::<&AlsaCard, glib_sys::gpointer>(acard) }; @@ -201,11 +199,10 @@ impl Drop for AlsaCard { } -extern "C" fn watch_cb( - chan: *mut glib_sys::GIOChannel, - cond: glib_sys::GIOCondition, - data: glib_sys::gpointer, -) -> glib_sys::gboolean { +extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel, + cond: glib_sys::GIOCondition, + data: glib_sys::gpointer) + -> glib_sys::gboolean { let acard = unsafe { mem::transmute::(data) }; @@ -224,15 +221,14 @@ extern "C" fn watch_cb( let mut buf: Vec = vec![0; 256]; while sread > 0 { - let stat: glib_sys::GIOStatus = unsafe { - glib_sys::g_io_channel_read_chars( - chan, - buf.as_mut_ptr() as *mut u8, - 256, - &mut sread as *mut size_t, - ptr::null_mut(), - ) - }; + let stat: glib_sys::GIOStatus = + unsafe { + glib_sys::g_io_channel_read_chars(chan, + buf.as_mut_ptr() as *mut u8, + 256, + &mut sread as *mut size_t, + ptr::null_mut()) + }; match stat { glib_sys::G_IO_STATUS_AGAIN => { @@ -250,4 +246,3 @@ extern "C" fn watch_cb( return true as glib_sys::gboolean; } - diff --git a/src/app_state.rs b/src/app_state.rs index 646cbb778..ca5d03b21 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -15,17 +15,15 @@ pub struct AppS { impl AppS { pub fn new() -> AppS { - let builder_popup_window = gtk::Builder::new_from_string(include_str!( - "../data/ui/popup-window.glade" - )); - let builder_popup_menu = gtk::Builder::new_from_string( - include_str!("../data/ui/popup-menu.glade"), - ); + let builder_popup_window = + gtk::Builder::new_from_string(include_str!("../data/ui/popup-window.glade")); + let builder_popup_menu = gtk::Builder::new_from_string(include_str!("../data/ui/popup-menu.glade")); return AppS { - gui: Gui::new(builder_popup_window, builder_popup_menu), - audio: Audio::new(None, Some(String::from("Master"))).unwrap(), - }; + gui: Gui::new(builder_popup_window, builder_popup_menu), + audio: Audio::new(None, Some(String::from("Master"))) + .unwrap(), + }; } } @@ -33,39 +31,34 @@ impl AppS { pub struct Gui { pub tray_icon: TrayIcon, pub popup_window: PopupWindow, - pub popup_menu: PopupMenu, + pub popup_menu: PopupMenu, /* prefs_dialog is dynamically created and destroyed */ } impl Gui { - pub fn new( - builder_popup_window: gtk::Builder, - builder_popup_menu: gtk::Builder, - ) -> Gui { + pub fn new(builder_popup_window: gtk::Builder, + builder_popup_menu: gtk::Builder) + -> Gui { return Gui { - tray_icon: TrayIcon::new().unwrap(), - popup_window: PopupWindow::new(builder_popup_window), - popup_menu: PopupMenu::new(builder_popup_menu), - }; + tray_icon: TrayIcon::new().unwrap(), + popup_window: PopupWindow::new(builder_popup_window), + popup_menu: PopupMenu::new(builder_popup_menu), + }; } } -create_builder_item!( - PopupWindow, - popup_window: gtk::Window, - vol_scale_adj: gtk::Adjustment, - vol_scale: gtk::Scale, - mute_check: gtk::CheckButton -); +create_builder_item!(PopupWindow, + popup_window: gtk::Window, + vol_scale_adj: gtk::Adjustment, + vol_scale: gtk::Scale, + mute_check: gtk::CheckButton); -create_builder_item!( - PopupMenu, - menu_window: gtk::Window, - menubar: gtk::MenuBar, - menu: gtk::Menu, - about_item: gtk::MenuItem, - prefs_item: gtk::MenuItem -); +create_builder_item!(PopupMenu, + menu_window: gtk::Window, + menubar: gtk::MenuBar, + menu: gtk::Menu, + about_item: gtk::MenuItem, + prefs_item: gtk::MenuItem); diff --git a/src/audio.rs b/src/audio.rs index f5c3a8ad9..d2c992d4c 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -73,10 +73,9 @@ pub struct Audio { impl Audio { - pub fn new( - card_name: Option, - elem_name: Option, - ) -> Result