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

View file

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

View file

@ -39,9 +39,7 @@ macro_rules! handle_load {
} }
}; };
$queue $queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()).unwrap();
.sync_roundtrip(&mut (), |_, _, _| unreachable!())
.unwrap();
let mut contents = String::new(); let mut contents = String::new();
let result = reader.read_to_string(&mut contents).map(|_| { let result = reader.read_to_string(&mut contents).map(|_| {
@ -67,14 +65,12 @@ macro_rules! handle_store {
($env:ident, ($env:ident,
$sel_source:ident, $sel_device:ident, $event_ty:ident, $sel_source:ident, $sel_device:ident, $event_ty:ident,
$seat:ident, $serial:ident, $queue:ident, $contents:ident) => { $seat:ident, $serial:ident, $queue:ident, $contents:ident) => {
let data_source = $env.$sel_source( let data_source =
vec![MimeType::TextPlainUtf8.to_string()], $env.$sel_source(vec![MimeType::TextPlainUtf8.to_string()], move |event, _| {
move |event, _| {
if let $event_ty::Send { mut pipe, .. } = event { if let $event_ty::Send { mut pipe, .. } = event {
write!(pipe, "{}", $contents).unwrap(); write!(pipe, "{}", $contents).unwrap();
} }
}, });
);
let _ = $env.$sel_device(&$seat, |device| { let _ = $env.$sel_device(&$seat, |device| {
device.set_selection(&Some(data_source), $serial); device.set_selection(&Some(data_source), $serial);
@ -86,11 +82,7 @@ macro_rules! handle_store {
/// Reply an error to a clipboard master. /// Reply an error to a clipboard master.
pub fn reply_error(tx: &Sender<Result<String>>, description: &str) { pub fn reply_error(tx: &Sender<Result<String>>, description: &str) {
tx.send(Err(std::io::Error::new( tx.send(Err(std::io::Error::new(std::io::ErrorKind::Other, description))).unwrap();
std::io::ErrorKind::Other,
description,
)))
.unwrap();
} }
/// Update seat and serial on pointer events. /// 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 env = Environment::init(&display_proxy, SmithayClipboard::new());
let req = queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()); let req = queue.sync_roundtrip(&mut (), |_, _, _| unreachable!());
let _ = req let _ = req.and_then(|_| queue.sync_roundtrip(&mut (), |_, _, _| unreachable!())).unwrap();
.and_then(|_| queue.sync_roundtrip(&mut (), |_, _, _| unreachable!()))
.unwrap();
// Get data device manager. // Get data device manager.
let data_device_manager = env.get_global::<WlDataDeviceManager>(); 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. // Reset the time we're sleeping.
sa_tracker.reset_sleep(); sa_tracker.reset_sleep();
queue queue.sync_roundtrip(&mut dispatch_data, |_, _, _| unimplemented!()).unwrap();
.sync_roundtrip(&mut dispatch_data, |_, _, _| unimplemented!())
.unwrap();
// Get latest observed seat and serial. // Get latest observed seat and serial.
let (seat, serial) = match dispatch_data.last_seat() { 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 let pending_events = queue.dispatch_pending(&mut dispatch_data, |_, _, _| {}).unwrap();
.dispatch_pending(&mut dispatch_data, |_, _, _| {})
.unwrap();
// If some application is trying to spam us when there're no seats, it's likely that // If some application is trying to spam us when there're no seats, it's likely that
// someone is trying to paste from us. // someone is trying to paste from us.

View file

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

View file

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