diff options
Diffstat (limited to 'pulse')
| -rw-r--r-- | pulse/Cargo.toml | 15 | ||||
| -rw-r--r-- | pulse/src/communication.rs | 37 | ||||
| -rw-r--r-- | pulse/src/config.rs | 66 | ||||
| -rw-r--r-- | pulse/src/lib.rs | 37 | ||||
| -rw-r--r-- | pulse/src/runnable.rs | 36 |
5 files changed, 191 insertions, 0 deletions
diff --git a/pulse/Cargo.toml b/pulse/Cargo.toml new file mode 100644 index 0000000..9aa4520 --- /dev/null +++ b/pulse/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "swaystatus-pulse" +version = "0.1.0" +authors = ["Andreas Grois <andi@grois.info>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +swaystatus-plugin = { path = '../swaystatus-plugin', version = '*'} +serde = { version = "1.0", features = ["derive"] } +erased-serde = "0.3" + +[lib] +crate-type = ["cdylib"] diff --git a/pulse/src/communication.rs b/pulse/src/communication.rs new file mode 100644 index 0000000..c8578b7 --- /dev/null +++ b/pulse/src/communication.rs @@ -0,0 +1,37 @@ +use std::sync::mpsc::*; +use crate::runnable::*; +use swaystatus_plugin::*; + +pub enum MessagesFromMain { + Quit, + Refresh +} + +pub struct SenderForMain { + sender : Sender<MessagesFromMain>, + pulse_loop : std::sync::Arc<PulseMainLoop> +} + +impl<'p> SenderForMain { + pub fn new(sender : Sender<MessagesFromMain>, pulse_loop : std::sync::Arc<PulseMainLoop>) -> Self { + SenderForMain{ + sender, + pulse_loop + } + } + + fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> + { + //TODO!!!! + Ok(()) + } +} + +impl MsgMainToModule for SenderForMain { + fn send_quit(&self) -> Result<(), PluginCommunicationError> { + self.send(MessagesFromMain::Quit) + } + fn send_refresh(&self) -> Result<(), PluginCommunicationError> { + self.send(MessagesFromMain::Refresh) + } +} diff --git a/pulse/src/config.rs b/pulse/src/config.rs new file mode 100644 index 0000000..77b2a22 --- /dev/null +++ b/pulse/src/config.rs @@ -0,0 +1,66 @@ +use serde::{Serialize,Deserialize}; +use std::collections::BTreeMap; +use swaystatus_plugin::*; + + +#[derive(Serialize, Deserialize)] +#[serde(tag = "Sink")] +enum Sink { + Default, + Specific { + sink_name : String + } +} + +#[derive(Serialize, Deserialize)] +#[serde(tag = "Format")] +enum Volume { + Off, + Numeric { + label : String + }, + Binned { + label: String, + bin_symbol_map : BTreeMap<u8,String> + } +} + +#[derive(Serialize, Deserialize)] +#[serde(tag = "Format")] +enum Balance { + Off, + Numeric { + label : String + }, + Binned { + label :String, + bin_symbol_map : BTreeMap<i8,String> + } +} + + +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "PascalCase", default)] +pub struct PulseVolumeConfig { + sink : Sink, + volume : Volume, + balance : Balance +} + +impl Default for PulseVolumeConfig { + fn default() -> Self { + PulseVolumeConfig { + sink : Sink::Default, + volume : Volume::Numeric { label : String::new()}, + balance : Balance::Off + } + } +} + +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); + (Box::new(runnable), Box::new(sender_for_main)) + } +} + diff --git a/pulse/src/lib.rs b/pulse/src/lib.rs new file mode 100644 index 0000000..cfecfd4 --- /dev/null +++ b/pulse/src/lib.rs @@ -0,0 +1,37 @@ +use swaystatus_plugin::*; + +mod runnable; +mod config; +mod communication; + +use config::*; + +pub struct PulseVolumePlugin; +impl SwayStatusModule for PulseVolumePlugin { + fn get_name(&self) -> &str { + "PulseVolume" + } + fn deserialize_config<'de>(&self, deserializer : &mut (dyn erased_serde::Deserializer + 'de)) -> Result<Box<dyn SwayStatusModuleInstance>, erased_serde::Error> { + let result : PulseVolumeConfig = erased_serde::deserialize(deserializer)?; + Ok(Box::new(result)) + } + fn get_default_config(&self) -> Box<dyn SwayStatusModuleInstance> { + let config = PulseVolumeConfig::default(); + Box::new(config) + } + fn print_help(&self) { + //TODO! + println!( +r#"Swaystatus Pulseaudio Volume plugin. + +Sorry, this help has not been finalized. If this ever gets public, slap Andi."#); + } +} + +impl PulseVolumePlugin { + fn new() -> Self { + Self + } +} + +declare_swaystatus_module!(PulseVolumePlugin, PulseVolumePlugin::new); diff --git a/pulse/src/runnable.rs b/pulse/src/runnable.rs new file mode 100644 index 0000000..d77a132 --- /dev/null +++ b/pulse/src/runnable.rs @@ -0,0 +1,36 @@ +use std::sync::mpsc::*; +use crate::config::*; +use swaystatus_plugin::*; +use crate::communication::*; + +pub struct PulseVolumeRunnable<'p> { + config : &'p PulseVolumeConfig, + to_main : Box<dyn MsgModuleToMain + 'p>, + from_main : Receiver<MessagesFromMain>, + pulse : std::sync::Arc<PulseMainLoop> +} + +impl<'p : 's, 's> PulseVolumeRunnable<'p> { + pub fn new(config : &'p PulseVolumeConfig, to_main : Box<dyn MsgModuleToMain + 'p>) -> (Self, SenderForMain) { + let (s, r) = channel(); + let pulse = std::sync::Arc::new(PulseMainLoop {});//TODO: initialize this properly + let result = PulseVolumeRunnable { + config, + to_main, + from_main : r, + pulse: pulse.clone() + }; + let sender = SenderForMain::new(s, pulse); + (result, sender) + } +} + +impl<'p> SwayStatusModuleRunnable for PulseVolumeRunnable<'p> { + fn run(&self) { + //TODO + } +} + +pub struct PulseMainLoop { + //TODO! +} |
