1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Remove winit dependency from alacritty_config

This commit is contained in:
Max Brunsfeld 2023-08-17 10:33:29 -07:00 committed by GitHub
parent 6143b3f4eb
commit 3330614219
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 12 deletions

1
Cargo.lock generated
View file

@ -66,7 +66,6 @@ dependencies = [
"log",
"serde",
"toml 0.7.4",
"winit",
]
[[package]]

View file

@ -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,
}

View file

@ -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,

View file

@ -1027,7 +1027,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
#[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

View file

@ -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);

View file

@ -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"] }

View file

@ -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<dyn Error>>
where
D: Deserialize<'de>,