From 56f6b1668dda6034205bf9f3d5b735f271a8c8b3 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 4 Mar 2021 00:23:09 +0100 Subject: [PATCH] cargo fmt --- src/app.rs | 77 ++++++++++++++++++++--------------------- src/doublemempool.rs | 1 - src/keyboard/keysyms.rs | 28 +++++++-------- src/keyboard/mod.rs | 22 +++++++----- src/keyboard/state.rs | 1 - src/main.rs | 9 +++-- src/widget.rs | 2 +- src/widgets/launcher.rs | 2 +- 8 files changed, 73 insertions(+), 69 deletions(-) diff --git a/src/app.rs b/src/app.rs index f75a3c1..692ce79 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,11 +5,9 @@ use std::sync::{Arc, Mutex}; use chrono::{Duration, Local, NaiveDateTime}; -use crate::keyboard::{ - keysyms, map_keyboard, Event as KbEvent, KeyState, ModifiersState, -}; +use crate::keyboard::{keysyms, map_keyboard, Event as KbEvent, KeyState, ModifiersState}; -use wayland_client::protocol::{wl_compositor, wl_output, wl_pointer, wl_shm, wl_surface, wl_seat}; +use wayland_client::protocol::{wl_compositor, wl_output, wl_pointer, wl_seat, wl_shm, wl_surface}; use wayland_client::{Display, EventQueue, GlobalEvent, GlobalManager, Main}; use wayland_protocols::wlr::unstable::layer_shell::v1::client::{ zwlr_layer_shell_v1, zwlr_layer_surface_v1, @@ -17,7 +15,7 @@ use wayland_protocols::wlr::unstable::layer_shell::v1::client::{ use crate::buffer::Buffer; use crate::color::Color; -use crate::widget::{WaitContext, DrawContext, Widget}; +use crate::widget::{DrawContext, WaitContext, Widget}; use crate::cmd::Cmd; use crate::doublemempool::DoubleMemPool; @@ -68,28 +66,26 @@ impl AppInner { Main, Main, ) { - let surface = compositor - .create_surface(); + let surface = compositor.create_surface(); let this_is_stupid = AtomicBool::new(false); - let shell_surface = shell - .get_layer_surface( - &surface, - output, - zwlr_layer_shell_v1::Layer::Overlay, - "".to_string()); - shell_surface.quick_assign(move |layer, event, _| match event { - zwlr_layer_surface_v1::Event::Configure { serial, .. } => { - if !this_is_stupid.compare_and_swap(false, true, Ordering::SeqCst) { - *(configured_surfaces.lock().unwrap()) += 1; - layer.ack_configure(serial); - tx.send(Cmd::ForceDraw).unwrap(); - } - } - _ => unreachable!(), - }, + let shell_surface = shell.get_layer_surface( + &surface, + output, + zwlr_layer_shell_v1::Layer::Overlay, + "".to_string(), ); + shell_surface.quick_assign(move |layer, event, _| match event { + zwlr_layer_surface_v1::Event::Configure { serial, .. } => { + if !this_is_stupid.compare_and_swap(false, true, Ordering::SeqCst) { + *(configured_surfaces.lock().unwrap()) += 1; + layer.ack_configure(serial); + tx.send(Cmd::ForceDraw).unwrap(); + } + } + _ => unreachable!(), + }); shell_surface.set_keyboard_interactivity(1); shell_surface.set_size(1, 1); @@ -401,8 +397,7 @@ impl<'a> App<'a> { version, } => { if let "wl_output" = &interface[..] { - let output = registry - .bind(version, id); + let output = registry.bind(version, id); inner_global.lock().unwrap().add_output(id, output); } } @@ -415,8 +410,8 @@ impl<'a> App<'a> { // double sync to retrieve the global list // and the globals metadata - event_queue.sync_roundtrip(&mut(), |_, _, _|{}).unwrap(); - event_queue.sync_roundtrip(&mut(), |_, _, _|{}).unwrap(); + event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); + event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); // wl_compositor let compositor = manager @@ -435,10 +430,8 @@ impl<'a> App<'a> { // // Get our seat // - let seat: Main = manager - .instantiate_range(1, 6) - .unwrap(); - event_queue.sync_roundtrip(&mut(), |_, _, _|{}).unwrap(); + let seat: Main = manager.instantiate_range(1, 6).unwrap(); + event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); // // Keyboard processing @@ -453,7 +446,7 @@ impl<'a> App<'a> { num_lock: false, })); - let keyboard = Arc::new(Mutex::new(AppKeyboard{ + let keyboard = Arc::new(Mutex::new(AppKeyboard { current: None, delay: 0, rate: 0, @@ -485,7 +478,10 @@ impl<'a> App<'a> { let mut kbd = kb2.lock().unwrap(); kbd.current = Some(ev.clone()); kbd.next = if kbd.delay > 0 { - Some(Local::now().naive_local() + Duration::milliseconds(kbd.delay.into())) + Some( + Local::now().naive_local() + + Duration::milliseconds(kbd.delay.into()), + ) } else { None }; @@ -496,10 +492,10 @@ impl<'a> App<'a> { } else { kb2.lock().unwrap().next = None; } - }, + } KbEvent::Leave { .. } => { kb2.lock().unwrap().next = None; - }, + } KbEvent::RepeatInfo { delay, rate } => { let mut kbd = kb2.lock().unwrap(); kbd.delay = delay; @@ -513,15 +509,16 @@ impl<'a> App<'a> { // // Prepare shell so that we can create our shell surface // - inner.lock().unwrap().set_shell(Some( - if let Ok(layer) = manager.instantiate_exact(1) { + inner + .lock() + .unwrap() + .set_shell(Some(if let Ok(layer) = manager.instantiate_exact(1) { layer } else { panic!("server didn't advertise `zwlr_layer_shell_v1`"); - }, - )); + })); - event_queue.sync_roundtrip(&mut(), |_, _, _|{}).unwrap(); + event_queue.sync_roundtrip(&mut (), |_, _, _| {}).unwrap(); // // Cursor processing diff --git a/src/doublemempool.rs b/src/doublemempool.rs index c00e372..8ab6975 100644 --- a/src/doublemempool.rs +++ b/src/doublemempool.rs @@ -228,7 +228,6 @@ fn create_shm_fd() -> io::Result { } } - pub struct DoubleMemPool { pool1: MemPool, pool2: MemPool, diff --git a/src/keyboard/keysyms.rs b/src/keyboard/keysyms.rs index b769680..088ec42 100644 --- a/src/keyboard/keysyms.rs +++ b/src/keyboard/keysyms.rs @@ -1,17 +1,17 @@ #![allow(missing_docs, non_upper_case_globals, unused_parens, clippy::all)] -pub const XKB_KEY_BackSpace :u32 = 0xff08; /* Back space, back char */ -pub const XKB_KEY_Tab :u32 = 0xff09; -pub const XKB_KEY_Return :u32 = 0xff0d; /* Return, enter */ -pub const XKB_KEY_Escape :u32 = 0xff1b; -pub const XKB_KEY_Delete :u32 = 0xffff; /* Delete, rubout */ -pub const XKB_KEY_Home :u32 = 0xff50; -pub const XKB_KEY_Left :u32 = 0xff51; /* Move left, left arrow */ -pub const XKB_KEY_Right :u32 = 0xff53; /* Move right, right arrow */ -pub const XKB_KEY_End :u32 = 0xff57; /* EOL */ +pub const XKB_KEY_BackSpace: u32 = 0xff08; /* Back space, back char */ +pub const XKB_KEY_Tab: u32 = 0xff09; +pub const XKB_KEY_Return: u32 = 0xff0d; /* Return, enter */ +pub const XKB_KEY_Escape: u32 = 0xff1b; +pub const XKB_KEY_Delete: u32 = 0xffff; /* Delete, rubout */ +pub const XKB_KEY_Home: u32 = 0xff50; +pub const XKB_KEY_Left: u32 = 0xff51; /* Move left, left arrow */ +pub const XKB_KEY_Right: u32 = 0xff53; /* Move right, right arrow */ +pub const XKB_KEY_End: u32 = 0xff57; /* EOL */ -pub const XKB_KEY_ISO_Left_Tab :u32 = 0xfe20; -pub const XKB_KEY_e :u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */ -pub const XKB_KEY_a :u32 = 0x0061; /* U+0061 LATIN SMALL LETTER A */ -pub const XKB_KEY_c :u32 = 0x0063; /* U+0063 LATIN SMALL LETTER C */ -pub const XKB_KEY_u :u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */ +pub const XKB_KEY_ISO_Left_Tab: u32 = 0xfe20; +pub const XKB_KEY_e: u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */ +pub const XKB_KEY_a: u32 = 0x0061; /* U+0061 LATIN SMALL LETTER A */ +pub const XKB_KEY_c: u32 = 0x0063; /* U+0063 LATIN SMALL LETTER C */ +pub const XKB_KEY_u: u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */ diff --git a/src/keyboard/mod.rs b/src/keyboard/mod.rs index 16add51..602f819 100644 --- a/src/keyboard/mod.rs +++ b/src/keyboard/mod.rs @@ -23,8 +23,8 @@ use wayland_client::{ }; mod ffi; -mod state; pub mod keysyms; +mod state; use self::state::KbState; pub use self::state::{ModifiersState, RMLVO}; @@ -118,10 +118,7 @@ where let callback = Rc::new(RefCell::new(callback)); // prepare the handler - let mut kbd_handler = KbdHandler { - callback, - state, - }; + let mut kbd_handler = KbdHandler { callback, state }; keyboard.quick_assign(move |keyboard, event, data| { kbd_handler.event(keyboard.detach(), event, data) @@ -331,8 +328,17 @@ impl KbdHandler { } } - fn repeat_info(&mut self, object: wl_keyboard::WlKeyboard, rate: i32, delay: i32, dispatch_data: wayland_client::DispatchData) { - (&mut *self.callback.borrow_mut())(Event::RepeatInfo { rate, delay }, object, dispatch_data); + fn repeat_info( + &mut self, + object: wl_keyboard::WlKeyboard, + rate: i32, + delay: i32, + dispatch_data: wayland_client::DispatchData, + ) { + (&mut *self.callback.borrow_mut())( + Event::RepeatInfo { rate, delay }, + object, + dispatch_data, + ); } } - diff --git a/src/keyboard/state.rs b/src/keyboard/state.rs index e687db6..a5996a4 100644 --- a/src/keyboard/state.rs +++ b/src/keyboard/state.rs @@ -398,4 +398,3 @@ impl Drop for KbState { } } } - diff --git a/src/main.rs b/src/main.rs index 20fa172..68dd057 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,6 @@ use timerfd::{SetTimeFlags, TimerFd, TimerState}; mod app; mod buffer; -mod keyboard; mod cmd; mod color; mod config; @@ -21,6 +20,7 @@ mod desktop; mod doublemempool; mod draw; mod fonts; +mod keyboard; mod widget; mod widgets; @@ -206,7 +206,10 @@ fn main() { }); let mut timer = TimerFd::new().unwrap(); - let ev_fd = PollFd::new(app.event_queue().display().get_connection_fd(), PollFlags::POLLIN); + let ev_fd = PollFd::new( + app.event_queue().display().get_connection_fd(), + PollFlags::POLLIN, + ); let rx_fd = PollFd::new(rx_pipe.as_raw_fd(), PollFlags::POLLIN); let tm_fd = PollFd::new(timer.as_raw_fd(), PollFlags::POLLIN); let ipc_fd = PollFd::new(listener.as_raw_fd(), PollFlags::POLLIN); @@ -323,7 +326,7 @@ fn main() { } app.event_queue() - .dispatch_pending(&mut (), |_, _, _|{}) + .dispatch_pending(&mut (), |_, _, _| {}) .expect("Failed to dispatch all messages."); } diff --git a/src/widget.rs b/src/widget.rs index 740cc71..36df21b 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -1,8 +1,8 @@ use crate::buffer::Buffer; use crate::color::Color; +pub use crate::keyboard::{KeyState, ModifiersState}; use chrono::NaiveDateTime; use nix::poll::PollFd; -pub use crate::keyboard::{KeyState, ModifiersState}; pub struct DrawContext<'a> { pub buf: &'a mut Buffer<'a>, diff --git a/src/widgets/launcher.rs b/src/widgets/launcher.rs index d40a17f..5eb164a 100644 --- a/src/widgets/launcher.rs +++ b/src/widgets/launcher.rs @@ -14,8 +14,8 @@ use std::collections::HashMap; use std::process::Command; use std::sync::mpsc::Sender; -use fuzzy_matcher::skim::{fuzzy_indices, fuzzy_match}; use crate::keyboard::keysyms; +use fuzzy_matcher::skim::{fuzzy_indices, fuzzy_match}; use unicode_segmentation::UnicodeSegmentation; pub struct Launcher<'a> {