Blah
This commit is contained in:
parent
e70e88690b
commit
47b3fe8b56
@ -36,10 +36,11 @@ pub struct AlsaCard {
|
||||
|
||||
|
||||
impl AlsaCard {
|
||||
pub fn new(card_name: Option<String>,
|
||||
elem_name: Option<String>,
|
||||
cb: Rc<Fn(AlsaEvent)>)
|
||||
-> Result<Box<AlsaCard>> {
|
||||
pub fn new(
|
||||
card_name: Option<String>,
|
||||
elem_name: Option<String>,
|
||||
cb: Rc<Fn(AlsaEvent)>,
|
||||
) -> Result<Box<AlsaCard>> {
|
||||
let card = {
|
||||
match card_name {
|
||||
Some(name) => get_alsa_card_by_name(name)?,
|
||||
@ -50,26 +51,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);
|
||||
@ -82,9 +83,7 @@ impl AlsaCard {
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -113,7 +112,9 @@ 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(());
|
||||
}
|
||||
@ -140,9 +141,10 @@ impl AlsaCard {
|
||||
}
|
||||
|
||||
|
||||
fn watch_poll_descriptors(polls: Vec<pollfd>,
|
||||
acard: &AlsaCard)
|
||||
-> Vec<c_uint> {
|
||||
fn watch_poll_descriptors(
|
||||
polls: Vec<pollfd>,
|
||||
acard: &AlsaCard,
|
||||
) -> Vec<c_uint> {
|
||||
let mut watch_ids: Vec<c_uint> = vec![];
|
||||
let acard_ptr =
|
||||
unsafe { mem::transmute::<&AlsaCard, glib_sys::gpointer>(acard) };
|
||||
@ -199,10 +201,11 @@ 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::<glib_sys::gpointer, &AlsaCard>(data) };
|
||||
@ -221,14 +224,15 @@ extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
|
||||
let mut buf: Vec<u8> = 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 => {
|
||||
|
@ -18,19 +18,21 @@ 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"),
|
||||
);
|
||||
let prefs = RefCell::new(Prefs::new().unwrap());
|
||||
let gui =
|
||||
Gui::new(builder_popup_window, builder_popup_menu, &prefs.borrow());
|
||||
|
||||
return AppS {
|
||||
gui: gui,
|
||||
audio: Audio::new(None, Some(String::from("Master")))
|
||||
.unwrap(),
|
||||
prefs: prefs,
|
||||
};
|
||||
gui: gui,
|
||||
audio: Audio::new(None, Some(String::from("Master"))).unwrap(),
|
||||
prefs: prefs,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,35 +40,67 @@ impl AppS {
|
||||
pub struct Gui {
|
||||
pub tray_icon: TrayIcon,
|
||||
pub popup_window: PopupWindow,
|
||||
pub popup_menu: PopupMenu,
|
||||
/* prefs_dialog is dynamically created and destroyed */
|
||||
pub popup_menu: PopupMenu,
|
||||
/* prefs_dialog is dynamically created and destroyed,
|
||||
* not part of the global app-state */
|
||||
pub prefs_dialog: RefCell<Option<PrefsDialog>>,
|
||||
}
|
||||
|
||||
|
||||
impl Gui {
|
||||
pub fn new(builder_popup_window: gtk::Builder,
|
||||
builder_popup_menu: gtk::Builder,
|
||||
prefs: &Prefs)
|
||||
-> Gui {
|
||||
pub fn new(
|
||||
builder_popup_window: gtk::Builder,
|
||||
builder_popup_menu: gtk::Builder,
|
||||
prefs: &Prefs,
|
||||
) -> Gui {
|
||||
return Gui {
|
||||
tray_icon: TrayIcon::new(prefs).unwrap(),
|
||||
popup_window: PopupWindow::new(builder_popup_window),
|
||||
popup_menu: PopupMenu::new(builder_popup_menu),
|
||||
};
|
||||
tray_icon: TrayIcon::new(prefs).unwrap(),
|
||||
popup_window: PopupWindow::new(builder_popup_window),
|
||||
popup_menu: PopupMenu::new(builder_popup_menu),
|
||||
prefs_dialog: RefCell::new(None),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
|
||||
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(
|
||||
response_callback: Box<Fn(PrefsDialog, i64)>,
|
||||
) -> 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(),
|
||||
card_combo: builder.get_object("card_combo").unwrap(),
|
||||
chan_combo: builder.get_object("chan_combo").unwrap(),
|
||||
response_callback,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
217
src/audio.rs
217
src/audio.rs
@ -73,9 +73,10 @@ pub struct Audio {
|
||||
|
||||
|
||||
impl Audio {
|
||||
pub fn new(card_name: Option<String>,
|
||||
elem_name: Option<String>)
|
||||
-> Result<Audio> {
|
||||
pub fn new(
|
||||
card_name: Option<String>,
|
||||
elem_name: Option<String>,
|
||||
) -> Result<Audio> {
|
||||
|
||||
let handlers = Handlers::new();
|
||||
let last_action_timestamp = Rc::new(RefCell::new(0));
|
||||
@ -84,10 +85,8 @@ impl Audio {
|
||||
let myhandler = handlers.clone();
|
||||
let ts = last_action_timestamp.clone();
|
||||
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 {
|
||||
@ -102,44 +101,40 @@ impl Audio {
|
||||
}
|
||||
|
||||
|
||||
pub fn switch_acard(&self,
|
||||
card_name: Option<String>,
|
||||
elem_name: Option<String>,
|
||||
user: AudioUser)
|
||||
-> Result<()> {
|
||||
pub fn switch_acard(
|
||||
&self,
|
||||
card_name: Option<String>,
|
||||
elem_name: Option<String>,
|
||||
user: AudioUser,
|
||||
) -> Result<()> {
|
||||
debug!("Switching cards");
|
||||
debug!("Old card name: {}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.card_name()
|
||||
.unwrap());
|
||||
debug!("Old chan name: {}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.chan_name()
|
||||
.unwrap());
|
||||
let cb = self.acard
|
||||
.borrow()
|
||||
.cb
|
||||
.clone();
|
||||
debug!(
|
||||
"Old card name: {}",
|
||||
self.acard.borrow().card_name().unwrap()
|
||||
);
|
||||
debug!(
|
||||
"Old chan name: {}",
|
||||
self.acard.borrow().chan_name().unwrap()
|
||||
);
|
||||
let cb = self.acard.borrow().cb.clone();
|
||||
{
|
||||
let mut ac = self.acard.borrow_mut();
|
||||
*ac = AlsaCard::new(card_name, elem_name, cb)?;
|
||||
}
|
||||
debug!("Old card name: {}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.card_name()
|
||||
.unwrap());
|
||||
debug!("Old chan name: {}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.chan_name()
|
||||
.unwrap());
|
||||
debug!(
|
||||
"Old card name: {}",
|
||||
self.acard.borrow().card_name().unwrap()
|
||||
);
|
||||
debug!(
|
||||
"Old chan name: {}",
|
||||
self.acard.borrow().chan_name().unwrap()
|
||||
);
|
||||
|
||||
invoke_handlers(&self.handlers.borrow(),
|
||||
AudioSignal::CardInitialized,
|
||||
user);
|
||||
invoke_handlers(
|
||||
&self.handlers.borrow(),
|
||||
AudioSignal::CardInitialized,
|
||||
user,
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@ -172,24 +167,20 @@ impl Audio {
|
||||
*rc = glib::get_monotonic_time();
|
||||
}
|
||||
|
||||
debug!("Setting vol on card {:?} and chan {:?} to {:?} by user {:?}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.card_name()
|
||||
.unwrap(),
|
||||
self.acard
|
||||
.borrow()
|
||||
.chan_name()
|
||||
.unwrap(),
|
||||
new_vol,
|
||||
user);
|
||||
self.acard
|
||||
.borrow()
|
||||
.set_vol(new_vol)?;
|
||||
debug!(
|
||||
"Setting vol on card {:?} and chan {:?} to {:?} by user {:?}",
|
||||
self.acard.borrow().card_name().unwrap(),
|
||||
self.acard.borrow().chan_name().unwrap(),
|
||||
new_vol,
|
||||
user
|
||||
);
|
||||
self.acard.borrow().set_vol(new_vol)?;
|
||||
|
||||
invoke_handlers(&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user);
|
||||
invoke_handlers(
|
||||
&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -202,23 +193,21 @@ impl Audio {
|
||||
let old_vol = self.vol()?;
|
||||
let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64));
|
||||
|
||||
debug!("Increase vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.card_name()
|
||||
.unwrap(),
|
||||
self.acard
|
||||
.borrow()
|
||||
.chan_name()
|
||||
.unwrap(),
|
||||
(new_vol - old_vol),
|
||||
new_vol);
|
||||
debug!(
|
||||
"Increase vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||
self.acard.borrow().card_name().unwrap(),
|
||||
self.acard.borrow().chan_name().unwrap(),
|
||||
(new_vol - old_vol),
|
||||
new_vol
|
||||
);
|
||||
|
||||
self.set_vol(new_vol, user)?;
|
||||
|
||||
invoke_handlers(&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user);
|
||||
invoke_handlers(
|
||||
&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -231,23 +220,21 @@ impl Audio {
|
||||
let old_vol = self.vol()?;
|
||||
let new_vol = old_vol - (self.scroll_step.get() as f64);
|
||||
|
||||
debug!("Decrease vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||
self.acard
|
||||
.borrow()
|
||||
.card_name()
|
||||
.unwrap(),
|
||||
self.acard
|
||||
.borrow()
|
||||
.chan_name()
|
||||
.unwrap(),
|
||||
(new_vol - old_vol),
|
||||
new_vol);
|
||||
debug!(
|
||||
"Decrease vol on card {:?} and chan {:?} by {:?} to {:?}",
|
||||
self.acard.borrow().card_name().unwrap(),
|
||||
self.acard.borrow().chan_name().unwrap(),
|
||||
(new_vol - old_vol),
|
||||
new_vol
|
||||
);
|
||||
|
||||
self.set_vol(new_vol, user)?;
|
||||
|
||||
invoke_handlers(&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user);
|
||||
invoke_handlers(
|
||||
&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -266,25 +253,21 @@ 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
|
||||
.borrow()
|
||||
.card_name()
|
||||
.unwrap(),
|
||||
self.acard
|
||||
.borrow()
|
||||
.chan_name()
|
||||
.unwrap(),
|
||||
user);
|
||||
debug!(
|
||||
"Setting mute to {} on card {:?} and chan {:?} by user {:?}",
|
||||
mute,
|
||||
self.acard.borrow().card_name().unwrap(),
|
||||
self.acard.borrow().chan_name().unwrap(),
|
||||
user
|
||||
);
|
||||
|
||||
self.acard
|
||||
.borrow()
|
||||
.set_mute(mute)?;
|
||||
self.acard.borrow().set_mute(mute)?;
|
||||
|
||||
invoke_handlers(&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user);
|
||||
invoke_handlers(
|
||||
&self.handlers.borrow(),
|
||||
AudioSignal::ValuesChanged,
|
||||
user,
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -301,12 +284,16 @@ impl Audio {
|
||||
}
|
||||
|
||||
|
||||
fn invoke_handlers(handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||
signal: AudioSignal,
|
||||
user: AudioUser) {
|
||||
debug!("Invoking handlers for signal {:?} by user {:?}",
|
||||
signal,
|
||||
user);
|
||||
fn invoke_handlers(
|
||||
handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||
signal: AudioSignal,
|
||||
user: AudioUser,
|
||||
) {
|
||||
debug!(
|
||||
"Invoking handlers for signal {:?} by user {:?}",
|
||||
signal,
|
||||
user
|
||||
);
|
||||
for handler in handlers {
|
||||
let unboxed = handler.as_ref();
|
||||
unboxed(signal, user);
|
||||
@ -314,9 +301,11 @@ fn invoke_handlers(handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||
}
|
||||
|
||||
|
||||
fn on_alsa_event(last_action_timestamp: &mut i64,
|
||||
handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||
alsa_event: AlsaEvent) {
|
||||
fn on_alsa_event(
|
||||
last_action_timestamp: &mut i64,
|
||||
handlers: &Vec<Box<Fn(AudioSignal, AudioUser)>>,
|
||||
alsa_event: AlsaEvent,
|
||||
) {
|
||||
let last: i64 = *last_action_timestamp;
|
||||
|
||||
if last != 0 {
|
||||
@ -336,9 +325,11 @@ fn on_alsa_event(last_action_timestamp: &mut i64,
|
||||
AlsaEvent::AlsaCardDiconnected => debug!("AlsaCardDiconnected"),
|
||||
AlsaEvent::AlsaCardValuesChanged => {
|
||||
debug!("AlsaCardValuesChanged");
|
||||
invoke_handlers(handlers,
|
||||
self::AudioSignal::ValuesChanged,
|
||||
self::AudioUser::Unknown);
|
||||
invoke_handlers(
|
||||
handlers,
|
||||
self::AudioSignal::ValuesChanged,
|
||||
self::AudioUser::Unknown,
|
||||
);
|
||||
}
|
||||
e => warn!("Unhandled alsa event: {:?}", e),
|
||||
}
|
||||
|
65
src/prefs.rs
65
src/prefs.rs
@ -36,16 +36,16 @@ impl Default for MiddleClickAction {
|
||||
#[serde(default)]
|
||||
pub struct DevicePrefs {
|
||||
pub card: String,
|
||||
pub channel: String,
|
||||
pub channel: String,
|
||||
// TODO: normalize volume?
|
||||
}
|
||||
|
||||
impl Default for DevicePrefs {
|
||||
fn default() -> DevicePrefs {
|
||||
return DevicePrefs {
|
||||
card: String::from("(default)"),
|
||||
channel: String::from("Master"),
|
||||
};
|
||||
card: String::from("(default)"),
|
||||
channel: String::from("Master"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,18 +56,18 @@ pub struct ViewPrefs {
|
||||
pub draw_vol_meter: bool,
|
||||
pub vol_meter_offset: i64,
|
||||
pub system_theme: bool,
|
||||
pub vol_meter_color: VolColor,
|
||||
pub vol_meter_color: VolColor,
|
||||
// TODO: Display text folume/text volume pos?
|
||||
}
|
||||
|
||||
impl Default for ViewPrefs {
|
||||
fn default() -> ViewPrefs {
|
||||
return ViewPrefs {
|
||||
draw_vol_meter: true,
|
||||
vol_meter_offset: 10,
|
||||
system_theme: true,
|
||||
vol_meter_color: VolColor::default(),
|
||||
};
|
||||
draw_vol_meter: true,
|
||||
vol_meter_offset: 10,
|
||||
system_theme: true,
|
||||
vol_meter_color: VolColor::default(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,10 +83,10 @@ pub struct VolColor {
|
||||
impl Default for VolColor {
|
||||
fn default() -> VolColor {
|
||||
return VolColor {
|
||||
red: 245,
|
||||
green: 180,
|
||||
blue: 0,
|
||||
};
|
||||
red: 245,
|
||||
green: 180,
|
||||
blue: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,17 +96,17 @@ impl Default for VolColor {
|
||||
pub struct BehaviorPrefs {
|
||||
pub vol_control_cmd: Option<String>,
|
||||
pub vol_scroll_step: f64,
|
||||
pub middle_click_action: MiddleClickAction,
|
||||
pub middle_click_action: MiddleClickAction,
|
||||
// TODO: fine scroll step?
|
||||
}
|
||||
|
||||
impl Default for BehaviorPrefs {
|
||||
fn default() -> BehaviorPrefs {
|
||||
return BehaviorPrefs {
|
||||
vol_control_cmd: None,
|
||||
vol_scroll_step: 5.0,
|
||||
middle_click_action: MiddleClickAction::default(),
|
||||
};
|
||||
vol_control_cmd: None,
|
||||
vol_scroll_step: 5.0,
|
||||
middle_click_action: MiddleClickAction::default(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,19 +118,19 @@ pub struct NotifyPrefs {
|
||||
pub notifcation_timeout: i64,
|
||||
pub notify_mouse_scroll: bool,
|
||||
pub notify_popup: bool,
|
||||
pub notify_external: bool,
|
||||
pub notify_external: bool,
|
||||
// TODO: notify_hotkeys?
|
||||
}
|
||||
|
||||
impl Default for NotifyPrefs {
|
||||
fn default() -> NotifyPrefs {
|
||||
return NotifyPrefs {
|
||||
enable_notifications: true,
|
||||
notifcation_timeout: 1500,
|
||||
notify_mouse_scroll: true,
|
||||
notify_popup: true,
|
||||
notify_external: true,
|
||||
};
|
||||
enable_notifications: true,
|
||||
notifcation_timeout: 1500,
|
||||
notify_mouse_scroll: true,
|
||||
notify_popup: true,
|
||||
notify_external: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ pub struct Prefs {
|
||||
pub device_prefs: DevicePrefs,
|
||||
pub view_prefs: ViewPrefs,
|
||||
pub behavior_prefs: BehaviorPrefs,
|
||||
pub notify_prefs: NotifyPrefs,
|
||||
pub notify_prefs: NotifyPrefs,
|
||||
// TODO: HotKeys?
|
||||
}
|
||||
|
||||
@ -184,8 +184,8 @@ impl Prefs {
|
||||
|
||||
|
||||
pub fn store_config(&self) -> Result<()> {
|
||||
let config_path = get_xdg_dirs().place_config_file("pnmixer.toml")
|
||||
.from_err()?;
|
||||
let config_path =
|
||||
get_xdg_dirs().place_config_file("pnmixer.toml").from_err()?;
|
||||
|
||||
debug!("Storing config in {:?}", config_path);
|
||||
|
||||
@ -218,9 +218,10 @@ impl Prefs {
|
||||
}
|
||||
|
||||
impl Display for Prefs {
|
||||
fn fmt(&self,
|
||||
f: &mut Formatter)
|
||||
-> std::result::Result<(), std::fmt::Error> {
|
||||
fn fmt(
|
||||
&self,
|
||||
f: &mut Formatter,
|
||||
) -> std::result::Result<(), std::fmt::Error> {
|
||||
let s = self.to_str();
|
||||
return write!(f, "{}", s);
|
||||
}
|
||||
|
@ -81,9 +81,7 @@ pub fn get_selem_names(mixer: &Mixer) -> Vec<String> {
|
||||
|
||||
pub fn get_selem_by_name(mixer: &Mixer, name: String) -> Result<Selem> {
|
||||
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 {
|
||||
return Ok(selem);
|
||||
|
@ -21,18 +21,21 @@ pub fn copy_pixbuf(pixbuf: &gdk_pixbuf::Pixbuf) -> gdk_pixbuf::Pixbuf {
|
||||
}
|
||||
|
||||
|
||||
pub fn pixbuf_new_from_theme(icon_name: &str,
|
||||
size: i32,
|
||||
theme: >k::IconTheme)
|
||||
-> Result<gdk_pixbuf::Pixbuf> {
|
||||
pub fn pixbuf_new_from_theme(
|
||||
icon_name: &str,
|
||||
size: i32,
|
||||
theme: >k::IconTheme,
|
||||
) -> Result<gdk_pixbuf::Pixbuf> {
|
||||
|
||||
let icon_info =
|
||||
theme.lookup_icon(icon_name, size, gtk::IconLookupFlags::empty())
|
||||
.ok_or(format!("Couldn't find icon {}", icon_name))?;
|
||||
let icon_info = theme
|
||||
.lookup_icon(icon_name, size, gtk::IconLookupFlags::empty())
|
||||
.ok_or(format!("Couldn't find icon {}", icon_name))?;
|
||||
|
||||
debug!("Loading stock icon {} from {:?}",
|
||||
icon_name,
|
||||
icon_info.get_filename().unwrap_or(PathBuf::new()));
|
||||
debug!(
|
||||
"Loading stock icon {} from {:?}",
|
||||
icon_name,
|
||||
icon_info.get_filename().unwrap_or(PathBuf::new())
|
||||
);
|
||||
|
||||
// TODO: propagate error
|
||||
let pixbuf = icon_info.load_icon().unwrap();
|
||||
|
@ -14,21 +14,15 @@ pub fn init_popup_menu(appstate: Rc<AppS>) {
|
||||
/* about_item.connect_activate_link */
|
||||
{
|
||||
let apps = appstate.clone();
|
||||
let about_item = &appstate.clone()
|
||||
.gui
|
||||
.popup_menu
|
||||
.about_item;
|
||||
about_item.connect_activate(move |_| {
|
||||
on_about_item_activate(&apps);
|
||||
});
|
||||
let about_item = &appstate.clone().gui.popup_menu.about_item;
|
||||
about_item.connect_activate(
|
||||
move |_| { on_about_item_activate(&apps); },
|
||||
);
|
||||
}
|
||||
|
||||
/* 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(
|
||||
move |_| { on_prefs_item_activate(appstate.clone()); },
|
||||
);
|
||||
|
@ -18,37 +18,25 @@ pub fn init_popup_window(appstate: Rc<AppS>) {
|
||||
/* mute_check.connect_toggled */
|
||||
{
|
||||
let _appstate = appstate.clone();
|
||||
let mute_check = &appstate.clone()
|
||||
.gui
|
||||
.popup_window
|
||||
.mute_check;
|
||||
toggle_signal =
|
||||
mute_check.connect_toggled(move |_| {
|
||||
on_mute_check_toggled(&_appstate)
|
||||
});
|
||||
let mute_check = &appstate.clone().gui.popup_window.mute_check;
|
||||
toggle_signal = mute_check.connect_toggled(
|
||||
move |_| on_mute_check_toggled(&_appstate),
|
||||
);
|
||||
}
|
||||
|
||||
/* popup_window.connect_show */
|
||||
{
|
||||
let _appstate = appstate.clone();
|
||||
let popup_window = &appstate.clone()
|
||||
.gui
|
||||
.popup_window
|
||||
.popup_window;
|
||||
popup_window.connect_show(move |w| {
|
||||
on_popup_window_show(w,
|
||||
&_appstate,
|
||||
toggle_signal)
|
||||
});
|
||||
let popup_window = &appstate.clone().gui.popup_window.popup_window;
|
||||
popup_window.connect_show(
|
||||
move |w| on_popup_window_show(w, &_appstate, toggle_signal),
|
||||
);
|
||||
}
|
||||
|
||||
/* vol_scale_adj.connect_value_changed */
|
||||
{
|
||||
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(
|
||||
move |_| on_vol_scale_value_changed(&_appstate),
|
||||
);
|
||||
@ -57,20 +45,19 @@ pub fn init_popup_window(appstate: Rc<AppS>) {
|
||||
/* popup_window.connect_event */
|
||||
{
|
||||
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| {
|
||||
on_popup_window_event(w, e, &_appstate)
|
||||
});
|
||||
on_popup_window_event(w, e, &_appstate)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn on_popup_window_show(window: >k::Window,
|
||||
appstate: &AppS,
|
||||
toggle_signal: u64) {
|
||||
fn on_popup_window_show(
|
||||
window: >k::Window,
|
||||
appstate: &AppS,
|
||||
toggle_signal: u64,
|
||||
) {
|
||||
let audio = &appstate.audio;
|
||||
let popup_window = &appstate.gui.popup_window;
|
||||
|
||||
@ -85,10 +72,11 @@ fn on_popup_window_show(window: >k::Window,
|
||||
}
|
||||
|
||||
|
||||
fn on_popup_window_event(w: >k::Window,
|
||||
e: &gdk::Event,
|
||||
appstate: &AppS)
|
||||
-> gtk::Inhibit {
|
||||
fn on_popup_window_event(
|
||||
w: >k::Window,
|
||||
e: &gdk::Event,
|
||||
appstate: &AppS,
|
||||
) -> gtk::Inhibit {
|
||||
match gdk::Event::get_event_type(e) {
|
||||
gdk::EventType::GrabBroken => w.hide(),
|
||||
gdk::EventType::KeyPress => {
|
||||
@ -120,10 +108,7 @@ fn on_popup_window_event(w: >k::Window,
|
||||
fn on_vol_scale_value_changed(appstate: &AppS) {
|
||||
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));
|
||||
}
|
||||
@ -135,9 +120,11 @@ fn on_mute_check_toggled(appstate: &AppS) {
|
||||
}
|
||||
|
||||
|
||||
pub fn update_mute_check(appstate: &AppS,
|
||||
toggle_signal: u64,
|
||||
muted: Result<bool>) {
|
||||
pub fn update_mute_check(
|
||||
appstate: &AppS,
|
||||
toggle_signal: u64,
|
||||
muted: Result<bool>,
|
||||
) {
|
||||
let check_button = &appstate.gui.popup_window.mute_check;
|
||||
|
||||
glib::signal_handler_block(check_button, toggle_signal);
|
||||
@ -170,32 +157,40 @@ fn grab_devices(window: >k::Window) -> Result<()> {
|
||||
let gdk_window = window.get_window().ok_or("No window?!")?;
|
||||
|
||||
/* Grab the mouse */
|
||||
let m_grab_status =
|
||||
device.grab(&gdk_window,
|
||||
GrabOwnership::None,
|
||||
true,
|
||||
BUTTON_PRESS_MASK,
|
||||
None,
|
||||
GDK_CURRENT_TIME as u32);
|
||||
let m_grab_status = device.grab(
|
||||
&gdk_window,
|
||||
GrabOwnership::None,
|
||||
true,
|
||||
BUTTON_PRESS_MASK,
|
||||
None,
|
||||
GDK_CURRENT_TIME as u32,
|
||||
);
|
||||
|
||||
if m_grab_status != GrabStatus::Success {
|
||||
warn!("Could not grab {}",
|
||||
device.get_name().unwrap_or(String::from("UNKNOWN DEVICE")));
|
||||
warn!(
|
||||
"Could not grab {}",
|
||||
device.get_name().unwrap_or(String::from("UNKNOWN DEVICE"))
|
||||
);
|
||||
}
|
||||
|
||||
/* Grab the keyboard */
|
||||
let k_dev = device.get_associated_device()
|
||||
.ok_or("Couldn't get associated device")?;
|
||||
let k_dev = device.get_associated_device().ok_or(
|
||||
"Couldn't get associated device",
|
||||
)?;
|
||||
|
||||
let k_grab_status = k_dev.grab(&gdk_window,
|
||||
GrabOwnership::None,
|
||||
true,
|
||||
KEY_PRESS_MASK,
|
||||
None,
|
||||
GDK_CURRENT_TIME as u32);
|
||||
let k_grab_status = k_dev.grab(
|
||||
&gdk_window,
|
||||
GrabOwnership::None,
|
||||
true,
|
||||
KEY_PRESS_MASK,
|
||||
None,
|
||||
GDK_CURRENT_TIME as u32,
|
||||
);
|
||||
if k_grab_status != GrabStatus::Success {
|
||||
warn!("Could not grab {}",
|
||||
k_dev.get_name().unwrap_or(String::from("UNKNOWN DEVICE")));
|
||||
warn!(
|
||||
"Could not grab {}",
|
||||
k_dev.get_name().unwrap_or(String::from("UNKNOWN DEVICE"))
|
||||
);
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
@ -7,21 +7,40 @@ use support_alsa::*;
|
||||
|
||||
|
||||
|
||||
create_builder_item!(PrefsDialog,
|
||||
prefs_dialog: gtk::Dialog,
|
||||
card_combo: gtk::ComboBoxText,
|
||||
chan_combo: gtk::ComboBoxText);
|
||||
// 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>) {
|
||||
let builder_prefs_dialog = gtk::Builder::new_from_string(include_str!("../data/ui/prefs-dialog.glade"));
|
||||
let prefs_dialog = Rc::new(PrefsDialog::new(builder_prefs_dialog));
|
||||
let prefs_dialog = Rc::new();
|
||||
init_prefs_dialog(&appstate, &prefs_dialog);
|
||||
{
|
||||
let prefs_dialog_w = &prefs_dialog.prefs_dialog;
|
||||
prefs_dialog_w.set_transient_for(&appstate.gui.popup_menu.menu_window);
|
||||
prefs_dialog_w.run();
|
||||
prefs_dialog_w.destroy();
|
||||
prefs_dialog_w.present();
|
||||
// prefs_dialog_w.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,9 +66,9 @@ pub fn init_prefs_dialog(appstate: &Rc<AppS>, prefs_dialog: &Rc<PrefsDialog>) {
|
||||
let pd = prefs_dialog.clone();
|
||||
|
||||
// TODO: refill channel combo
|
||||
card_combo.connect_changed(move |_| {
|
||||
on_card_combo_changed(&apps, &pd);
|
||||
});
|
||||
card_combo.connect_changed(
|
||||
move |_| { on_card_combo_changed(&apps, &pd); },
|
||||
);
|
||||
}
|
||||
/* card_combo.connect_changed */
|
||||
{
|
||||
@ -57,9 +76,9 @@ pub fn init_prefs_dialog(appstate: &Rc<AppS>, prefs_dialog: &Rc<PrefsDialog>) {
|
||||
let chan_combo = &prefs_dialog.chan_combo;
|
||||
let pd = prefs_dialog.clone();
|
||||
|
||||
chan_combo.connect_changed(move |_| {
|
||||
on_chan_combo_changed(&apps, &pd);
|
||||
});
|
||||
chan_combo.connect_changed(
|
||||
move |_| { on_chan_combo_changed(&apps, &pd); },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,8 +90,8 @@ fn on_prefs_dialog_show(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
|
||||
|
||||
/* set card combo */
|
||||
let cur_card_name = try_w!(acard.card_name(),
|
||||
"Can't get current card name!");
|
||||
let cur_card_name =
|
||||
try_w!(acard.card_name(), "Can't get current card name!");
|
||||
let available_card_names = get_alsa_card_names();
|
||||
|
||||
/* set_active_id doesn't work, so save the index */
|
||||
@ -113,8 +132,9 @@ fn on_prefs_dialog_show(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
fn on_card_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
let card_combo = &prefs_dialog.card_combo;
|
||||
let chan_combo = &prefs_dialog.chan_combo;
|
||||
let active_card_item =
|
||||
try_w!(card_combo.get_active_text().ok_or("No active Card item found"));
|
||||
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 cur_card_name = {
|
||||
let acard = appstate.audio.acard.borrow();
|
||||
@ -122,9 +142,11 @@ fn on_card_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
};
|
||||
|
||||
if active_card_item != cur_card_name {
|
||||
appstate.audio.switch_acard(Some(cur_card_name),
|
||||
active_chan_item,
|
||||
AudioUser::PrefsWindow);
|
||||
appstate.audio.switch_acard(
|
||||
Some(cur_card_name),
|
||||
active_chan_item,
|
||||
AudioUser::PrefsWindow,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,8 +154,9 @@ fn on_card_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
fn on_chan_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
let card_combo = &prefs_dialog.card_combo;
|
||||
let chan_combo = &prefs_dialog.chan_combo;
|
||||
let active_chan_item =
|
||||
try_w!(chan_combo.get_active_text().ok_or("No active Chan item found"));
|
||||
let active_chan_item = try_w!(chan_combo.get_active_text().ok_or(
|
||||
"No active Chan item found",
|
||||
));
|
||||
let cur_card_name = {
|
||||
let acard = appstate.audio.acard.borrow();
|
||||
acard.card_name().ok()
|
||||
@ -144,8 +167,10 @@ fn on_chan_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||
};
|
||||
|
||||
if active_chan_item != cur_chan_name {
|
||||
appstate.audio.switch_acard(cur_card_name,
|
||||
Some(active_chan_item),
|
||||
AudioUser::PrefsWindow);
|
||||
appstate.audio.switch_acard(
|
||||
cur_card_name,
|
||||
Some(active_chan_item),
|
||||
AudioUser::PrefsWindow,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -43,18 +43,19 @@ impl TrayIcon {
|
||||
let status_icon = gtk::StatusIcon::new();
|
||||
|
||||
return Ok(TrayIcon {
|
||||
volmeter,
|
||||
audio_pix: RefCell::new(audio_pix),
|
||||
status_icon,
|
||||
icon_size: Cell::new(ICON_MIN_SIZE),
|
||||
});
|
||||
volmeter,
|
||||
audio_pix: RefCell::new(audio_pix),
|
||||
status_icon,
|
||||
icon_size: Cell::new(ICON_MIN_SIZE),
|
||||
});
|
||||
}
|
||||
|
||||
fn update(&self,
|
||||
prefs: &Prefs,
|
||||
audio: &Audio,
|
||||
m_size: Option<i32>)
|
||||
-> Result<()> {
|
||||
fn update(
|
||||
&self,
|
||||
prefs: &Prefs,
|
||||
audio: &Audio,
|
||||
m_size: Option<i32>,
|
||||
) -> Result<()> {
|
||||
match m_size {
|
||||
Some(s) => {
|
||||
if s < ICON_MIN_SIZE {
|
||||
@ -104,30 +105,37 @@ pub struct VolMeter {
|
||||
impl VolMeter {
|
||||
pub fn new(prefs: &Prefs) -> VolMeter {
|
||||
return VolMeter {
|
||||
red: prefs.view_prefs.vol_meter_color.red,
|
||||
green: prefs.view_prefs.vol_meter_color.green,
|
||||
blue: prefs.view_prefs.vol_meter_color.blue,
|
||||
x_offset_pct: prefs.view_prefs.vol_meter_offset,
|
||||
y_offset_pct: 10,
|
||||
/* dynamic */
|
||||
width: Cell::new(0),
|
||||
row: RefCell::new(vec![]),
|
||||
};
|
||||
red: prefs.view_prefs.vol_meter_color.red,
|
||||
green: prefs.view_prefs.vol_meter_color.green,
|
||||
blue: prefs.view_prefs.vol_meter_color.blue,
|
||||
x_offset_pct: prefs.view_prefs.vol_meter_offset,
|
||||
y_offset_pct: 10,
|
||||
/* dynamic */
|
||||
width: Cell::new(0),
|
||||
row: RefCell::new(vec![]),
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: cache input pixbuf?
|
||||
fn meter_draw(&self,
|
||||
volume: i64,
|
||||
pixbuf: &gdk_pixbuf::Pixbuf)
|
||||
-> Result<gdk_pixbuf::Pixbuf> {
|
||||
fn meter_draw(
|
||||
&self,
|
||||
volume: i64,
|
||||
pixbuf: &gdk_pixbuf::Pixbuf,
|
||||
) -> Result<gdk_pixbuf::Pixbuf> {
|
||||
|
||||
ensure!(pixbuf.get_colorspace() == GDK_COLORSPACE_RGB,
|
||||
"Invalid colorspace in pixbuf");
|
||||
ensure!(pixbuf.get_bits_per_sample() == 8,
|
||||
"Invalid bits per sample in pixbuf");
|
||||
ensure!(
|
||||
pixbuf.get_colorspace() == GDK_COLORSPACE_RGB,
|
||||
"Invalid colorspace 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_n_channels() == 4,
|
||||
"Invalid number of channels in pixbuf");
|
||||
ensure!(
|
||||
pixbuf.get_n_channels() == 4,
|
||||
"Invalid number of channels in pixbuf"
|
||||
);
|
||||
|
||||
let i_width = pixbuf.get_width() as i64;
|
||||
let i_height = pixbuf.get_height() as i64;
|
||||
@ -136,16 +144,21 @@ impl VolMeter {
|
||||
|
||||
let vm_width = i_width / 6;
|
||||
let x = (self.x_offset_pct as f64 *
|
||||
((i_width - vm_width) as f64 / 100.0)) as i64;
|
||||
ensure!(x >= 0 && (x + vm_width) <= i_width,
|
||||
"x coordinate invalid: {}",
|
||||
x);
|
||||
((i_width - vm_width) as f64 / 100.0)) as
|
||||
i64;
|
||||
ensure!(
|
||||
x >= 0 && (x + vm_width) <= i_width,
|
||||
"x coordinate invalid: {}",
|
||||
x
|
||||
);
|
||||
let y = (self.y_offset_pct as f64 * (i_height as f64 / 100.0)) as i64;
|
||||
let vm_height =
|
||||
((i_height - (y * 2)) as f64 * (volume as f64 / 100.0)) as i64;
|
||||
ensure!(y >= 0 && (y + vm_height) <= i_height,
|
||||
"y coordinate invalid: {}",
|
||||
y);
|
||||
ensure!(
|
||||
y >= 0 && (y + vm_height) <= i_height,
|
||||
"y coordinate invalid: {}",
|
||||
y
|
||||
);
|
||||
|
||||
/* Let's check if the icon width changed, in which case we
|
||||
* must reinit our internal row of pixels.
|
||||
@ -181,8 +194,9 @@ impl VolMeter {
|
||||
let p_index = ((row_offset * rowstride) + col_offset) as usize;
|
||||
|
||||
let row = self.row.borrow();
|
||||
pixels[p_index..p_index + row.len()]
|
||||
.copy_from_slice(row.as_ref());
|
||||
pixels[p_index..p_index + row.len()].copy_from_slice(
|
||||
row.as_ref(),
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@ -211,28 +225,45 @@ impl AudioPix {
|
||||
|
||||
let pix = {
|
||||
if system_theme {
|
||||
let theme: gtk::IconTheme = gtk::IconTheme::get_default().ok_or(
|
||||
"Couldn't get default icon theme",
|
||||
)?;
|
||||
let theme: gtk::IconTheme =
|
||||
gtk::IconTheme::get_default().ok_or(
|
||||
"Couldn't get default icon theme",
|
||||
)?;
|
||||
AudioPix {
|
||||
muted: pixbuf_new_from_theme("audio-volume-muted",
|
||||
size, &theme)?,
|
||||
low: pixbuf_new_from_theme("audio-volume-low",
|
||||
size, &theme)?,
|
||||
medium: pixbuf_new_from_theme("audio-volume-medium",
|
||||
size, &theme)?,
|
||||
high: pixbuf_new_from_theme("audio-volume-high",
|
||||
size, &theme)?,
|
||||
muted: pixbuf_new_from_theme(
|
||||
"audio-volume-muted",
|
||||
size,
|
||||
&theme,
|
||||
)?,
|
||||
low: pixbuf_new_from_theme(
|
||||
"audio-volume-low",
|
||||
size,
|
||||
&theme,
|
||||
)?,
|
||||
medium: pixbuf_new_from_theme(
|
||||
"audio-volume-medium",
|
||||
size,
|
||||
&theme,
|
||||
)?,
|
||||
high: pixbuf_new_from_theme(
|
||||
"audio-volume-high",
|
||||
size,
|
||||
&theme,
|
||||
)?,
|
||||
/* 'audio-volume-off' is not available in every icon set.
|
||||
* Check freedesktop standard for more info:
|
||||
* http://standards.freedesktop.org/icon-naming-spec/
|
||||
* icon-naming-spec-latest.html
|
||||
*/
|
||||
off: pixbuf_new_from_theme("audio-volume-off",
|
||||
size, &theme).or(
|
||||
pixbuf_new_from_theme("audio-volume-low",
|
||||
size, &theme),
|
||||
)?,
|
||||
off: pixbuf_new_from_theme(
|
||||
"audio-volume-off",
|
||||
size,
|
||||
&theme,
|
||||
).or(pixbuf_new_from_theme(
|
||||
"audio-volume-low",
|
||||
size,
|
||||
&theme,
|
||||
))?,
|
||||
}
|
||||
} else {
|
||||
AudioPix {
|
||||
@ -273,7 +304,11 @@ pub fn init_tray_icon(appstate: Rc<AppS>) {
|
||||
appstate.audio.connect_handler(
|
||||
Box::new(move |s, u| match (s, u) {
|
||||
(AudioSignal::ValuesChanged, _) => {
|
||||
try_w!(apps.gui.tray_icon.update(&apps.prefs.borrow_mut(), &apps.audio, None));
|
||||
try_w!(apps.gui.tray_icon.update(
|
||||
&apps.prefs.borrow_mut(),
|
||||
&apps.audio,
|
||||
None,
|
||||
));
|
||||
}
|
||||
_ => (),
|
||||
}),
|
||||
@ -284,7 +319,14 @@ pub fn init_tray_icon(appstate: Rc<AppS>) {
|
||||
{
|
||||
let apps = appstate.clone();
|
||||
tray_icon.status_icon.connect_size_changed(move |_, size| {
|
||||
try_wr!(apps.gui.tray_icon.update(&apps.prefs.borrow_mut(), &apps.audio, Some(size)), false);
|
||||
try_wr!(
|
||||
apps.gui.tray_icon.update(
|
||||
&apps.prefs.borrow_mut(),
|
||||
&apps.audio,
|
||||
Some(size),
|
||||
),
|
||||
false
|
||||
);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@ -292,9 +334,9 @@ pub fn init_tray_icon(appstate: Rc<AppS>) {
|
||||
/* tray_icon.connect_activate */
|
||||
{
|
||||
let apps = appstate.clone();
|
||||
tray_icon.status_icon.connect_activate(move |_| {
|
||||
on_tray_icon_activate(&apps)
|
||||
});
|
||||
tray_icon.status_icon.connect_activate(
|
||||
move |_| on_tray_icon_activate(&apps),
|
||||
);
|
||||
}
|
||||
|
||||
/* tray_icon.connect_scroll_event */
|
||||
@ -308,17 +350,17 @@ pub fn init_tray_icon(appstate: Rc<AppS>) {
|
||||
/* tray_icon.connect_popup_menu */
|
||||
{
|
||||
let apps = appstate.clone();
|
||||
tray_icon.status_icon.connect_popup_menu(
|
||||
move |_, _, _| on_tray_icon_popup_menu(&apps),
|
||||
);
|
||||
tray_icon.status_icon.connect_popup_menu(move |_, _, _| {
|
||||
on_tray_icon_popup_menu(&apps)
|
||||
});
|
||||
}
|
||||
|
||||
/* tray_icon.connect_button_release_event */
|
||||
{
|
||||
let apps = appstate.clone();
|
||||
tray_icon.status_icon.connect_button_release_event(
|
||||
move |_, eb| on_tray_button_release_event(&apps, eb),
|
||||
);
|
||||
tray_icon.status_icon.connect_button_release_event(move |_, eb| {
|
||||
on_tray_button_release_event(&apps, eb)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -343,9 +385,10 @@ fn on_tray_icon_popup_menu(appstate: &AppS) {
|
||||
}
|
||||
|
||||
|
||||
fn on_tray_icon_scroll_event(appstate: &AppS,
|
||||
event: &gdk::EventScroll)
|
||||
-> bool {
|
||||
fn on_tray_icon_scroll_event(
|
||||
appstate: &AppS,
|
||||
event: &gdk::EventScroll,
|
||||
) -> bool {
|
||||
|
||||
let scroll_dir: gdk::ScrollDirection = event.get_direction();
|
||||
match scroll_dir {
|
||||
@ -362,9 +405,10 @@ fn on_tray_icon_scroll_event(appstate: &AppS,
|
||||
}
|
||||
|
||||
|
||||
fn on_tray_button_release_event(appstate: &AppS,
|
||||
event_button: &gdk::EventButton)
|
||||
-> bool {
|
||||
fn on_tray_button_release_event(
|
||||
appstate: &AppS,
|
||||
event_button: &gdk::EventButton,
|
||||
) -> bool {
|
||||
let button = event_button.get_button();
|
||||
|
||||
if button != 2 {
|
||||
|
Loading…
Reference in New Issue
Block a user