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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
use std::ops::Deref;
use wayland_client::protocol::{wl_compositor, wl_pointer, wl_seat, wl_shm};
use wayland_client::{NewProxy, Proxy, QueueToken};
use wayland_client::protocol::wl_seat::RequestsTrait as SeatRequests;
mod theme;
pub use self::theme::{ThemeManager, ThemedPointer};
pub enum AutoThemer {
Themed(ThemeManager),
UnThemed,
}
impl AutoThemer {
pub fn init(
name: Option<&str>,
compositor: Proxy<wl_compositor::WlCompositor>,
shm: &Proxy<wl_shm::WlShm>,
) -> AutoThemer {
match ThemeManager::init(name, compositor, &shm) {
Ok(mgr) => AutoThemer::Themed(mgr),
Err(()) => AutoThemer::UnThemed,
}
}
pub fn theme_pointer(&self, pointer: Proxy<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: &Proxy<wl_seat::WlSeat>,
mut implementation: Impl,
user_data: UD,
) -> AutoPointer
where
Impl: FnMut(wl_pointer::Event, AutoPointer) + Send + 'static,
UD: Send + Sync + '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(
move |event, seat| implementation(event, AutoPointer::UnThemed(seat)),
user_data,
)
})
.unwrap();
AutoPointer::UnThemed(pointer)
}
}
}
pub unsafe fn theme_pointer_with_nonsend_impl<Impl, UD>(
&self,
pointer: NewProxy<wl_pointer::WlPointer>,
mut implementation: Impl,
user_data: UD,
token: &QueueToken,
) -> AutoPointer
where
Impl: FnMut(wl_pointer::Event, AutoPointer) + Send + 'static,
UD: Send + Sync + 'static,
{
match *self {
AutoThemer::Themed(ref mgr) => {
let pointer = mgr.theme_pointer_with_nonsend_impl(
pointer,
move |event, pointer| implementation(event, AutoPointer::Themed(pointer)),
user_data,
token,
);
AutoPointer::Themed(pointer)
}
AutoThemer::UnThemed => {
let pointer = pointer.implement_nonsend(
move |event, pointer| implementation(event, AutoPointer::UnThemed(pointer)),
user_data,
token,
);
AutoPointer::UnThemed(pointer)
}
}
}
}
pub enum AutoPointer {
Themed(ThemedPointer),
UnThemed(Proxy<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(()),
}
}
}
impl Deref for AutoPointer {
type Target = Proxy<wl_pointer::WlPointer>;
fn deref(&self) -> &Proxy<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()),
}
}
}