x11 wl separation
This commit is contained in:
96
rklipd/Cargo.lock
generated
96
rklipd/Cargo.lock
generated
@ -292,6 +292,12 @@ dependencies = [
|
|||||||
"objc2",
|
"objc2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "downcast-rs"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.15.0"
|
version = "1.15.0"
|
||||||
@ -948,6 +954,16 @@ version = "1.21.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_pipe"
|
||||||
|
version = "1.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.5"
|
version = "0.12.5"
|
||||||
@ -1076,6 +1092,15 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quick-xml"
|
||||||
|
version = "0.39.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "958f21e8e7ceb5a1aa7fa87fab28e7c75976e0bfe7e23ff069e0a260f894067d"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.45"
|
version = "1.0.45"
|
||||||
@ -1220,6 +1245,7 @@ dependencies = [
|
|||||||
"image",
|
"image",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
"wayland-clipboard-listener",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1548,6 +1574,76 @@ dependencies = [
|
|||||||
"semver",
|
"semver",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayland-backend"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aa75f400b7f719bcd68b3f47cd939ba654cedeef690f486db71331eec4c6a406"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"downcast-rs",
|
||||||
|
"rustix",
|
||||||
|
"smallvec",
|
||||||
|
"wayland-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayland-client"
|
||||||
|
version = "0.31.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ab51d9f7c071abeee76007e2b742499e535148035bb835f97aaed1338cf516c3"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"rustix",
|
||||||
|
"wayland-backend",
|
||||||
|
"wayland-scanner",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayland-clipboard-listener"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e27b4464dcbc041268b018226dceda1ce94ca9d1a020fe47c251fa3de88e7706"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"os_pipe",
|
||||||
|
"thiserror",
|
||||||
|
"wayland-client",
|
||||||
|
"wayland-protocols",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayland-protocols"
|
||||||
|
version = "0.32.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b23b5df31ceff1328f06ac607591d5ba360cf58f90c8fad4ac8d3a55a3c4aec7"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"wayland-backend",
|
||||||
|
"wayland-client",
|
||||||
|
"wayland-scanner",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayland-scanner"
|
||||||
|
version = "0.31.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c86287151a309799b821ca709b7345a048a2956af05957c89cb824ab919fa4e3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quick-xml",
|
||||||
|
"quote",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayland-sys"
|
||||||
|
version = "0.31.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "374f6b70e8e0d6bf9461a32988fd553b59ff630964924dad6e4a4eb6bd538d17"
|
||||||
|
dependencies = [
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "weezl"
|
name = "weezl"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
|
|||||||
@ -9,6 +9,7 @@ image = "0.25.9"
|
|||||||
clipboard-master = "4.0.0"
|
clipboard-master = "4.0.0"
|
||||||
uuid = {version = "1.22.0", features = ["v4", "serde"]}
|
uuid = {version = "1.22.0", features = ["v4", "serde"]}
|
||||||
rusqlite = "0.38.0"
|
rusqlite = "0.38.0"
|
||||||
|
wayland-clipboard-listener = "0.6.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
x11 = []
|
x11 = []
|
||||||
|
|||||||
@ -6,22 +6,6 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use crate::models::{ClipboardData, ClipboardEntry, Image};
|
use crate::models::{ClipboardData, ClipboardEntry, Image};
|
||||||
|
|
||||||
use clipboard_master::{CallbackResult, ClipboardHandler};
|
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
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 trait ImageDataExt {
|
pub trait ImageDataExt {
|
||||||
fn to_png(&self) -> Result<Vec<u8>, Box<dyn Error>>;
|
fn to_png(&self) -> Result<Vec<u8>, Box<dyn Error>>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use arboard::Clipboard;
|
|
||||||
|
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
|
use arboard::Clipboard;
|
||||||
|
|
||||||
mod clipboard;
|
mod clipboard;
|
||||||
mod database;
|
mod database;
|
||||||
mod models;
|
mod models;
|
||||||
mod monitor;
|
mod monitor;
|
||||||
|
mod ws;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let clipboard = Clipboard::new()?;
|
let clipboard = Clipboard::new()?;
|
||||||
@ -14,7 +14,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let db = Database::init(dir_path)?;
|
let db = Database::init(dir_path)?;
|
||||||
|
|
||||||
println!("{:#?}", db.read_history());
|
// println!("{:#?}", db.read_history());
|
||||||
|
|
||||||
monitor::start(db, clipboard)?;
|
monitor::start(db, clipboard)?;
|
||||||
|
|
||||||
|
|||||||
@ -1,32 +1,24 @@
|
|||||||
use std::{error::Error, sync::mpsc::channel};
|
|
||||||
|
|
||||||
use arboard::Clipboard;
|
|
||||||
use clipboard_master::Master;
|
|
||||||
|
|
||||||
use crate::clipboard::Handler;
|
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
use crate::models::ClipboardEntry;
|
use arboard::Clipboard;
|
||||||
|
use std::error::Error;
|
||||||
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 {
|
|
||||||
print!("Clipboard changed!");
|
|
||||||
if let Ok(entry) = ClipboardEntry::new(&mut clipboard) {
|
|
||||||
if let Err(e) = db.append(entry) {
|
|
||||||
eprintln!("SQLite writing error: {}", e);
|
|
||||||
} else {
|
|
||||||
println!("SQLite edited!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#[cfg(feature = "x11")]
|
||||||
|
use crate::ws;
|
||||||
|
#[cfg(feature = "x11")]
|
||||||
|
pub fn start(db: Database, clipboard: Clipboard) -> Result<(), Box<dyn Error>> {
|
||||||
|
ws::x11::start(db, clipboard)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
use crate::ws;
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
pub fn start(db: Database, clipboard: Clipboard) -> Result<(), Box<dyn Error>> {
|
||||||
|
ws::wayland::start(db, clipboard)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(feature = "x11", feature = "wayland")))]
|
||||||
|
pub fn start(_db: Database, _clipboard: Clipboard) -> Result<(), Box<dyn Error>> {
|
||||||
|
Err("No window system feature enabled".into())
|
||||||
|
}
|
||||||
|
|||||||
2
rklipd/src/ws.rs
Normal file
2
rklipd/src/ws.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod wayland;
|
||||||
|
pub mod x11;
|
||||||
7
rklipd/src/ws/wayland.rs
Normal file
7
rklipd/src/ws/wayland.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use crate::database::Database;
|
||||||
|
use arboard::Clipboard;
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
pub fn start(db: Database, mut clipboard: Clipboard) -> Result<(), Box<dyn Error>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
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