summaryrefslogtreecommitdiff
path: root/src/tags.rs
blob: d22853db1206bfed5330c1b8f4803740c25d3268 (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
use crate::text::{Attributes, ComputedText};
use cairo::Context;
use pango::FontDescription;
use pangocairo::{cairo, pango};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TagState {
    Urgent,
    Focused,
    Active,
    Inactive,
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct TagsInfo {
    pub focused: u32,
    pub urgent: u32,
    pub active: u32,
}

impl TagsInfo {
    pub fn get_state(self, tag: usize) -> TagState {
        if self.urgent >> tag & 1 == 1 {
            TagState::Urgent
        } else if self.focused >> tag & 1 == 1 {
            TagState::Focused
        } else if self.active >> tag & 1 == 1 {
            TagState::Active
        } else {
            TagState::Inactive
        }
    }
}

pub fn compute_tag_label(label: &str, font: &FontDescription, context: &Context) -> ComputedText {
    ComputedText::new(
        label,
        Attributes {
            font,
            padding_left: 25.0,
            padding_right: 25.0,
            min_width: None,
            align: Default::default(),
            markup: false,
        },
        context,
    )
}