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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use std::ops::BitOr;
/// Interest used when creating a [stream] or a [subscription].
/// They indicate which preferences should be retrieved and monitored.
///
/// [stream]: `crate::Preferences::stream`
/// [subscription]: `crate::Preferences::subscribe`
#[derive(Debug, Default, Clone, Copy)]
pub struct Interest(u8);
macro_rules! impl_interest {
(impl $name:ident { $(#[cfg($cfg:meta)] $(#[$($meta:meta)*])* $vis:vis const $ident:ident: $ty:ty = $expr:expr;)* }) => {
#[allow(non_upper_case_globals)]
impl $name {
/// A shortcut for all available preferences.
///
/// Note that only the preferences that have their
/// corresponding feature enabled will actually be reported.
pub const All: $name = {
#[allow(unused_mut)]
let mut value = 0;
$(
#[cfg($cfg)]
{
value |= Self::$ident.0;
}
)*
$name(value)
};
$(#[cfg($cfg)] $(#[$($meta)*])* $vis const $ident: $ty = $expr;)*
}
};
}
impl_interest! {
impl Interest {
#[cfg(feature = "color-scheme")]
/// Retrieve the [`ColorScheme`](`crate::ColorScheme`) preference
/// and store it in [`Preferences::color_scheme`](`crate::Preferences::color_scheme`).
pub const ColorScheme: Interest = Interest(1 << 0);
#[cfg(feature = "contrast")]
/// Retrieve the [`Contrast`](`crate::Contrast`) preference
/// and store it in [`Preferences::contrast`](`crate::Preferences::contrast`).
pub const Contrast: Interest = Interest(1 << 1);
#[cfg(feature = "reduced-motion")]
/// Retrieve the [`ReducedMotion`](`crate::ReducedMotion`) preference
/// and store it in [`Preferences::reduced_motion`](`crate::Preferences::reduced_motion`).
pub const ReducedMotion: Interest = Interest(1 << 2);
#[cfg(feature = "reduced-transparency")]
/// Retrieve the [`ReducedTransparency`](`crate::ReducedTransparency`) preference
/// and store it in [`Preferences::reduced_transparency`](`crate::Preferences::reduced_transparency`).
pub const ReducedTransparency: Interest = Interest(1 << 3);
#[cfg(feature = "accent-color")]
/// Retrieve the [`AccentColor`](`crate::AccentColor`) preference
/// and store it in [`Preferences::accent_color`](`crate::Preferences::accent_color`).
pub const AccentColor: Interest = Interest(1 << 4);
#[cfg(feature = "double-click-interval")]
/// Retrieve the [`DoubleClickInterval`](`crate::DoubleClickInterval`) preference
/// and store it in [`Preferences::double_click_interval`](`crate::Preferences::double_click_interval`).
pub const DoubleClickInterval: Interest = Interest(1 << 5);
#[cfg(feature = "scrollbar-visibility")]
/// Retrieve the [`ScrollbarVisibility`](`crate::ScrollbarVisibility`) preference
/// and store it in [`Preferences::scrollbar_visibility`](`crate::Preferences::scrollbar_visibility`).
pub const ScrollbarVisibility: Interest = Interest(1 << 6);
}
}
#[cfg(target_os = "macos")]
#[allow(non_upper_case_globals)]
impl Interest {
#[cfg(feature = "_macos-accessibility")]
pub(crate) const MacOSAccessibility: Interest = {
let mut value = 0;
#[cfg(feature = "contrast")]
{
value |= Interest::Contrast.0;
}
#[cfg(feature = "reduced-motion")]
{
value |= Interest::ReducedMotion.0;
}
#[cfg(feature = "reduced-transparency")]
{
value |= Interest::ReducedTransparency.0;
}
Interest(value)
};
}
#[cfg(target_os = "linux")]
#[allow(non_upper_case_globals)]
impl Interest {
#[cfg(feature = "_gnome_only")]
pub(crate) const GnomeOnly: Interest = {
let mut value = 0;
#[cfg(feature = "reduced-motion")]
{
value |= Interest::ReducedMotion.0;
}
#[cfg(feature = "double-click-interval")]
{
value |= Interest::DoubleClickInterval.0;
}
#[cfg(feature = "scrollbar-visibility")]
{
value |= Interest::ScrollbarVisibility.0;
}
Interest(value)
};
}
impl Interest {
/// Tests if `self` is a superset of `other`.
/// In other words: Tests if all flags set in `other` are set in `self.
pub fn is(self, other: Self) -> bool {
(other.0 & self.0) == other.0
}
/// Tests if `self` is empty.
/// In other words: Tests if no flags are set.
pub fn is_empty(self) -> bool {
self.0 == 0
}
}
impl BitOr for Interest {
type Output = Interest;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}