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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
//! Register wlc callbacks to events.
//!
//! See individual methods for callback details.
//!
//! # wlc Example
//! ```no_run
//! use rustwlc;
//! use rustwlc::callback;
//! use rustwlc::WlcView;
//!
//! // An example callback function
//! // See the various functions in this module for more information
//! extern "C" fn view_focus_callback(view: WlcView, focused: bool) {
//! println!("A view came into focus!");
//! }
//!
//! // Set a default log callback
//! rustwlc::log_set_default_handler();
//!
//! // Register some callbacks
//! callback::view_focus(view_focus_callback);
//! // ... and additional callbacks
//!
//! // The only thing your code should do before init2 is register callbacks
//! // and log handlers.
//! let run_wlc = rustwlc::init2()
//! .expect("Unable to initialize wlc!");
//!
//! run_wlc();
//! ```
use *;
use ;
/// Callback invoked when an output is created.
/// Return `true` to allow the output to exist.
///
/// # Example
/// ```rust
/// use rustwlc::WlcOutput;
///
/// extern fn on_output_created(output: WlcOutput) -> bool {
/// println!("Output {} ({:?}) was created", output.get_name(), output);
/// return true;
/// }
/// # fn main() { }
/// ```
/// Callback invoked when an output is destroyed.
///
/// # Example
/// ```rust
/// use rustwlc::WlcOutput;
///
/// extern fn output_destroyed(output: WlcOutput) {
/// println!("Goodbye, {:?}", output);
/// }
/// # fn main() { }
/// ```
/// Callback invoked when an output gains focus.
///
/// # Example
/// ```rust
/// use rustwlc::WlcOutput;
///
/// extern fn output_focus(output: WlcOutput, focused: bool) {
/// println!("Output {} {} focus", output.get_name(),
/// if focused { "gained" } else { "lost" });
/// }
/// # fn main() { }
/// ```
/// Callback invoked when an output's resolution changes.
///
/// # Example
/// ```rust
/// use rustwlc::WlcOutput;
/// use rustwlc::Size;
///
/// extern fn output_resolution(output: WlcOutput,
/// old_size: &Size, new_size: &Size) {
/// println!("Output {} went from {} to {}",
/// output.get_name(), old_size, new_size);
/// }
/// # fn main() { }
/// ```
/// Output context created. This generally happens on a tty switch.
/// Output context destroyed
/// Callback invoked pre-render for an output.
/// Callback invoked post-render for an output.
/// Callback invoked when a view is created.
/// Return `true` to allow the view to be created.
///
/// When a new view is created, the following should probably be applied:
/// * Set the view's mask to the output's mask
/// * Focus the view
/// * Bring the view to the front
///
/// # Example
/// ```rust
/// use rustwlc::WlcView;
///
/// extern fn view_created(view: WlcView) -> bool {
/// println!("View \"{}\" was created ({:?})", view.get_class(), view);
/// view.set_mask(view.get_output().get_mask());
/// view.bring_to_front();
/// view.focus();
/// return true;
/// }
/// # fn main() { }
/// ```
/// Callback invoked when a view is destroyed.
///
/// When a view is destroyed, it's a good idea to shift focus to
/// some other view, i.e. the last one used.
///
/// # Example
/// ```rust
/// use rustwlc::WlcView;
///
/// extern fn view_destroyed(view: WlcView) {
/// println!("Goodbye, {:?}", view);
/// }
/// # fn main() { }
/// ```
/// Callback invoked when a view is focused.
///
/// The view's `ViewState::VIEW_ACTIVATED` bit should be set to true here.
///
/// # Example
/// ```rust
/// use rustwlc::WlcView;
/// // The bitflags constants need to be imported manually.
/// use rustwlc::VIEW_ACTIVATED;
///
/// extern fn view_focus(view: WlcView, focused: bool) {
/// println!("View {:?} is {} focus, updating...",
/// view, if focused { "in" } else { "out of" });
/// view.set_state(VIEW_ACTIVATED, focused);
/// }
/// ```
/// Callback invoked when a view switches outputs.
///
/// Moving views between outputs is unsupported in wlc at the time of writing.
/// Wayland mandates each output have its own memory buffer so it may take wlc
/// some time before this is implemented.
/// Callback invoked when a view requests geometry.
/// Callback invoked when a view requests a `ViewState`.
/// Callback invoked when a view requests a move.
/// Callback invoked when a view requests a resize.
/// Callback invoked pre-view-render.
/// Callback invoked post-view-render.
/// Callback invoked on keypresses.
/// Return `true` to block the press from the view.
///
/// # Arguments
/// The first `u32` is a timestamp, the second is the key code. The view may be
/// the root window.
///
/// Proper values for `key` can be found in `input.h` or a similar library/crate
/// - see wlc documentation on the subject, it may not support your keyboard
/// layout at the moment.
///
/// # Example
/// ```rust
/// use rustwlc::WlcView;
/// use rustwlc::{KeyboardModifiers, KeyState};
///
/// extern fn keyboard_key(view: WlcView, time: u32, mods: &KeyboardModifiers,
/// key: u32, state: KeyState) -> bool {
/// println!("Key {} {:?} on {:?} at {} with modifiers {:?}",
/// key, view, state, time, mods);
/// return false;
/// }
/// # fn main() { }
/// ```
/// Callback invoked on mouse clicks.
/// Return `true` to block the click from the view.
///
/// # Arguments
/// The first u32 is a timestamp, the second is the button code.
/// The view may be the root window. Proper values for `button`
/// can be found in `input.h` or a similar library/crate.
///
/// # Example
/// ```rust
/// use rustwlc::WlcView;
/// use rustwlc::{KeyboardModifiers, ButtonState, Point};
///
/// extern fn pointer_button(view: WlcView, time: u32,
/// mods: &KeyboardModifiers, button: u32,
/// state: ButtonState, point: &Point) -> bool {
/// println!("Button {} {:?} at {} at {} in {:?}, keyboard mods: {:?}",
/// button, state, time, point, view, mods);
/// return false;
/// }
/// # fn main() { }
/// ```
/// Callback invoked on mouse scroll.
/// Return `true` to block the scroll from the view.
///
/// # Arguments
/// * view: The WlcView (or output root) that was scrolled in
/// * time: Timestamp
/// * mods: Current pressed keyboard modifiers
/// * axis: Which direction the scroll was in
/// * amount: The first argument seems to be either 10 or -10 depending on
/// up/down (or right/left if `axis == ScrollAxis::Horizontal`).
/// The second one, when tested on a standard laptop trackpad, seems to be
/// a double slightly above zero.
/// Callback invoked on pointer motion.
/// Return `true` to block the motion from the view.
///
/// `rustwlc::input::pointer::set_position`
/// must be invoked to actually move the cursor!
///
/// # Example
/// ```rust
/// use rustwlc::WlcView;
/// use rustwlc::Point;
/// use rustwlc::input::pointer;
///
/// extern fn pointer_motion(view: WlcView, time: u32, point: &Point) -> bool {
/// println!("Pointer was moved to {} in {:?} at {}", point, view, time);
/// // This is very important.
/// pointer::set_position(point);
/// return false;
/// }
/// # fn main() { }
/// ```
/// Callback invoked on touchscreen touch.
/// Return `true` to block the touch from the view.
///
/// # Arguments
/// * `mods`: Which keyboard modifiers are being pressed during the event
/// * `touch`: What kind of event it is (a touch down, a frame being made,
/// a touch release). In the case of `TouchType::Frame`, `slot` and `point`
/// will both be zero.
/// * `slot`: Which finger - in cases of multiple touches down - is causing
/// the event
/// * `point`: Where the touch event happened
/// Callback invoked by wlc after `rustwlc::init` is called.
/// Callback invoked by wlc when a compositor is terminating
/// Get size requested by positioner, as defined in xdg-shell v6.
/// Get anchor requested by positioner, as defined in xdg-shell v6.
/// Returns default value WLC_BIT_GRAVITY_NONE if view has no valid positioner
/// or if positioner has no gravity set.