1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 03:39:16 +03:00

integrated-title-bar: Add libadwaita styled buttons

This commit is contained in:
YuraIz 2022-11-08 22:45:25 +03:00 committed by Wez Furlong
parent 2cd325fecd
commit 0401dc26d6
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
2 changed files with 131 additions and 2 deletions

View File

@ -534,11 +534,12 @@ fn default_active_tab() -> TabBarColor {
}
// Colors for window buttons
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "linux")))]
fn default_window_button_color() -> TabBarColor {
default_inactive_tab()
}
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "linux")))]
fn default_window_button_hover_color() -> TabBarColor {
default_inactive_tab_hover()
}
@ -596,6 +597,25 @@ fn default_window_close_hover_color() -> TabBarColor {
}
}
// Linux dependend colors for window buttons
#[cfg(target_os = "linux")]
fn default_window_button_color() -> TabBarColor {
TabBarColor {
bg_color: (0x45, 0x45, 0x45).into(),
fg_color: (0xFF, 0xFF, 0xFF).into(),
..TabBarColor::default()
}
}
#[cfg(target_os = "linux")]
fn default_window_button_hover_color() -> TabBarColor {
TabBarColor {
bg_color: (0x4F, 0x4F, 0x4F).into(),
fg_color: (0xFF, 0xFF, 0xFF).into(),
..TabBarColor::default()
}
}
#[derive(Debug, Clone, FromDynamic, ToDynamic)]
pub struct TabBarStyle {
#[dynamic(default = "default_new_tab")]

View File

@ -242,6 +242,60 @@ mod window_buttons {
}
}
}
pub(super) mod gnome {
use super::*;
pub const CLOSE: &[Poly] = &[Poly {
path: &[
PolyCommand::LineTo(BlockCoord::One, BlockCoord::One),
PolyCommand::MoveTo(BlockCoord::One, BlockCoord::Zero),
PolyCommand::LineTo(BlockCoord::Zero, BlockCoord::One),
],
intensity: BlockAlpha::Full,
style: PolyStyle::Outline,
}];
pub const HIDE: &[Poly] = &[Poly {
path: &[
PolyCommand::MoveTo(BlockCoord::Zero, BlockCoord::Frac(15, 16)),
PolyCommand::LineTo(BlockCoord::One, BlockCoord::Frac(15, 16)),
],
intensity: BlockAlpha::Full,
style: PolyStyle::Outline,
}];
pub const MAXIMIZE: &[Poly] = &[Poly {
path: &[
PolyCommand::LineTo(BlockCoord::Frac(1, 16), BlockCoord::Frac(15, 16)),
PolyCommand::LineTo(BlockCoord::Frac(15, 16), BlockCoord::Frac(15, 16)),
PolyCommand::LineTo(BlockCoord::Frac(15, 16), BlockCoord::Frac(1, 16)),
PolyCommand::LineTo(BlockCoord::Frac(1, 16), BlockCoord::Frac(1, 16)),
],
intensity: BlockAlpha::Full,
style: PolyStyle::Outline,
}];
pub const RESTORE: &[Poly] = &[Poly {
path: &[
PolyCommand::MoveTo(BlockCoord::Frac(3, 16), BlockCoord::Frac(3, 16)),
PolyCommand::LineTo(BlockCoord::Frac(3, 16), BlockCoord::Frac(13, 16)),
PolyCommand::LineTo(BlockCoord::Frac(13, 16), BlockCoord::Frac(13, 16)),
PolyCommand::LineTo(BlockCoord::Frac(13, 16), BlockCoord::Frac(3, 16)),
PolyCommand::LineTo(BlockCoord::Frac(3, 16), BlockCoord::Frac(3, 16)),
],
intensity: BlockAlpha::Full,
style: PolyStyle::Outline,
}];
pub fn sized_poly(poly: &'static [Poly]) -> SizedPoly {
let size = Dimension::Pixels(8.);
SizedPoly {
poly,
width: size,
height: size,
}
}
}
}
fn window_button_element(
@ -265,6 +319,20 @@ fn window_button_element(
TabBarItem::WindowCloseButton => CLOSE,
_ => unreachable!(),
}
} else if cfg!(target_os = "linux") {
use window_buttons::gnome::{CLOSE, HIDE, MAXIMIZE, RESTORE};
match window_button {
TabBarItem::WindowHideButton => HIDE,
TabBarItem::WindowMaximizeButton => {
if is_maximized {
RESTORE
} else {
MAXIMIZE
}
}
TabBarItem::WindowCloseButton => CLOSE,
_ => unreachable!(),
}
} else {
match window_button {
TabBarItem::WindowHideButton => HIDE_BUTTON,
@ -276,6 +344,8 @@ fn window_button_element(
let poly = if cfg!(windows) {
window_buttons::windows::sized_poly(poly)
} else if cfg!(target_os = "linux") {
window_buttons::gnome::sized_poly(poly)
} else if cfg!(macos) {
SizedPoly {
poly: &[],
@ -319,6 +389,45 @@ fn window_button_element(
top: Dimension::Points(10. * scale),
bottom: Dimension::Points(10. * scale),
})
} else if cfg!(target_os = "linux") {
element
.zindex(1)
.vertical_align(VerticalAlign::Middle)
.padding(BoxDimension {
left: Dimension::Pixels(7.),
right: Dimension::Pixels(7.),
top: Dimension::Pixels(7.),
bottom: Dimension::Pixels(7.),
})
.border(BoxDimension::new(Dimension::Pixels(1.)))
.border_corners(Some(Corners {
top_left: SizedPoly {
width: Dimension::Pixels(14.),
height: Dimension::Pixels(14.),
poly: TOP_LEFT_ROUNDED_CORNER,
},
top_right: SizedPoly {
width: Dimension::Pixels(14.),
height: Dimension::Pixels(14.),
poly: TOP_RIGHT_ROUNDED_CORNER,
},
bottom_left: SizedPoly {
width: Dimension::Pixels(14.),
height: Dimension::Pixels(14.),
poly: BOTTOM_LEFT_ROUNDED_CORNER,
},
bottom_right: SizedPoly {
width: Dimension::Pixels(14.),
height: Dimension::Pixels(14.),
poly: BOTTOM_RIGHT_ROUNDED_CORNER,
},
}))
.margin(BoxDimension {
left: Dimension::Pixels(7.),
right: Dimension::Pixels(7.),
top: Dimension::Pixels(7.),
bottom: Dimension::Pixels(7.),
})
} else if cfg!(macos) {
element
.zindex(1)