x11 wl separation

This commit is contained in:
2026-03-08 12:38:00 +01:00
parent eb34efb652
commit d46c35c49f
8 changed files with 174 additions and 47 deletions

45
rklipd/src/ws/x11.rs Normal file
View 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(())
}