pnmixer-rust/src/ui_tray_icon.rs

64 lines
1.5 KiB
Rust
Raw Normal View History

2017-06-29 12:55:07 +00:00
use app_state::*;
2017-06-30 23:56:32 +00:00
use gdk;
use gdk_sys;
use glib;
use glib_sys;
use std::mem;
2017-06-29 12:55:07 +00:00
use gtk::prelude::*;
2017-06-30 15:24:26 +00:00
use std::rc::Rc;
2017-06-30 23:56:32 +00:00
use std::cell::RefCell;
use libc;
use audio::AudioUser::*;
use errors::*;
2017-06-29 12:55:07 +00:00
2017-06-30 15:24:26 +00:00
pub fn init_tray_icon(appstate: Rc<AppS>) {
2017-06-30 23:56:32 +00:00
{
let apps = appstate.clone();
let tray_icon = &appstate.gui.status_icon;
tray_icon.connect_activate(move |_| on_tray_icon_activate(&apps));
tray_icon.set_visible(true);
}
{
let tray_icon = &appstate.clone().gui.status_icon;
tray_icon.connect_scroll_event(move |_, e| {
on_tray_icon_scroll_event(&appstate.clone(), &e)
});
tray_icon.set_visible(true);
}
2017-06-29 12:55:07 +00:00
2017-06-30 15:24:26 +00:00
}
2017-06-29 12:55:07 +00:00
2017-06-30 15:24:26 +00:00
fn on_tray_icon_activate(appstate: &AppS) {
let popup_window = &appstate.gui.popup_window.window;
if popup_window.get_visible() {
popup_window.hide();
} else {
popup_window.show_now();
}
2017-06-29 12:55:07 +00:00
}
2017-06-30 23:56:32 +00:00
fn on_tray_icon_scroll_event(appstate: &AppS,
event: &gdk::EventScroll)
-> bool {
let scroll_dir = event.as_ref().direction;
match scroll_dir {
gdk_sys::GdkScrollDirection::Up => {
try_wr!(appstate.acard.borrow().increase_vol(AudioUserTrayIcon),
false);
}
gdk_sys::GdkScrollDirection::Down => {
try_wr!(appstate.acard.borrow().decrease_vol(AudioUserTrayIcon),
false);
}
_ => (),
}
return false;
}