Add rustfmt.toml

Add rustfmt.toml that is being used by projects under smithay's
umbrella.
This commit is contained in:
Kirill Chibisov 2020-08-06 02:04:14 +03:00 committed by Victor Berger
parent 7fc533d55f
commit 597086c42c
8 changed files with 29 additions and 84 deletions

View file

@ -25,10 +25,7 @@ struct DispatchData {
impl DispatchData {
fn new(clipboard: Clipboard) -> Self {
Self {
pending_frame_event: None,
clipboard,
}
Self { pending_frame_event: None, clipboard }
}
}
@ -68,15 +65,11 @@ fn main() {
.expect("failed to create a window.");
// Set title and app id
window.set_title(String::from(
"smithay-clipboard example. Press C/P to copy/paste",
));
window.set_title(String::from("smithay-clipboard example. Press C/P to copy/paste"));
window.set_app_id(String::from("smithay-clipboard-example"));
// Create memory pool
let mut pools = env
.create_double_pool(|_| {})
.expect("failed to create a memory pool.");
let mut pools = env.create_double_pool(|_| {}).expect("failed to create a memory pool.");
// Structure to track seats
let mut seats = Vec::<(WlSeat, Option<(WlKeyboard, EventLoopSource<_>)>)>::new();
@ -110,10 +103,7 @@ fn main() {
seats.push((seat.detach(), Some((keyboard, repeat_source))));
}
Err(err) => {
eprintln!(
"Failed to map keyboard on seat {:?} : {:?}",
seat_data.name, err
);
eprintln!("Failed to map keyboard on seat {:?} : {:?}", seat_data.name, err);
seats.push((seat.detach(), None));
}
}
@ -155,10 +145,7 @@ fn main() {
*mapped_keyboard = Some((keyboard, repeat_source));
}
Err(err) => {
eprintln!(
"Failed to map keyboard on seat {} : {:?}",
seat_data.name, err
);
eprintln!("Failed to map keyboard on seat {} : {:?}", seat_data.name, err);
}
}
}
@ -178,9 +165,7 @@ fn main() {
window.refresh();
}
sctk::WaylandSource::new(queue)
.quick_insert(event_loop.handle())
.unwrap();
sctk::WaylandSource::new(queue).quick_insert(event_loop.handle()).unwrap();
let clipboard = Clipboard::new(display.get_display_ptr() as *mut _);
let mut dispatch_data = DispatchData::new(clipboard);
@ -214,14 +199,8 @@ fn main() {
fn process_keyboard_event(event: KeyboardEvent, dispatch_data: &mut DispatchData) {
let text = match event {
KeyboardEvent::Key {
state,
utf8: Some(text),
..
} if state == KeyState::Pressed => text,
KeyboardEvent::Repeat {
utf8: Some(text), ..
} => text,
KeyboardEvent::Key { state, utf8: Some(text), .. } if state == KeyState::Pressed => text,
KeyboardEvent::Repeat { utf8: Some(text), .. } => text,
_ => return,
};
@ -263,8 +242,7 @@ fn draw(
surface: WlSurface,
dimensions: (u32, u32),
) -> Result<(), std::io::Error> {
pool.resize((4 * dimensions.0 * dimensions.1) as usize)
.expect("failed to resize memory pool");
pool.resize((4 * dimensions.0 * dimensions.1) as usize).expect("failed to resize memory pool");
{
pool.seek(SeekFrom::Start(0))?;

4
rustfmt.toml Normal file
View file

@ -0,0 +1,4 @@
use_small_heuristics = "Max"
use_field_init_shorthand = true
newline_style = "Unix"
edition = "2018"

View file

@ -20,11 +20,7 @@ impl SmithayClipboard {
let mut seats = SeatHandler::new();
let data_device_manager = DataDeviceHandler::init(&mut seats);
let primary_selection_manager = PrimarySelectionHandler::init(&mut seats);
Self {
seats,
primary_selection_manager,
data_device_manager,
}
Self { seats, primary_selection_manager, data_device_manager }
}
}
@ -44,13 +40,11 @@ impl PrimarySelectionHandling for SmithayClipboard {
seat: &WlSeat,
f: F,
) -> Result<(), ()> {
self.primary_selection_manager
.with_primary_selection(seat, f)
self.primary_selection_manager.with_primary_selection(seat, f)
}
fn get_primary_selection_manager(&self) -> Option<PrimarySelectionDeviceManager> {
self.primary_selection_manager
.get_primary_selection_manager()
self.primary_selection_manager.get_primary_selection_manager()
}
}

View file

@ -32,18 +32,10 @@ impl Clipboard {
let (clipboard_reply_sender, request_receiver) = mpsc::channel();
let name = String::from("smithay-clipboard");
let clipboard_thread = worker::spawn(
name,
display,
clipboard_request_receiver,
clipboard_reply_sender,
);
let clipboard_thread =
worker::spawn(name, display, clipboard_request_receiver, clipboard_reply_sender);
Self {
request_receiver,
request_sender,
clipboard_thread,
}
Self { request_receiver, request_sender, clipboard_thread }
}
/// Load clipboard data.

View file

@ -39,9 +39,7 @@ macro_rules! handle_load {
}
};
$queue
.sync_roundtrip(&mut (), |_, _, _| unreachable!())
.unwrap();
$queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()).unwrap();
let mut contents = String::new();
let result = reader.read_to_string(&mut contents).map(|_| {
@ -67,14 +65,12 @@ macro_rules! handle_store {
($env:ident,
$sel_source:ident, $sel_device:ident, $event_ty:ident,
$seat:ident, $serial:ident, $queue:ident, $contents:ident) => {
let data_source = $env.$sel_source(
vec![MimeType::TextPlainUtf8.to_string()],
move |event, _| {
let data_source =
$env.$sel_source(vec![MimeType::TextPlainUtf8.to_string()], move |event, _| {
if let $event_ty::Send { mut pipe, .. } = event {
write!(pipe, "{}", $contents).unwrap();
}
},
);
});
let _ = $env.$sel_device(&$seat, |device| {
device.set_selection(&Some(data_source), $serial);
@ -86,11 +82,7 @@ macro_rules! handle_store {
/// Reply an error to a clipboard master.
pub fn reply_error(tx: &Sender<Result<String>>, description: &str) {
tx.send(Err(std::io::Error::new(
std::io::ErrorKind::Other,
description,
)))
.unwrap();
tx.send(Err(std::io::Error::new(std::io::ErrorKind::Other, description))).unwrap();
}
/// Update seat and serial on pointer events.

View file

@ -68,9 +68,7 @@ fn worker_impl(display: Display, request_rx: Receiver<Command>, reply_tx: Sender
let env = Environment::init(&display_proxy, SmithayClipboard::new());
let req = queue.sync_roundtrip(&mut (), |_, _, _| unreachable!());
let _ = req
.and_then(|_| queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()))
.unwrap();
let _ = req.and_then(|_| queue.sync_roundtrip(&mut (), |_, _, _| unreachable!())).unwrap();
// Get data device manager.
let data_device_manager = env.get_global::<WlDataDeviceManager>();
@ -211,9 +209,7 @@ fn worker_impl(display: Display, request_rx: Receiver<Command>, reply_tx: Sender
// Reset the time we're sleeping.
sa_tracker.reset_sleep();
queue
.sync_roundtrip(&mut dispatch_data, |_, _, _| unimplemented!())
.unwrap();
queue.sync_roundtrip(&mut dispatch_data, |_, _, _| unimplemented!()).unwrap();
// Get latest observed seat and serial.
let (seat, serial) = match dispatch_data.last_seat() {
@ -274,9 +270,7 @@ fn worker_impl(display: Display, request_rx: Receiver<Command>, reply_tx: Sender
}
}
let pending_events = queue
.dispatch_pending(&mut dispatch_data, |_, _, _| {})
.unwrap();
let pending_events = queue.dispatch_pending(&mut dispatch_data, |_, _, _| {}).unwrap();
// If some application is trying to spam us when there're no seats, it's likely that
// someone is trying to paste from us.

View file

@ -11,10 +11,6 @@ pub struct SeatData {
impl SeatData {
pub fn new(seat: WlSeat, keyboard: Option<WlKeyboard>, pointer: Option<WlPointer>) -> Self {
SeatData {
seat,
keyboard,
pointer,
}
SeatData { seat, keyboard, pointer }
}
}

View file

@ -16,12 +16,7 @@ impl SleepAmountTracker {
/// `max_time_to_sleep` - maximum sleep value for a thread.
/// ``
pub fn new(max_time_to_sleep: u8, max_warm_wakeups: u8) -> Self {
Self {
max_time_to_sleep,
max_warm_wakeups,
warm_wakeup: 0,
time_to_sleep: 0,
}
Self { max_time_to_sleep, max_warm_wakeups, warm_wakeup: 0, time_to_sleep: 0 }
}
/// Reset the current sleep amount to 0ms.