From 38fed9a7c233e11e5f62433298235281fc3de885 Mon Sep 17 00:00:00 2001 From: EBADBEEF Date: Thu, 16 May 2024 14:15:20 -0700 Subject: Fix mouse mode bindings with multiple actions The following config was broken: ``` [mouse] bindings = [ { mouse = "Right", mods = "Shift", action = "Copy" }, { mouse = "Right", mods = "Shift", action = "ClearSelection" }, ] ``` Only the first action was applied. Change to allow more than one exact match in mouse mode with shift held, but keep the logic to not allow fallback search if any exact match was found. Regression was introduced in 1a143d11. --- alacritty/src/input/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs index 095e8737..4900e26f 100644 --- a/alacritty/src/input/mod.rs +++ b/alacritty/src/input/mod.rs @@ -1004,17 +1004,18 @@ impl> Processor { let mouse_bindings = self.ctx.config().mouse_bindings().to_owned(); // If mouse mode is active, also look for bindings without shift. - let mut check_fallback = mouse_mode && mods.contains(ModifiersState::SHIFT); + let fallback_allowed = mouse_mode && mods.contains(ModifiersState::SHIFT); + let mut exact_match_found = false; for binding in &mouse_bindings { // Don't trigger normal bindings in mouse mode unless Shift is pressed. - if binding.is_triggered_by(mode, mods, &button) && (check_fallback || !mouse_mode) { + if binding.is_triggered_by(mode, mods, &button) && (fallback_allowed || !mouse_mode) { binding.action.execute(&mut self.ctx); - check_fallback = false; + exact_match_found = true; } } - if check_fallback { + if fallback_allowed && !exact_match_found { let fallback_mods = mods & !ModifiersState::SHIFT; for binding in &mouse_bindings { if binding.is_triggered_by(mode, fallback_mods, &button) { -- cgit From 8dc27cebce277392bda3ef27671750990e1bde4f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 23 May 2024 16:16:34 +0200 Subject: Fix error with missing imports This fixes a regression, likely introduced in 5d173f6df, which changed the severity of missing imports from `info` back to `error`. The cause of this issue was a more complicated error handling mechanism, which explicitly translated IO errors to a separate enum variant without accounting for it in all scenarios. While retrospectively this seems completely unnecessary to me, it did mean shorter error messages in case the main config file was not found. To preserve the benefits of both approaches, explicit handling for the `NotFound` IO error has been added when loading the main configuration file. --- alacritty/src/config/mod.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index 4ae3b67d..f043d73b 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -44,9 +44,6 @@ pub type Result = std::result::Result; /// Errors occurring during config loading. #[derive(Debug)] pub enum Error { - /// Config file not found. - NotFound, - /// Couldn't read $HOME environment variable. ReadingEnvHome(env::VarError), @@ -66,7 +63,6 @@ pub enum Error { impl std::error::Error for Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Error::NotFound => None, Error::ReadingEnvHome(err) => err.source(), Error::Io(err) => err.source(), Error::Toml(err) => err.source(), @@ -79,7 +75,6 @@ impl std::error::Error for Error { impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - Error::NotFound => write!(f, "Unable to locate config file"), Error::ReadingEnvHome(err) => { write!(f, "Unable to read $HOME environment variable: {}", err) }, @@ -99,11 +94,7 @@ impl From for Error { impl From for Error { fn from(val: io::Error) -> Self { - if val.kind() == io::ErrorKind::NotFound { - Error::NotFound - } else { - Error::Io(val) - } + Error::Io(val) } } @@ -179,6 +170,10 @@ fn after_loading(config: &mut UiConfig, options: &mut Options) { fn load_from(path: &Path) -> Result { match read_config(path) { Ok(config) => Ok(config), + Err(Error::Io(io)) if io.kind() == io::ErrorKind::NotFound => { + error!(target: LOG_TARGET_CONFIG, "Unable to load config {:?}: File not found", path); + Err(Error::Io(io)) + }, Err(err) => { error!(target: LOG_TARGET_CONFIG, "Unable to load config {:?}: {}", path, err); Err(err) -- cgit From a89d4f50dc6ac0256d6d52371c3711107de8c7d2 Mon Sep 17 00:00:00 2001 From: jadedpasta <86900272+jadedpasta@users.noreply.github.com> Date: Thu, 23 May 2024 13:36:14 -0500 Subject: Fix Kitty protocol reporting shifted keycodes The [kitty keyboard protocol][1] explicitly requires that the *un-shifted* version of the pressed key is used to report the primary code point in `CSI code-point;modifiers u` sequences. > Note that the codepoint used is always the lower-case (or more > technically, un-shifted) version of the key. If the user presses, for > example, ctrl+shift+a the escape code would be CSI 97;modifiers u. It > must not be CSI 65; modifiers u. Alacritty's current behavior is to report the shifted version when shift is pressed, and the un-shifted version otherwise: ```console # Note that you'll have to kill Alacritty after running this to get # control back! $ echo -ne '\x1b[>1u'; cat ^[[97;5u^[[65;6u ``` The above was generated by pressing `CTRL`+`a` followed by `CTRL`+`SHIFT`+`a` after running the command. Here `97` and `65` are the codepoints for `a` and `A` respectively. This change makes Alacritty match the protocol (and Kitty's) behavior. With this change applied, `97` is reported for both `CTRL`+`a` and `CTRL`+`SHIFT`+`a`. [1]: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#key-codes --- alacritty/src/input/keyboard.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'alacritty/src') diff --git a/alacritty/src/input/keyboard.rs b/alacritty/src/input/keyboard.rs index b4c35741..fce5efbf 100644 --- a/alacritty/src/input/keyboard.rs +++ b/alacritty/src/input/keyboard.rs @@ -373,7 +373,7 @@ impl SequenceBuilder { { format!("{unicode_key_code}:{alternate_key_code}") } else { - alternate_key_code.to_string() + unicode_key_code.to_string() }; Some(SequenceBase::new(payload.into(), SequenceTerminator::Kitty)) -- cgit From cacdb5bb3b72bad2c729227537979d95af75978f Mon Sep 17 00:00:00 2001 From: Josh Soref <2119212+jsoref@users.noreply.github.com> Date: Fri, 24 May 2024 13:32:11 -0400 Subject: Fix spelling errors --- alacritty/src/config/ui_config.rs | 2 +- alacritty/src/event.rs | 4 ++-- alacritty/src/input/keyboard.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index 580a3dad..a40dcaf8 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -499,7 +499,7 @@ impl<'de> Deserialize<'de> for HintContent { // Require at least one of hyperlinks or regex trigger hint matches. if content.regex.is_none() && !content.hyperlinks { return Err(M::Error::custom( - "Config error: At least on of the hint's regex or hint's hyperlinks must \ + "Config error: At least one of the hint's regex or hint's hyperlinks must \ be set", )); } diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 9505e1a3..b9bf3030 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -142,7 +142,7 @@ impl Processor { ) -> Result<(), Box> { let window = self.windows.iter().next().as_ref().unwrap().1; - // Overide config with CLI/IPC options. + // Override config with CLI/IPC options. let mut config_overrides = options.config_overrides(); #[cfg(unix)] config_overrides.extend_from_slice(&self.global_ipc_options); @@ -1439,7 +1439,7 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> { self.scheduler.unschedule(TimerId::new(Topic::BlinkCursor, window_id)); self.scheduler.unschedule(TimerId::new(Topic::BlinkTimeout, window_id)); - // Reset blinkinig timeout. + // Reset blinking timeout. *self.cursor_blink_timed_out = false; if blinking && self.terminal.is_focused { diff --git a/alacritty/src/input/keyboard.rs b/alacritty/src/input/keyboard.rs index fce5efbf..d63da9f2 100644 --- a/alacritty/src/input/keyboard.rs +++ b/alacritty/src/input/keyboard.rs @@ -230,7 +230,7 @@ impl> Processor { _ if mode.contains(TermMode::REPORT_ALL_KEYS_AS_ESC) => { build_sequence(key, mods, mode).into() }, - // Winit uses different keys for `Backspace` so we expliictly specify the + // Winit uses different keys for `Backspace` so we explicitly specify the // values, instead of using what was passed to us from it. Key::Named(NamedKey::Tab) => [b'\t'].as_slice().into(), Key::Named(NamedKey::Enter) => [b'\r'].as_slice().into(), -- cgit From 64ba0b8e915ad167b6d5cb4395da018e436385d6 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sat, 8 Jun 2024 15:28:51 +0300 Subject: Bump glutin to 0.32.0 --- alacritty/src/clipboard.rs | 4 ++-- alacritty/src/display/mod.rs | 2 +- alacritty/src/display/window.rs | 20 +++++++++++--------- alacritty/src/event.rs | 4 ++-- alacritty/src/main.rs | 9 ++++++--- alacritty/src/renderer/platform.rs | 2 +- alacritty/src/window_context.rs | 4 ++-- 7 files changed, 25 insertions(+), 20 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/clipboard.rs b/alacritty/src/clipboard.rs index bb90a13d..7853de47 100644 --- a/alacritty/src/clipboard.rs +++ b/alacritty/src/clipboard.rs @@ -1,5 +1,5 @@ use log::{debug, warn}; -use raw_window_handle::RawDisplayHandle; +use winit::raw_window_handle::RawDisplayHandle; use alacritty_terminal::term::ClipboardType; @@ -23,7 +23,7 @@ impl Clipboard { #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] RawDisplayHandle::Wayland(display) => { let (selection, clipboard) = - wayland_clipboard::create_clipboards_from_external(display.display); + wayland_clipboard::create_clipboards_from_external(display.display.as_ptr()); Self { clipboard: Box::new(clipboard), selection: Some(Box::new(selection)) } }, _ => Self::default(), diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index 4dafa80f..1841b167 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -14,10 +14,10 @@ use glutin::surface::{Surface, SwapInterval, WindowSurface}; use log::{debug, info}; use parking_lot::MutexGuard; -use raw_window_handle::RawWindowHandle; use serde::{Deserialize, Serialize}; use winit::dpi::PhysicalSize; use winit::keyboard::ModifiersState; +use winit::raw_window_handle::RawWindowHandle; use winit::window::CursorIcon; use crossfont::{Rasterize, Rasterizer, Size as FontSize}; diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 09793fa0..da5d85bc 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -26,12 +26,12 @@ use { winit::platform::macos::{OptionAsAlt, WindowAttributesExtMacOS, WindowExtMacOS}, }; -use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; use winit::dpi::{PhysicalPosition, PhysicalSize}; use winit::event_loop::ActiveEventLoop; use winit::monitor::MonitorHandle; #[cfg(windows)] use winit::platform::windows::IconExtWindows; +use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle}; use winit::window::{ CursorIcon, Fullscreen, ImePurpose, Theme, UserAttentionType, Window as WinitWindow, WindowAttributes, WindowId, @@ -190,7 +190,7 @@ impl Window { let scale_factor = window.scale_factor(); log::info!("Window scale factor: {}", scale_factor); - let is_x11 = matches!(window.raw_window_handle(), RawWindowHandle::Xlib(_)); + let is_x11 = matches!(window.window_handle().unwrap().as_raw(), RawWindowHandle::Xlib(_)); Ok(Self { requested_redraw: false, @@ -206,7 +206,7 @@ impl Window { #[inline] pub fn raw_window_handle(&self) -> RawWindowHandle { - self.window.raw_window_handle() + self.window.window_handle().unwrap().as_raw() } #[inline] @@ -444,14 +444,15 @@ impl Window { /// This prevents rendering artifacts from showing up when the window is transparent. #[cfg(target_os = "macos")] pub fn set_has_shadow(&self, has_shadows: bool) { - let raw_window = match self.raw_window_handle() { - RawWindowHandle::AppKit(handle) => handle.ns_window as id, + let ns_view = match self.raw_window_handle() { + RawWindowHandle::AppKit(handle) => handle.ns_view.as_ptr() as id, _ => return, }; let value = if has_shadows { YES } else { NO }; unsafe { - let _: id = msg_send![raw_window, setHasShadow: value]; + let ns_window: id = msg_send![ns_view, window]; + let _: id = msg_send![ns_window, setHasShadow: value]; } } @@ -487,12 +488,13 @@ impl Window { #[cfg(target_os = "macos")] fn use_srgb_color_space(window: &WinitWindow) { - let raw_window = match window.raw_window_handle() { - RawWindowHandle::AppKit(handle) => handle.ns_window as id, + let ns_view = match window.window_handle().unwrap().as_raw() { + RawWindowHandle::AppKit(handle) => handle.ns_view.as_ptr() as id, _ => return, }; unsafe { - let _: () = msg_send![raw_window, setColorSpace: NSColorSpace::sRGBColorSpace(nil)]; + let ns_window: id = msg_send![ns_view, window]; + let _: () = msg_send![ns_window, setColorSpace: NSColorSpace::sRGBColorSpace(nil)]; } } diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index b9bf3030..8da758df 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -17,13 +17,13 @@ use ahash::RandomState; use crossfont::Size as FontSize; use glutin::display::{Display as GlutinDisplay, GetGlDisplay}; use log::{debug, error, info, warn}; -use raw_window_handle::HasRawDisplayHandle; use winit::application::ApplicationHandler; use winit::event::{ ElementState, Event as WinitEvent, Ime, Modifiers, MouseButton, StartCause, Touch as TouchEvent, WindowEvent, }; use winit::event_loop::{ActiveEventLoop, ControlFlow, DeviceEvents, EventLoop, EventLoopProxy}; +use winit::raw_window_handle::HasDisplayHandle; use winit::window::WindowId; use alacritty_terminal::event::{Event as TerminalEvent, EventListener, Notify}; @@ -99,7 +99,7 @@ impl Processor { // SAFETY: Since this takes a pointer to the winit event loop, it MUST be dropped first, // which is done in `loop_exiting`. - let clipboard = unsafe { Clipboard::new(event_loop.raw_display_handle()) }; + let clipboard = unsafe { Clipboard::new(event_loop.display_handle().unwrap().as_raw()) }; Processor { initial_window_options, diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 2951c224..6219dd78 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -19,11 +19,11 @@ use std::path::PathBuf; use std::{env, fs}; use log::info; -#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] -use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle}; #[cfg(windows)] use windows_sys::Win32::System::Console::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS}; use winit::event_loop::EventLoop; +#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] +use winit::raw_window_handle::{HasDisplayHandle, RawDisplayHandle}; use alacritty_terminal::tty; @@ -137,7 +137,10 @@ fn alacritty(mut options: Options) -> Result<(), Box> { #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] info!( "Running on {}", - if matches!(window_event_loop.raw_display_handle(), RawDisplayHandle::Wayland(_)) { + if matches!( + window_event_loop.display_handle().unwrap().as_raw(), + RawDisplayHandle::Wayland(_) + ) { "Wayland" } else { "X11" diff --git a/alacritty/src/renderer/platform.rs b/alacritty/src/renderer/platform.rs index 3568bd20..87ed29c2 100644 --- a/alacritty/src/renderer/platform.rs +++ b/alacritty/src/renderer/platform.rs @@ -12,10 +12,10 @@ use glutin::prelude::*; use glutin::surface::{Surface, SurfaceAttributesBuilder, WindowSurface}; use log::{debug, LevelFilter}; -use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; use winit::dpi::PhysicalSize; #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] use winit::platform::x11; +use winit::raw_window_handle::{RawDisplayHandle, RawWindowHandle}; /// Create the GL display. pub fn create_gl_display( diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index f5fb5cc5..062f9ef0 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -14,10 +14,10 @@ use glutin::display::GetGlDisplay; #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] use glutin::platform::x11::X11GlConfigExt; use log::info; -use raw_window_handle::HasRawDisplayHandle; use serde_json as json; use winit::event::{Event as WinitEvent, Modifiers, WindowEvent}; use winit::event_loop::{ActiveEventLoop, EventLoopProxy}; +use winit::raw_window_handle::HasDisplayHandle; use winit::window::WindowId; use alacritty_terminal::event::Event as TerminalEvent; @@ -75,7 +75,7 @@ impl WindowContext { config: Rc, options: WindowOptions, ) -> Result> { - let raw_display_handle = event_loop.raw_display_handle(); + let raw_display_handle = event_loop.display_handle().unwrap().as_raw(); let mut identity = config.window.identity.clone(); options.window_identity.override_identity_config(&mut identity); -- cgit From 5e6b92db85b3ea7ffd06a7a5ae0d2d62ad5946a6 Mon Sep 17 00:00:00 2001 From: Joshua Cao Date: Tue, 2 Jul 2024 12:14:25 -0700 Subject: Support relative imports in config file Co-authored-by: Christian Duerr --- alacritty/src/config/mod.rs | 18 +++++++++++++++--- alacritty/src/migrate.rs | 5 +++-- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index f043d73b..488ef537 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -205,7 +205,7 @@ fn parse_config( let config = deserialize_config(path, false)?; // Merge config with imports. - let imports = load_imports(&config, config_paths, recursion_limit); + let imports = load_imports(&config, path, config_paths, recursion_limit); Ok(serde_utils::merge(imports, config)) } @@ -237,9 +237,14 @@ pub fn deserialize_config(path: &Path, warn_pruned: bool) -> Result { } /// Load all referenced configuration files. -fn load_imports(config: &Value, config_paths: &mut Vec, recursion_limit: usize) -> Value { +fn load_imports( + config: &Value, + base_path: &Path, + config_paths: &mut Vec, + recursion_limit: usize, +) -> Value { // Get paths for all imports. - let import_paths = match imports(config, recursion_limit) { + let import_paths = match imports(config, base_path, recursion_limit) { Ok(import_paths) => import_paths, Err(err) => { error!(target: LOG_TARGET_CONFIG, "{err}"); @@ -278,6 +283,7 @@ fn load_imports(config: &Value, config_paths: &mut Vec, recursion_limit /// Get all import paths for a configuration. pub fn imports( config: &Value, + base_path: &Path, recursion_limit: usize, ) -> StdResult>, String> { let imports = match config.get("import") { @@ -307,6 +313,12 @@ pub fn imports( path = home_dir.join(stripped); } + if path.is_relative() { + if let Some(base_path) = base_path.parent() { + path = base_path.join(path) + } + } + import_paths.push(Ok(path)); } diff --git a/alacritty/src/migrate.rs b/alacritty/src/migrate.rs index dbcfb2ae..6d116858 100644 --- a/alacritty/src/migrate.rs +++ b/alacritty/src/migrate.rs @@ -81,7 +81,7 @@ fn migrate_config( // Migrate config imports. if !options.skip_imports { - migrate_imports(options, &mut config, recursion_limit)?; + migrate_imports(options, &mut config, path, recursion_limit)?; } // Migrate deprecated field names to their new location. @@ -110,9 +110,10 @@ fn migrate_config( fn migrate_imports( options: &MigrateOptions, config: &mut Value, + base_path: &Path, recursion_limit: usize, ) -> Result<(), String> { - let imports = match config::imports(config, recursion_limit) { + let imports = match config::imports(config, base_path, recursion_limit) { Ok(imports) => imports, Err(err) => return Err(format!("import error: {err}")), }; -- cgit From b3f0f68184b0d6b6221a5955acfcc4e33c01b766 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 5 Jul 2024 12:12:15 +0200 Subject: Fix search bug with wrapline on first character This fixes an issue where an inline search in the left direction would incorrectly assume that the first cell searched would not contain the `WRAPLINE` flag, causing the second search for the match end to terminate prematurely. Fixes #8060. --- alacritty/src/renderer/text/glyph_cache.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/renderer/text/glyph_cache.rs b/alacritty/src/renderer/text/glyph_cache.rs index 957cde1a..6acc3189 100644 --- a/alacritty/src/renderer/text/glyph_cache.rs +++ b/alacritty/src/renderer/text/glyph_cache.rs @@ -187,14 +187,9 @@ impl GlyphCache { /// /// This will fail when the glyph could not be rasterized. Usually this is due to the glyph /// not being present in any font. - pub fn get( - &mut self, - glyph_key: GlyphKey, - loader: &mut L, - show_missing: bool, - ) -> Glyph + pub fn get(&mut self, glyph_key: GlyphKey, loader: &mut L, show_missing: bool) -> Glyph where - L: LoadGlyph, + L: LoadGlyph + ?Sized, { // Try to load glyph from cache. if let Some(glyph) = self.cache.get(&glyph_key) { @@ -242,9 +237,9 @@ impl GlyphCache { /// Load glyph into the atlas. /// /// This will apply all transforms defined for the glyph cache to the rasterized glyph before - pub fn load_glyph(&self, loader: &mut L, mut glyph: RasterizedGlyph) -> Glyph + pub fn load_glyph(&self, loader: &mut L, mut glyph: RasterizedGlyph) -> Glyph where - L: LoadGlyph, + L: LoadGlyph + ?Sized, { glyph.left += i32::from(self.glyph_offset.x); glyph.top += i32::from(self.glyph_offset.y); -- cgit From 3504246c3f57769ca0528fe397e866a13c49f039 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 17 Jul 2024 05:07:32 +0300 Subject: Bump MSRV to 1.74.0 --- alacritty/src/string.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'alacritty/src') diff --git a/alacritty/src/string.rs b/alacritty/src/string.rs index e41b0785..a7af4394 100644 --- a/alacritty/src/string.rs +++ b/alacritty/src/string.rs @@ -51,6 +51,7 @@ impl<'a> StrShortener<'a> { if direction == ShortenDirection::Right { return Self { + #[allow(clippy::iter_skip_zero)] chars: text.chars().skip(0), accumulated_len: 0, text_action: TextAction::Char, -- cgit From f5e02862ffdcc579264ce85f11aed96732b257ff Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Wed, 17 Jul 2024 04:47:13 +0300 Subject: Bump dependencies Update winit and clap to latest versions. --- alacritty/src/cli.rs | 4 ++-- alacritty/src/display/hint.rs | 2 +- alacritty/src/input/mod.rs | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index e7f2d3ef..803c1f8c 100644 --- a/alacritty/src/cli.rs +++ b/alacritty/src/cli.rs @@ -216,10 +216,10 @@ impl WindowIdentity { /// Override the [`WindowIdentity`]'s fields with the [`WindowOptions`]. pub fn override_identity_config(&self, identity: &mut Identity) { if let Some(title) = &self.title { - identity.title = title.clone(); + identity.title.clone_from(title); } if let Some(class) = &self.class { - identity.class = class.clone(); + identity.class.clone_from(class); } } } diff --git a/alacritty/src/display/hint.rs b/alacritty/src/display/hint.rs index f118dbe0..a01a1d03 100644 --- a/alacritty/src/display/hint.rs +++ b/alacritty/src/display/hint.rs @@ -183,7 +183,7 @@ impl HintState { /// Update the alphabet used for hint labels. pub fn update_alphabet(&mut self, alphabet: &str) { if self.alphabet != alphabet { - self.alphabet = alphabet.to_owned(); + alphabet.clone_into(&mut self.alphabet); self.keys.clear(); } } diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs index 4900e26f..9f7074f4 100644 --- a/alacritty/src/input/mod.rs +++ b/alacritty/src/input/mod.rs @@ -1327,9 +1327,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Left, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::Click, input_delay: Duration::ZERO, @@ -1343,9 +1343,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Right, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::Click, input_delay: Duration::ZERO, @@ -1359,9 +1359,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Middle, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::Click, input_delay: Duration::ZERO, @@ -1375,9 +1375,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Left, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::DoubleClick, input_delay: Duration::ZERO, @@ -1391,9 +1391,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Left, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::Click, input_delay: CLICK_THRESHOLD, @@ -1407,9 +1407,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Left, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::TripleClick, input_delay: Duration::ZERO, @@ -1423,9 +1423,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Left, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::Click, input_delay: CLICK_THRESHOLD, @@ -1439,9 +1439,9 @@ mod tests { event: WindowEvent::MouseInput { state: ElementState::Pressed, button: MouseButton::Right, - device_id: unsafe { DeviceId::dummy() }, + device_id: DeviceId::dummy(), }, - window_id: unsafe { WindowId::dummy() }, + window_id: WindowId::dummy(), }, end_state: ClickState::Click, input_delay: Duration::ZERO, -- cgit From 6bd1674bd80e73df0d41e4342ad4e34bb7d04f84 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 21 Jul 2024 10:49:47 +0200 Subject: Restart config monitor on import change This patch checks the hash of the import paths on every config change and restarts the config monitor whenever the current monitor's hash diverges from the updated config's list of imports. Closes #7981. --- alacritty/src/config/monitor.rs | 37 ++++++++++++++++++++++++++++++++++++- alacritty/src/event.rs | 29 +++++++++++++++++++++++++++-- alacritty/src/main.rs | 14 ++------------ 3 files changed, 65 insertions(+), 15 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/monitor.rs b/alacritty/src/config/monitor.rs index 53cff1c9..3f73f120 100644 --- a/alacritty/src/config/monitor.rs +++ b/alacritty/src/config/monitor.rs @@ -1,3 +1,5 @@ +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; use std::path::PathBuf; use std::sync::mpsc::{self, RecvTimeoutError, Sender}; use std::thread::JoinHandle; @@ -23,6 +25,7 @@ const FALLBACK_POLLING_TIMEOUT: Duration = Duration::from_secs(1); pub struct ConfigMonitor { thread: JoinHandle<()>, shutdown_tx: Sender>, + watched_hash: Option, } impl ConfigMonitor { @@ -32,6 +35,9 @@ impl ConfigMonitor { return None; } + // Calculate the hash for the unmodified list of paths. + let watched_hash = Self::hash_paths(&paths); + // Exclude char devices like `/dev/null`, sockets, and so on, by checking that file type is // a regular file. paths.retain(|path| { @@ -139,7 +145,7 @@ impl ConfigMonitor { } }); - Some(Self { thread: join_handle, shutdown_tx: tx }) + Some(Self { watched_hash, thread: join_handle, shutdown_tx: tx }) } /// Synchronously shut down the monitor. @@ -154,4 +160,33 @@ impl ConfigMonitor { warn!("config monitor shutdown failed: {err:?}"); } } + + /// Check if the config monitor needs to be restarted. + /// + /// This checks the supplied list of files against the monitored files to determine if a + /// restart is necessary. + pub fn needs_restart(&self, files: &[PathBuf]) -> bool { + Self::hash_paths(files).map_or(true, |hash| Some(hash) == self.watched_hash) + } + + /// Generate the hash for a list of paths. + fn hash_paths(files: &[PathBuf]) -> Option { + // Use file count limit to avoid allocations. + const MAX_PATHS: usize = 1024; + if files.len() > MAX_PATHS { + return None; + } + + // Sort files to avoid restart on order change. + let mut sorted_files = [None; MAX_PATHS]; + for (i, file) in files.iter().enumerate() { + sorted_files[i] = Some(file); + } + sorted_files.sort_unstable(); + + // Calculate hash for the paths, regardless of order. + let mut hasher = DefaultHasher::new(); + Hash::hash_slice(&sorted_files, &mut hasher); + Some(hasher.finish()) + } } diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 8da758df..72009d88 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -1,5 +1,6 @@ //! Process window events. +use crate::ConfigMonitor; use std::borrow::Cow; use std::cmp::min; use std::collections::{HashMap, HashSet, VecDeque}; @@ -70,6 +71,8 @@ const TOUCH_ZOOM_FACTOR: f32 = 0.01; /// Stores some state from received events and dispatches actions when they are /// triggered. pub struct Processor { + pub config_monitor: Option, + clipboard: Clipboard, scheduler: Scheduler, initial_window_options: Option, @@ -101,6 +104,16 @@ impl Processor { // which is done in `loop_exiting`. let clipboard = unsafe { Clipboard::new(event_loop.display_handle().unwrap().as_raw()) }; + // Create a config monitor. + // + // The monitor watches the config file for changes and reloads it. Pending + // config changes are processed in the main loop. + let mut config_monitor = None; + if config.live_config_reload { + config_monitor = + ConfigMonitor::new(config.config_paths.clone(), event_loop.create_proxy()); + } + Processor { initial_window_options, initial_window_error: None, @@ -113,6 +126,7 @@ impl Processor { windows: Default::default(), #[cfg(unix)] global_ipc_options: Default::default(), + config_monitor, } } @@ -160,8 +174,8 @@ impl Processor { /// Run the event loop. /// /// The result is exit code generate from the loop. - pub fn run(mut self, event_loop: EventLoop) -> Result<(), Box> { - let result = event_loop.run_app(&mut self); + pub fn run(&mut self, event_loop: EventLoop) -> Result<(), Box> { + let result = event_loop.run_app(self); if let Some(initial_window_error) = self.initial_window_error.take() { Err(initial_window_error) } else { @@ -297,6 +311,17 @@ impl ApplicationHandler for Processor { if let Ok(config) = config::reload(path, &mut self.cli_options) { self.config = Rc::new(config); + // Restart config monitor if imports changed. + if let Some(monitor) = self.config_monitor.take() { + let paths = &self.config.config_paths; + self.config_monitor = if monitor.needs_restart(paths) { + monitor.shutdown(); + ConfigMonitor::new(paths.clone(), self.proxy.clone()) + } else { + Some(monitor) + }; + } + for window_context in self.windows.values_mut() { window_context.update_config(self.config.clone()); } diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 6219dd78..da50c3e4 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -172,16 +172,6 @@ fn alacritty(mut options: Options) -> Result<(), Box> { #[cfg(target_os = "macos")] locale::set_locale_environment(); - // Create a config monitor when config was loaded from path. - // - // The monitor watches the config file for changes and reloads it. Pending - // config changes are processed in the main loop. - let mut config_monitor = None; - if config.live_config_reload { - config_monitor = - ConfigMonitor::new(config.config_paths.clone(), window_event_loop.create_proxy()); - } - // Create the IPC socket listener. #[cfg(unix)] let socket_path = if config.ipc_socket { @@ -199,7 +189,7 @@ fn alacritty(mut options: Options) -> Result<(), Box> { }; // Event processor. - let processor = Processor::new(config, options, &window_event_loop); + let mut processor = Processor::new(config, options, &window_event_loop); // Start event loop and block until shutdown. let result = processor.run(window_event_loop); @@ -219,7 +209,7 @@ fn alacritty(mut options: Options) -> Result<(), Box> { // FIXME: Change PTY API to enforce the correct drop order with the typesystem. // Terminate the config monitor. - if let Some(config_monitor) = config_monitor.take() { + if let Some(config_monitor) = processor.config_monitor.take() { config_monitor.shutdown(); } -- cgit From d021a7b6f871f4078073848cf8744881561eb254 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Tue, 23 Jul 2024 18:37:35 -0700 Subject: Unify string formatting --- alacritty/src/cli.rs | 2 +- alacritty/src/config/bindings.rs | 11 ++++------- alacritty/src/config/mod.rs | 10 +++++----- alacritty/src/daemon.rs | 2 +- alacritty/src/display/mod.rs | 2 +- alacritty/src/display/window.rs | 2 +- alacritty/src/input/keyboard.rs | 2 +- alacritty/src/input/mod.rs | 2 +- alacritty/src/ipc.rs | 2 +- alacritty/src/logging.rs | 4 ++-- alacritty/src/renderer/mod.rs | 8 ++++---- alacritty/src/renderer/shader.rs | 6 +++--- 12 files changed, 25 insertions(+), 28 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index 803c1f8c..f0c9be7e 100644 --- a/alacritty/src/cli.rs +++ b/alacritty/src/cli.rs @@ -524,7 +524,7 @@ mod tests { let generated = String::from_utf8_lossy(&generated); let mut completion = String::new(); - let mut file = File::open(format!("../extra/completions/{}", file)).unwrap(); + let mut file = File::open(format!("../extra/completions/{file}")).unwrap(); file.read_to_string(&mut completion).unwrap(); assert_eq!(generated, completion); diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 62ca03a0..dfe31853 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -287,7 +287,7 @@ impl Display for Action { Action::ViMotion(motion) => motion.fmt(f), Action::Vi(action) => action.fmt(f), Action::Mouse(action) => action.fmt(f), - _ => write!(f, "{:?}", self), + _ => write!(f, "{self:?}"), } } } @@ -1024,8 +1024,7 @@ impl<'a> Deserialize<'a> for RawBinding { }, Err(_) => { return Err(::custom(format!( - "Invalid key binding, scancode is too big: {}", - scancode + "Invalid key binding, scancode is too big: {scancode}" ))); }, }, @@ -1080,8 +1079,7 @@ impl<'a> Deserialize<'a> for RawBinding { _ => return Err(err), }; return Err(V::Error::custom(format!( - "unknown keyboard action `{}`", - value + "unknown keyboard action `{value}`" ))); }, } @@ -1122,8 +1120,7 @@ impl<'a> Deserialize<'a> for RawBinding { (Some(action @ Action::Mouse(_)), None, None) => { if mouse.is_none() { return Err(V::Error::custom(format!( - "action `{}` is only available for mouse bindings", - action, + "action `{action}` is only available for mouse bindings", ))); } action diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index 488ef537..f8fccb13 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -76,12 +76,12 @@ impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Error::ReadingEnvHome(err) => { - write!(f, "Unable to read $HOME environment variable: {}", err) + write!(f, "Unable to read $HOME environment variable: {err}") }, - Error::Io(err) => write!(f, "Error reading config file: {}", err), - Error::Toml(err) => write!(f, "Config error: {}", err), - Error::TomlSe(err) => write!(f, "Yaml conversion error: {}", err), - Error::Yaml(err) => write!(f, "Config error: {}", err), + Error::Io(err) => write!(f, "Error reading config file: {err}"), + Error::Toml(err) => write!(f, "Config error: {err}"), + Error::TomlSe(err) => write!(f, "Yaml conversion error: {err}"), + Error::Yaml(err) => write!(f, "Config error: {err}"), } } } diff --git a/alacritty/src/daemon.rs b/alacritty/src/daemon.rs index df66646a..c8fb88d1 100644 --- a/alacritty/src/daemon.rs +++ b/alacritty/src/daemon.rs @@ -94,7 +94,7 @@ pub fn foreground_process_path( } #[cfg(not(any(target_os = "macos", target_os = "freebsd")))] - let link_path = format!("/proc/{}/cwd", pid); + let link_path = format!("/proc/{pid}/cwd"); #[cfg(target_os = "freebsd")] let link_path = format!("/compat/linux/proc/{}/cwd", pid); diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index 1841b167..7809c824 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -1241,7 +1241,7 @@ impl Display { fn draw_search(&mut self, config: &UiConfig, text: &str) { // Assure text length is at least num_cols. let num_cols = self.size_info.columns(); - let text = format!("{:<1$}", text, num_cols); + let text = format!("{text:) -> fmt::Result { match self { - Error::WindowCreation(err) => write!(f, "Error creating GL context; {}", err), + Error::WindowCreation(err) => write!(f, "Error creating GL context; {err}"), Error::Font(err) => err.fmt(f), } } diff --git a/alacritty/src/input/keyboard.rs b/alacritty/src/input/keyboard.rs index d63da9f2..4bc3ffee 100644 --- a/alacritty/src/input/keyboard.rs +++ b/alacritty/src/input/keyboard.rs @@ -294,7 +294,7 @@ fn build_sequence(key: KeyEvent, mods: ModifiersState, mode: TermMode) -> Vec return Vec::new(), }; - let mut payload = format!("\x1b[{}", payload); + let mut payload = format!("\x1b[{payload}"); // Add modifiers information. if kitty_event_type || !modifiers.is_empty() || associated_text.is_some() { diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs index 9f7074f4..c10777f2 100644 --- a/alacritty/src/input/mod.rs +++ b/alacritty/src/input/mod.rs @@ -809,7 +809,7 @@ impl> Processor { if self.ctx.terminal().mode().contains(TermMode::FOCUS_IN_OUT) { let chr = if is_focused { "I" } else { "O" }; - let msg = format!("\x1b[{}", chr); + let msg = format!("\x1b[{chr}"); self.ctx.write_to_pty(msg.into_bytes()); } } diff --git a/alacritty/src/ipc.rs b/alacritty/src/ipc.rs index 1cb7a1c8..d06d395e 100644 --- a/alacritty/src/ipc.rs +++ b/alacritty/src/ipc.rs @@ -111,7 +111,7 @@ fn find_socket(socket_path: Option) -> IoResult { if let Some(socket_path) = socket_path { // Ensure we inform the user about an invalid path. return UnixStream::connect(&socket_path).map_err(|err| { - let message = format!("invalid socket path {:?}", socket_path); + let message = format!("invalid socket path {socket_path:?}"); IoError::new(err.kind(), message) }); } diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index 59303649..08e79469 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -108,7 +108,7 @@ impl Logger { }; #[cfg(not(windows))] - let env_var = format!("${}", ALACRITTY_LOG_ENV); + let env_var = format!("${ALACRITTY_LOG_ENV}"); #[cfg(windows)] let env_var = format!("%{}%", ALACRITTY_LOG_ENV); @@ -227,7 +227,7 @@ impl OnDemandLogFile { writeln!(io::stdout(), "Created log file at \"{}\"", self.path.display()); }, Err(e) => { - let _ = writeln!(io::stdout(), "Unable to create log file: {}", e); + let _ = writeln!(io::stdout(), "Unable to create log file: {e}"); return Err(e); }, } diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index f4f1397f..16885b31 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -66,10 +66,10 @@ impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::Shader(err) => { - write!(f, "There was an error initializing the shaders: {}", err) + write!(f, "There was an error initializing the shaders: {err}") }, Error::Other(err) => { - write!(f, "{}", err) + write!(f, "{err}") }, } } @@ -111,9 +111,9 @@ fn gl_get_string( Ok(CStr::from_ptr(string_ptr as *const _).to_string_lossy()) }, gl::INVALID_ENUM => { - Err(format!("OpenGL error requesting {}: invalid enum", description).into()) + Err(format!("OpenGL error requesting {description}: invalid enum").into()) }, - error_id => Err(format!("OpenGL error {} requesting {}", error_id, description).into()), + error_id => Err(format!("OpenGL error {error_id} requesting {description}").into()), } } } diff --git a/alacritty/src/renderer/shader.rs b/alacritty/src/renderer/shader.rs index e3baab9e..86938e45 100644 --- a/alacritty/src/renderer/shader.rs +++ b/alacritty/src/renderer/shader.rs @@ -196,9 +196,9 @@ impl std::error::Error for ShaderError {} impl fmt::Display for ShaderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Compile(reason) => write!(f, "Failed compiling shader: {}", reason), - Self::Link(reason) => write!(f, "Failed linking shader: {}", reason), - Self::Uniform(name) => write!(f, "Failed to get uniform location of {:?}", name), + Self::Compile(reason) => write!(f, "Failed compiling shader: {reason}"), + Self::Link(reason) => write!(f, "Failed linking shader: {reason}"), + Self::Uniform(name) => write!(f, "Failed to get uniform location of {name:?}"), } } } -- cgit