Code Monkey home page Code Monkey logo

Comments (4)

DoumanAsh avatar DoumanAsh commented on September 13, 2024

If anyone will find it interesting: On windows i cam up with simple workaround for console applications to get notified on clipboard change events properly https://github.com/DoumanAsh/clipboard-master

Basic sequence of actions:

  1. Add window, you can create dummy window as console application, to clipboard updates using AddClipboardFormatListener
  2. Listen for WM_CLIPBOARDUPDATE messages(each time clipboard is changed, message is sent)
  3. To remove yourself from listening use RemoveClipboardFormatListener

I'm not familiar with Linux/MacOS ways to do it, but considering that Qt does it, it should be possible.

from rust-clipboard.

aweinstock314 avatar aweinstock314 commented on September 13, 2024

cdaringe's link demonstrates how to do it on MacOS (via some swift code, which can be adapted to use msg_send!).

It looks like x11-clipboard doesn't have an event loop for this feature yet, but it's probably possible to adapt the existing getter loop (i.e. from Clipboard::load), and ideally factor out some common event loop that can be used for both the getter and the notifier.

Since it's supportable on all the platforms so far, it's in-scope for the library.

As far as interface goes, does adding a function like get_change_notifier(&self) -> Receiver</* something like an enum over formats or a String */> to the ClipboardProvider trait seem reasonable?

cc @DoumanAsh @quininer

from rust-clipboard.

quininer avatar quininer commented on September 13, 2024

In X11 this can be implement with FixesExt, but I don't have much time. I'd be happy if someone could help.

quininer/x11-clipboard#3

from rust-clipboard.

DoumanAsh avatar DoumanAsh commented on September 13, 2024

@aweinstock314 By Receiver do you mean it is going to be channel's end? It might be fine API but it would imply that thread will be started implicitly to wait for clipboard changes.
I wouldn't recommend returning content of clipboard and instead the Receiver should be over simple enum:

enum ClipboardStateChange<T> {
    NewContent,
    Error(T)

As clipboard is global on windows, having option to read/write in multiple threads is a bad idea.

But I also think there should be configuration option to identify type of clipboard change.
For example user might be interested only in plain text or image.

So maybe it could be something like:

let listener = ClipboardListenerBuilder::new().listen(Event::Text).listen(Event::Image)
let clipboard_change = clipboard.enable_listener(listener);

I guess having it as both iterator or channel's receiver would be good.

P.s. for Windows I'm also thinking maybe moving into clipboard crate itself.

from rust-clipboard.

Related Issues (20)

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.