diff --git a/src/font/fontconfigandfreetype.rs b/src/font/fontconfigandfreetype.rs index 3e64f72f7..6c4e15cca 100644 --- a/src/font/fontconfigandfreetype.rs +++ b/src/font/fontconfigandfreetype.rs @@ -79,7 +79,7 @@ impl NamedFontListImpl { if candidate < f.font_list_size { return Some((f, candidate)); } - candidate = candidate - f.font_list_size; + candidate -= f.font_list_size; } None } diff --git a/src/font/ftfont.rs b/src/font/ftfont.rs index 200784805..79a864f48 100644 --- a/src/font/ftfont.rs +++ b/src/font/ftfont.rs @@ -101,6 +101,7 @@ impl Font for FreeTypeFontImpl { } } + #[allow(clippy::cognitive_complexity)] fn rasterize_glyph(&self, glyph_pos: u32) -> Result { let render_mode = //ftwrap::FT_Render_Mode::FT_RENDER_MODE_NORMAL; // ftwrap::FT_Render_Mode::FT_RENDER_MODE_LCD; diff --git a/src/frontend/gui/quad.rs b/src/frontend/gui/quad.rs index 2adafc5f4..e9191deb5 100644 --- a/src/frontend/gui/quad.rs +++ b/src/frontend/gui/quad.rs @@ -1,3 +1,7 @@ +// Clippy hates the implement_vertex macro and won't let me scope +// this warning to its use +#![allow(clippy::unneeded_field_pattern)] + use ::window::bitmaps::TextureRect; use ::window::*; diff --git a/src/frontend/gui/tabbar.rs b/src/frontend/gui/tabbar.rs index 5bab48e23..b862e0429 100644 --- a/src/frontend/gui/tabbar.rs +++ b/src/frontend/gui/tabbar.rs @@ -70,7 +70,7 @@ impl TabBarState { available_cells / number_of_tabs }; - let colors = colors.cloned().unwrap_or_else(|| TabBarColors::default()); + let colors = colors.cloned().unwrap_or_else(TabBarColors::default); let mut line = Line::with_width(title_width); diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index cb0244bf8..a87f66262 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -138,13 +138,10 @@ impl WindowCallbacks for TermWindow { self.last_mouse_coords = (x, y); if self.show_tab_bar && y == 0 { - match event.kind { - WMEK::Press(MousePress::Left) => self.drag_start_coords = Some(event.coords), - _ => {} - } + if let WMEK::Press(MousePress::Left) = event.kind { + self.drag_start_coords = Some(event.coords); - match event.kind { - WMEK::Press(MousePress::Left) => match self.tab_bar.hit_test(x) { + match self.tab_bar.hit_test(x) { TabBarItem::Tab(tab_idx) => { self.activate_tab(tab_idx).ok(); } @@ -152,8 +149,7 @@ impl WindowCallbacks for TermWindow { self.spawn_tab(&SpawnTabDomain::CurrentTabDomain).ok(); } TabBarItem::None => {} - }, - _ => {} + } } } else { let y = y.saturating_sub(first_line_offset); @@ -262,10 +258,9 @@ impl WindowCallbacks for TermWindow { if !self.config.send_composed_key_when_alt_is_pressed && modifiers.contains(::termwiz::input::Modifiers::ALT) + && tab.key_down(key, modifiers).is_ok() { - if tab.key_down(key, modifiers).is_ok() { - return true; - } + return true; } } } diff --git a/src/ratelim.rs b/src/ratelim.rs index 7a5dfc995..c63d12031 100644 --- a/src/ratelim.rs +++ b/src/ratelim.rs @@ -41,7 +41,7 @@ impl RateLimiter { // we use a 32k buffer which means that in the worst case // (where the buffer is 100% full), we'll take ~15 iterations // to reach a decision of a single byte or a sleep delay. - amount = amount / 2; + amount /= 2; } } } diff --git a/src/ssh.rs b/src/ssh.rs index 177635f72..ffbff50ef 100644 --- a/src/ssh.rs +++ b/src/ssh.rs @@ -26,7 +26,7 @@ fn password_prompt( username: &str, remote_address: &str, ) -> Option { - let title = format!("🔐 wezterm: SSH authentication"); + let title = "🔐 wezterm: SSH authentication".to_string(); let text = format!( "🔐 SSH Authentication for {} @ {}\r\n{}\r\n", username, remote_address, instructions @@ -92,7 +92,7 @@ fn input_prompt( username: &str, remote_address: &str, ) -> Option { - let title = format!("🔐 wezterm: SSH authentication"); + let title = "🔐 wezterm: SSH authentication".to_string(); let text = format!( "SSH Authentication for {} @ {}\r\n{}\r\n{}\r\n", username, remote_address, instructions, prompt @@ -224,7 +224,7 @@ pub fn ssh_connect(remote_address: &str, username: &str) -> Fallible bool { } } +fn encode_modifiers(mods: KeyModifiers) -> u8 { + let mut number = 0; + if mods.contains(KeyModifiers::SHIFT) { + number |= 1; + } + if mods.contains(KeyModifiers::ALT) { + number |= 2; + } + if mods.contains(KeyModifiers::CTRL) { + number |= 4; + } + number +} + +fn csi_u_encode(buf: &mut String, c: char, mods: KeyModifiers) -> Result<(), Error> { + // FIXME: provide an option to enable this, because it is super annoying + // in vim when accidentally pressing shift-space and it emits a sequence + // that undoes some number of commands + if false { + write!(buf, "\x1b[{};{}u", c as u32, 1 + encode_modifiers(mods))?; + } + Ok(()) +} + +/// characters that when masked for CTRL could be an ascii control character +/// or could be a key that a user legitimately wants to process in their +/// terminal application +fn is_ambiguous_ascii_ctrl(c: char) -> bool { + match c { + 'i' | 'I' | 'm' | 'M' | '[' | '{' | '@' => true, + _ => false, + } +} + impl TerminalState { pub fn new( physical_rows: usize, @@ -822,6 +856,7 @@ impl TerminalState { /// that is embedding the Terminal. This method translates the /// keycode into a sequence of bytes to send to the slave end /// of the pty via the `Write`-able object provided by the caller. + #[allow(clippy::cognitive_complexity)] pub fn key_down( &mut self, key: KeyCode, @@ -843,44 +878,10 @@ impl TerminalState { _ => mods, }; - fn encode_modifiers(mods: KeyModifiers) -> u8 { - let mut number = 0; - if mods.contains(KeyModifiers::SHIFT) { - number |= 1; - } - if mods.contains(KeyModifiers::ALT) { - number |= 2; - } - if mods.contains(KeyModifiers::CTRL) { - number |= 4; - } - number - } - let mut buf = String::new(); // TODO: also respect self.application_keypad - fn csi_u_encode(buf: &mut String, c: char, mods: KeyModifiers) -> Result<(), Error> { - // FIXME: provide an option to enable this, because it is super annoying - // in vim when accidentally pressing shift-space and it emits a sequence - // that undoes some number of commands - if false { - write!(buf, "\x1b[{};{}u", c as u32, 1 + encode_modifiers(mods))?; - } - Ok(()) - } - - /// characters that when masked for CTRL could be an ascii control character - /// or could be a key that a user legitimately wants to process in their - /// terminal application - fn is_ambiguous_ascii_ctrl(c: char) -> bool { - match c { - 'i' | 'I' | 'm' | 'M' | '[' | '{' | '@' => true, - _ => false, - } - } - let to_send = match key { Char(c) if is_ambiguous_ascii_ctrl(c) && mods.contains(KeyModifiers::CTRL) => { csi_u_encode(&mut buf, c, mods)?; diff --git a/window/src/bitmaps/mod.rs b/window/src/bitmaps/mod.rs index e75631137..6dd623a36 100644 --- a/window/src/bitmaps/mod.rs +++ b/window/src/bitmaps/mod.rs @@ -67,7 +67,7 @@ impl Texture2d for SrgbTexture2d { // glium to use SRGB for the texture. fn conv(v: u8) -> u8 { let f = (v as f32) / 255.; - let c = if f <= 0.0031308 { + let c = if f <= 0.003_130_8 { f * 12.92 } else { f.powf(1.0 / 2.4) * 1.055 - 0.055 @@ -121,6 +121,9 @@ mod avx { size == align_lo(size, align) } + /// # Safety + /// It is up to the caller to ensure that the destination pointer, + /// stride, width and height all result in valid memory operations. #[allow(clippy::cast_ptr_alignment)] pub unsafe fn fill_pixel( mut dest: *mut u8, diff --git a/window/src/os/x11/connection.rs b/window/src/os/x11/connection.rs index b528b88d3..8b69d3fec 100644 --- a/window/src/os/x11/connection.rs +++ b/window/src/os/x11/connection.rs @@ -408,13 +408,7 @@ impl Connection { .allowed_depths() .filter(|depth| depth.depth() == 24) .flat_map(|depth| depth.visuals()) - .filter_map(|vis| { - if vis.class() == xcb::xproto::VISUAL_CLASS_TRUE_COLOR as _ { - Some(vis.clone()) - } else { - None - } - }) + .filter(|vis| vis.class() == xcb::xproto::VISUAL_CLASS_TRUE_COLOR as _) .nth(0) .ok_or_else(|| failure::err_msg("did not find 24-bit visual"))?; eprintln!( diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs index 073ebaea2..6a7aca321 100644 --- a/window/src/os/x11/window.rs +++ b/window/src/os/x11/window.rs @@ -353,7 +353,7 @@ impl WindowInner { Ok(()) } - #[allow(dead_code)] + #[allow(dead_code, clippy::identity_op)] fn disable_decorations(&mut self) -> Fallible<()> { // Set the motif hints to disable decorations. // See https://stackoverflow.com/a/1909708 diff --git a/window/src/spawn.rs b/window/src/spawn.rs index 0f2ee6853..dde5f92de 100644 --- a/window/src/spawn.rs +++ b/window/src/spawn.rs @@ -65,14 +65,8 @@ impl SpawnQueue { } fn has_any_queued(&self) -> bool { - let len = self.spawned_funcs.lock().unwrap().len(); - let low_len = self.spawned_funcs_low_pri.lock().unwrap().len(); - if len + low_len > 0 { - // eprintln!("{} + {} queued spawns", len, low_len); - true - } else { - false - } + !self.spawned_funcs.lock().unwrap().is_empty() + || !self.spawned_funcs_low_pri.lock().unwrap().is_empty() } }