aboutsummaryrefslogtreecommitdiff
path: root/pulse
diff options
context:
space:
mode:
Diffstat (limited to 'pulse')
-rw-r--r--pulse/src/communication.rs2
-rw-r--r--pulse/src/config.rs12
-rw-r--r--pulse/src/runnable/pulse.rs35
3 files changed, 21 insertions, 28 deletions
diff --git a/pulse/src/communication.rs b/pulse/src/communication.rs
index 51456d9..ce31875 100644
--- a/pulse/src/communication.rs
+++ b/pulse/src/communication.rs
@@ -21,7 +21,7 @@ impl<'p> SenderForMain {
}
fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> {
- if let Ok(_) = self.sender.send(message) {
+ if self.sender.send(message).is_ok() {
//The cool thing about pulse using poll() is that poll() also wakes up if started after
//the actual wake up call. So no need to worry about races, this is inherently sane!
self.pulse_waker.as_ref().ok_or(PluginCommunicationError {})?.wake_up()?;
diff --git a/pulse/src/config.rs b/pulse/src/config.rs
index f95bd46..0be7367 100644
--- a/pulse/src/config.rs
+++ b/pulse/src/config.rs
@@ -128,7 +128,7 @@ impl Default for PulseVolumeConfig {
impl SwayStatusModuleInstance for PulseVolumeConfig {
fn make_runnable<'p>(&'p self,to_main : Box<dyn MsgModuleToMain + 'p>) -> (Box<dyn SwayStatusModuleRunnable + 'p>, Box<dyn MsgMainToModule + 'p>) {
- let (runnable, sender_for_main) = crate::runnable::PulseVolumeRunnable::new(&self, to_main);
+ let (runnable, sender_for_main) = crate::runnable::PulseVolumeRunnable::new(self, to_main);
(Box::new(runnable), Box::new(sender_for_main))
}
}
@@ -162,13 +162,11 @@ impl<KeyTypeMetadata : VolumeKeyBackingTypeMetadata> FormatableVolume<KeyTypeMet
if let Some((_,msg)) = bin_symbol_map.range(..=value_to_match).next_back() {
Ok(format!("{}{}",label,msg))
}
+ else if let Some((_,msg)) = bin_symbol_map.iter().next() {
+ Ok(format!("{}{}",label,msg))
+ }
else {
- if let Some((_,msg)) = bin_symbol_map.iter().next() {
- Ok(format!("{}{}",label,msg))
- }
- else {
- Err(FormattingError::EmptyMap{numeric_fallback : Self::format_float_numeric(float, label, 0) })
- }
+ Err(FormattingError::EmptyMap{numeric_fallback : Self::format_float_numeric(float, label, 0) })
}
}
fn format_float_numeric(float : f32, label : &str, digits : u8) -> String {
diff --git a/pulse/src/runnable/pulse.rs b/pulse/src/runnable/pulse.rs
index 2f8398a..32d31e6 100644
--- a/pulse/src/runnable/pulse.rs
+++ b/pulse/src/runnable/pulse.rs
@@ -47,30 +47,28 @@ impl<'c> PulseContext<'c> {
if api.is_null() {
Err(PulseContextCreationError::FailedToGetPulseApi)
}
- else {
- if let Ok(plugin_name) = CString::new("Swaystatus Pulse Plugin") {
- let context = unsafe { pa_context_new(api, plugin_name.as_ptr()) };
- if context.is_null() {
- Err(PulseContextCreationError::ContextNewFailed)
- }
- else {
- Ok(PulseContext { context, scratch, main : pulse})
- }
+ else if let Ok(plugin_name) = CString::new("Swaystatus Pulse Plugin") {
+ let context = unsafe { pa_context_new(api, plugin_name.as_ptr()) };
+ if context.is_null() {
+ Err(PulseContextCreationError::ContextNewFailed)
}
else {
- Err(PulseContextCreationError::SettingNameFailed)
+ Ok(PulseContext { context, scratch, main : pulse})
}
}
+ else {
+ Err(PulseContextCreationError::SettingNameFailed)
+ }
}
pub(super) fn iterate(&mut self, relevant_sink : &Option<SinkHandle>) -> Result<IterationResult,MainLoopIterationError> {
self.scratch.sink_we_care_about = relevant_sink.clone();
self.scratch.volume = None;
self.scratch.default_sink = None;
self.main.main_loop.iterate()?;
- return Ok(IterationResult {
+ Ok(IterationResult {
default_sink : self.scratch.default_sink.clone(),
volume : self.scratch.volume.clone()
- });
+ })
}
pub(super) fn get_state(&self) -> PaContextState {
unsafe { pa_context_get_state(self.context) }
@@ -98,12 +96,9 @@ impl<'c> PulseContext<'c> {
extern "C" fn on_context_state_change(context : *mut PaContext, scratch : *mut c_void) {
unsafe {
- match pa_context_get_state(context) {
- PaContextState::Ready => {
- pa_context_set_subscribe_callback(context,Some(Self::on_context_event),scratch);
- pa_operation_unref(pa_context_subscribe(context,0x80 /* SERVER */ | 0x01 /* SINK */, None, std::ptr::null_mut()));
- }
- _ => {}
+ if let PaContextState::Ready = pa_context_get_state(context) {
+ pa_context_set_subscribe_callback(context,Some(Self::on_context_event),scratch);
+ pa_operation_unref(pa_context_subscribe(context,0x80 /* SERVER */ | 0x01 /* SINK */, None, std::ptr::null_mut()));
}
}
}
@@ -121,7 +116,7 @@ impl<'c> PulseContext<'c> {
pa_operation_unref(pa_context_get_server_info(context,Some(Self::on_server_info_received),scratch as *mut c_void));
}
_ /* should not happen */ => {
- assert!(false);
+ unreachable!();
}
}
}
@@ -424,7 +419,7 @@ impl PulseOperation {
Cancelled
}
-#[allow(dead_code)] //this is partially dead code, but the unused enum values are kept for readability reasons.
+#[allow(dead_code, clippy::enum_variant_names)] //this is partially dead code, but the unused enum values are kept for readability reasons. Also, clippy is over-zealous here.
#[repr(C)] enum PaContextFlags {
NoFlags = 0,
NoAutoSpawn = 1,