mirror of
https://github.com/wez/wezterm.git
synced 2024-12-28 07:55:03 +03:00
integrated-title-bar: Add Native button style parameter
This commit is contained in:
parent
ab52277393
commit
6b2137de0b
@ -338,7 +338,6 @@ fn window_button_element(
|
||||
is_maximized: bool,
|
||||
font: &Rc<LoadedFont>,
|
||||
metrics: &RenderMetrics,
|
||||
colors: &TabBarColors,
|
||||
config: &ConfigHandle,
|
||||
) -> Element {
|
||||
use window::IntegratedTitleButtonStyle as Style;
|
||||
@ -346,8 +345,12 @@ fn window_button_element(
|
||||
|
||||
let style = config.integrated_title_button_style;
|
||||
|
||||
if style == Style::Native {
|
||||
return Element::new(font, ElementContent::Text(String::new()));
|
||||
}
|
||||
|
||||
let poly = {
|
||||
let (CLOSE, HIDE, MAXIMIZE, RESTORE) = match style {
|
||||
let (close, hide, maximize, restore) = match style {
|
||||
Style::Windows => {
|
||||
use window_buttons::windows::{CLOSE, HIDE, MAXIMIZE, RESTORE};
|
||||
(CLOSE, HIDE, MAXIMIZE, RESTORE)
|
||||
@ -356,22 +359,24 @@ fn window_button_element(
|
||||
use window_buttons::gnome::{CLOSE, HIDE, MAXIMIZE, RESTORE};
|
||||
(CLOSE, HIDE, MAXIMIZE, RESTORE)
|
||||
}
|
||||
Style::Native => unreachable!(),
|
||||
};
|
||||
let poly = match window_button {
|
||||
Button::Hide => HIDE,
|
||||
Button::Hide => hide,
|
||||
Button::Maximize => {
|
||||
if is_maximized {
|
||||
RESTORE
|
||||
restore
|
||||
} else {
|
||||
MAXIMIZE
|
||||
maximize
|
||||
}
|
||||
}
|
||||
Button::Close => CLOSE,
|
||||
Button::Close => close,
|
||||
};
|
||||
|
||||
match style {
|
||||
Style::Windows => window_buttons::windows::sized_poly(poly),
|
||||
Style::Gnome => window_buttons::gnome::sized_poly(poly),
|
||||
Style::Native => unreachable!(),
|
||||
}
|
||||
};
|
||||
|
||||
@ -442,6 +447,7 @@ fn window_button_element(
|
||||
bottom: Dimension::Pixels(7.),
|
||||
})
|
||||
}
|
||||
Style::Native => unreachable!(),
|
||||
};
|
||||
|
||||
let foreground = config.integrated_title_button_color.clone();
|
||||
@ -461,6 +467,7 @@ fn window_button_element(
|
||||
let window_button_colors_fn = match style {
|
||||
Style::Windows => window_buttons::windows::window_button_colors,
|
||||
Style::Gnome => window_buttons::gnome::window_button_colors,
|
||||
Style::Native => unreachable!(),
|
||||
};
|
||||
|
||||
let colors = window_button_colors_fn(background_lightness, foreground, window_button);
|
||||
@ -1140,7 +1147,6 @@ impl super::TermWindow {
|
||||
self.window_state.contains(window::WindowState::MAXIMIZED),
|
||||
&font,
|
||||
&metrics,
|
||||
&colors,
|
||||
&self.config,
|
||||
),
|
||||
}
|
||||
|
@ -1465,11 +1465,52 @@ pub enum IntegratedTitleButtonAlignment {
|
||||
Left,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, FromDynamic, ToDynamic, PartialEq, Eq, Clone, Copy)]
|
||||
#[derive(Debug, Default, ToDynamic, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum IntegratedTitleButtonStyle {
|
||||
#[default]
|
||||
Windows,
|
||||
Gnome,
|
||||
// macos only
|
||||
Native,
|
||||
}
|
||||
|
||||
impl FromDynamic for IntegratedTitleButtonStyle {
|
||||
fn from_dynamic(
|
||||
value: &wezterm_dynamic::Value,
|
||||
_options: wezterm_dynamic::FromDynamicOptions,
|
||||
) -> Result<Self, wezterm_dynamic::Error>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let type_name = "integrated_title_button_style";
|
||||
|
||||
if let wezterm_dynamic::Value::String(string) = value {
|
||||
let style = match string.as_str() {
|
||||
"Windows" => Self::Windows,
|
||||
"Gnome" => Self::Gnome,
|
||||
"Native" if cfg!(target_os = "macos") => Self::Native,
|
||||
_ => {
|
||||
let possible: &[&str] = if cfg!(target_os = "macos") {
|
||||
&["Windows", "Gnome", "Native"]
|
||||
} else {
|
||||
&["Windows", "Gnome"]
|
||||
};
|
||||
return Err(wezterm_dynamic::Error::InvalidVariantForType {
|
||||
variant_name: string.to_string(),
|
||||
type_name,
|
||||
possible,
|
||||
});
|
||||
}
|
||||
};
|
||||
Ok(style)
|
||||
} else {
|
||||
Err(wezterm_dynamic::Error::InvalidVariantForType {
|
||||
variant_name: value.variant_name().to_string(),
|
||||
type_name,
|
||||
possible: &["String"],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Map c to its Ctrl equivalent.
|
||||
|
Loading…
Reference in New Issue
Block a user