Git Product home page Git Product logo

clipboard-master's Introduction

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");
}

clipboard-master's People

Contributors

alex222222222222 avatar doumanash avatar heychsea avatar morn-0 avatar thecoldvoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

clipboard-master's Issues

How to stop the process?

I am running it using a thread.

thread::spawn(async move {
      let _ = Master::new(Handler).run();
});

But don't know how to stop it. Maybe a flag can be passed in to stop the thread?

On 4.0.0-beta.4, Linux is spamming event handler with same clipboard value.

On other platforms, we have the assumptions that the event handler callback is called when there is any change in the clipboard. However on Linux, version 4.0.0-beta.4 will trigger the callback every sleep_interval seconds. I've noticed that the load_wait is explicitly changed to load in the new version which leads to this behavior. What is that for? Is load_wait doing anything unexpected?

Update dependency `x11-clipboard`

The dependency x11-clipboard = "0.5" has used xcb = "0.10.1",which several critical issues have been discovered for this version.
The following is the report from GitHub dependent bot:

An issue was discovered in the xcb crate through 2021-02-04 for Rust. It has a soundness violation because xcb::xproto::GetAtomNameReply::name() calls std::str::from_utf8_unchecked() on unvalidated bytes from an X server.

An issue was discovered in the xcb crate through 2021-02-04 for Rust. It has a soundness violation because there is an out-of-bounds read in xcb::xproto::change_property(), as demonstrated by a format=32 T=u8 situation where out-of-bounds bytes are sent to an X server.

The function xcb::xproto::GetPropertyReply::value() returns a slice of type T where T is an unconstrained type parameter. The raw bytes received from the X11 server are interpreted as the requested type. The users of the xcb crate are advised to only call this function with the intended types. These are u8, u16, and u32.
This issue is tracked here: https://github.com/rust-x-bindings/rust-xcb/issues/95

Linux support

Hi,
compiling your example code gives:

error[E0432]: unresolved imports `clipboard_master::Master`, `clipboard_master::ClipboardHandler`, `clipboard_master::CallbackResult`
 --> src/main.rs:3:24
  |
3 | use clipboard_master::{Master, ClipboardHandler, CallbackResult};
  |                        ^^^^^^  ^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^ no `CallbackResult` in the root
  |                        |       |
  |                        |       no `ClipboardHandler` in the root
  |                        no `Master` in the root

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.