aboutsummaryrefslogtreecommitdiff
path: root/clock
diff options
context:
space:
mode:
Diffstat (limited to 'clock')
-rw-r--r--clock/.cargo/config2
-rw-r--r--clock/.gitignore4
-rw-r--r--clock/Cargo.toml16
-rw-r--r--clock/src/lib.rs87
4 files changed, 109 insertions, 0 deletions
diff --git a/clock/.cargo/config b/clock/.cargo/config
new file mode 100644
index 0000000..d046680
--- /dev/null
+++ b/clock/.cargo/config
@@ -0,0 +1,2 @@
+[build]
+rustflags = ["-C", "prefer-dynamic"]
diff --git a/clock/.gitignore b/clock/.gitignore
new file mode 100644
index 0000000..db08ac5
--- /dev/null
+++ b/clock/.gitignore
@@ -0,0 +1,4 @@
+/target
+Cargo.lock
+*~
+*.swp
diff --git a/clock/Cargo.toml b/clock/Cargo.toml
new file mode 100644
index 0000000..2215005
--- /dev/null
+++ b/clock/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "swaystatus-clock"
+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"
+chrono = { version = "0.4", features = ["serde"] }
+
+[lib]
+crate-type = ["dylib"]
diff --git a/clock/src/lib.rs b/clock/src/lib.rs
new file mode 100644
index 0000000..b3ad0e8
--- /dev/null
+++ b/clock/src/lib.rs
@@ -0,0 +1,87 @@
+use serde::{Serialize, Deserialize};
+use swaystatus_plugin::*;
+use std::sync::mpsc::*;
+
+pub struct ClockPlugin;
+pub struct ClockRunnable<'c> {
+ config : &'c ClockConfig,
+ from_main : Receiver<MessagesFromMain>,
+ to_main : Box<dyn MsgModuleToMain +'c>
+}
+
+impl<'c> SwayStatusModuleRunnable for ClockRunnable<'c> {
+ fn run(&self) {
+ for i in 0..4 {
+ println!("Sending Error {}",i);
+ self.to_main.send_update(Err(PluginError::PrintToStdErr(format!("Hello {}", i)))).unwrap();
+ std::thread::sleep(std::time::Duration::from_secs(2));
+ }
+ }
+}
+
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "PascalCase",default)]
+struct ClockConfig {
+ format : String,
+ refresh_rate : f32
+}
+
+impl Default for ClockConfig {
+ fn default() -> Self {
+ ClockConfig {
+ format : String::from("%R"),
+ refresh_rate : 1.0
+ }
+ }
+}
+
+impl SwayStatusModuleInstance for ClockConfig {
+ fn make_runnable<'p>(&'p self, to_main : Box<dyn MsgModuleToMain + 'p>) -> (Box<dyn SwayStatusModuleRunnable + 'p>, Box<dyn MsgMainToModule + 'p>) {
+ let (sender_from_main, from_main) = channel();
+ let runnable = ClockRunnable {
+ config : &self,
+ from_main,
+ to_main
+ };
+ let s = SenderForMain(sender_from_main);
+ (Box::new(runnable), Box::new(s))
+ }
+}
+
+impl SwayStatusModule for ClockPlugin {
+ fn get_name(&self) -> &str {
+ "ClockPlugin"
+ }
+ fn deserialize_config<'de>(&self, deserializer : &mut (dyn erased_serde::Deserializer + 'de)) -> Result<Box<dyn SwayStatusModuleInstance>, erased_serde::Error> {
+ let result : ClockConfig = erased_serde::deserialize(deserializer)?;
+ Ok(Box::new(result))
+ }
+ fn get_default_config(&self) -> Box<dyn SwayStatusModuleInstance> {
+ let config = ClockConfig::default();
+ Box::new(config)
+ }
+}
+
+impl ClockPlugin {
+ fn new() -> ClockPlugin {
+ ClockPlugin
+ }
+}
+
+enum MessagesFromMain {
+ Quit,
+ Refresh
+}
+
+struct SenderForMain(Sender<MessagesFromMain>);
+
+impl MsgMainToModule for SenderForMain {
+ fn send_quit(&self) -> Result<(),()> {
+ self.0.send(MessagesFromMain::Quit).map_err(|_| ())
+ }
+ fn send_refresh(&self) -> Result<(),()> {
+ self.0.send(MessagesFromMain::Refresh).map_err(|_| ())
+ }
+}
+
+declare_swaystatus_module!(ClockPlugin, ClockPlugin::new);