From 33306142195b354ef3485ca2b1d8a85dfc6605ca Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 17 Aug 2023 10:33:29 -0700 Subject: [PATCH] Remove winit dependency from alacritty_config --- Cargo.lock | 1 - alacritty/src/config/window.rs | 31 +++++++++++++++++++++++++++++-- alacritty/src/display/window.rs | 2 +- alacritty/src/input.rs | 2 +- alacritty/src/window_context.rs | 2 +- alacritty_config/Cargo.toml | 3 --- alacritty_config/src/lib.rs | 3 --- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dd0b2a0..a7d82aca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -66,7 +66,6 @@ dependencies = [ "log", "serde", "toml 0.7.4", - "winit", ] [[package]] diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs index e4236b99..d546f686 100644 --- a/alacritty/src/config/window.rs +++ b/alacritty/src/config/window.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Deserializer, Serialize}; use winit::window::{Fullscreen, Theme}; #[cfg(target_os = "macos")] -use winit::platform::macos::OptionAsAlt; +use winit::platform::macos::OptionAsAlt as WinitOptionAsAlt; use alacritty_config_derive::{ConfigDeserialize, SerdeReplace}; use alacritty_terminal::config::{Percentage, LOG_TARGET_CONFIG}; @@ -51,7 +51,7 @@ pub struct WindowConfig { /// Controls which `Option` key should be treated as `Alt`. #[cfg(target_os = "macos")] - pub option_as_alt: OptionAsAlt, + option_as_alt: OptionAsAlt, /// Resize increments. pub resize_increments: bool, @@ -137,6 +137,16 @@ impl WindowConfig { pub fn maximized(&self) -> bool { self.startup_mode == StartupMode::Maximized } + + #[cfg(target_os = "macos")] + pub fn option_as_alt(&self) -> WinitOptionAsAlt { + match self.option_as_alt { + OptionAsAlt::OnlyLeft => WinitOptionAsAlt::OnlyLeft, + OptionAsAlt::OnlyRight => WinitOptionAsAlt::OnlyRight, + OptionAsAlt::Both => WinitOptionAsAlt::Both, + OptionAsAlt::None => WinitOptionAsAlt::None, + } + } } #[derive(ConfigDeserialize, Debug, Clone, PartialEq, Eq)] @@ -263,3 +273,20 @@ impl<'de> Deserialize<'de> for Class { deserializer.deserialize_any(ClassVisitor) } } + +#[cfg(target_os = "macos")] +#[derive(ConfigDeserialize, Default, Debug, Clone, Copy, PartialEq, Eq)] +pub enum OptionAsAlt { + /// The left `Option` key is treated as `Alt`. + OnlyLeft, + + /// The right `Option` key is treated as `Alt`. + OnlyRight, + + /// Both `Option` keys are treated as `Alt`. + Both, + + /// No special handling is applied for `Option` key. + #[default] + None, +} diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 185e7305..0cf95f7f 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -314,7 +314,7 @@ impl Window { #[cfg(target_os = "macos")] pub fn get_platform_window(_: &Identity, window_config: &WindowConfig) -> WindowBuilder { - let window = WindowBuilder::new().with_option_as_alt(window_config.option_as_alt); + let window = WindowBuilder::new().with_option_as_alt(window_config.option_as_alt()); match window_config.decorations { Decorations::Full => window, diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index dc46a316..5075729b 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -1027,7 +1027,7 @@ impl> Processor { #[cfg(target_os = "macos")] fn alt_send_esc(&mut self) -> bool { - let option_as_alt = self.ctx.config().window.option_as_alt; + let option_as_alt = self.ctx.config().window.option_as_alt(); self.ctx.modifiers().state().alt_key() && (option_as_alt == OptionAsAlt::Both || (option_as_alt == OptionAsAlt::OnlyLeft diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index 568f8c22..8935a9cc 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -337,7 +337,7 @@ impl WindowContext { self.display.window.set_has_shadow(opaque); #[cfg(target_os = "macos")] - self.display.window.set_option_as_alt(self.config.window.option_as_alt); + self.display.window.set_option_as_alt(self.config.window.option_as_alt()); // Change opacity state. self.display.window.set_transparent(!opaque); diff --git a/alacritty_config/Cargo.toml b/alacritty_config/Cargo.toml index 48e603ea..c8397d2a 100644 --- a/alacritty_config/Cargo.toml +++ b/alacritty_config/Cargo.toml @@ -12,6 +12,3 @@ rust-version = "1.65.0" log = { version = "0.4.17", features = ["serde"] } serde = "1.0.163" toml = "0.7.1" - -[target.'cfg(target_os = "macos")'.dependencies] -winit = { version = "0.29.0-beta.0", default-features = false, features = ["serde"] } diff --git a/alacritty_config/src/lib.rs b/alacritty_config/src/lib.rs index 1e5282d7..c5a43b87 100644 --- a/alacritty_config/src/lib.rs +++ b/alacritty_config/src/lib.rs @@ -32,9 +32,6 @@ impl_replace!( LevelFilter, ); -#[cfg(target_os = "macos")] -impl_replace!(winit::platform::macos::OptionAsAlt,); - fn replace_simple<'de, D>(data: &mut D, value: Value) -> Result<(), Box> where D: Deserialize<'de>,