diff --git a/media/myxer_thumbnail.png b/media/myxer_thumbnail.png index 685cbf7..55b6f9a 100644 Binary files a/media/myxer_thumbnail.png and b/media/myxer_thumbnail.png differ diff --git a/src/card.rs b/src/card.rs index 85eaa7a..904e070 100644 --- a/src/card.rs +++ b/src/card.rs @@ -86,8 +86,7 @@ impl Card { let index = self.data.index; let pulse = self.pulse.as_ref().unwrap().clone(); self.combo_connect_id = Some(self.widgets.combo.connect_changed(move |combo| { - let val = combo.get_active_id().unwrap().as_str().to_owned(); - pulse.borrow_mut().set_card_profile(index, val.as_str()); + pulse.borrow_mut().set_card_profile(index, &String::from(combo.get_active_id().unwrap())); })); } @@ -100,23 +99,21 @@ impl Card { if data.name != self.data.name { self.data.name = data.name.clone(); - self.widgets.label.set_label(self.data.name.as_str()); + self.widgets.label.set_label(&self.data.name); } if data.profiles.len() != self.data.profiles.len() { self.disconnect(); self.data.profiles = data.profiles.clone(); self.widgets.combo.remove_all(); - for (i, n) in data.profiles.iter() { - self.widgets.combo.append(Some(i.as_str()), n.as_str()); - } + for (i, n) in &data.profiles { self.widgets.combo.append(Some(&i), &n); } self.connect(); } if data.active_profile != self.data.active_profile { self.disconnect(); self.data.active_profile = data.active_profile.clone(); - self.widgets.combo.set_active_id(Some(self.data.active_profile.as_str())); + self.widgets.combo.set_active_id(Some(&self.data.active_profile)); self.connect(); } } diff --git a/src/meter/sink_meter.rs b/src/meter/sink_meter.rs index 98b0fbb..fd7e685 100644 --- a/src/meter/sink_meter.rs +++ b/src/meter/sink_meter.rs @@ -108,11 +108,11 @@ impl SinkMeter { label.set_sensitive(false); menu.pack_start(&label, true, true, 3); - for (i, v) in pulse.sinks.iter() { + for (i, v) in &pulse.sinks { let button = gtk::ModelButton::new(); button.set_property_role(gtk::ButtonRole::Radio); button.set_property_active(v.data.index == index); - let button_label = gtk::Label::new(Some(v.data.description.as_str())); + let button_label = gtk::Label::new(Some(&v.data.description)); button_label.set_ellipsize(pango::EllipsizeMode::End); button_label.set_max_width_chars(18); button.get_child().unwrap().downcast::().unwrap().add(&button_label); @@ -129,7 +129,7 @@ impl SinkMeter { } } - root.get_children().iter().for_each(|i| i.show_all()); + for child in &root.get_children() { child.show_all(); } root.set_relative_to(Some(trigger)); root.popup(); } @@ -159,7 +159,7 @@ impl Meter for SinkMeter { if data.icon != self.data.icon { self.data.icon = data.icon.clone(); - self.widgets.icon.set_from_icon_name(Some(&self.data.icon.as_str()), gtk::IconSize::Dnd); + self.widgets.icon.set_from_icon_name(Some(&self.data.icon), gtk::IconSize::Dnd); } if data.name != self.data.name { @@ -169,7 +169,7 @@ impl Meter for SinkMeter { if data.description != self.data.description { self.data.description = data.description.clone(); - self.widgets.label.set_label(self.data.description.as_str()); + self.widgets.label.set_label(&self.data.description); } if volume_changed || data.muted != self.data.muted { @@ -188,7 +188,7 @@ impl Meter for SinkMeter { let mut string = vol_scaled.to_string(); string.push_str("%"); - self.widgets.status.set_label(string.as_str()); + self.widgets.status.set_label(&string); let status_ctx = self.widgets.status.get_style_context(); if self.data.muted { status_ctx.add_class("muted") } @@ -210,7 +210,7 @@ impl Meter for SinkMeter { } } else { - for s in self.widgets.scales_inner.get_children().iter() { + for s in &self.widgets.scales_inner.get_children() { let s = s.clone().downcast::().expect("Scales box has non-scale children."); s.set_show_fill_level(false); s.get_style_context().remove_class("visualizer"); diff --git a/src/meter/source_meter.rs b/src/meter/source_meter.rs index 3734278..20c2a67 100644 --- a/src/meter/source_meter.rs +++ b/src/meter/source_meter.rs @@ -112,11 +112,11 @@ impl SourceMeter { label.set_sensitive(false); menu.pack_start(&label, true, true, 3); - for (i, v) in pulse.sources.iter() { + for (i, v) in &pulse.sources { let button = gtk::ModelButton::new(); button.set_property_role(gtk::ButtonRole::Radio); button.set_property_active(v.data.index == index); - let button_label = gtk::Label::new(Some(v.data.description.as_str())); + let button_label = gtk::Label::new(Some(&v.data.description)); button_label.set_ellipsize(pango::EllipsizeMode::End); button_label.set_max_width_chars(18); button.get_child().unwrap().downcast::().unwrap().add(&button_label); @@ -133,7 +133,7 @@ impl SourceMeter { } } - root.get_children().iter().for_each(|i| i.show_all()); + for child in &root.get_children() { child.show_all(); } root.set_relative_to(Some(trigger)); root.popup(); } @@ -163,7 +163,7 @@ impl Meter for SourceMeter { if data.icon != self.data.icon { self.data.icon = data.icon.clone(); - self.widgets.icon.set_from_icon_name(Some(&self.data.icon.as_str()), gtk::IconSize::Dnd); + self.widgets.icon.set_from_icon_name(Some(&self.data.icon), gtk::IconSize::Dnd); } if data.name != self.data.name { @@ -173,7 +173,7 @@ impl Meter for SourceMeter { if data.description != self.data.description { self.data.description = data.description.clone(); - self.widgets.label.set_label(self.data.description.as_str()); + self.widgets.label.set_label(&self.data.description); } if volume_changed || data.muted != self.data.muted { @@ -192,7 +192,7 @@ impl Meter for SourceMeter { let mut string = vol_scaled.to_string(); string.push_str("%"); - self.widgets.status.set_label(string.as_str()); + self.widgets.status.set_label(&string); let status_ctx = self.widgets.status.get_style_context(); if self.data.muted { status_ctx.add_class("muted") } @@ -214,7 +214,7 @@ impl Meter for SourceMeter { } } else { - for s in self.widgets.scales_inner.get_children().iter() { + for s in &self.widgets.scales_inner.get_children() { let s = s.clone().downcast::().expect("Scales box has non-scale children."); s.set_show_fill_level(false); s.get_style_context().remove_class("visualizer"); diff --git a/src/meter/stream_meter.rs b/src/meter/stream_meter.rs index 549fc12..5cfe444 100644 --- a/src/meter/stream_meter.rs +++ b/src/meter/stream_meter.rs @@ -88,7 +88,7 @@ impl Meter for StreamMeter { if data.icon != self.data.icon { self.data.icon = data.icon.clone(); - self.widgets.icon.set_from_icon_name(Some(&self.data.icon.as_str()), gtk::IconSize::Dnd); + self.widgets.icon.set_from_icon_name(Some(&self.data.icon), gtk::IconSize::Dnd); } if data.name != self.data.name { @@ -97,7 +97,7 @@ impl Meter for StreamMeter { if data.description != self.data.description { self.data.description = data.description.clone(); - self.widgets.label.set_label(self.data.description.as_str()); + self.widgets.label.set_label(&self.data.description); } if volume_changed || data.muted != self.data.muted { @@ -119,7 +119,7 @@ impl Meter for StreamMeter { let mut string = vol_scaled.to_string(); string.push_str("%"); - self.widgets.status.set_label(string.as_str()); + self.widgets.status.set_label(&string); let status_ctx = self.widgets.status.get_style_context(); if self.data.muted { status_ctx.add_class("muted") } @@ -141,7 +141,7 @@ impl Meter for StreamMeter { } } else { - for s in self.widgets.scales_inner.get_children().iter() { + for s in &self.widgets.scales_inner.get_children() { let s = s.clone().downcast::().expect("Scales box has non-scale children."); s.set_show_fill_level(false); s.get_style_context().remove_class("visualizer"); diff --git a/src/pulse.rs b/src/pulse.rs index 505d59a..ce65b20 100644 --- a/src/pulse.rs +++ b/src/pulse.rs @@ -184,7 +184,10 @@ impl Pulse { pub fn set_default_sink(&self, sink: u32) { if let Some(sink) = self.sinks.get(&sink) { - self.context.borrow_mut().set_default_sink(sink.data.name.as_str(), |_|()); + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); + self.context.borrow_mut().set_default_sink(&sink.data.name, |_|()); + mainloop.unlock(); } } @@ -197,7 +200,10 @@ impl Pulse { pub fn set_default_source(&self, source: u32) { if let Some(source) = self.sources.get(&source) { - self.context.borrow_mut().set_default_source(source.data.name.as_str(), |_|()); + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); + self.context.borrow_mut().set_default_source(&source.data.name, |_|()); + mainloop.unlock(); } } @@ -234,13 +240,17 @@ impl Pulse { pub fn set_volume(&self, t: StreamType, index: u32, volumes: ChannelVolumes) { let mut introspect = self.context.borrow().introspect(); - + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); + match t { StreamType::Sink => drop(introspect.set_sink_volume_by_index(index, &volumes, None)), StreamType::SinkInput => drop(introspect.set_sink_input_volume(index, &volumes, None)), StreamType::Source => drop(introspect.set_source_volume_by_index(index, &volumes, None)), StreamType::SourceOutput => drop(introspect.set_source_output_volume(index, &volumes, None)) }; + + mainloop.unlock(); } @@ -254,12 +264,17 @@ impl Pulse { pub fn set_muted(&self, t: StreamType, index: u32, muted: bool) { let mut introspect = self.context.borrow().introspect(); + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); + match t { StreamType::Sink => drop(introspect.set_sink_mute_by_index(index, muted, None)), StreamType::SinkInput => drop(introspect.set_sink_input_mute(index, muted, None)), StreamType::Source => drop(introspect.set_source_mute_by_index(index, muted, None)), StreamType::SourceOutput => drop(introspect.set_source_output_mute(index, muted, None)) }; + + mainloop.unlock(); } @@ -272,7 +287,10 @@ impl Pulse { pub fn set_card_profile(&self, index: u32, profile: &str) { let mut introspect = self.context.borrow().introspect(); + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); introspect.set_card_profile_by_index(index, profile, None); + mainloop.unlock(); } @@ -372,6 +390,8 @@ impl Pulse { } } + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); let mut context = self.context.borrow_mut(); let introspect = context.introspect(); @@ -421,6 +441,8 @@ impl Pulse { _ => () }; }))); + + mainloop.unlock(); } @@ -478,7 +500,7 @@ impl Pulse { */ fn update_default(&mut self, sink: String, source: String) { - for (i, v) in self.sinks.iter() { + for (i, v) in &self.sinks { if v.data.name == sink { self.default_sink = *i; self.active_sink = *i; @@ -486,7 +508,7 @@ impl Pulse { } } - for (i, v) in self.sources.iter() { + for (i, v) in &self.sources { if v.data.name == source { self.default_source = *i; self.active_source = *i; @@ -517,7 +539,7 @@ impl Pulse { if let Some(stream) = entry { stream.data = data; } else { let source_str = stream.monitor_index.to_string(); - let monitor = self.create_monitor_stream(t, if t == StreamType::SinkInput { None } else { Some(source_str.as_str()) }, index); + let monitor = self.create_monitor_stream(t, if t == StreamType::SinkInput { None } else { Some(&source_str) }, index); let data = StreamData { data, peak: 0, monitor, monitor_index: stream.monitor_index }; match t { StreamType::Sink => self.sinks.insert(index, data), @@ -546,10 +568,13 @@ impl Pulse { if let Some(stream) = stream_opt { let mut monitor = stream.monitor.borrow_mut(); + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); if monitor.get_state().is_good() { monitor.set_read_callback(None); let _ = monitor.disconnect(); } + mainloop.unlock(); } match t { @@ -620,8 +645,11 @@ impl Pulse { stream.set_monitor_stream(stream_index).unwrap(); } + let mut mainloop = self.mainloop.borrow_mut(); + mainloop.lock(); stream.connect_record(source, Some(&attr), StreamFlagSet::DONT_MOVE | StreamFlagSet::ADJUST_LATENCY | StreamFlagSet::PEAK_DETECT).unwrap(); + mainloop.unlock(); let t = t.clone(); let sc = s.clone(); diff --git a/src/window/myxer.rs b/src/window/myxer.rs index c4128be..2b39408 100644 --- a/src/window/myxer.rs +++ b/src/window/myxer.rs @@ -255,7 +255,7 @@ impl Myxer { meters.sink.set_peak(if show { Some(sink.peak) } else { None }); } - for (index, input) in pulse.sink_inputs.iter() { + for (index, input) in &pulse.sink_inputs { let sink_inputs_box = meters.sink_inputs_box.clone(); let meter = meters.sink_inputs.entry(*index).or_insert_with(|| StreamMeter::new(self.pulse.clone())); @@ -278,7 +278,7 @@ impl Myxer { meters.source.set_peak(if show { Some(source.peak) } else { None }); } - for (index, output) in pulse.source_outputs.iter() { + for (index, output) in &pulse.source_outputs { let source_outputs_box = meters.source_outputs_box.clone(); let meter = meters.source_outputs.entry(*index).or_insert_with(|| StreamMeter::new(self.pulse.clone())); diff --git a/src/window/profiles.rs b/src/window/profiles.rs index 7be8c76..8c65166 100644 --- a/src/window/profiles.rs +++ b/src/window/profiles.rs @@ -70,7 +70,7 @@ impl Profiles { let pulse = self.pulse.borrow_mut(); let mut cards = self.cards.borrow_mut(); - for (index, data) in pulse.cards.iter() { + for (index, data) in &pulse.cards { let cards_box = cards.cards_box.clone(); let card = cards.cards.entry(*index).or_insert_with(|| Card::new(Some(self.pulse.clone()))); diff --git a/src/window/style.rs b/src/window/style.rs index 9ec172b..58c30af 100644 --- a/src/window/style.rs +++ b/src/window/style.rs @@ -11,7 +11,7 @@ pub fn style(window: >k::ApplicationWindow) { s.push_str("@define-color "); s.push_str(identifier); s.push_str(" "); - s.push_str(colorsys::Rgb::new(color.red * 255.0, color.green * 255.0, color.blue * 255.0, None).to_css_string().as_str()); + s.push_str(&colorsys::Rgb::new(color.red * 255.0, color.green * 255.0, color.blue * 255.0, None).to_css_string()); s.push_str(";\n"); };