Skip to content

Commit

Permalink
Make rustfmt happy
Browse files Browse the repository at this point in the history
Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed May 23, 2021
1 parent f26d5b4 commit bfad91d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
4 changes: 3 additions & 1 deletion druid-shell/src/platform/x11/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ use anyhow::{anyhow, Context, Error};
use x11rb::connection::Connection;
use x11rb::protocol::present::ConnectionExt as _;
use x11rb::protocol::xfixes::ConnectionExt as _;
use x11rb::protocol::xproto::{self, ConnectionExt, CreateWindowAux, EventMask, Timestamp, WindowClass};
use x11rb::protocol::xproto::{
self, ConnectionExt, CreateWindowAux, EventMask, Timestamp, WindowClass,
};
use x11rb::protocol::Event;
use x11rb::resource_manager::Database as ResourceDb;
use x11rb::xcb_ffi::XCBConnection;
Expand Down
66 changes: 43 additions & 23 deletions druid-shell/src/platform/x11/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ use std::rc::Rc;

use x11rb::connection::Connection;
use x11rb::errors::ReplyOrIdError;
use x11rb::protocol::xproto::{
AtomEnum, ChangeWindowAttributesAux, ConnectionExt, EventMask, GetPropertyType, Property,
Timestamp, WindowClass,
};
use x11rb::protocol::Event;
use x11rb::protocol::xproto::{AtomEnum, ChangeWindowAttributesAux, ConnectionExt, EventMask, GetPropertyType, Property, Timestamp, WindowClass};
use x11rb::xcb_ffi::XCBConnection;

use crate::clipboard::{ClipboardFormat, FormatId};
Expand Down Expand Up @@ -53,7 +56,12 @@ impl Clipboard {
event_queue: Rc<RefCell<VecDeque<Event>>>,
timestamp: Rc<Cell<Timestamp>>,
) -> Self {
Clipboard { connection, screen_num, event_queue, timestamp }
Clipboard {
connection,
screen_num,
event_queue,
timestamp,
}
}

pub fn put_string(&mut self, _s: impl AsRef<str>) {
Expand Down Expand Up @@ -97,7 +105,11 @@ impl Clipboard {
let format = conn.intern_atom(false, format.as_bytes())?;
let clipboard = conn.intern_atom(false, b"CLIPBOARD")?;
let incr = conn.intern_atom(false, b"INCR")?;
(format.reply()?.atom, clipboard.reply()?.atom, incr.reply()?.atom)
(
format.reply()?.atom,
clipboard.reply()?.atom,
incr.reply()?.atom,
)
};

// Create a window for the transfer
Expand All @@ -115,7 +127,9 @@ impl Clipboard {
conn.flush()?;
let notify = loop {
match conn.wait_for_event()? {
Event::SelectionNotify(notify) if notify.requestor == window.window => break notify,
Event::SelectionNotify(notify) if notify.requestor == window.window => {
break notify
}
event => self.event_queue.borrow_mut().push_back(event),
}
};
Expand All @@ -129,14 +143,16 @@ impl Clipboard {
&ChangeWindowAttributesAux::default().event_mask(EventMask::PROPERTY_CHANGE),
)?;

let property = conn.get_property(
true,
window.window,
TRANSFER_ATOM,
GetPropertyType::ANY,
0,
u32::MAX,
)?.reply()?;
let property = conn
.get_property(
true,
window.window,
TRANSFER_ATOM,
GetPropertyType::ANY,
0,
u32::MAX,
)?
.reply()?;

if property.type_ != incr_atom {
Ok(Some(property.value))
Expand All @@ -148,26 +164,30 @@ impl Clipboard {
conn.flush()?;
loop {
match conn.wait_for_event()? {
Event::PropertyNotify(notify) if (notify.window, notify.state) == (window.window, Property::NEW_VALUE) => {
let property = conn.get_property(
true,
window.window,
TRANSFER_ATOM,
GetPropertyType::ANY,
0,
u32::MAX,
)?.reply()?;
Event::PropertyNotify(notify)
if (notify.window, notify.state)
== (window.window, Property::NEW_VALUE) =>
{
let property = conn
.get_property(
true,
window.window,
TRANSFER_ATOM,
GetPropertyType::ANY,
0,
u32::MAX,
)?
.reply()?;
if property.value.is_empty() {
// End of transfer
return Ok(Some(value));
} else {
value.extend_from_slice(&property.value);
}
},
}
event => self.event_queue.borrow_mut().push_back(event),
}
}

}
}
}
Expand Down

0 comments on commit bfad91d

Please sign in to comment.