term_model/config/
window.rsuse std::os::raw::c_ulong;
use serde::Deserialize;
use crate::config::{
failure_default, from_string_or_deserialize, option_explicit_none, Delta, FromString,
};
use crate::index::{Column, Line};
pub const DEFAULT_NAME: &str = "Alacritty";
#[serde(default)]
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct WindowConfig {
#[serde(deserialize_with = "failure_default")]
pub dimensions: Dimensions,
#[serde(deserialize_with = "failure_default")]
pub position: Option<Delta<i32>>,
#[serde(deserialize_with = "failure_default")]
pub padding: Delta<u8>,
#[serde(deserialize_with = "failure_default")]
pub decorations: Decorations,
#[serde(deserialize_with = "failure_default")]
pub dynamic_padding: bool,
#[serde(deserialize_with = "failure_default")]
startup_mode: StartupMode,
#[serde(default = "default_title")]
pub title: String,
#[serde(deserialize_with = "from_string_or_deserialize")]
pub class: Class,
#[serde(skip)]
pub embed: Option<c_ulong>,
#[serde(deserialize_with = "option_explicit_none")]
pub gtk_theme_variant: Option<String>,
#[serde(deserialize_with = "failure_default")]
pub start_maximized: Option<bool>,
}
pub fn default_title() -> String {
DEFAULT_NAME.to_string()
}
impl WindowConfig {
pub fn startup_mode(&self) -> StartupMode {
match self.start_maximized {
Some(true) => StartupMode::Maximized,
_ => self.startup_mode,
}
}
}
impl Default for WindowConfig {
fn default() -> WindowConfig {
WindowConfig {
dimensions: Default::default(),
position: Default::default(),
padding: Default::default(),
decorations: Default::default(),
dynamic_padding: Default::default(),
startup_mode: Default::default(),
class: Default::default(),
embed: Default::default(),
gtk_theme_variant: Default::default(),
start_maximized: Default::default(),
title: default_title(),
}
}
}
#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
pub enum StartupMode {
Windowed,
Maximized,
Fullscreen,
#[cfg(target_os = "macos")]
SimpleFullscreen,
}
impl Default for StartupMode {
fn default() -> StartupMode {
StartupMode::Windowed
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize)]
pub enum Decorations {
#[serde(rename = "full")]
Full,
#[cfg(target_os = "macos")]
#[serde(rename = "transparent")]
Transparent,
#[cfg(target_os = "macos")]
#[serde(rename = "buttonless")]
Buttonless,
#[serde(rename = "none")]
None,
}
impl Default for Decorations {
fn default() -> Decorations {
Decorations::Full
}
}
#[serde(default)]
#[derive(Default, Debug, Copy, Clone, Deserialize, PartialEq, Eq)]
pub struct Dimensions {
#[serde(deserialize_with = "failure_default")]
columns: Column,
#[serde(deserialize_with = "failure_default")]
lines: Line,
}
impl Dimensions {
pub fn new(columns: Column, lines: Line) -> Self {
Dimensions { columns, lines }
}
#[inline]
pub fn lines_u32(&self) -> u32 {
self.lines.0 as u32
}
#[inline]
pub fn columns_u32(&self) -> u32 {
self.columns.0 as u32
}
}
#[serde(default)]
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Class {
pub instance: String,
pub general: String,
}
impl Default for Class {
fn default() -> Self {
Class { instance: DEFAULT_NAME.into(), general: DEFAULT_NAME.into() }
}
}
impl FromString for Class {
fn from(value: String) -> Self {
Class { instance: value, general: DEFAULT_NAME.into() }
}
}