diff options
Diffstat (limited to 'pulse/src/communication.rs')
| -rw-r--r-- | pulse/src/communication.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/pulse/src/communication.rs b/pulse/src/communication.rs index c8578b7..cfb800e 100644 --- a/pulse/src/communication.rs +++ b/pulse/src/communication.rs @@ -1,5 +1,5 @@ use std::sync::mpsc::*; -use crate::runnable::*; +use crate::runnable::pulse::*; use swaystatus_plugin::*; pub enum MessagesFromMain { @@ -9,21 +9,27 @@ pub enum MessagesFromMain { pub struct SenderForMain { sender : Sender<MessagesFromMain>, - pulse_loop : std::sync::Arc<PulseMainLoop> + pulse_waker : PulseWakeUp } impl<'p> SenderForMain { - pub fn new(sender : Sender<MessagesFromMain>, pulse_loop : std::sync::Arc<PulseMainLoop>) -> Self { + pub fn new(sender : Sender<MessagesFromMain>, pulse_waker : PulseWakeUp) -> Self { SenderForMain{ sender, - pulse_loop + pulse_waker } } - fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> - { - //TODO!!!! - Ok(()) + fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> { + if let Ok(_) = self.sender.send(message) { + //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.wake_up()?; + Ok(()) + } + else { + Err(PluginCommunicationError{}) + } } } @@ -35,3 +41,9 @@ impl MsgMainToModule for SenderForMain { self.send(MessagesFromMain::Refresh) } } + +impl From<PulseWakeUpError> for PluginCommunicationError { + fn from(error : PulseWakeUpError) -> Self { + PluginCommunicationError {} + } +} |
