diff options
| author | Ayose <ayosec@gmail.com> | 2024-07-29 00:00:00 +0000 |
|---|---|---|
| committer | Ayose <ayosec@gmail.com> | 2024-07-29 00:00:00 +0000 |
| commit | 23c1b2fbcfdc84df806163ea26c5284e598cba2b (patch) | |
| tree | 9cb0c2c362105007efc6866bf1100f3e72831f94 /alacritty/src | |
| parent | 6c4910fd20c7bab08b3bcee00eed4b5e4b37ef08 (diff) | |
| parent | d021a7b6f871f4078073848cf8744881561eb254 (diff) | |
| download | r-alacritty-23c1b2fbcfdc84df806163ea26c5284e598cba2b.tar.gz r-alacritty-23c1b2fbcfdc84df806163ea26c5284e598cba2b.tar.bz2 r-alacritty-23c1b2fbcfdc84df806163ea26c5284e598cba2b.zip | |
Merge remote-tracking branch 'vendor/master' into graphics
Diffstat (limited to 'alacritty/src')
| -rw-r--r-- | alacritty/src/cli.rs | 6 | ||||
| -rw-r--r-- | alacritty/src/clipboard.rs | 4 | ||||
| -rw-r--r-- | alacritty/src/config/bindings.rs | 11 | ||||
| -rw-r--r-- | alacritty/src/config/mod.rs | 43 | ||||
| -rw-r--r-- | alacritty/src/config/monitor.rs | 37 | ||||
| -rw-r--r-- | alacritty/src/config/ui_config.rs | 2 | ||||
| -rw-r--r-- | alacritty/src/daemon.rs | 2 | ||||
| -rw-r--r-- | alacritty/src/display/hint.rs | 2 | ||||
| -rw-r--r-- | alacritty/src/display/mod.rs | 4 | ||||
| -rw-r--r-- | alacritty/src/display/window.rs | 22 | ||||
| -rw-r--r-- | alacritty/src/event.rs | 37 | ||||
| -rw-r--r-- | alacritty/src/input/keyboard.rs | 6 | ||||
| -rw-r--r-- | alacritty/src/input/mod.rs | 43 | ||||
| -rw-r--r-- | alacritty/src/ipc.rs | 2 | ||||
| -rw-r--r-- | alacritty/src/logging.rs | 4 | ||||
| -rw-r--r-- | alacritty/src/main.rs | 23 | ||||
| -rw-r--r-- | alacritty/src/migrate.rs | 5 | ||||
| -rw-r--r-- | alacritty/src/renderer/mod.rs | 8 | ||||
| -rw-r--r-- | alacritty/src/renderer/platform.rs | 2 | ||||
| -rw-r--r-- | alacritty/src/renderer/shader.rs | 6 | ||||
| -rw-r--r-- | alacritty/src/renderer/text/glyph_cache.rs | 13 | ||||
| -rw-r--r-- | alacritty/src/string.rs | 1 | ||||
| -rw-r--r-- | alacritty/src/window_context.rs | 4 |
23 files changed, 172 insertions, 115 deletions
diff --git a/alacritty/src/cli.rs b/alacritty/src/cli.rs index e7f2d3ef..f0c9be7e 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); } } } @@ -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/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/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(<V::Error as Error>::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 4ae3b67d..f8fccb13 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -44,9 +44,6 @@ pub type Result<T> = std::result::Result<T, Error>; /// 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,14 +75,13 @@ 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) + 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}"), } } } @@ -99,11 +94,7 @@ impl From<env::VarError> for Error { impl From<io::Error> 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<UiConfig> { 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) @@ -210,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)) } @@ -242,9 +237,14 @@ pub fn deserialize_config(path: &Path, warn_pruned: bool) -> Result<Value> { } /// Load all referenced configuration files. -fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit: usize) -> Value { +fn load_imports( + config: &Value, + base_path: &Path, + config_paths: &mut Vec<PathBuf>, + 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}"); @@ -283,6 +283,7 @@ fn load_imports(config: &Value, config_paths: &mut Vec<PathBuf>, recursion_limit /// Get all import paths for a configuration. pub fn imports( config: &Value, + base_path: &Path, recursion_limit: usize, ) -> StdResult<Vec<StdResult<PathBuf, String>>, String> { let imports = match config.get("import") { @@ -312,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/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<Result<NotifyEvent, NotifyError>>, + watched_hash: Option<u64>, } 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<u64> { + // 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/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/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/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/display/mod.rs b/alacritty/src/display/mod.rs index 1e7534d0..25c004a9 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}; @@ -1266,7 +1266,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:<num_cols$}"); let point = Point::new(self.size_info.screen_lines(), Column(0)); diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 09793fa0..2bb59b2c 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, @@ -76,7 +76,7 @@ impl std::error::Error for Error { impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> 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), } } @@ -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 9505e1a3..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}; @@ -17,13 +18,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}; @@ -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<ConfigMonitor>, + clipboard: Clipboard, scheduler: Scheduler, initial_window_options: Option<WindowOptions>, @@ -99,7 +102,17 @@ 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()) }; + + // 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, @@ -113,6 +126,7 @@ impl Processor { windows: Default::default(), #[cfg(unix)] global_ipc_options: Default::default(), + config_monitor, } } @@ -142,7 +156,7 @@ impl Processor { ) -> Result<(), Box<dyn Error>> { 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); @@ -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<Event>) -> Result<(), Box<dyn Error>> { - let result = event_loop.run_app(&mut self); + pub fn run(&mut self, event_loop: EventLoop<Event>) -> Result<(), Box<dyn Error>> { + 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<Event> 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()); } @@ -1439,7 +1464,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 b4c35741..4bc3ffee 100644 --- a/alacritty/src/input/keyboard.rs +++ b/alacritty/src/input/keyboard.rs @@ -230,7 +230,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { _ 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(), @@ -294,7 +294,7 @@ fn build_sequence(key: KeyEvent, mods: ModifiersState, mode: TermMode) -> Vec<u8 _ => 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() { @@ -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)) diff --git a/alacritty/src/input/mod.rs b/alacritty/src/input/mod.rs index 095e8737..c10777f2 100644 --- a/alacritty/src/input/mod.rs +++ b/alacritty/src/input/mod.rs @@ -809,7 +809,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { 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()); } } @@ -1004,17 +1004,18 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> { 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) { @@ -1326,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, @@ -1342,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, @@ -1358,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, @@ -1374,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, @@ -1390,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, @@ -1406,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, @@ -1422,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, @@ -1438,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, 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<PathBuf>) -> IoResult<UnixStream> { 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/main.rs b/alacritty/src/main.rs index 2951c224..da50c3e4 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<dyn Error>> { #[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" @@ -169,16 +172,6 @@ fn alacritty(mut options: Options) -> Result<(), Box<dyn Error>> { #[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 { @@ -196,7 +189,7 @@ fn alacritty(mut options: Options) -> Result<(), Box<dyn Error>> { }; // 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); @@ -216,7 +209,7 @@ fn alacritty(mut options: Options) -> Result<(), Box<dyn Error>> { // 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(); } 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}")), }; diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 165e28ec..a1ffb311 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -69,10 +69,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}") }, } } @@ -115,9 +115,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/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/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:?}"), } } } 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<L: ?Sized>( - &mut self, - glyph_key: GlyphKey, - loader: &mut L, - show_missing: bool, - ) -> Glyph + pub fn get<L>(&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<L: ?Sized>(&self, loader: &mut L, mut glyph: RasterizedGlyph) -> Glyph + pub fn load_glyph<L>(&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); 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, 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<UiConfig>, options: WindowOptions, ) -> Result<Self, Box<dyn Error>> { - 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); |