clipboard-master

Crates.ioclipboard-master
lib.rsclipboard-master
version4.0.0-beta.6
sourcesrc
created_at2017-03-17 07:36:45.783987
updated_at2024-06-04 14:41:27.756308
descriptionSimple utility crate to monitor clipboard changes
homepagehttps://github.com/DoumanAsh/clipboard-master
repositoryhttps://github.com/DoumanAsh/clipboard-master
max_upload_size
id9005
size25,964
Douman (DoumanAsh)

documentation

README

clipboard-master

Crates.io Docs.rs

Clipboard monitoring library.

Supported platforms

  • Windows - uses dummy window to receive messages when clipboard changes;
  • Linux - uses x11_clipboard
  • MacOS - uses polling via NSPasteboard::changeCount as there is no event notification.

Clipboard Master Library

This project exports Master struct that provides simple way to handle clipboard updates.

Example:

extern crate clipboard_master;

use clipboard_master::{Master, ClipboardHandler, CallbackResult};

use std::io;

struct Handler;

impl ClipboardHandler for Handler {
    fn on_clipboard_change(&mut self) -> CallbackResult {
        println!("Clipboard change happened!");
        CallbackResult::Next
    }

    fn on_clipboard_error(&mut self, error: io::Error) -> CallbackResult {
        eprintln!("Error: {}", error);
        CallbackResult::Next
    }
}

fn main() {
    let mut master = Master::new(Handler).expect("create new monitor");

    let shutdown = master.shutdown_channel();
    std::thread::spawn(move || {
        std::thread::sleep(core::time::Duration::from_secs(1));
        println!("I did some work so time to finish...");
        shutdown.signal();
    });
    //Working until shutdown
    master.run().expect("Success");
}
Commit count: 38

cargo fmt