Compare commits

...

3 Commits

Author SHA1 Message Date
62fb8cd330 .local path 2026-03-08 15:40:28 +01:00
86cff34cd5 .local path 2026-03-08 15:40:01 +01:00
fb8c852a4d png to jpg for space 2026-03-08 15:31:55 +01:00
5 changed files with 82 additions and 8 deletions

65
rklipd/Cargo.lock generated
View File

@ -282,6 +282,27 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
[[package]]
name = "directories"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.61.2",
]
[[package]]
name = "dispatch2"
version = "0.3.1"
@ -440,6 +461,17 @@ dependencies = [
"windows-link",
]
[[package]]
name = "getrandom"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "getrandom"
version = "0.3.4"
@ -651,6 +683,15 @@ dependencies = [
"cc",
]
[[package]]
name = "libredox"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a"
dependencies = [
"libc",
]
[[package]]
name = "libsqlite3-sys"
version = "0.36.0"
@ -954,6 +995,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "os_pipe"
version = "1.2.3"
@ -1230,6 +1277,17 @@ dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"
dependencies = [
"getrandom 0.2.17",
"libredox",
"thiserror",
]
[[package]]
name = "rgb"
version = "0.8.53"
@ -1242,6 +1300,7 @@ version = "0.1.0"
dependencies = [
"arboard",
"clipboard-master",
"directories",
"image",
"rusqlite",
"uuid",
@ -1477,6 +1536,12 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasip2"
version = "1.0.2+wasi-0.2.9"

View File

@ -10,6 +10,7 @@ clipboard-master = "4.0.0"
uuid = {version = "1.22.0", features = ["v4", "serde"]}
rusqlite = "0.38.0"
wayland-clipboard-listener = "0.6.0"
directories = "6.0.0"
[features]
x11 = []

View File

@ -1,4 +1,5 @@
use crate::models::{ClipboardData, ClipboardEntry, Image};
use image::codecs::jpeg::JpegEncoder;
use image::codecs::png::PngEncoder;
use image::{ExtendedColorType, ImageEncoder};
use rusqlite::Connection;
@ -49,12 +50,16 @@ impl Database {
let img_path = img.file_path(&self.dir_path);
let file = fs::File::create(&img_path)?;
let encoder = PngEncoder::new(file);
let rgb_pixels: Vec<u8> = raw_pixels
.chunks_exact(4)
.flat_map(|rgba| [rgba[0], rgba[1], rgba[2]])
.collect();
let encoder = JpegEncoder::new_with_quality(file, 70);
encoder.write_image(
raw_pixels,
&rgb_pixels,
img.width,
img.height,
ExtendedColorType::Rgba8,
ExtendedColorType::Rgb8,
)?;
}
("image", img.id.to_string())

View File

@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};
use crate::database::Database;
use arboard::Clipboard;
use directories::ProjectDirs;
use std::sync::{Arc, Mutex};
mod clipboard;
mod database;
@ -11,9 +11,12 @@ mod ws;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let clipboard = Clipboard::new()?;
let dir_path = "clipboard";
let db = Arc::new(Mutex::new(Database::init(dir_path)?));
let proj_dirs = ProjectDirs::from("com", "zefad", "rklipd").expect("Unable to open dir");
let dir_path = proj_dirs.data_dir();
let dir_path_str = dir_path.to_str().expect("Invalid path").to_string();
let db = Arc::new(Mutex::new(Database::init(&dir_path_str)?));
// println!("{:#?}", db.lock().unwrap().read_history());

View File

@ -27,7 +27,7 @@ impl Image {
pub fn file_path(&self, base_dir: &str) -> PathBuf {
std::path::Path::new(base_dir)
.join("images")
.join(format!("{}.png", self.id))
.join(format!("{}.jpg", self.id))
}
pub fn load_bytes(&self, dir_path: &str) -> io::Result<Vec<u8>> {