x11 wl separation
This commit is contained in:
45
rklipd/src/ws/x11.rs
Normal file
45
rklipd/src/ws/x11.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use arboard::Clipboard;
|
||||
use clipboard_master::{CallbackResult, ClipboardHandler, Master};
|
||||
use std::{
|
||||
error::Error,
|
||||
sync::mpsc::{Sender, channel},
|
||||
};
|
||||
|
||||
use crate::{database::Database, models::ClipboardEntry};
|
||||
|
||||
pub struct Handler {
|
||||
pub clipboard_tx: Sender<()>,
|
||||
}
|
||||
|
||||
impl ClipboardHandler for Handler {
|
||||
fn on_clipboard_change(&mut self) -> CallbackResult {
|
||||
if let Err(e) = self.clipboard_tx.send(()) {
|
||||
eprintln!("{}", e);
|
||||
}
|
||||
CallbackResult::Next
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(db: Database, mut clipboard: Clipboard) -> Result<(), Box<dyn Error>> {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
let mut master = Master::new(Handler { clipboard_tx: tx })?;
|
||||
std::thread::spawn(move || {
|
||||
if let Err(e) = master.run() {
|
||||
eprintln!("Clipboard monitor error : {}", e);
|
||||
}
|
||||
});
|
||||
|
||||
for _ in rx {
|
||||
println!("Clipboard update!");
|
||||
if let Ok(entry) = ClipboardEntry::new(&mut clipboard) {
|
||||
if let Err(e) = db.append(entry) {
|
||||
eprintln!("SQLite writing error: {}", e);
|
||||
} else {
|
||||
// println!("SQLite edited!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user