diff options
author | Christian Duerr <contact@christianduerr.com> | 2024-01-02 14:34:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 13:34:57 +0000 |
commit | 5685ce8bf8cb919f454518f1206b7ebc52636378 (patch) | |
tree | e20dde7f70bb06ad4edc277f2faa2b25ccf8938c /alacritty | |
parent | 8f57367eadeca92706193fc40030081f40e81fbf (diff) |
Fix replacing optional fields
This fixes an issue with the default `SerdeReplace` implementation where
it would never recurse through options but always replace the entire
option with the new value.
Closes #7518.
Diffstat (limited to 'alacritty')
-rw-r--r-- | alacritty/src/config/debug.rs | 10 | ||||
-rw-r--r-- | alacritty/src/config/ui_config.rs | 10 | ||||
-rw-r--r-- | alacritty/src/config/window.rs | 28 | ||||
-rw-r--r-- | alacritty/src/display/window.rs | 2 | ||||
-rw-r--r-- | alacritty/src/window_context.rs | 2 |
5 files changed, 40 insertions, 12 deletions
diff --git a/alacritty/src/config/debug.rs b/alacritty/src/config/debug.rs index a8be77d9..15c06454 100644 --- a/alacritty/src/config/debug.rs +++ b/alacritty/src/config/debug.rs @@ -1,7 +1,5 @@ use log::LevelFilter; -use serde::Deserialize; - use alacritty_config_derive::ConfigDeserialize; /// Debugging options. @@ -47,17 +45,17 @@ impl Default for Debug { } /// The renderer configuration options. -#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(ConfigDeserialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum RendererPreference { /// OpenGL 3.3 renderer. - #[serde(rename = "glsl3")] + #[config(rename = "glsl3")] Glsl3, /// GLES 2 renderer, with optional extensions like dual source blending. - #[serde(rename = "gles2")] + #[config(rename = "gles2")] Gles2, /// Pure GLES 2 renderer. - #[serde(rename = "gles2_pure")] + #[config(rename = "gles2_pure")] Gles2Pure, } diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs index f4f67cb6..21059734 100644 --- a/alacritty/src/config/ui_config.rs +++ b/alacritty/src/config/ui_config.rs @@ -1,9 +1,11 @@ use std::cell::RefCell; use std::collections::HashMap; +use std::error::Error; use std::fmt::{self, Formatter}; use std::path::PathBuf; use std::rc::Rc; +use alacritty_config::SerdeReplace; use alacritty_terminal::term::Config as TermConfig; use alacritty_terminal::tty::{Options as PtyOptions, Shell}; use log::{error, warn}; @@ -656,6 +658,14 @@ impl From<Program> for Shell { } } +impl SerdeReplace for Program { + fn replace(&mut self, value: toml::Value) -> Result<(), Box<dyn Error>> { + *self = Self::deserialize(value)?; + + Ok(()) + } +} + pub(crate) struct StringVisitor; impl<'de> serde::de::Visitor<'de> for StringVisitor { type Value = String; diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs index 3ae4e29e..ed84622e 100644 --- a/alacritty/src/config/window.rs +++ b/alacritty/src/config/window.rs @@ -3,10 +3,10 @@ use std::fmt::{self, Formatter}; use log::{error, warn}; use serde::de::{self, MapAccess, Visitor}; use serde::{Deserialize, Deserializer, Serialize}; -use winit::window::{Fullscreen, Theme}; #[cfg(target_os = "macos")] use winit::platform::macos::OptionAsAlt as WinitOptionAsAlt; +use winit::window::{Fullscreen, Theme as WinitTheme}; use alacritty_config_derive::{ConfigDeserialize, SerdeReplace}; @@ -31,9 +31,6 @@ pub struct WindowConfig { #[config(skip)] pub embed: Option<u32>, - /// System decorations theme variant. - pub decorations_theme_variant: Option<Theme>, - /// Spread out additional padding evenly. pub dynamic_padding: bool, @@ -62,6 +59,9 @@ pub struct WindowConfig { /// Initial dimensions. dimensions: Dimensions, + + /// System decorations theme variant. + decorations_theme_variant: Option<Theme>, } impl Default for WindowConfig { @@ -149,6 +149,10 @@ impl WindowConfig { OptionAsAlt::None => WinitOptionAsAlt::None, } } + + pub fn theme(&self) -> Option<WinitTheme> { + self.decorations_theme_variant.map(WinitTheme::from) + } } #[derive(ConfigDeserialize, Debug, Clone, PartialEq, Eq)] @@ -292,3 +296,19 @@ pub enum OptionAsAlt { #[default] None, } + +/// System decorations theme variant. +#[derive(ConfigDeserialize, Debug, Clone, Copy, PartialEq, Eq)] +pub enum Theme { + Light, + Dark, +} + +impl From<Theme> for WinitTheme { + fn from(theme: Theme) -> Self { + match theme { + Theme::Light => WinitTheme::Light, + Theme::Dark => WinitTheme::Dark, + } + } +} diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index f36d05e9..e4bfa2cb 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -165,7 +165,7 @@ impl Window { let window = window_builder .with_title(&identity.title) - .with_theme(config.window.decorations_theme_variant) + .with_theme(config.window.theme()) .with_visible(false) .with_transparent(true) .with_blur(config.window.blur) diff --git a/alacritty/src/window_context.rs b/alacritty/src/window_context.rs index c87c2210..3f3e6807 100644 --- a/alacritty/src/window_context.rs +++ b/alacritty/src/window_context.rs @@ -289,7 +289,7 @@ impl WindowContext { } // Always reload the theme to account for auto-theme switching. - self.display.window.set_theme(self.config.window.decorations_theme_variant); + self.display.window.set_theme(self.config.window.theme()); // Update display if either padding options or resize increments were changed. let window_config = &old_config.window; |