This commit is contained in:
Julian Ospald 2017-07-03 23:52:41 +02:00
parent 17a6ba615c
commit d12d43f404
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 33 additions and 8 deletions

View File

@ -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<Fn(AudioSignal, AudioUser)>) {
self.handlers.add_handler(cb);
}

View File

@ -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))
}

View File

@ -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<AppS>) {
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<AppS>) {
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;
}