refactor: fix handle_selection_request 8/7 args

Resolve Clippy's `too_many_arguments` lint on
`handle_selection_request` by removing the `success` and `refuse`
parameters and returning a bool indicating which needs to be run.

Use the helper functions defined last commit to simplify
`incr_copy_from_x11`

Reduce the `match` statement checking if the target is the TARGET
atom to an if statement. Although using `match` statements as
`if`/`else if`/`else` chains occur elsewhere, this one is both only 2
cases, and already of particular relevance to the current work.

Refactor `paste_impl` to be much easier to read. I did this code algebra
way back while investigating #142, but since I never figured that out,
the change has just been sitting in my stash.

refactor: simplify paste_data logic, some unnests
This commit is contained in:
En-En 2025-09-28 01:36:09 +00:00 committed by Supreeeme
parent 1ec45141e6
commit cc011f3251
4 changed files with 117 additions and 147 deletions

View file

@ -669,48 +669,38 @@ impl Server {
};
let mut ret = Vec::new();
let mut try_transfer =
|pending_ret: &mut PendingRet, mime: String, mut pending: PendingData| {
self.display.flush_clients().unwrap();
let transfer_complete = send_data_for_mime(&mime, self);
if transfer_complete {
pending.rx.read_to_end(&mut pending.data).unwrap();
ret.push(PasteData {
mime_type: mime,
data: pending.data,
});
} else {
loop {
match pending.rx.read(&mut pending.data) {
Ok(0) => break,
Ok(_) => {}
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => break,
Err(e) => panic!("Failed reading data for mime {mime}: {e:?}"),
}
}
pending_ret.push((mime, Some(pending)));
self.dispatch();
}
};
while let Some((mime, pending)) = pending_ret.pop() {
match pending {
Some(pending) => try_transfer(&mut pending_ret, mime, pending),
None => {
let (rx, tx) = rustix::pipe::pipe().unwrap();
send_selection(mime.clone(), tx.as_fd());
drop(tx);
let mut pending = pending.unwrap_or_else(|| {
let (rx, tx) = rustix::pipe::pipe().unwrap();
send_selection(mime.clone(), tx.as_fd());
drop(tx);
let rx = std::fs::File::from(rx);
try_transfer(
&mut pending_ret,
mime,
PendingData {
rx,
data: Vec::new(),
},
);
let rx = std::fs::File::from(rx);
PendingData {
rx,
data: Vec::new(),
}
});
self.display.flush_clients().unwrap();
let transfer_complete = send_data_for_mime(&mime, self);
if transfer_complete {
pending.rx.read_to_end(&mut pending.data).unwrap();
ret.push(PasteData {
mime_type: mime,
data: pending.data,
});
} else {
loop {
match pending.rx.read(&mut pending.data) {
Ok(0) => break,
Ok(_) => {}
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => break,
Err(e) => panic!("Failed reading data for mime {mime}: {e:?}"),
}
}
pending_ret.push((mime, Some(pending)));
self.dispatch();
}
}