aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock9
-rw-r--r--Cargo.toml1
-rw-r--r--alsa/Cargo.toml15
-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
8 files changed, 133 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index b0c2531..83fa555 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/target
*~
*.swp
+*/target
diff --git a/Cargo.lock b/Cargo.lock
index 03e4f00..afcf1a0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -508,6 +508,15 @@ dependencies = [
]
[[package]]
+name = "swaystatus-alsa"
+version = "0.1.0"
+dependencies = [
+ "erased-serde",
+ "serde",
+ "swaystatus-plugin",
+]
+
+[[package]]
name = "swaystatus-clock"
version = "0.1.0"
dependencies = [
diff --git a/Cargo.toml b/Cargo.toml
index a450197..49dc253 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,6 +3,7 @@
members = [
"swaystatus",
"swaystatus-plugin",
+ "alsa",
"clock",
"pulse"
]
diff --git a/alsa/Cargo.toml b/alsa/Cargo.toml
new file mode 100644
index 0000000..c89855e
--- /dev/null
+++ b/alsa/Cargo.toml
@@ -0,0 +1,15 @@
+[package]
+name = "swaystatus-alsa"
+version = "0.1.0"
+authors = ["Andreas Grois <andi@grois.info>"]
+edition = "2021"
+
+# 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/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!()
+ }
+}