diff --git a/examples/clipboard.rs b/examples/clipboard.rs index 23f0156..e8e0caf 100644 --- a/examples/clipboard.rs +++ b/examples/clipboard.rs @@ -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))?; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9e91dd0 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,4 @@ +use_small_heuristics = "Max" +use_field_init_shorthand = true +newline_style = "Unix" +edition = "2018" diff --git a/src/env.rs b/src/env.rs index 8c49765..700c3e2 100644 --- a/src/env.rs +++ b/src/env.rs @@ -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 { - self.primary_selection_manager - .get_primary_selection_manager() + self.primary_selection_manager.get_primary_selection_manager() } } diff --git a/src/lib.rs b/src/lib.rs index 6f572b3..26fc5ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. diff --git a/src/worker/handlers.rs b/src/worker/handlers.rs index 5e96b2c..23e4a6c 100644 --- a/src/worker/handlers.rs +++ b/src/worker/handlers.rs @@ -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>, 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. diff --git a/src/worker/mod.rs b/src/worker/mod.rs index 429446b..cf54b1a 100644 --- a/src/worker/mod.rs +++ b/src/worker/mod.rs @@ -68,9 +68,7 @@ fn worker_impl(display: Display, request_rx: Receiver, 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::(); @@ -211,9 +209,7 @@ fn worker_impl(display: Display, request_rx: Receiver, 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, 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. diff --git a/src/worker/seat_data.rs b/src/worker/seat_data.rs index 9ab58fa..c6374f7 100644 --- a/src/worker/seat_data.rs +++ b/src/worker/seat_data.rs @@ -11,10 +11,6 @@ pub struct SeatData { impl SeatData { pub fn new(seat: WlSeat, keyboard: Option, pointer: Option) -> Self { - SeatData { - seat, - keyboard, - pointer, - } + SeatData { seat, keyboard, pointer } } } diff --git a/src/worker/sleep_amount_tracker.rs b/src/worker/sleep_amount_tracker.rs index 9e254ac..28ec2ed 100644 --- a/src/worker/sleep_amount_tracker.rs +++ b/src/worker/sleep_amount_tracker.rs @@ -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.