Skip to content

Commit

Permalink
Apply rustfmt
Browse files Browse the repository at this point in the history
Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed May 31, 2021
1 parent 890196b commit 6e09b50
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions druid-shell/src/platform/x11/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use std::rc::Rc;
use x11rb::connection::Connection;
use x11rb::errors::ReplyOrIdError;
use x11rb::protocol::xproto::{
AtomEnum, ChangeWindowAttributesAux, ConnectionExt, EventMask, GetPropertyReply, GetPropertyType,
Property, Timestamp, WindowClass,
AtomEnum, ChangeWindowAttributesAux, ConnectionExt, EventMask, GetPropertyReply,
GetPropertyType, Property, Timestamp, WindowClass,
};
use x11rb::protocol::Event;
use x11rb::xcb_ffi::XCBConnection;
Expand Down Expand Up @@ -85,7 +85,8 @@ impl Clipboard {

pub fn preferred_format(&self, formats: &[FormatId]) -> Option<FormatId> {
let available = self.available_type_names();
formats.iter()
formats
.iter()
.find(|f1| available.iter().any(|f2| *f1 == f2))
.copied()
}
Expand All @@ -94,16 +95,22 @@ impl Clipboard {
self.do_transfer(format, |prop| prop.value)
}

#[allow(clippy::needless-collect)]
#[allow(clippy::needless_collect)]
pub fn available_type_names(&self) -> Vec<String> {
let requests = self.do_transfer("TARGETS", |prop| prop.value32().map(|iter| iter.collect()).unwrap_or_default())
let requests = self
.do_transfer("TARGETS", |prop| {
prop.value32()
.map(|iter| iter.collect())
.unwrap_or_default()
})
.unwrap_or_default()
.into_iter()
.filter_map(|atom| self.connection.get_atom_name(atom).ok())
.collect::<Vec<_>>();
// We first send all requests above and then fetch the replies with only one round-trip to
// the X11 server. Hence, the collect() above is not unnecessary!
requests.into_iter()
requests
.into_iter()
.filter_map(|req| req.reply().ok())
.filter_map(|reply| String::from_utf8(reply.name).ok())
.collect()
Expand All @@ -123,7 +130,11 @@ impl Clipboard {
}
}

fn do_transfer_impl<R, F>(&self, format: FormatId, mut converter: F) -> Result<Option<Vec<R>>, ReplyOrIdError>
fn do_transfer_impl<R, F>(
&self,
format: FormatId,
mut converter: F,
) -> Result<Option<Vec<R>>, ReplyOrIdError>
where
R: Clone,
F: FnMut(GetPropertyReply) -> Vec<R>,
Expand Down Expand Up @@ -194,8 +205,7 @@ impl Clipboard {
loop {
match conn.wait_for_event()? {
Event::PropertyNotify(notify)
if (notify.window, notify.state)
== (window.window, Property::NEW_VALUE) =>
if (notify.window, notify.state) == (window.window, Property::NEW_VALUE) =>
{
let property = conn
.get_property(
Expand Down

0 comments on commit 6e09b50

Please sign in to comment.