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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use std::ops::Deref;
use wayland_client::protocol::{wl_compositor, wl_pointer, wl_seat, wl_shm};
mod theme;
pub use self::theme::{ThemeManager, ThemedPointer};
pub enum AutoThemer {
Themed(ThemeManager),
UnThemed,
}
impl AutoThemer {
pub fn init(
name: Option<&str>,
compositor: wl_compositor::WlCompositor,
shm: &wl_shm::WlShm,
) -> AutoThemer {
match ThemeManager::init(name, compositor, &shm) {
Ok(mgr) => AutoThemer::Themed(mgr),
Err(()) => AutoThemer::UnThemed,
}
}
pub fn theme_pointer(&self, pointer: wl_pointer::WlPointer) -> AutoPointer {
match *self {
AutoThemer::Themed(ref mgr) => AutoPointer::Themed(mgr.theme_pointer(pointer)),
AutoThemer::UnThemed => AutoPointer::UnThemed(pointer),
}
}
pub fn theme_pointer_with_impl<Impl, UD>(
&self,
seat: &wl_seat::WlSeat,
mut implementation: Impl,
user_data: UD,
) -> AutoPointer
where
Impl: FnMut(wl_pointer::Event, AutoPointer) + 'static,
UD: 'static,
{
match *self {
AutoThemer::Themed(ref mgr) => {
let pointer = mgr.theme_pointer_with_impl(
seat,
move |event, seat| implementation(event, AutoPointer::Themed(seat)),
user_data,
);
AutoPointer::Themed(pointer)
}
AutoThemer::UnThemed => {
let pointer = seat
.get_pointer(|pointer| {
pointer.implement_closure(
move |event, seat| implementation(event, AutoPointer::UnThemed(seat)),
user_data,
)
})
.unwrap();
AutoPointer::UnThemed(pointer)
}
}
}
}
pub enum AutoPointer {
Themed(ThemedPointer),
UnThemed(wl_pointer::WlPointer),
}
impl AutoPointer {
pub fn set_cursor(&self, name: &str, serial: Option<u32>) -> Result<(), ()> {
match *self {
AutoPointer::Themed(ref themed) => themed.set_cursor(name, serial),
AutoPointer::UnThemed(_) => Ok(()),
}
}
pub fn set_cursor_with_scale(
&self,
name: &str,
scale: u32,
serial: Option<u32>,
) -> Result<(), ()> {
match *self {
AutoPointer::Themed(ref themed) => themed.set_cursor_with_scale(name, scale, serial),
AutoPointer::UnThemed(_) => Ok(()),
}
}
}
impl Deref for AutoPointer {
type Target = wl_pointer::WlPointer;
fn deref(&self) -> &wl_pointer::WlPointer {
match *self {
AutoPointer::Themed(ref themed) => &**themed,
AutoPointer::UnThemed(ref ptr) => ptr,
}
}
}
impl Clone for AutoPointer {
fn clone(&self) -> AutoPointer {
match *self {
AutoPointer::Themed(ref themed) => AutoPointer::Themed(themed.clone()),
AutoPointer::UnThemed(ref ptr) => AutoPointer::UnThemed(ptr.clone()),
}
}
}