| 1 | pub use tiny_skia::Color; |
| 2 | use tiny_skia::{Paint, Shader}; |
| 3 | |
| 4 | // https://gitlab.gnome.org/GNOME/gtk/-/blob/1bf88f1d81043fd99740e2f91e56ade7ede7303b/gtk/gtkwindow.c#L165 |
| 5 | pub(crate) const RESIZE_HANDLE_SIZE: u32 = 12; |
| 6 | // https://gitlab.gnome.org/GNOME/gtk/-/blob/1bf88f1d81043fd99740e2f91e56ade7ede7303b/gtk/gtkwindow.c#L166 |
| 7 | pub(crate) const RESIZE_HANDLE_CORNER_SIZE: u32 = 24; |
| 8 | pub(crate) const BORDER_SIZE: u32 = crate::shadow::SHADOW_SIZE + VISIBLE_BORDER_SIZE; |
| 9 | pub(crate) const HEADER_SIZE: u32 = 35; |
| 10 | pub(crate) const CORNER_RADIUS: u32 = 10; |
| 11 | pub(crate) const VISIBLE_BORDER_SIZE: u32 = 1; |
| 12 | |
| 13 | /// The color theme to use with the decorations frame. |
| 14 | #[derive (Debug, Clone)] |
| 15 | pub struct ColorTheme { |
| 16 | pub active: ColorMap, |
| 17 | pub inactive: ColorMap, |
| 18 | } |
| 19 | |
| 20 | impl ColorTheme { |
| 21 | /// Automatically choose between light & dark themes based on: |
| 22 | /// * dbus org.freedesktop.portal.Settings |
| 23 | /// <https://flatpak.github.io/xdg-desktop-portal/#gdbus-interface-org-freedesktop-portal-Settings> |
| 24 | pub fn auto() -> Self { |
| 25 | match crate::config::prefer_dark() { |
| 26 | true => Self::dark(), |
| 27 | false => Self::light(), |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | /// Predefined light variant, which aims to replecate Adwaita theme. |
| 32 | pub fn light() -> Self { |
| 33 | Self { |
| 34 | active: ColorMap { |
| 35 | headerbar: Color::from_rgba8(235, 235, 235, 255), |
| 36 | button_idle: Color::from_rgba8(216, 216, 216, 255), |
| 37 | button_hover: Color::from_rgba8(207, 207, 207, 255), |
| 38 | button_icon: Color::from_rgba8(42, 42, 42, 255), |
| 39 | border_color: Color::from_rgba8(220, 220, 220, 255), |
| 40 | font_color: Color::from_rgba8(47, 47, 47, 255), |
| 41 | }, |
| 42 | inactive: ColorMap { |
| 43 | headerbar: Color::from_rgba8(250, 250, 250, 255), |
| 44 | button_idle: Color::from_rgba8(240, 240, 240, 255), |
| 45 | button_hover: Color::from_rgba8(216, 216, 216, 255), |
| 46 | button_icon: Color::from_rgba8(148, 148, 148, 255), |
| 47 | border_color: Color::from_rgba8(220, 220, 220, 255), |
| 48 | font_color: Color::from_rgba8(150, 150, 150, 255), |
| 49 | }, |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /// Predefined dark variant, which aims to replecate Adwaita-dark theme. |
| 54 | pub fn dark() -> Self { |
| 55 | Self { |
| 56 | active: ColorMap { |
| 57 | headerbar: Color::from_rgba8(48, 48, 48, 255), |
| 58 | button_idle: Color::from_rgba8(69, 69, 69, 255), |
| 59 | button_hover: Color::from_rgba8(79, 79, 79, 255), |
| 60 | button_icon: Color::from_rgba8(255, 255, 255, 255), |
| 61 | border_color: Color::from_rgba8(58, 58, 58, 255), |
| 62 | font_color: Color::from_rgba8(255, 255, 255, 255), |
| 63 | }, |
| 64 | inactive: ColorMap { |
| 65 | headerbar: Color::from_rgba8(36, 36, 36, 255), |
| 66 | button_idle: Color::from_rgba8(47, 47, 47, 255), |
| 67 | button_hover: Color::from_rgba8(57, 57, 57, 255), |
| 68 | button_icon: Color::from_rgba8(144, 144, 144, 255), |
| 69 | border_color: Color::from_rgba8(58, 58, 58, 255), |
| 70 | font_color: Color::from_rgba8(144, 144, 144, 255), |
| 71 | }, |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | pub(crate) fn for_state(&self, active: bool) -> &ColorMap { |
| 76 | if active { |
| 77 | &self.active |
| 78 | } else { |
| 79 | &self.inactive |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl Default for ColorTheme { |
| 85 | fn default() -> Self { |
| 86 | Self::auto() |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /// The color map for various decorcation parts. |
| 91 | #[derive (Debug, Clone)] |
| 92 | pub struct ColorMap { |
| 93 | pub headerbar: Color, |
| 94 | pub button_idle: Color, |
| 95 | pub button_hover: Color, |
| 96 | pub button_icon: Color, |
| 97 | pub border_color: Color, |
| 98 | pub font_color: Color, |
| 99 | } |
| 100 | |
| 101 | impl ColorMap { |
| 102 | pub(crate) fn headerbar_paint(&self) -> Paint { |
| 103 | Paint { |
| 104 | shader: Shader::SolidColor(self.headerbar), |
| 105 | anti_alias: true, |
| 106 | ..Default::default() |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | pub(crate) fn button_idle_paint(&self) -> Paint { |
| 111 | Paint { |
| 112 | shader: Shader::SolidColor(self.button_idle), |
| 113 | anti_alias: true, |
| 114 | ..Default::default() |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | pub(crate) fn button_hover_paint(&self) -> Paint { |
| 119 | Paint { |
| 120 | shader: Shader::SolidColor(self.button_hover), |
| 121 | anti_alias: true, |
| 122 | ..Default::default() |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | pub(crate) fn button_icon_paint(&self) -> Paint { |
| 127 | Paint { |
| 128 | shader: Shader::SolidColor(self.button_icon), |
| 129 | ..Default::default() |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | pub(crate) fn border_paint(&self) -> Paint { |
| 134 | Paint { |
| 135 | shader: Shader::SolidColor(self.border_color), |
| 136 | ..Default::default() |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |