1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-02 03:01:04 +02:00

Merge pull request #458 from JakeStanger/fix/clipboard-xwayland

fix(clipboard): unable to paste large images into xwayland
This commit is contained in:
Jake Stanger 2024-02-18 00:48:25 +00:00 committed by GitHub
commit 0cc1f79be0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -179,6 +179,9 @@ impl Environment {
MimeTypeCategory::Image => { MimeTypeCategory::Image => {
let mut bytes = vec![]; let mut bytes = vec![];
file.read_to_end(&mut bytes)?; file.read_to_end(&mut bytes)?;
debug!("Read bytes: {}", bytes.len());
let bytes = Bytes::from(&bytes); let bytes = Bytes::from(&bytes);
ClipboardValue::Image(bytes) ClipboardValue::Image(bytes)
@ -234,6 +237,8 @@ impl DataControlDeviceHandler for Environment {
return; return;
}; };
debug!("Receiving mime type: {}", mime_type.value);
if let Ok(read_pipe) = cur_offer.offer.receive(mime_type.value.clone()) { if let Ok(read_pipe) = cur_offer.offer.receive(mime_type.value.clone()) {
let offer_clone = cur_offer.offer.clone(); let offer_clone = cur_offer.offer.clone();
@ -331,9 +336,9 @@ impl DataControlSourceHandler for Environment {
let pipe_size = set_pipe_size(fd.as_raw_fd(), bytes.len()) let pipe_size = set_pipe_size(fd.as_raw_fd(), bytes.len())
.expect("Failed to increase pipe size"); .expect("Failed to increase pipe size");
let mut file = File::from(fd.try_clone().expect("Failed to clone fd")); let mut file = File::from(fd.try_clone().expect("to be able to clone"));
trace!("Num bytes: {}", bytes.len()); debug!("Writing {} bytes", bytes.len());
let mut events = (0..16).map(|_| EpollEvent::empty()).collect::<Vec<_>>(); let mut events = (0..16).map(|_| EpollEvent::empty()).collect::<Vec<_>>();
let epoll_event = EpollEvent::new(EpollFlags::EPOLLOUT, 0); let epoll_event = EpollEvent::new(EpollFlags::EPOLLOUT, 0);
@ -347,20 +352,23 @@ impl DataControlSourceHandler for Environment {
while !bytes.is_empty() { while !bytes.is_empty() {
let chunk = &bytes[..min(pipe_size as usize, bytes.len())]; let chunk = &bytes[..min(pipe_size as usize, bytes.len())];
trace!("Writing {} bytes ({} remain)", chunk.len(), bytes.len());
epoll_fd epoll_fd
.wait(&mut events, 100) .wait(&mut events, 100)
.expect("Failed to wait to epoll"); .expect("Failed to wait to epoll");
match file.write(chunk) { match file.write(chunk) {
Ok(_) => bytes = &bytes[chunk.len()..], Ok(written) => {
trace!("Wrote {} bytes ({} remain)", written, bytes.len());
bytes = &bytes[written..];
}
Err(err) => { Err(err) => {
error!("{err:?}"); error!("{err:?}");
break; break;
} }
} }
} }
debug!("Done writing");
} else { } else {
error!("Failed to find source"); error!("Failed to find source");
} }
@ -388,7 +396,7 @@ impl DataControlSourceHandler for Environment {
/// If the requested size is larger than the kernel max (normally 1MB), /// If the requested size is larger than the kernel max (normally 1MB),
/// it will be clamped at this. /// it will be clamped at this.
/// ///
/// Returns the new size if succeeded /// Returns the new size if succeeded.
fn set_pipe_size(fd: RawFd, size: usize) -> io::Result<i32> { fn set_pipe_size(fd: RawFd, size: usize) -> io::Result<i32> {
// clamp size at kernel max // clamp size at kernel max
let max_pipe_size = fs::read_to_string("/proc/sys/fs/pipe-max-size") let max_pipe_size = fs::read_to_string("/proc/sys/fs/pipe-max-size")