From d12d43f40475cd5c2f74c2926a140127392268fa Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 3 Jul 2017 23:52:41 +0200 Subject: [PATCH] Update --- src/audio.rs | 8 ++++++-- src/ui_popup_window.rs | 4 +--- src/ui_tray_icon.rs | 29 ++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/audio.rs b/src/audio.rs index 2f33e2757..8eae24038 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -260,8 +260,6 @@ impl Audio { let mut rc = self.last_action_timestamp.borrow_mut(); *rc = glib::get_monotonic_time(); - - debug!("Setting mute to {} on card {:?} and chan {:?} by user {:?}", mute, self.acard @@ -285,6 +283,12 @@ impl Audio { } + pub fn toggle_mute(&self, user: AudioUser) -> Result<()> { + let muted = self.get_mute()?; + return self.set_mute(!muted, user); + } + + pub fn connect_handler(&self, cb: Box) { self.handlers.add_handler(cb); } diff --git a/src/ui_popup_window.rs b/src/ui_popup_window.rs index c9e82e62e..a7f46cc22 100644 --- a/src/ui_popup_window.rs +++ b/src/ui_popup_window.rs @@ -131,9 +131,7 @@ fn on_vol_scale_value_changed(appstate: &AppS) { fn on_mute_check_toggled(appstate: &AppS) { let audio = &appstate.audio; - - let muted = try_w!(audio.get_mute()); - let _ = try_w!(audio.set_mute(!muted, AudioUser::Popup)); + try_w!(audio.toggle_mute(AudioUser::Popup)) } diff --git a/src/ui_tray_icon.rs b/src/ui_tray_icon.rs index 272eeaa4b..4e6d56065 100644 --- a/src/ui_tray_icon.rs +++ b/src/ui_tray_icon.rs @@ -115,10 +115,8 @@ fn pixbuf_new_from_theme(icon_name: &str, fn update_tray_icon(audio_pix: &AudioPix, appstate: &AppS) { - debug!("Update tray icon"); let status_icon = &appstate.gui.status_icon; let pixbuf = audio_pix.select_pix(appstate.audio.vol_level()); - debug!("VolLevel: {:?}", appstate.audio.vol_level()); status_icon.set_from_pixbuf(Some(pixbuf)); } @@ -134,7 +132,6 @@ pub fn init_tray_icon(appstate: Rc) { appstate.audio.connect_handler(Box::new(move |s, u| { match (s, u) { (AudioSignal::ValuesChanged, _) => { - debug!("tray icon handler: {:?} {:?}", s, u); update_tray_icon(&_audio_pix.borrow(), &apps); }, _ => (), @@ -176,6 +173,15 @@ pub fn init_tray_icon(appstate: Rc) { on_tray_icon_popup_menu(&apps) }); } + + /* tray_icon.connect_button_release_event */ + { + let apps = appstate.clone(); + let tray_icon = &appstate.clone().gui.status_icon; + tray_icon.connect_button_release_event(move |_, eb| { + on_tray_button_release_event(&apps, eb) + }); + } } @@ -241,3 +247,20 @@ fn on_tray_icon_size_changed(appstate: &AppS, return false; } + + +fn on_tray_button_release_event(appstate: &AppS, + event_button: &gdk::EventButton) + -> bool { + let button = event_button.get_button(); + + if button != 2 { + // not middle-click + return false; + } + + let audio = &appstate.audio; + try_wr!(audio.toggle_mute(AudioUser::Popup), false); + + return false; +}