1Password / arboard

A clipboard for Rust
Apache License 2.0
641 stars 73 forks source link

Handle clipboard change event? #78

Open bit-ranger opened 2 years ago

bit-ranger commented 2 years ago

Is there any way to handle clipboard change event?

complexspaces commented 2 years ago

Hey there, @bit-ranger. AFAIK, clipboard change events are a feature of window managers and not raw clipboard accesses. Windows, for example, has AddClipboardFormatListener that can fire WM events for you, but I don't know if its usable in the context of a CLI application off the top of my head.

0-don commented 1 year ago

its posible https://crates.io/crates/clipboard-master

huangganggui commented 4 months ago

@complexspaces Can i start a thread monitor the clipboard.get_text() change or not?

complexspaces commented 4 months ago

@huangganggui No, that won't work like you want. get_text() does not block waiting for changes, it will either return the current clipboard contents or an error if nothing is available.

In theory: you could read the current clipboard value, poll the clipboard every second in a thread, and see if the value has changed but that's pretty inefficient.

huangganggui commented 4 months ago

@complexspaces Nice! I will try poll the clipboard every 0.1s in a thread. In my case, efficiency maybe not such important. Thanks a lot.