wayland-clipboard-listener

I would rather to use animate girl to name the crate, but it will cannot show how the crate do

it impl wlr-data-control-unstable-v1, you can see the protocol under

wlr-data-control-unstable-v1

you can use it on sway or kde

it is GPL-v3, if you use the code, you need to privide your code, you should not fuck to use the code to listen on people's clipboard and upload it to you company or government, you must fuck to opensource your code.

General Induction

impl wlr-data-control-unstable-v1, handle the clipboard on sway, hyperland or kde animpl the protocol. You can view the protocol in wlr-data-control-unstable-v1. Here we simply explain it.

This protocol involves there register: WlSeat, ZwlrDataControlManagerV1, ZwlrDataControlDeviceV1, and zwlrDataControlOfferV1, seat is used to create a device, and the device will handle the copy and paste,

when you want to use this protocol, you need to init these first, then enter the eventloop, you can view our code, part of init()

Paste

Copy is mainly in the part of device dispatch and dataoffer one, there are two road to finished a copy event, this is decided by the time you send the receive request of ZwlrDataControlDeviceV1;

Road 1

Road 2

it is similar with Road 1, but send receive request when receive selection event, this time you will receive mimetype. Here you can only receive the data which is by copy

Copy

Paste with wlr-data-control-unstable-v1, need data provider alive, you can make an experiment, if you copy a text from firefox, and kill firefox, you will find, you cannot paste! It is amazing, doesn't it? So the copy event need to keep alive if the data is still available. You will find that if you copy a text with wl-copy, it will always alive in htop, if you view the code, you will find it fork itself, and live in the backend, until you copy another text from other place, it will die.

Then the problem is, how to copy the data, and when to kill the progress?

Copy event involves ZwlrDataControlDeviceV1 and ZwlrDataControlSourceV1.

A simple example to create a clipboard listener is following:

```rust use waylandclipboardlistener::WlClipboardPasteStream; use waylandclipboardlistener::WlListenType;

fn main() { let mut stream = WlClipboardPasteStream::init(WlListenType::ListenOnCopy).unwrap(); for context in stream.paste_stream().flatten().flatten() { println!("{context:?}"); } }

```

A simple example to create a wl-copy is following: ``` rust use waylandclipboardlistener::{WlClipboardCopyStream, WlClipboardListenerError}; fn main() -> Result<(), WlClipboardListenerError> { let args = std::env::args(); if args.len() != 2 { println!("You need to pass a string to it"); return Ok(()); } let context: &str = &args.last().unwrap(); let mut stream = WlClipboardCopyStream::init()?; stream.copytoclipboard(context.asbytes().tovec())?; Ok(()) }