Skip to content

Commit

Permalink
Remove winit dependency from alacritty_config
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Aug 17, 2023
1 parent 6143b3f commit 3330614
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 29 additions & 2 deletions alacritty/src/config/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion alacritty/src/display/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion alacritty/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion alacritty/src/window_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions alacritty_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 0 additions & 3 deletions alacritty_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down

0 comments on commit 3330614

Please sign in to comment.