aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/wayland_theme.rs
blob: 5d3bd922460712be962e304aae6e040ea459f450 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use glutin::platform::unix::{ARGBColor, Button, ButtonState, Element, Theme as WaylandTheme};

use alacritty_terminal::config::Colors;
use alacritty_terminal::term::color::Rgb;

const INACTIVE_OPACITY: u8 = 127;

#[derive(Debug, Clone)]
pub struct AlacrittyWaylandTheme {
    pub background: ARGBColor,
    pub foreground: ARGBColor,
    pub dim_foreground: ARGBColor,
    pub hovered_close_icon: ARGBColor,
    pub hovered_maximize_icon: ARGBColor,
    pub hovered_minimize_icon: ARGBColor,
}

impl AlacrittyWaylandTheme {
    pub fn new(colors: &Colors) -> Self {
        let hovered_close_icon = colors.normal.red.into_rgba();
        let hovered_maximize_icon = colors.normal.green.into_rgba();
        let hovered_minimize_icon = colors.normal.yellow.into_rgba();
        let foreground = colors.search_bar_foreground().into_rgba();
        let background = colors.search_bar_background().into_rgba();

        let mut dim_foreground = foreground;
        dim_foreground.a = INACTIVE_OPACITY;

        Self {
            foreground,
            background,
            dim_foreground,
            hovered_close_icon,
            hovered_minimize_icon,
            hovered_maximize_icon,
        }
    }
}

impl WaylandTheme for AlacrittyWaylandTheme {
    fn element_color(&self, element: Element, window_active: bool) -> ARGBColor {
        match element {
            Element::Bar | Element::Separator => self.background,
            Element::Text if window_active => self.foreground,
            Element::Text => self.dim_foreground,
        }
    }

    fn button_color(
        &self,
        button: Button,
        state: ButtonState,
        foreground: bool,
        window_active: bool,
    ) -> ARGBColor {
        if !foreground {
            return ARGBColor { a: 0, r: 0, g: 0, b: 0 };
        } else if !window_active {
            return self.dim_foreground;
        }

        match (state, button) {
            (ButtonState::Idle, _) => self.foreground,
            (ButtonState::Disabled, _) => self.dim_foreground,
            (_, Button::Minimize) => self.hovered_minimize_icon,
            (_, Button::Maximize) => self.hovered_maximize_icon,
            (_, Button::Close) => self.hovered_close_icon,
        }
    }
}

trait IntoARGBColor {
    fn into_rgba(self) -> ARGBColor;
}

impl IntoARGBColor for Rgb {
    fn into_rgba(self) -> ARGBColor {
        ARGBColor { a: 0xff, r: self.r, g: self.g, b: self.b }
    }
}