Add clippyboard-clear command

This commit is contained in:
nora 2025-09-19 20:57:58 +02:00
parent a2bfdf331b
commit 0779094712
5 changed files with 34 additions and 2 deletions

View file

@ -9,6 +9,9 @@ name = "clippyboard-daemon"
[[bin]]
name = "clippyboard-select"
[[bin]]
name = "clippyboard-clear"
[dependencies]
ciborium = "0.2.2"
ctrlc = "3.5.0"
@ -22,3 +25,6 @@ tracing = { version = "0.1.41", features = ["attributes"] }
tracing-subscriber = { version = "0.3.20", features = ["env-filter"] }
wayland-client = "0.31.11"
wayland-protocols = { version = "0.32.9", features = ["staging"] }
[profile.release]
lto = "thin"

View file

@ -25,6 +25,8 @@
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
wrapProgram $out/bin/clippyboard-daemon \
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
wrapProgram $out/bin/clippyboard-clear \
--suffix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath buildInputs}
'';
cargoLock.lockFile = ./Cargo.lock;

View file

@ -0,0 +1,19 @@
use std::{io::Write, os::unix::net::UnixStream};
use eyre::Context;
fn main() -> eyre::Result<()> {
let socket_path = clippyboard::socket_path()?;
let mut socket = UnixStream::connect(&socket_path).wrap_err_with(|| {
format!(
"connecting to socket at {}. is the daemon running?",
socket_path.display()
)
})?;
socket
.write_all(&[clippyboard::MESSAGE_CLEAR])
.wrap_err("writing clear message to socket")?;
Ok(())
}

View file

@ -375,6 +375,10 @@ fn handle_peer(mut peer: UnixStream, shared_state: &SharedState) -> eyre::Result
super::MESSAGE_COPY => {
handle_copy_message(peer, shared_state).wrap_err("handling copy message")?;
}
super::MESSAGE_CLEAR => {
shared_state.items.lock().unwrap().clear();
info!("Cleared history");
}
_ => {}
};
Ok(())

View file

@ -29,9 +29,10 @@ fn serialize_data<S: Serializer>(data: &Arc<[u8]>, serializer: S) -> Result<S::O
data.serialize(serializer)
}
const MESSAGE_READ: u8 = 1;
pub const MESSAGE_READ: u8 = 1;
/// Argument: One u64-bit LE value, the ID
const MESSAGE_COPY: u8 = 2;
pub const MESSAGE_COPY: u8 = 2;
pub const MESSAGE_CLEAR: u8 = 3;
pub fn socket_path() -> eyre::Result<PathBuf> {
if let Some(path) = std::env::var_os("CLIPPYBOARD_SOCKET") {