Lol
This commit is contained in:
parent
47b3fe8b56
commit
ca28ad51ed
@ -36,11 +36,10 @@ pub struct AlsaCard {
|
|||||||
|
|
||||||
|
|
||||||
impl AlsaCard {
|
impl AlsaCard {
|
||||||
pub fn new(
|
pub fn new(card_name: Option<String>,
|
||||||
card_name: Option<String>,
|
elem_name: Option<String>,
|
||||||
elem_name: Option<String>,
|
cb: Rc<Fn(AlsaEvent)>)
|
||||||
cb: Rc<Fn(AlsaEvent)>,
|
-> Result<Box<AlsaCard>> {
|
||||||
) -> Result<Box<AlsaCard>> {
|
|
||||||
let card = {
|
let card = {
|
||||||
match card_name {
|
match card_name {
|
||||||
Some(name) => get_alsa_card_by_name(name)?,
|
Some(name) => get_alsa_card_by_name(name)?,
|
||||||
@ -51,26 +50,26 @@ impl AlsaCard {
|
|||||||
|
|
||||||
let vec_pollfd = PollDescriptors::get(&mixer)?;
|
let vec_pollfd = PollDescriptors::get(&mixer)?;
|
||||||
|
|
||||||
let selem_id = get_selem_by_name(
|
let selem_id =
|
||||||
&mixer,
|
get_selem_by_name(&mixer,
|
||||||
elem_name.unwrap_or(String::from("Master")),
|
elem_name.unwrap_or(String::from("Master")))
|
||||||
).unwrap()
|
.unwrap()
|
||||||
.get_id();
|
.get_id();
|
||||||
|
|
||||||
let acard = Box::new(AlsaCard {
|
let acard = Box::new(AlsaCard {
|
||||||
_cannot_construct: (),
|
_cannot_construct: (),
|
||||||
card: card,
|
card: card,
|
||||||
mixer: mixer,
|
mixer: mixer,
|
||||||
selem_id: selem_id,
|
selem_id: selem_id,
|
||||||
watch_ids: Cell::new(vec![]),
|
watch_ids: Cell::new(vec![]),
|
||||||
cb: cb,
|
cb: cb,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* TODO: callback is registered here, which must be unregistered
|
/* TODO: callback is registered here, which must be unregistered
|
||||||
* when the card is destroyed!!
|
* when the card is destroyed!!
|
||||||
* poll descriptors must be unwatched too */
|
* poll descriptors must be unwatched too */
|
||||||
let watch_ids =
|
let watch_ids = AlsaCard::watch_poll_descriptors(vec_pollfd,
|
||||||
AlsaCard::watch_poll_descriptors(vec_pollfd, acard.as_ref());
|
acard.as_ref());
|
||||||
acard.watch_ids.set(watch_ids);
|
acard.watch_ids.set(watch_ids);
|
||||||
|
|
||||||
return Ok(acard);
|
return Ok(acard);
|
||||||
@ -83,7 +82,9 @@ impl AlsaCard {
|
|||||||
|
|
||||||
|
|
||||||
pub fn chan_name(&self) -> Result<String> {
|
pub fn chan_name(&self) -> Result<String> {
|
||||||
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);
|
return Ok(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,9 +113,7 @@ impl AlsaCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let range = selem.get_playback_volume_range();
|
let range = selem.get_playback_volume_range();
|
||||||
selem.set_playback_volume_all(
|
selem.set_playback_volume_all(percent_to_vol(new_vol, range))?;
|
||||||
percent_to_vol(new_vol, range),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -141,10 +140,9 @@ impl AlsaCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn watch_poll_descriptors(
|
fn watch_poll_descriptors(polls: Vec<pollfd>,
|
||||||
polls: Vec<pollfd>,
|
acard: &AlsaCard)
|
||||||
acard: &AlsaCard,
|
-> Vec<c_uint> {
|
||||||
) -> Vec<c_uint> {
|
|
||||||
let mut watch_ids: Vec<c_uint> = vec![];
|
let mut watch_ids: Vec<c_uint> = vec![];
|
||||||
let acard_ptr =
|
let acard_ptr =
|
||||||
unsafe { mem::transmute::<&AlsaCard, glib_sys::gpointer>(acard) };
|
unsafe { mem::transmute::<&AlsaCard, glib_sys::gpointer>(acard) };
|
||||||
@ -201,11 +199,10 @@ impl Drop for AlsaCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" fn watch_cb(
|
extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
|
||||||
chan: *mut glib_sys::GIOChannel,
|
cond: glib_sys::GIOCondition,
|
||||||
cond: glib_sys::GIOCondition,
|
data: glib_sys::gpointer)
|
||||||
data: glib_sys::gpointer,
|
-> glib_sys::gboolean {
|
||||||
) -> glib_sys::gboolean {
|
|
||||||
|
|
||||||
let acard =
|
let acard =
|
||||||
unsafe { mem::transmute::<glib_sys::gpointer, &AlsaCard>(data) };
|
unsafe { mem::transmute::<glib_sys::gpointer, &AlsaCard>(data) };
|
||||||
@ -224,15 +221,14 @@ extern "C" fn watch_cb(
|
|||||||
let mut buf: Vec<u8> = vec![0; 256];
|
let mut buf: Vec<u8> = vec![0; 256];
|
||||||
|
|
||||||
while sread > 0 {
|
while sread > 0 {
|
||||||
let stat: glib_sys::GIOStatus = unsafe {
|
let stat: glib_sys::GIOStatus =
|
||||||
glib_sys::g_io_channel_read_chars(
|
unsafe {
|
||||||
chan,
|
glib_sys::g_io_channel_read_chars(chan,
|
||||||
buf.as_mut_ptr() as *mut u8,
|
buf.as_mut_ptr() as *mut u8,
|
||||||
256,
|
256,
|
||||||
&mut sread as *mut size_t,
|
&mut sread as *mut size_t,
|
||||||
ptr::null_mut(),
|
ptr::null_mut())
|
||||||
)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
match stat {
|
match stat {
|
||||||
glib_sys::G_IO_STATUS_AGAIN => {
|
glib_sys::G_IO_STATUS_AGAIN => {
|
||||||
|
261
src/app_state.rs
261
src/app_state.rs
@ -1,6 +1,13 @@
|
|||||||
use audio::Audio;
|
use audio::Audio;
|
||||||
|
use gdk;
|
||||||
use gtk;
|
use gtk;
|
||||||
use prefs::Prefs;
|
use gtk::ComboBoxTextExt;
|
||||||
|
use gtk::ComboBoxExt;
|
||||||
|
use gtk::ToggleButtonExt;
|
||||||
|
use gtk::SpinButtonExt;
|
||||||
|
use gtk::ColorChooserExt;
|
||||||
|
use gtk::EntryExt;
|
||||||
|
use prefs::*;
|
||||||
use ui_tray_icon::TrayIcon;
|
use ui_tray_icon::TrayIcon;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
@ -18,21 +25,19 @@ pub struct AppS {
|
|||||||
|
|
||||||
impl AppS {
|
impl AppS {
|
||||||
pub fn new() -> AppS {
|
pub fn new() -> AppS {
|
||||||
let builder_popup_window = gtk::Builder::new_from_string(include_str!(
|
let builder_popup_window =
|
||||||
"../data/ui/popup-window.glade"
|
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_menu = gtk::Builder::new_from_string(
|
|
||||||
include_str!("../data/ui/popup-menu.glade"),
|
|
||||||
);
|
|
||||||
let prefs = RefCell::new(Prefs::new().unwrap());
|
let prefs = RefCell::new(Prefs::new().unwrap());
|
||||||
let gui =
|
let gui =
|
||||||
Gui::new(builder_popup_window, builder_popup_menu, &prefs.borrow());
|
Gui::new(builder_popup_window, builder_popup_menu, &prefs.borrow());
|
||||||
|
|
||||||
return AppS {
|
return AppS {
|
||||||
gui: gui,
|
gui: gui,
|
||||||
audio: Audio::new(None, Some(String::from("Master"))).unwrap(),
|
audio: Audio::new(None, Some(String::from("Master")))
|
||||||
prefs: prefs,
|
.unwrap(),
|
||||||
};
|
prefs: prefs,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,66 +46,228 @@ pub struct Gui {
|
|||||||
pub tray_icon: TrayIcon,
|
pub tray_icon: TrayIcon,
|
||||||
pub popup_window: PopupWindow,
|
pub popup_window: PopupWindow,
|
||||||
pub popup_menu: PopupMenu,
|
pub popup_menu: PopupMenu,
|
||||||
/* prefs_dialog is dynamically created and destroyed,
|
/* prefs_dialog is dynamically created and destroyed */
|
||||||
* not part of the global app-state */
|
|
||||||
pub prefs_dialog: RefCell<Option<PrefsDialog>>,
|
pub prefs_dialog: RefCell<Option<PrefsDialog>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Gui {
|
impl Gui {
|
||||||
pub fn new(
|
pub fn new(builder_popup_window: gtk::Builder,
|
||||||
builder_popup_window: gtk::Builder,
|
builder_popup_menu: gtk::Builder,
|
||||||
builder_popup_menu: gtk::Builder,
|
prefs: &Prefs)
|
||||||
prefs: &Prefs,
|
-> Gui {
|
||||||
) -> Gui {
|
|
||||||
return Gui {
|
return Gui {
|
||||||
tray_icon: TrayIcon::new(prefs).unwrap(),
|
tray_icon: TrayIcon::new(prefs).unwrap(),
|
||||||
popup_window: PopupWindow::new(builder_popup_window),
|
popup_window: PopupWindow::new(builder_popup_window),
|
||||||
popup_menu: PopupMenu::new(builder_popup_menu),
|
popup_menu: PopupMenu::new(builder_popup_menu),
|
||||||
prefs_dialog: RefCell::new(None),
|
prefs_dialog: RefCell::new(None),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
create_builder_item!(
|
create_builder_item!(PopupWindow,
|
||||||
PopupWindow,
|
popup_window: gtk::Window,
|
||||||
popup_window: gtk::Window,
|
vol_scale_adj: gtk::Adjustment,
|
||||||
vol_scale_adj: gtk::Adjustment,
|
vol_scale: gtk::Scale,
|
||||||
vol_scale: gtk::Scale,
|
mute_check: gtk::CheckButton);
|
||||||
mute_check: gtk::CheckButton
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
create_builder_item!(
|
create_builder_item!(PopupMenu,
|
||||||
PopupMenu,
|
menu_window: gtk::Window,
|
||||||
menu_window: gtk::Window,
|
menubar: gtk::MenuBar,
|
||||||
menubar: gtk::MenuBar,
|
menu: gtk::Menu,
|
||||||
menu: gtk::Menu,
|
about_item: gtk::MenuItem,
|
||||||
about_item: gtk::MenuItem,
|
prefs_item: gtk::MenuItem);
|
||||||
prefs_item: gtk::MenuItem
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
pub struct PrefsDialog {
|
pub struct PrefsDialog {
|
||||||
pub prefs_dialog: gtk::Dialog,
|
pub prefs_dialog: gtk::Dialog,
|
||||||
|
|
||||||
|
/* DevicePrefs */
|
||||||
pub card_combo: gtk::ComboBoxText,
|
pub card_combo: gtk::ComboBoxText,
|
||||||
pub chan_combo: gtk::ComboBoxText,
|
pub chan_combo: gtk::ComboBoxText,
|
||||||
pub response_callback: Box<Fn(PrefsDialog, i64)>,
|
|
||||||
|
/* ViewPrefs */
|
||||||
|
pub vol_meter_draw_check: gtk::CheckButton,
|
||||||
|
pub vol_meter_pos_spin: gtk::SpinButton,
|
||||||
|
pub vol_meter_color_button: gtk::ColorButton,
|
||||||
|
pub system_theme: gtk::CheckButton,
|
||||||
|
|
||||||
|
/* BehaviorPrefs */
|
||||||
|
pub vol_control_entry: gtk::Entry,
|
||||||
|
pub scroll_step_spin: gtk::SpinButton,
|
||||||
|
pub middle_click_combo: gtk::ComboBoxText,
|
||||||
|
pub custom_entry: gtk::Entry,
|
||||||
|
|
||||||
|
/* NotifyPrefs */
|
||||||
|
pub noti_enable_check: gtk::CheckButton,
|
||||||
|
pub noti_timeout_spin: gtk::SpinButton,
|
||||||
|
// pub noti_hotkey_check: gtk::CheckButton,
|
||||||
|
pub noti_mouse_check: gtk::CheckButton,
|
||||||
|
pub noti_popup_check: gtk::CheckButton,
|
||||||
|
pub noti_ext_check: gtk::CheckButton,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrefsDialog {
|
impl PrefsDialog {
|
||||||
pub fn new(
|
pub fn new() -> PrefsDialog {
|
||||||
response_callback: Box<Fn(PrefsDialog, i64)>,
|
let builder = gtk::Builder::new_from_string(include_str!("../data/ui/prefs-dialog.glade"));
|
||||||
) -> PrefsDialog {
|
let prefs_dialog = PrefsDialog {
|
||||||
let builder = gtk::Builder::new_from_string(
|
|
||||||
include_str!("../data/ui/prefs-dialog.glade"),
|
|
||||||
);
|
|
||||||
return PrefsDialog {
|
|
||||||
prefs_dialog: builder.get_object("prefs_dialog").unwrap(),
|
prefs_dialog: builder.get_object("prefs_dialog").unwrap(),
|
||||||
|
|
||||||
card_combo: builder.get_object("card_combo").unwrap(),
|
card_combo: builder.get_object("card_combo").unwrap(),
|
||||||
chan_combo: builder.get_object("chan_combo").unwrap(),
|
chan_combo: builder.get_object("chan_combo").unwrap(),
|
||||||
response_callback,
|
|
||||||
|
vol_meter_draw_check: builder.get_object("vol_meter_draw_check")
|
||||||
|
.unwrap(),
|
||||||
|
vol_meter_pos_spin: builder.get_object("vol_meter_pos_spin")
|
||||||
|
.unwrap(),
|
||||||
|
vol_meter_color_button: builder.get_object("vol_meter_color_button")
|
||||||
|
.unwrap(),
|
||||||
|
system_theme: builder.get_object("system_theme").unwrap(),
|
||||||
|
|
||||||
|
vol_control_entry: builder.get_object("vol_control_entry").unwrap(),
|
||||||
|
scroll_step_spin: builder.get_object("scroll_step_spin").unwrap(),
|
||||||
|
middle_click_combo: builder.get_object("middle_click_combo")
|
||||||
|
.unwrap(),
|
||||||
|
custom_entry: builder.get_object("custom_entry").unwrap(),
|
||||||
|
|
||||||
|
noti_enable_check: builder.get_object("noti_enable_check").unwrap(),
|
||||||
|
noti_timeout_spin: builder.get_object("noti_timeout_spin").unwrap(),
|
||||||
|
// noti_hotkey_check: builder.get_object("noti_hotkey_check").unwrap(),
|
||||||
|
noti_mouse_check: builder.get_object("noti_mouse_check").unwrap(),
|
||||||
|
noti_popup_check: builder.get_object("noti_popup_check").unwrap(),
|
||||||
|
noti_ext_check: builder.get_object("noti_ext_check").unwrap(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
return prefs_dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn from_prefs(&self, prefs: &Prefs) {
|
||||||
|
/* DevicePrefs */
|
||||||
|
self.card_combo.remove_all();
|
||||||
|
self.card_combo.append_text(prefs.device_prefs.card.as_str());
|
||||||
|
self.card_combo.set_active(0);
|
||||||
|
|
||||||
|
self.chan_combo.remove_all();
|
||||||
|
self.chan_combo.append_text(prefs.device_prefs.channel.as_str());
|
||||||
|
self.chan_combo.set_active(0);
|
||||||
|
|
||||||
|
/* ViewPrefs */
|
||||||
|
self.vol_meter_draw_check.set_active(prefs.view_prefs.draw_vol_meter);
|
||||||
|
self.vol_meter_pos_spin.set_value(prefs.view_prefs.vol_meter_offset as
|
||||||
|
f64);
|
||||||
|
|
||||||
|
// TODO don't convert like that
|
||||||
|
let rgba = gdk::RGBA {
|
||||||
|
red: prefs.view_prefs.vol_meter_color.red as f64 / 255.0,
|
||||||
|
green: prefs.view_prefs.vol_meter_color.green as f64 / 255.0,
|
||||||
|
blue: prefs.view_prefs.vol_meter_color.blue as f64 / 255.0,
|
||||||
|
alpha: 1.0,
|
||||||
|
};
|
||||||
|
self.vol_meter_color_button.set_rgba(&rgba);
|
||||||
|
self.system_theme.set_active(prefs.view_prefs.system_theme);
|
||||||
|
|
||||||
|
/* BehaviorPrefs */
|
||||||
|
self.vol_control_entry.set_text(prefs.behavior_prefs
|
||||||
|
.vol_control_cmd
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&String::from(""))
|
||||||
|
.as_str());
|
||||||
|
self.scroll_step_spin.set_value(prefs.behavior_prefs.vol_scroll_step);
|
||||||
|
|
||||||
|
// TODO: make sure these values always match, must be a better way
|
||||||
|
// also check to_prefs()
|
||||||
|
self.middle_click_combo.append_text("Toggle Mute");
|
||||||
|
self.middle_click_combo.append_text("Show Preferences");
|
||||||
|
self.middle_click_combo.append_text("Volume Control");
|
||||||
|
self.middle_click_combo.append_text("Custom Command");
|
||||||
|
self.middle_click_combo.set_active(prefs.behavior_prefs
|
||||||
|
.middle_click_action
|
||||||
|
.into());
|
||||||
|
self.custom_entry.set_text(prefs.behavior_prefs
|
||||||
|
.custom_command
|
||||||
|
.as_ref()
|
||||||
|
.unwrap_or(&String::from(""))
|
||||||
|
.as_str());
|
||||||
|
|
||||||
|
/* NotifyPrefs */
|
||||||
|
self.noti_enable_check
|
||||||
|
.set_active(prefs.notify_prefs.enable_notifications);
|
||||||
|
self.noti_timeout_spin
|
||||||
|
.set_value(prefs.notify_prefs.notifcation_timeout as f64);
|
||||||
|
self.noti_mouse_check
|
||||||
|
.set_active(prefs.notify_prefs.notify_mouse_scroll);
|
||||||
|
self.noti_popup_check.set_active(prefs.notify_prefs.notify_popup);
|
||||||
|
self.noti_ext_check.set_active(prefs.notify_prefs.notify_external);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn to_prefs(&self) -> Prefs {
|
||||||
|
// TODO: remove duplication with default instance
|
||||||
|
let device_prefs =
|
||||||
|
DevicePrefs {
|
||||||
|
card: self.card_combo
|
||||||
|
.get_active_text()
|
||||||
|
.unwrap_or(String::from("(default)")),
|
||||||
|
channel: self.chan_combo
|
||||||
|
.get_active_text()
|
||||||
|
.unwrap_or(String::from("Master")),
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO don't convert like that
|
||||||
|
let vol_meter_color = VolColor {
|
||||||
|
red: (self.vol_meter_color_button.get_rgba().red * 255.0) as u8,
|
||||||
|
green: (self.vol_meter_color_button.get_rgba().green * 255.0) as u8,
|
||||||
|
blue: (self.vol_meter_color_button.get_rgba().blue * 255.0) as u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
let view_prefs = ViewPrefs {
|
||||||
|
draw_vol_meter: self.vol_meter_draw_check.get_active(),
|
||||||
|
vol_meter_offset: self.vol_meter_pos_spin.get_value_as_int(),
|
||||||
|
system_theme: self.system_theme.get_active(),
|
||||||
|
vol_meter_color,
|
||||||
|
};
|
||||||
|
|
||||||
|
let vol_control_cmd =
|
||||||
|
self.vol_control_entry.get_text().and_then(|x| if x.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(x)
|
||||||
|
});
|
||||||
|
|
||||||
|
let custom_command =
|
||||||
|
self.custom_entry.get_text().and_then(|x| if x.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(x)
|
||||||
|
});
|
||||||
|
|
||||||
|
let behavior_prefs = BehaviorPrefs {
|
||||||
|
vol_control_cmd,
|
||||||
|
vol_scroll_step: self.scroll_step_spin.get_value(),
|
||||||
|
middle_click_action: From::from(self.middle_click_combo
|
||||||
|
.get_active()),
|
||||||
|
custom_command,
|
||||||
|
};
|
||||||
|
|
||||||
|
let notify_prefs = NotifyPrefs {
|
||||||
|
enable_notifications: self.noti_enable_check.get_active(),
|
||||||
|
notifcation_timeout: self.noti_timeout_spin.get_value_as_int() as
|
||||||
|
i64,
|
||||||
|
notify_mouse_scroll: self.noti_mouse_check.get_active(),
|
||||||
|
notify_popup: self.noti_popup_check.get_active(),
|
||||||
|
notify_external: self.noti_ext_check.get_active(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return Prefs {
|
||||||
|
device_prefs,
|
||||||
|
view_prefs,
|
||||||
|
behavior_prefs,
|
||||||
|
notify_prefs,
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
217
src/audio.rs
217
src/audio.rs
@ -73,10 +73,9 @@ pub struct Audio {
|
|||||||
|
|
||||||
|
|
||||||
impl Audio {
|
impl Audio {
|
||||||
pub fn new(
|
pub fn new(card_name: Option<String>,
|
||||||
card_name: Option<String>,
|
elem_name: Option<String>)
|
||||||
elem_name: Option<String>,
|
-> Result<Audio> {
|
||||||
) -> Result<Audio> {
|
|
||||||
|
|
||||||
let handlers = Handlers::new();
|
let handlers = Handlers::new();
|
||||||
let last_action_timestamp = Rc::new(RefCell::new(0));
|
let last_action_timestamp = Rc::new(RefCell::new(0));
|
||||||
@ -85,8 +84,10 @@ impl Audio {
|
|||||||
let myhandler = handlers.clone();
|
let myhandler = handlers.clone();
|
||||||
let ts = last_action_timestamp.clone();
|
let ts = last_action_timestamp.clone();
|
||||||
Rc::new(move |event| {
|
Rc::new(move |event| {
|
||||||
on_alsa_event(&mut *ts.borrow_mut(), &myhandler.borrow(), event)
|
on_alsa_event(&mut *ts.borrow_mut(),
|
||||||
})
|
&myhandler.borrow(),
|
||||||
|
event)
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let audio = Audio {
|
let audio = Audio {
|
||||||
@ -101,40 +102,44 @@ impl Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn switch_acard(
|
pub fn switch_acard(&self,
|
||||||
&self,
|
card_name: Option<String>,
|
||||||
card_name: Option<String>,
|
elem_name: Option<String>,
|
||||||
elem_name: Option<String>,
|
user: AudioUser)
|
||||||
user: AudioUser,
|
-> Result<()> {
|
||||||
) -> Result<()> {
|
|
||||||
debug!("Switching cards");
|
debug!("Switching cards");
|
||||||
debug!(
|
debug!("Old card name: {}",
|
||||||
"Old card name: {}",
|
self.acard
|
||||||
self.acard.borrow().card_name().unwrap()
|
.borrow()
|
||||||
);
|
.card_name()
|
||||||
debug!(
|
.unwrap());
|
||||||
"Old chan name: {}",
|
debug!("Old chan name: {}",
|
||||||
self.acard.borrow().chan_name().unwrap()
|
self.acard
|
||||||
);
|
.borrow()
|
||||||
let cb = self.acard.borrow().cb.clone();
|
.chan_name()
|
||||||
|
.unwrap());
|
||||||
|
let cb = self.acard
|
||||||
|
.borrow()
|
||||||
|
.cb
|
||||||
|
.clone();
|
||||||
{
|
{
|
||||||
let mut ac = self.acard.borrow_mut();
|
let mut ac = self.acard.borrow_mut();
|
||||||
*ac = AlsaCard::new(card_name, elem_name, cb)?;
|
*ac = AlsaCard::new(card_name, elem_name, cb)?;
|
||||||
}
|
}
|
||||||
debug!(
|
debug!("Old card name: {}",
|
||||||
"Old card name: {}",
|
self.acard
|
||||||
self.acard.borrow().card_name().unwrap()
|
.borrow()
|
||||||
);
|
.card_name()
|
||||||
debug!(
|
.unwrap());
|
||||||
"Old chan name: {}",
|
debug!("Old chan name: {}",
|
||||||
self.acard.borrow().chan_name().unwrap()
|
self.acard
|
||||||
);
|
.borrow()
|
||||||
|
.chan_name()
|
||||||
|
.unwrap());
|
||||||
|
|
||||||
invoke_handlers(
|
invoke_handlers(&self.handlers.borrow(),
|
||||||
&self.handlers.borrow(),
|
AudioSignal::CardInitialized,
|
||||||
AudioSignal::CardInitialized,
|
user);
|
||||||
user,
|
|
||||||
);
|
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -167,20 +172,24 @@ impl Audio {
|
|||||||
*rc = glib::get_monotonic_time();
|
*rc = glib::get_monotonic_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(
|
debug!("Setting vol on card {:?} and chan {:?} to {:?} by user {:?}",
|
||||||
"Setting vol on card {:?} and chan {:?} to {:?} by user {:?}",
|
self.acard
|
||||||
self.acard.borrow().card_name().unwrap(),
|
.borrow()
|
||||||
self.acard.borrow().chan_name().unwrap(),
|
.card_name()
|
||||||
new_vol,
|
.unwrap(),
|
||||||
user
|
self.acard
|
||||||
);
|
.borrow()
|
||||||
self.acard.borrow().set_vol(new_vol)?;
|
.chan_name()
|
||||||
|
.unwrap(),
|
||||||
|
new_vol,
|
||||||
|
user);
|
||||||
|
self.acard
|
||||||
|
.borrow()
|
||||||
|
.set_vol(new_vol)?;
|
||||||
|
|
||||||
invoke_handlers(
|
invoke_handlers(&self.handlers.borrow(),
|
||||||
&self.handlers.borrow(),
|
AudioSignal::ValuesChanged,
|
||||||
AudioSignal::ValuesChanged,
|
user);
|
||||||
user,
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,21 +202,23 @@ impl Audio {
|
|||||||
let old_vol = self.vol()?;
|
let old_vol = self.vol()?;
|
||||||
let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64));
|
let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64));
|
||||||
|
|
||||||
debug!(
|
debug!("Increase vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||||
"Increase vol on card {:?} and chan {:?} by {:?} to {:?}",
|
self.acard
|
||||||
self.acard.borrow().card_name().unwrap(),
|
.borrow()
|
||||||
self.acard.borrow().chan_name().unwrap(),
|
.card_name()
|
||||||
(new_vol - old_vol),
|
.unwrap(),
|
||||||
new_vol
|
self.acard
|
||||||
);
|
.borrow()
|
||||||
|
.chan_name()
|
||||||
|
.unwrap(),
|
||||||
|
(new_vol - old_vol),
|
||||||
|
new_vol);
|
||||||
|
|
||||||
self.set_vol(new_vol, user)?;
|
self.set_vol(new_vol, user)?;
|
||||||
|
|
||||||
invoke_handlers(
|
invoke_handlers(&self.handlers.borrow(),
|
||||||
&self.handlers.borrow(),
|
AudioSignal::ValuesChanged,
|
||||||
AudioSignal::ValuesChanged,
|
user);
|
||||||
user,
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,21 +231,23 @@ impl Audio {
|
|||||||
let old_vol = self.vol()?;
|
let old_vol = self.vol()?;
|
||||||
let new_vol = old_vol - (self.scroll_step.get() as f64);
|
let new_vol = old_vol - (self.scroll_step.get() as f64);
|
||||||
|
|
||||||
debug!(
|
debug!("Decrease vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||||
"Decrease vol on card {:?} and chan {:?} by {:?} to {:?}",
|
self.acard
|
||||||
self.acard.borrow().card_name().unwrap(),
|
.borrow()
|
||||||
self.acard.borrow().chan_name().unwrap(),
|
.card_name()
|
||||||
(new_vol - old_vol),
|
.unwrap(),
|
||||||
new_vol
|
self.acard
|
||||||
);
|
.borrow()
|
||||||
|
.chan_name()
|
||||||
|
.unwrap(),
|
||||||
|
(new_vol - old_vol),
|
||||||
|
new_vol);
|
||||||
|
|
||||||
self.set_vol(new_vol, user)?;
|
self.set_vol(new_vol, user)?;
|
||||||
|
|
||||||
invoke_handlers(
|
invoke_handlers(&self.handlers.borrow(),
|
||||||
&self.handlers.borrow(),
|
AudioSignal::ValuesChanged,
|
||||||
AudioSignal::ValuesChanged,
|
user);
|
||||||
user,
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,21 +266,25 @@ impl Audio {
|
|||||||
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();
|
||||||
|
|
||||||
debug!(
|
debug!("Setting mute to {} on card {:?} and chan {:?} by user {:?}",
|
||||||
"Setting mute to {} on card {:?} and chan {:?} by user {:?}",
|
mute,
|
||||||
mute,
|
self.acard
|
||||||
self.acard.borrow().card_name().unwrap(),
|
.borrow()
|
||||||
self.acard.borrow().chan_name().unwrap(),
|
.card_name()
|
||||||
user
|
.unwrap(),
|
||||||
);
|
self.acard
|
||||||
|
.borrow()
|
||||||
|
.chan_name()
|
||||||
|
.unwrap(),
|
||||||
|
user);
|
||||||
|
|
||||||
self.acard.borrow().set_mute(mute)?;
|
self.acard
|
||||||
|
.borrow()
|
||||||
|
.set_mute(mute)?;
|
||||||
|
|
||||||
invoke_handlers(
|
invoke_handlers(&self.handlers.borrow(),
|
||||||
&self.handlers.borrow(),
|
AudioSignal::ValuesChanged,
|
||||||
AudioSignal::ValuesChanged,
|
user);
|
||||||
user,
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,16 +301,12 @@ impl Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn invoke_handlers(
|
fn invoke_handlers(handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||||
handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
signal: AudioSignal,
|
||||||
signal: AudioSignal,
|
user: AudioUser) {
|
||||||
user: AudioUser,
|
debug!("Invoking handlers for signal {:?} by user {:?}",
|
||||||
) {
|
signal,
|
||||||
debug!(
|
user);
|
||||||
"Invoking handlers for signal {:?} by user {:?}",
|
|
||||||
signal,
|
|
||||||
user
|
|
||||||
);
|
|
||||||
for handler in handlers {
|
for handler in handlers {
|
||||||
let unboxed = handler.as_ref();
|
let unboxed = handler.as_ref();
|
||||||
unboxed(signal, user);
|
unboxed(signal, user);
|
||||||
@ -301,11 +314,9 @@ fn invoke_handlers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_alsa_event(
|
fn on_alsa_event(last_action_timestamp: &mut i64,
|
||||||
last_action_timestamp: &mut i64,
|
handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||||
handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
alsa_event: AlsaEvent) {
|
||||||
alsa_event: AlsaEvent,
|
|
||||||
) {
|
|
||||||
let last: i64 = *last_action_timestamp;
|
let last: i64 = *last_action_timestamp;
|
||||||
|
|
||||||
if last != 0 {
|
if last != 0 {
|
||||||
@ -325,11 +336,9 @@ fn on_alsa_event(
|
|||||||
AlsaEvent::AlsaCardDiconnected => debug!("AlsaCardDiconnected"),
|
AlsaEvent::AlsaCardDiconnected => debug!("AlsaCardDiconnected"),
|
||||||
AlsaEvent::AlsaCardValuesChanged => {
|
AlsaEvent::AlsaCardValuesChanged => {
|
||||||
debug!("AlsaCardValuesChanged");
|
debug!("AlsaCardValuesChanged");
|
||||||
invoke_handlers(
|
invoke_handlers(handlers,
|
||||||
handlers,
|
self::AudioSignal::ValuesChanged,
|
||||||
self::AudioSignal::ValuesChanged,
|
self::AudioUser::Unknown);
|
||||||
self::AudioUser::Unknown,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
e => warn!("Unhandled alsa event: {:?}", e),
|
e => warn!("Unhandled alsa event: {:?}", e),
|
||||||
}
|
}
|
||||||
|
100
src/prefs.rs
100
src/prefs.rs
@ -16,13 +16,13 @@ const VOL_CONTROL_COMMANDS: [&str; 3] =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Serialize)]
|
#[derive(Deserialize, Debug, Serialize, Clone, Copy)]
|
||||||
#[serde(tag = "action", rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum MiddleClickAction {
|
pub enum MiddleClickAction {
|
||||||
ToggleMute,
|
ToggleMute,
|
||||||
ShowPreferences,
|
ShowPreferences,
|
||||||
VolumeControl,
|
VolumeControl,
|
||||||
CustomCommand { cmd: String },
|
CustomCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MiddleClickAction {
|
impl Default for MiddleClickAction {
|
||||||
@ -32,20 +32,46 @@ impl Default for MiddleClickAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl From<i32> for MiddleClickAction {
|
||||||
|
fn from(i: i32) -> Self {
|
||||||
|
match i {
|
||||||
|
0 => MiddleClickAction::ToggleMute,
|
||||||
|
1 => MiddleClickAction::ShowPreferences,
|
||||||
|
2 => MiddleClickAction::VolumeControl,
|
||||||
|
3 => MiddleClickAction::CustomCommand,
|
||||||
|
_ => Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Into<i32> for MiddleClickAction {
|
||||||
|
fn into(self) -> i32 {
|
||||||
|
match self {
|
||||||
|
MiddleClickAction::ToggleMute => 0,
|
||||||
|
MiddleClickAction::ShowPreferences => 1,
|
||||||
|
MiddleClickAction::VolumeControl => 2,
|
||||||
|
MiddleClickAction::CustomCommand => 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Serialize)]
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct DevicePrefs {
|
pub struct DevicePrefs {
|
||||||
pub card: String,
|
pub card: String,
|
||||||
pub channel: String,
|
pub channel: String,
|
||||||
// TODO: normalize volume?
|
// TODO: normalize volume?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DevicePrefs {
|
impl Default for DevicePrefs {
|
||||||
fn default() -> DevicePrefs {
|
fn default() -> DevicePrefs {
|
||||||
return DevicePrefs {
|
return DevicePrefs {
|
||||||
card: String::from("(default)"),
|
card: String::from("(default)"),
|
||||||
channel: String::from("Master"),
|
channel: String::from("Master"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,20 +80,20 @@ impl Default for DevicePrefs {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct ViewPrefs {
|
pub struct ViewPrefs {
|
||||||
pub draw_vol_meter: bool,
|
pub draw_vol_meter: bool,
|
||||||
pub vol_meter_offset: i64,
|
pub vol_meter_offset: i32,
|
||||||
pub system_theme: bool,
|
pub system_theme: bool,
|
||||||
pub vol_meter_color: VolColor,
|
pub vol_meter_color: VolColor,
|
||||||
// TODO: Display text folume/text volume pos?
|
// TODO: Display text folume/text volume pos?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ViewPrefs {
|
impl Default for ViewPrefs {
|
||||||
fn default() -> ViewPrefs {
|
fn default() -> ViewPrefs {
|
||||||
return ViewPrefs {
|
return ViewPrefs {
|
||||||
draw_vol_meter: true,
|
draw_vol_meter: true,
|
||||||
vol_meter_offset: 10,
|
vol_meter_offset: 10,
|
||||||
system_theme: true,
|
system_theme: true,
|
||||||
vol_meter_color: VolColor::default(),
|
vol_meter_color: VolColor::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,10 +109,10 @@ pub struct VolColor {
|
|||||||
impl Default for VolColor {
|
impl Default for VolColor {
|
||||||
fn default() -> VolColor {
|
fn default() -> VolColor {
|
||||||
return VolColor {
|
return VolColor {
|
||||||
red: 245,
|
red: 245,
|
||||||
green: 180,
|
green: 180,
|
||||||
blue: 0,
|
blue: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,16 +123,17 @@ pub struct BehaviorPrefs {
|
|||||||
pub vol_control_cmd: Option<String>,
|
pub vol_control_cmd: Option<String>,
|
||||||
pub vol_scroll_step: f64,
|
pub vol_scroll_step: f64,
|
||||||
pub middle_click_action: MiddleClickAction,
|
pub middle_click_action: MiddleClickAction,
|
||||||
// TODO: fine scroll step?
|
pub custom_command: Option<String>, // TODO: fine scroll step?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BehaviorPrefs {
|
impl Default for BehaviorPrefs {
|
||||||
fn default() -> BehaviorPrefs {
|
fn default() -> BehaviorPrefs {
|
||||||
return BehaviorPrefs {
|
return BehaviorPrefs {
|
||||||
vol_control_cmd: None,
|
vol_control_cmd: None,
|
||||||
vol_scroll_step: 5.0,
|
vol_scroll_step: 5.0,
|
||||||
middle_click_action: MiddleClickAction::default(),
|
middle_click_action: MiddleClickAction::default(),
|
||||||
};
|
custom_command: None,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,19 +145,19 @@ pub struct NotifyPrefs {
|
|||||||
pub notifcation_timeout: i64,
|
pub notifcation_timeout: i64,
|
||||||
pub notify_mouse_scroll: bool,
|
pub notify_mouse_scroll: bool,
|
||||||
pub notify_popup: bool,
|
pub notify_popup: bool,
|
||||||
pub notify_external: bool,
|
pub notify_external: bool,
|
||||||
// TODO: notify_hotkeys?
|
// TODO: notify_hotkeys?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NotifyPrefs {
|
impl Default for NotifyPrefs {
|
||||||
fn default() -> NotifyPrefs {
|
fn default() -> NotifyPrefs {
|
||||||
return NotifyPrefs {
|
return NotifyPrefs {
|
||||||
enable_notifications: true,
|
enable_notifications: true,
|
||||||
notifcation_timeout: 1500,
|
notifcation_timeout: 1500,
|
||||||
notify_mouse_scroll: true,
|
notify_mouse_scroll: true,
|
||||||
notify_popup: true,
|
notify_popup: true,
|
||||||
notify_external: true,
|
notify_external: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +168,7 @@ pub struct Prefs {
|
|||||||
pub device_prefs: DevicePrefs,
|
pub device_prefs: DevicePrefs,
|
||||||
pub view_prefs: ViewPrefs,
|
pub view_prefs: ViewPrefs,
|
||||||
pub behavior_prefs: BehaviorPrefs,
|
pub behavior_prefs: BehaviorPrefs,
|
||||||
pub notify_prefs: NotifyPrefs,
|
pub notify_prefs: NotifyPrefs,
|
||||||
// TODO: HotKeys?
|
// TODO: HotKeys?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +211,8 @@ impl Prefs {
|
|||||||
|
|
||||||
|
|
||||||
pub fn store_config(&self) -> Result<()> {
|
pub fn store_config(&self) -> Result<()> {
|
||||||
let config_path =
|
let config_path = get_xdg_dirs().place_config_file("pnmixer.toml")
|
||||||
get_xdg_dirs().place_config_file("pnmixer.toml").from_err()?;
|
.from_err()?;
|
||||||
|
|
||||||
debug!("Storing config in {:?}", config_path);
|
debug!("Storing config in {:?}", config_path);
|
||||||
|
|
||||||
@ -218,10 +245,9 @@ impl Prefs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Prefs {
|
impl Display for Prefs {
|
||||||
fn fmt(
|
fn fmt(&self,
|
||||||
&self,
|
f: &mut Formatter)
|
||||||
f: &mut Formatter,
|
-> std::result::Result<(), std::fmt::Error> {
|
||||||
) -> std::result::Result<(), std::fmt::Error> {
|
|
||||||
let s = self.to_str();
|
let s = self.to_str();
|
||||||
return write!(f, "{}", s);
|
return write!(f, "{}", s);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,9 @@ pub fn get_selem_names(mixer: &Mixer) -> Vec<String> {
|
|||||||
|
|
||||||
pub fn get_selem_by_name(mixer: &Mixer, name: String) -> Result<Selem> {
|
pub fn get_selem_by_name(mixer: &Mixer, name: String) -> Result<Selem> {
|
||||||
for selem in get_selems(mixer) {
|
for selem in get_selems(mixer) {
|
||||||
let n = selem.get_id().get_name().map(|y| String::from(y))?;
|
let n = selem.get_id()
|
||||||
|
.get_name()
|
||||||
|
.map(|y| String::from(y))?;
|
||||||
|
|
||||||
if n == name {
|
if n == name {
|
||||||
return Ok(selem);
|
return Ok(selem);
|
||||||
|
@ -21,21 +21,18 @@ pub fn copy_pixbuf(pixbuf: &gdk_pixbuf::Pixbuf) -> gdk_pixbuf::Pixbuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pixbuf_new_from_theme(
|
pub fn pixbuf_new_from_theme(icon_name: &str,
|
||||||
icon_name: &str,
|
size: i32,
|
||||||
size: i32,
|
theme: >k::IconTheme)
|
||||||
theme: >k::IconTheme,
|
-> Result<gdk_pixbuf::Pixbuf> {
|
||||||
) -> Result<gdk_pixbuf::Pixbuf> {
|
|
||||||
|
|
||||||
let icon_info = theme
|
let icon_info =
|
||||||
.lookup_icon(icon_name, size, gtk::IconLookupFlags::empty())
|
theme.lookup_icon(icon_name, size, gtk::IconLookupFlags::empty())
|
||||||
.ok_or(format!("Couldn't find icon {}", icon_name))?;
|
.ok_or(format!("Couldn't find icon {}", icon_name))?;
|
||||||
|
|
||||||
debug!(
|
debug!("Loading stock icon {} from {:?}",
|
||||||
"Loading stock icon {} from {:?}",
|
icon_name,
|
||||||
icon_name,
|
icon_info.get_filename().unwrap_or(PathBuf::new()));
|
||||||
icon_info.get_filename().unwrap_or(PathBuf::new())
|
|
||||||
);
|
|
||||||
|
|
||||||
// TODO: propagate error
|
// TODO: propagate error
|
||||||
let pixbuf = icon_info.load_icon().unwrap();
|
let pixbuf = icon_info.load_icon().unwrap();
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
use app_state::*;
|
use app_state::*;
|
||||||
use audio::*;
|
use audio::*;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use std::cell::RefCell;
|
||||||
use ui_popup_menu::*;
|
use ui_popup_menu::*;
|
||||||
use ui_popup_window::*;
|
use ui_popup_window::*;
|
||||||
use ui_tray_icon::*;
|
use ui_tray_icon::*;
|
||||||
use ui_prefs_dialog::*;
|
use ui_prefs_dialog::*;
|
||||||
|
use std::ptr;
|
||||||
|
use gtk::ResponseType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn init(appstate: Rc<AppS>) {
|
pub fn init(appstate: Rc<AppS>) {
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let mut apps = appstate.clone();
|
||||||
appstate.audio.connect_handler(
|
// appstate.audio.connect_handler(
|
||||||
Box::new(move |s, u| match (s, u) {
|
// Box::new(move |s, u| match (s, u) {
|
||||||
(AudioSignal::ValuesChanged, AudioUser::Unknown) => {
|
// (AudioSignal::ValuesChanged, AudioUser::Unknown) => {
|
||||||
debug!("External volume change!");
|
// debug!("External volume change!");
|
||||||
|
|
||||||
|
// }
|
||||||
|
// _ => debug!("Nix"),
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
}
|
|
||||||
_ => debug!("Nix"),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_tray_icon(appstate.clone());
|
init_tray_icon(appstate.clone());
|
||||||
|
@ -14,15 +14,21 @@ pub fn init_popup_menu(appstate: Rc<AppS>) {
|
|||||||
/* about_item.connect_activate_link */
|
/* about_item.connect_activate_link */
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let apps = appstate.clone();
|
||||||
let about_item = &appstate.clone().gui.popup_menu.about_item;
|
let about_item = &appstate.clone()
|
||||||
about_item.connect_activate(
|
.gui
|
||||||
move |_| { on_about_item_activate(&apps); },
|
.popup_menu
|
||||||
);
|
.about_item;
|
||||||
|
about_item.connect_activate(move |_| {
|
||||||
|
on_about_item_activate(&apps);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* about_item.connect_activate_link */
|
/* about_item.connect_activate_link */
|
||||||
{
|
{
|
||||||
let prefs_item = &appstate.clone().gui.popup_menu.prefs_item;
|
let prefs_item = &appstate.clone()
|
||||||
|
.gui
|
||||||
|
.popup_menu
|
||||||
|
.prefs_item;
|
||||||
prefs_item.connect_activate(
|
prefs_item.connect_activate(
|
||||||
move |_| { on_prefs_item_activate(appstate.clone()); },
|
move |_| { on_prefs_item_activate(appstate.clone()); },
|
||||||
);
|
);
|
||||||
|
@ -18,25 +18,37 @@ pub fn init_popup_window(appstate: Rc<AppS>) {
|
|||||||
/* mute_check.connect_toggled */
|
/* mute_check.connect_toggled */
|
||||||
{
|
{
|
||||||
let _appstate = appstate.clone();
|
let _appstate = appstate.clone();
|
||||||
let mute_check = &appstate.clone().gui.popup_window.mute_check;
|
let mute_check = &appstate.clone()
|
||||||
toggle_signal = mute_check.connect_toggled(
|
.gui
|
||||||
move |_| on_mute_check_toggled(&_appstate),
|
.popup_window
|
||||||
);
|
.mute_check;
|
||||||
|
toggle_signal =
|
||||||
|
mute_check.connect_toggled(move |_| {
|
||||||
|
on_mute_check_toggled(&_appstate)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* popup_window.connect_show */
|
/* popup_window.connect_show */
|
||||||
{
|
{
|
||||||
let _appstate = appstate.clone();
|
let _appstate = appstate.clone();
|
||||||
let popup_window = &appstate.clone().gui.popup_window.popup_window;
|
let popup_window = &appstate.clone()
|
||||||
popup_window.connect_show(
|
.gui
|
||||||
move |w| on_popup_window_show(w, &_appstate, toggle_signal),
|
.popup_window
|
||||||
);
|
.popup_window;
|
||||||
|
popup_window.connect_show(move |w| {
|
||||||
|
on_popup_window_show(w,
|
||||||
|
&_appstate,
|
||||||
|
toggle_signal)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vol_scale_adj.connect_value_changed */
|
/* vol_scale_adj.connect_value_changed */
|
||||||
{
|
{
|
||||||
let _appstate = appstate.clone();
|
let _appstate = appstate.clone();
|
||||||
let vol_scale_adj = &appstate.clone().gui.popup_window.vol_scale_adj;
|
let vol_scale_adj = &appstate.clone()
|
||||||
|
.gui
|
||||||
|
.popup_window
|
||||||
|
.vol_scale_adj;
|
||||||
vol_scale_adj.connect_value_changed(
|
vol_scale_adj.connect_value_changed(
|
||||||
move |_| on_vol_scale_value_changed(&_appstate),
|
move |_| on_vol_scale_value_changed(&_appstate),
|
||||||
);
|
);
|
||||||
@ -45,19 +57,20 @@ pub fn init_popup_window(appstate: Rc<AppS>) {
|
|||||||
/* popup_window.connect_event */
|
/* popup_window.connect_event */
|
||||||
{
|
{
|
||||||
let _appstate = appstate.clone();
|
let _appstate = appstate.clone();
|
||||||
let popup_window = &appstate.clone().gui.popup_window.popup_window;
|
let popup_window = &appstate.clone()
|
||||||
|
.gui
|
||||||
|
.popup_window
|
||||||
|
.popup_window;
|
||||||
popup_window.connect_event(move |w, e| {
|
popup_window.connect_event(move |w, e| {
|
||||||
on_popup_window_event(w, e, &_appstate)
|
on_popup_window_event(w, e, &_appstate)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_popup_window_show(
|
fn on_popup_window_show(window: >k::Window,
|
||||||
window: >k::Window,
|
appstate: &AppS,
|
||||||
appstate: &AppS,
|
toggle_signal: u64) {
|
||||||
toggle_signal: u64,
|
|
||||||
) {
|
|
||||||
let audio = &appstate.audio;
|
let audio = &appstate.audio;
|
||||||
let popup_window = &appstate.gui.popup_window;
|
let popup_window = &appstate.gui.popup_window;
|
||||||
|
|
||||||
@ -72,11 +85,10 @@ fn on_popup_window_show(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_popup_window_event(
|
fn on_popup_window_event(w: >k::Window,
|
||||||
w: >k::Window,
|
e: &gdk::Event,
|
||||||
e: &gdk::Event,
|
appstate: &AppS)
|
||||||
appstate: &AppS,
|
-> gtk::Inhibit {
|
||||||
) -> gtk::Inhibit {
|
|
||||||
match gdk::Event::get_event_type(e) {
|
match gdk::Event::get_event_type(e) {
|
||||||
gdk::EventType::GrabBroken => w.hide(),
|
gdk::EventType::GrabBroken => w.hide(),
|
||||||
gdk::EventType::KeyPress => {
|
gdk::EventType::KeyPress => {
|
||||||
@ -108,7 +120,10 @@ fn on_popup_window_event(
|
|||||||
fn on_vol_scale_value_changed(appstate: &AppS) {
|
fn on_vol_scale_value_changed(appstate: &AppS) {
|
||||||
let audio = &appstate.audio;
|
let audio = &appstate.audio;
|
||||||
|
|
||||||
let val = appstate.gui.popup_window.vol_scale.get_value();
|
let val = appstate.gui
|
||||||
|
.popup_window
|
||||||
|
.vol_scale
|
||||||
|
.get_value();
|
||||||
|
|
||||||
try_w!(audio.set_vol(val, AudioUser::Popup));
|
try_w!(audio.set_vol(val, AudioUser::Popup));
|
||||||
}
|
}
|
||||||
@ -120,11 +135,9 @@ fn on_mute_check_toggled(appstate: &AppS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn update_mute_check(
|
pub fn update_mute_check(appstate: &AppS,
|
||||||
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;
|
||||||
|
|
||||||
glib::signal_handler_block(check_button, toggle_signal);
|
glib::signal_handler_block(check_button, toggle_signal);
|
||||||
@ -157,40 +170,32 @@ fn grab_devices(window: >k::Window) -> Result<()> {
|
|||||||
let gdk_window = window.get_window().ok_or("No window?!")?;
|
let gdk_window = window.get_window().ok_or("No window?!")?;
|
||||||
|
|
||||||
/* Grab the mouse */
|
/* Grab the mouse */
|
||||||
let m_grab_status = device.grab(
|
let m_grab_status =
|
||||||
&gdk_window,
|
device.grab(&gdk_window,
|
||||||
GrabOwnership::None,
|
GrabOwnership::None,
|
||||||
true,
|
true,
|
||||||
BUTTON_PRESS_MASK,
|
BUTTON_PRESS_MASK,
|
||||||
None,
|
None,
|
||||||
GDK_CURRENT_TIME as u32,
|
GDK_CURRENT_TIME as u32);
|
||||||
);
|
|
||||||
|
|
||||||
if m_grab_status != GrabStatus::Success {
|
if m_grab_status != GrabStatus::Success {
|
||||||
warn!(
|
warn!("Could not grab {}",
|
||||||
"Could not grab {}",
|
device.get_name().unwrap_or(String::from("UNKNOWN DEVICE")));
|
||||||
device.get_name().unwrap_or(String::from("UNKNOWN DEVICE"))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grab the keyboard */
|
/* Grab the keyboard */
|
||||||
let k_dev = device.get_associated_device().ok_or(
|
let k_dev = device.get_associated_device()
|
||||||
"Couldn't get associated device",
|
.ok_or("Couldn't get associated device")?;
|
||||||
)?;
|
|
||||||
|
|
||||||
let k_grab_status = k_dev.grab(
|
let k_grab_status = k_dev.grab(&gdk_window,
|
||||||
&gdk_window,
|
GrabOwnership::None,
|
||||||
GrabOwnership::None,
|
true,
|
||||||
true,
|
KEY_PRESS_MASK,
|
||||||
KEY_PRESS_MASK,
|
None,
|
||||||
None,
|
GDK_CURRENT_TIME as u32);
|
||||||
GDK_CURRENT_TIME as u32,
|
|
||||||
);
|
|
||||||
if k_grab_status != GrabStatus::Success {
|
if k_grab_status != GrabStatus::Success {
|
||||||
warn!(
|
warn!("Could not grab {}",
|
||||||
"Could not grab {}",
|
k_dev.get_name().unwrap_or(String::from("UNKNOWN DEVICE")));
|
||||||
k_dev.get_name().unwrap_or(String::from("UNKNOWN DEVICE"))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -4,56 +4,78 @@ use gtk::prelude::*;
|
|||||||
use gtk;
|
use gtk;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use support_alsa::*;
|
use support_alsa::*;
|
||||||
|
use gtk::ResponseType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: misbehavior when popup_window is open
|
// TODO: misbehavior when popup_window is open
|
||||||
|
|
||||||
|
|
||||||
pub struct PrefsDialog {
|
|
||||||
pub prefs_dialog: gtk::Dialog,
|
|
||||||
pub card_combo: gtk::ComboBoxText,
|
|
||||||
pub chan_combo: gtk::ComboBoxText,
|
|
||||||
pub response_callback: Box<Fn(PrefsDialog, i64)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PrefsDialog {
|
|
||||||
pub fn new(
|
|
||||||
builder: gtk::Builder,
|
|
||||||
response_callback: Box<Fn(PrefsDialog, i64)>,
|
|
||||||
) -> PrefsDialog {
|
|
||||||
return PrefsDialog {
|
|
||||||
prefs_dialog: builder.get_object("prefs_dialog").unwrap(),
|
|
||||||
card_combo: builder.get_object("card_combo").unwrap(),
|
|
||||||
chan_combo: builder.get_object("chan_combo").unwrap(),
|
|
||||||
response_callback,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn show_prefs_dialog(appstate: Rc<AppS>) {
|
pub fn show_prefs_dialog(appstate: Rc<AppS>) {
|
||||||
let prefs_dialog = Rc::new();
|
if appstate.gui
|
||||||
init_prefs_dialog(&appstate, &prefs_dialog);
|
.prefs_dialog
|
||||||
|
.borrow()
|
||||||
|
.is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*appstate.gui.prefs_dialog.borrow_mut() = Some(PrefsDialog::new());
|
||||||
|
init_prefs_dialog(&appstate);
|
||||||
{
|
{
|
||||||
|
let m_pd = appstate.gui.prefs_dialog.borrow();
|
||||||
|
let prefs_dialog = &m_pd.as_ref().unwrap();
|
||||||
let prefs_dialog_w = &prefs_dialog.prefs_dialog;
|
let prefs_dialog_w = &prefs_dialog.prefs_dialog;
|
||||||
|
|
||||||
|
prefs_dialog.from_prefs(&appstate.prefs.borrow());
|
||||||
|
|
||||||
prefs_dialog_w.set_transient_for(&appstate.gui.popup_menu.menu_window);
|
prefs_dialog_w.set_transient_for(&appstate.gui.popup_menu.menu_window);
|
||||||
|
// TODO: destruct PrefsDialog when clicking Ok/Apply
|
||||||
prefs_dialog_w.present();
|
prefs_dialog_w.present();
|
||||||
// prefs_dialog_w.destroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TODO: do the references get dropped when the dialog window is gone? */
|
/* TODO: do the references get dropped when the dialog window is gone? */
|
||||||
pub fn init_prefs_dialog(appstate: &Rc<AppS>, prefs_dialog: &Rc<PrefsDialog>) {
|
pub fn init_prefs_dialog(appstate: &Rc<AppS>) {
|
||||||
|
|
||||||
/* prefs_dialog.connect_show */
|
/* prefs_dialog.connect_show */
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let apps = appstate.clone();
|
||||||
let pd = prefs_dialog.clone();
|
let m_pd = appstate.gui.prefs_dialog.borrow();
|
||||||
prefs_dialog.clone().prefs_dialog.connect_show(move |_| {
|
let pd = m_pd.as_ref().unwrap();
|
||||||
on_prefs_dialog_show(&apps, &pd);
|
pd.prefs_dialog.connect_show(move |_| { on_prefs_dialog_show(&apps); });
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prefs_dialog.connect_show */
|
||||||
|
{
|
||||||
|
let apps = appstate.clone();
|
||||||
|
let m_pd = appstate.gui.prefs_dialog.borrow();
|
||||||
|
let pd = m_pd.as_ref().unwrap();
|
||||||
|
pd.prefs_dialog.connect_response(move |_, response_id| {
|
||||||
|
|
||||||
|
let foo = 1;
|
||||||
|
if response_id == ResponseType::Ok.into() ||
|
||||||
|
response_id == ResponseType::Apply.into() {
|
||||||
|
let mut prefs = apps.prefs.borrow_mut();
|
||||||
|
let prefs_dialog = apps.gui.prefs_dialog.borrow();
|
||||||
|
*prefs = prefs_dialog.as_ref().unwrap().to_prefs();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if response_id != ResponseType::Apply.into() {
|
||||||
|
let mut prefs_dialog = apps.gui.prefs_dialog.borrow_mut();
|
||||||
|
prefs_dialog.as_ref().unwrap().prefs_dialog.destroy();
|
||||||
|
*prefs_dialog = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if response_id == ResponseType::Ok.into() ||
|
||||||
|
response_id == ResponseType::Apply.into() {
|
||||||
|
// TODO: update popup, tray_icon, hotkeys, notification and audio
|
||||||
|
let prefs = apps.prefs.borrow_mut();
|
||||||
|
try_w!(prefs.store_config());
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,36 +84,34 @@ pub fn init_prefs_dialog(appstate: &Rc<AppS>, prefs_dialog: &Rc<PrefsDialog>) {
|
|||||||
/* card_combo.connect_changed */
|
/* card_combo.connect_changed */
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let apps = appstate.clone();
|
||||||
let card_combo = &prefs_dialog.card_combo;
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
let pd = prefs_dialog.clone();
|
let card_combo = &m_cc.as_ref().unwrap().card_combo;
|
||||||
|
|
||||||
// TODO: refill channel combo
|
// TODO: refill channel combo
|
||||||
card_combo.connect_changed(
|
card_combo.connect_changed(move |_| { on_card_combo_changed(&apps); });
|
||||||
move |_| { on_card_combo_changed(&apps, &pd); },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
/* card_combo.connect_changed */
|
/* card_combo.connect_changed */
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let apps = appstate.clone();
|
||||||
let chan_combo = &prefs_dialog.chan_combo;
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
let pd = prefs_dialog.clone();
|
let chan_combo = &m_cc.as_ref().unwrap().chan_combo;
|
||||||
|
|
||||||
chan_combo.connect_changed(
|
chan_combo.connect_changed(move |_| { on_chan_combo_changed(&apps); });
|
||||||
move |_| { on_chan_combo_changed(&apps, &pd); },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_prefs_dialog_show(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
fn on_prefs_dialog_show(appstate: &AppS) {
|
||||||
let card_combo = &prefs_dialog.card_combo;
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
let chan_combo = &prefs_dialog.chan_combo;
|
let card_combo = &m_cc.as_ref().unwrap().card_combo;
|
||||||
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
|
let chan_combo = &m_cc.as_ref().unwrap().chan_combo;
|
||||||
let acard = appstate.audio.acard.borrow();
|
let acard = appstate.audio.acard.borrow();
|
||||||
|
|
||||||
|
|
||||||
/* set card combo */
|
/* set card combo */
|
||||||
let cur_card_name =
|
let cur_card_name = try_w!(acard.card_name(),
|
||||||
try_w!(acard.card_name(), "Can't get current card name!");
|
"Can't get current card name!");
|
||||||
let available_card_names = get_alsa_card_names();
|
let available_card_names = get_alsa_card_names();
|
||||||
|
|
||||||
/* set_active_id doesn't work, so save the index */
|
/* set_active_id doesn't work, so save the index */
|
||||||
@ -129,12 +149,13 @@ fn on_prefs_dialog_show(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_card_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
fn on_card_combo_changed(appstate: &AppS) {
|
||||||
let card_combo = &prefs_dialog.card_combo;
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
let chan_combo = &prefs_dialog.chan_combo;
|
let card_combo = &m_cc.as_ref().unwrap().card_combo;
|
||||||
let active_card_item = try_w!(card_combo.get_active_text().ok_or(
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
"No active Card item found",
|
let chan_combo = &m_cc.as_ref().unwrap().chan_combo;
|
||||||
));
|
let active_card_item =
|
||||||
|
try_w!(card_combo.get_active_text().ok_or("No active Card item found"));
|
||||||
let active_chan_item = chan_combo.get_active_id();
|
let active_chan_item = chan_combo.get_active_id();
|
||||||
let cur_card_name = {
|
let cur_card_name = {
|
||||||
let acard = appstate.audio.acard.borrow();
|
let acard = appstate.audio.acard.borrow();
|
||||||
@ -142,21 +163,20 @@ fn on_card_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if active_card_item != cur_card_name {
|
if active_card_item != cur_card_name {
|
||||||
appstate.audio.switch_acard(
|
appstate.audio.switch_acard(Some(cur_card_name),
|
||||||
Some(cur_card_name),
|
active_chan_item,
|
||||||
active_chan_item,
|
AudioUser::PrefsWindow);
|
||||||
AudioUser::PrefsWindow,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_chan_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
fn on_chan_combo_changed(appstate: &AppS) {
|
||||||
let card_combo = &prefs_dialog.card_combo;
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
let chan_combo = &prefs_dialog.chan_combo;
|
let card_combo = &m_cc.as_ref().unwrap().card_combo;
|
||||||
let active_chan_item = try_w!(chan_combo.get_active_text().ok_or(
|
let m_cc = appstate.gui.prefs_dialog.borrow();
|
||||||
"No active Chan item found",
|
let chan_combo = &m_cc.as_ref().unwrap().chan_combo;
|
||||||
));
|
let active_chan_item =
|
||||||
|
try_w!(chan_combo.get_active_text().ok_or("No active Chan item found"));
|
||||||
let cur_card_name = {
|
let cur_card_name = {
|
||||||
let acard = appstate.audio.acard.borrow();
|
let acard = appstate.audio.acard.borrow();
|
||||||
acard.card_name().ok()
|
acard.card_name().ok()
|
||||||
@ -167,10 +187,11 @@ fn on_chan_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if active_chan_item != cur_chan_name {
|
if active_chan_item != cur_chan_name {
|
||||||
appstate.audio.switch_acard(
|
appstate.audio.switch_acard(cur_card_name,
|
||||||
cur_card_name,
|
Some(active_chan_item),
|
||||||
Some(active_chan_item),
|
AudioUser::PrefsWindow);
|
||||||
AudioUser::PrefsWindow,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn prefs_dialog_to_prefs(prefs_dialog: &PrefsDialog) {}
|
||||||
|
@ -43,19 +43,18 @@ impl TrayIcon {
|
|||||||
let status_icon = gtk::StatusIcon::new();
|
let status_icon = gtk::StatusIcon::new();
|
||||||
|
|
||||||
return Ok(TrayIcon {
|
return Ok(TrayIcon {
|
||||||
volmeter,
|
volmeter,
|
||||||
audio_pix: RefCell::new(audio_pix),
|
audio_pix: RefCell::new(audio_pix),
|
||||||
status_icon,
|
status_icon,
|
||||||
icon_size: Cell::new(ICON_MIN_SIZE),
|
icon_size: Cell::new(ICON_MIN_SIZE),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(
|
fn update(&self,
|
||||||
&self,
|
prefs: &Prefs,
|
||||||
prefs: &Prefs,
|
audio: &Audio,
|
||||||
audio: &Audio,
|
m_size: Option<i32>)
|
||||||
m_size: Option<i32>,
|
-> Result<()> {
|
||||||
) -> Result<()> {
|
|
||||||
match m_size {
|
match m_size {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
if s < ICON_MIN_SIZE {
|
if s < ICON_MIN_SIZE {
|
||||||
@ -105,37 +104,30 @@ pub struct VolMeter {
|
|||||||
impl VolMeter {
|
impl VolMeter {
|
||||||
pub fn new(prefs: &Prefs) -> VolMeter {
|
pub fn new(prefs: &Prefs) -> VolMeter {
|
||||||
return VolMeter {
|
return VolMeter {
|
||||||
red: prefs.view_prefs.vol_meter_color.red,
|
red: prefs.view_prefs.vol_meter_color.red,
|
||||||
green: prefs.view_prefs.vol_meter_color.green,
|
green: prefs.view_prefs.vol_meter_color.green,
|
||||||
blue: prefs.view_prefs.vol_meter_color.blue,
|
blue: prefs.view_prefs.vol_meter_color.blue,
|
||||||
x_offset_pct: prefs.view_prefs.vol_meter_offset,
|
x_offset_pct: prefs.view_prefs.vol_meter_offset as i64,
|
||||||
y_offset_pct: 10,
|
y_offset_pct: 10,
|
||||||
/* dynamic */
|
/* dynamic */
|
||||||
width: Cell::new(0),
|
width: Cell::new(0),
|
||||||
row: RefCell::new(vec![]),
|
row: RefCell::new(vec![]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: cache input pixbuf?
|
// TODO: cache input pixbuf?
|
||||||
fn meter_draw(
|
fn meter_draw(&self,
|
||||||
&self,
|
volume: i64,
|
||||||
volume: i64,
|
pixbuf: &gdk_pixbuf::Pixbuf)
|
||||||
pixbuf: &gdk_pixbuf::Pixbuf,
|
-> Result<gdk_pixbuf::Pixbuf> {
|
||||||
) -> Result<gdk_pixbuf::Pixbuf> {
|
|
||||||
|
|
||||||
ensure!(
|
ensure!(pixbuf.get_colorspace() == GDK_COLORSPACE_RGB,
|
||||||
pixbuf.get_colorspace() == GDK_COLORSPACE_RGB,
|
"Invalid colorspace in pixbuf");
|
||||||
"Invalid colorspace in pixbuf"
|
ensure!(pixbuf.get_bits_per_sample() == 8,
|
||||||
);
|
"Invalid bits per sample in pixbuf");
|
||||||
ensure!(
|
|
||||||
pixbuf.get_bits_per_sample() == 8,
|
|
||||||
"Invalid bits per sample in pixbuf"
|
|
||||||
);
|
|
||||||
ensure!(pixbuf.get_has_alpha(), "No alpha channel in pixbuf");
|
ensure!(pixbuf.get_has_alpha(), "No alpha channel in pixbuf");
|
||||||
ensure!(
|
ensure!(pixbuf.get_n_channels() == 4,
|
||||||
pixbuf.get_n_channels() == 4,
|
"Invalid number of channels in pixbuf");
|
||||||
"Invalid number of channels in pixbuf"
|
|
||||||
);
|
|
||||||
|
|
||||||
let i_width = pixbuf.get_width() as i64;
|
let i_width = pixbuf.get_width() as i64;
|
||||||
let i_height = pixbuf.get_height() as i64;
|
let i_height = pixbuf.get_height() as i64;
|
||||||
@ -144,21 +136,16 @@ impl VolMeter {
|
|||||||
|
|
||||||
let vm_width = i_width / 6;
|
let vm_width = i_width / 6;
|
||||||
let x = (self.x_offset_pct as f64 *
|
let x = (self.x_offset_pct as f64 *
|
||||||
((i_width - vm_width) as f64 / 100.0)) as
|
((i_width - vm_width) as f64 / 100.0)) as i64;
|
||||||
i64;
|
ensure!(x >= 0 && (x + vm_width) <= i_width,
|
||||||
ensure!(
|
"x coordinate invalid: {}",
|
||||||
x >= 0 && (x + vm_width) <= i_width,
|
x);
|
||||||
"x coordinate invalid: {}",
|
|
||||||
x
|
|
||||||
);
|
|
||||||
let y = (self.y_offset_pct as f64 * (i_height as f64 / 100.0)) as i64;
|
let y = (self.y_offset_pct as f64 * (i_height as f64 / 100.0)) as i64;
|
||||||
let vm_height =
|
let vm_height =
|
||||||
((i_height - (y * 2)) as f64 * (volume as f64 / 100.0)) as i64;
|
((i_height - (y * 2)) as f64 * (volume as f64 / 100.0)) as i64;
|
||||||
ensure!(
|
ensure!(y >= 0 && (y + vm_height) <= i_height,
|
||||||
y >= 0 && (y + vm_height) <= i_height,
|
"y coordinate invalid: {}",
|
||||||
"y coordinate invalid: {}",
|
y);
|
||||||
y
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Let's check if the icon width changed, in which case we
|
/* Let's check if the icon width changed, in which case we
|
||||||
* must reinit our internal row of pixels.
|
* must reinit our internal row of pixels.
|
||||||
@ -194,9 +181,8 @@ impl VolMeter {
|
|||||||
let p_index = ((row_offset * rowstride) + col_offset) as usize;
|
let p_index = ((row_offset * rowstride) + col_offset) as usize;
|
||||||
|
|
||||||
let row = self.row.borrow();
|
let row = self.row.borrow();
|
||||||
pixels[p_index..p_index + row.len()].copy_from_slice(
|
pixels[p_index..p_index + row.len()]
|
||||||
row.as_ref(),
|
.copy_from_slice(row.as_ref());
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,14 +305,10 @@ pub fn init_tray_icon(appstate: Rc<AppS>) {
|
|||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let apps = appstate.clone();
|
||||||
tray_icon.status_icon.connect_size_changed(move |_, size| {
|
tray_icon.status_icon.connect_size_changed(move |_, size| {
|
||||||
try_wr!(
|
try_wr!(apps.gui.tray_icon.update(&apps.prefs.borrow_mut(),
|
||||||
apps.gui.tray_icon.update(
|
&apps.audio,
|
||||||
&apps.prefs.borrow_mut(),
|
Some(size)),
|
||||||
&apps.audio,
|
false);
|
||||||
Some(size),
|
|
||||||
),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -334,9 +316,9 @@ pub fn init_tray_icon(appstate: Rc<AppS>) {
|
|||||||
/* tray_icon.connect_activate */
|
/* tray_icon.connect_activate */
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
let apps = appstate.clone();
|
||||||
tray_icon.status_icon.connect_activate(
|
tray_icon.status_icon.connect_activate(move |_| {
|
||||||
move |_| on_tray_icon_activate(&apps),
|
on_tray_icon_activate(&apps)
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tray_icon.connect_scroll_event */
|
/* tray_icon.connect_scroll_event */
|
||||||
@ -385,10 +367,9 @@ fn on_tray_icon_popup_menu(appstate: &AppS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_tray_icon_scroll_event(
|
fn on_tray_icon_scroll_event(appstate: &AppS,
|
||||||
appstate: &AppS,
|
event: &gdk::EventScroll)
|
||||||
event: &gdk::EventScroll,
|
-> bool {
|
||||||
) -> bool {
|
|
||||||
|
|
||||||
let scroll_dir: gdk::ScrollDirection = event.get_direction();
|
let scroll_dir: gdk::ScrollDirection = event.get_direction();
|
||||||
match scroll_dir {
|
match scroll_dir {
|
||||||
@ -405,10 +386,9 @@ fn on_tray_icon_scroll_event(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_tray_button_release_event(
|
fn on_tray_button_release_event(appstate: &AppS,
|
||||||
appstate: &AppS,
|
event_button: &gdk::EventButton)
|
||||||
event_button: &gdk::EventButton,
|
-> bool {
|
||||||
) -> bool {
|
|
||||||
let button = event_button.get_button();
|
let button = event_button.get_button();
|
||||||
|
|
||||||
if button != 2 {
|
if button != 2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user