aboutsummaryrefslogtreecommitdiff
path: root/alsa/src
diff options
context:
space:
mode:
Diffstat (limited to 'alsa/src')
-rw-r--r--alsa/src/communication.rs30
-rw-r--r--alsa/src/config.rs19
-rw-r--r--alsa/src/lib.rs36
-rw-r--r--alsa/src/runnable.rs22
4 files changed, 107 insertions, 0 deletions
diff --git a/alsa/src/communication.rs b/alsa/src/communication.rs
new file mode 100644
index 0000000..be11dd8
--- /dev/null
+++ b/alsa/src/communication.rs
@@ -0,0 +1,30 @@
+use std::sync::mpsc::*;
+use swaystatus_plugin::*;
+
+pub enum MessagesFromMain {
+ Quit,
+ Refresh
+}
+
+pub struct SenderForMain {
+ sender : Sender<MessagesFromMain>,
+}
+
+impl<'p> SenderForMain {
+ pub fn new(sender : Sender<MessagesFromMain>) -> Self {
+ Self { sender }
+ }
+
+ fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> {
+ self.sender.send(message).map_err(|_| PluginCommunicationError)
+ }
+}
+
+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/alsa/src/config.rs b/alsa/src/config.rs
new file mode 100644
index 0000000..a617690
--- /dev/null
+++ b/alsa/src/config.rs
@@ -0,0 +1,19 @@
+use std::sync::mpsc::channel;
+
+use serde::{Serialize, Deserialize};
+use swaystatus_plugin::*;
+
+use crate::{runnable::AlsaVolumeRunnable, communication::SenderForMain};
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct AlsaVolumeConfig{
+
+}
+
+
+impl SwayStatusModuleInstance for AlsaVolumeConfig {
+ fn make_runnable<'p>(&'p self, to_main : Box<dyn MsgModuleToMain + 'p>) -> (Box<dyn SwayStatusModuleRunnable + 'p>, Box<dyn MsgMainToModule + 'p>) {
+ let (s,r) = channel();
+ (Box::new(AlsaVolumeRunnable::new(to_main, r, self)), Box::new(SenderForMain::new(s)))
+ }
+}
diff --git a/alsa/src/lib.rs b/alsa/src/lib.rs
new file mode 100644
index 0000000..42800c8
--- /dev/null
+++ b/alsa/src/lib.rs
@@ -0,0 +1,36 @@
+use swaystatus_plugin::*;
+
+mod config;
+mod communication;
+mod runnable;
+
+use config::AlsaVolumeConfig;
+
+pub struct AlsaVolumePlugin;
+impl SwayStatusModule for AlsaVolumePlugin {
+ fn get_name(&self) -> &str {
+ "AlsaVolume"
+ }
+ fn deserialize_config<'de, 'p>(&'p self, deserializer : &mut (dyn erased_serde::Deserializer + 'de)) -> Result<Box<dyn SwayStatusModuleInstance + 'p>,erased_serde::Error> {
+ erased_serde::deserialize::<AlsaVolumeConfig>(deserializer)
+ .map(|c| Box::new(c) as Box<dyn SwayStatusModuleInstance>)
+ }
+ fn get_default_config<'p>(&'p self) -> Box<dyn SwayStatusModuleInstance + 'p> {
+ todo!();
+ }
+ fn print_help(&self) {
+ println!(
+r#"Swaystatus Alsa Volume plugin.
+
+This is a volume display for ALSA. You can either choose a specific device, mixer and element to display, or just show the default output's volume."#
+ );
+ }
+}
+
+impl AlsaVolumePlugin {
+ fn new() -> Self {
+ Self
+ }
+}
+
+declare_swaystatus_module!(AlsaVolumePlugin, AlsaVolumePlugin::new);
diff --git a/alsa/src/runnable.rs b/alsa/src/runnable.rs
new file mode 100644
index 0000000..85d23a4
--- /dev/null
+++ b/alsa/src/runnable.rs
@@ -0,0 +1,22 @@
+use std::sync::mpsc::Receiver;
+use swaystatus_plugin::*;
+use super::config::AlsaVolumeConfig;
+use super::communication::MessagesFromMain;
+
+pub struct AlsaVolumeRunnable<'r>{
+ to_main : Box<dyn MsgModuleToMain + 'r>,
+ from_main : Receiver<MessagesFromMain>,
+ config : &'r AlsaVolumeConfig,
+}
+
+impl<'r> AlsaVolumeRunnable<'r> {
+ pub fn new(to_main : Box<dyn MsgModuleToMain + 'r>, from_main : Receiver<MessagesFromMain>, config : &'r AlsaVolumeConfig) -> Self {
+ Self { to_main, from_main, config }
+ }
+}
+
+impl<'r> SwayStatusModuleRunnable for AlsaVolumeRunnable<'r> {
+ fn run(&self) {
+ todo!()
+ }
+}