dummy_rustwlc/
callback.rs

1//! Register wlc callbacks to events.
2//!
3//! See individual methods for callback details.
4//!
5//! # wlc Example
6//! ```no_run
7//! use rustwlc;
8//! use rustwlc::callback;
9//! use rustwlc::WlcView;
10//!
11//! // An example callback function
12//! // See the various functions in this module for more information
13//! extern "C" fn view_focus_callback(view: WlcView, focused: bool) {
14//!     println!("A view came into focus!");
15//! }
16//!
17//! // Set a default log callback
18//! rustwlc::log_set_default_handler();
19//!
20//! // Register some callbacks
21//! callback::view_focus(view_focus_callback);
22//! // ... and additional callbacks
23//!
24//! // The only thing your code should do before init2 is register callbacks
25//! // and log handlers.
26//! let run_wlc = rustwlc::init2()
27//!     .expect("Unable to initialize wlc!");
28//!
29//! run_wlc();
30//! ```
31
32use super::types::*;
33use super::handle::{WlcOutput, WlcView};
34
35/// Callback invoked when an output is created.
36/// Return `true` to allow the output to exist.
37///
38/// # Example
39/// ```rust
40/// use rustwlc::WlcOutput;
41///
42/// extern fn on_output_created(output: WlcOutput) -> bool {
43///     println!("Output {} ({:?}) was created", output.get_name(), output);
44///     return true;
45/// }
46/// # fn main() { }
47/// ```
48pub fn output_created(callback: extern "C" fn(output: WlcOutput) -> bool) {
49    
50}
51
52/// Callback invoked when an output is destroyed.
53///
54/// # Example
55/// ```rust
56/// use rustwlc::WlcOutput;
57///
58/// extern fn output_destroyed(output: WlcOutput) {
59///     println!("Goodbye, {:?}", output);
60/// }
61/// # fn main() { }
62/// ```
63pub fn output_destroyed(callback: extern "C" fn(output: WlcOutput)) {
64    
65}
66
67/// Callback invoked when an output gains focus.
68///
69/// # Example
70/// ```rust
71/// use rustwlc::WlcOutput;
72///
73/// extern fn output_focus(output: WlcOutput, focused: bool) {
74///     println!("Output {} {} focus", output.get_name(),
75///              if focused { "gained" } else { "lost" });
76/// }
77/// # fn main() { }
78/// ```
79pub fn output_focus(callback: extern "C" fn(output: WlcOutput, focused: bool)) {
80    
81}
82
83/// Callback invoked when an output's resolution changes.
84///
85/// # Example
86/// ```rust
87/// use rustwlc::WlcOutput;
88/// use rustwlc::Size;
89///
90/// extern fn output_resolution(output: WlcOutput,
91///                             old_size: &Size, new_size: &Size) {
92///     println!("Output {} went from {} to {}",
93///              output.get_name(), old_size, new_size);
94/// }
95/// # fn main() { }
96/// ```
97pub fn output_resolution(callback: extern "C" fn(output: WlcOutput,
98                                                 old_size: &Size,
99                                                 new_size: &Size)) {
100    
101}
102
103/// Output context created. This generally happens on a tty switch.
104pub fn output_context_destroyed(cb: extern "C" fn(output: WlcOutput)) {
105    
106}
107
108/// Output context destroyed
109pub fn output_context_created(cb: extern "C" fn(output: WlcOutput)) {
110    
111}
112
113/// Callback invoked pre-render for an output.
114pub fn output_render_pre(callback: extern "C" fn(output: WlcOutput)) {
115    
116}
117
118/// Callback invoked post-render for an output.
119pub fn output_render_post(callback: extern "C" fn(output: WlcOutput)) {
120    
121}
122
123/// Callback invoked when a view is created.
124/// Return `true` to allow the view to be created.
125///
126/// When a new view is created, the following should probably be applied:
127/// * Set the view's mask to the output's mask
128/// * Focus the view
129/// * Bring the view to the front
130///
131/// # Example
132/// ```rust
133/// use rustwlc::WlcView;
134///
135/// extern fn view_created(view: WlcView) -> bool {
136///     println!("View \"{}\" was created ({:?})", view.get_class(), view);
137///     view.set_mask(view.get_output().get_mask());
138///     view.bring_to_front();
139///     view.focus();
140///     return true;
141/// }
142/// # fn main() { }
143/// ```
144pub fn view_created(callback: extern "C" fn(view: WlcView) -> bool) {
145    
146}
147
148/// Callback invoked when a view is destroyed.
149///
150/// When a view is destroyed, it's a good idea to shift focus to
151/// some other view, i.e. the last one used.
152///
153/// # Example
154/// ```rust
155/// use rustwlc::WlcView;
156///
157/// extern fn view_destroyed(view: WlcView) {
158///     println!("Goodbye, {:?}", view);
159/// }
160/// # fn main() { }
161/// ```
162pub fn view_destroyed(callback: extern "C" fn(view: WlcView)) {
163    
164}
165
166/// Callback invoked when a view is focused.
167///
168/// The view's `ViewState::VIEW_ACTIVATED` bit should be set to true here.
169///
170/// # Example
171/// ```rust
172/// use rustwlc::WlcView;
173/// // The bitflags constants need to be imported manually.
174/// use rustwlc::VIEW_ACTIVATED;
175///
176/// extern fn view_focus(view: WlcView, focused: bool) {
177///     println!("View {:?} is {} focus, updating...",
178///               view, if focused { "in" } else { "out of" });
179///     view.set_state(VIEW_ACTIVATED, focused);
180/// }
181/// ```
182pub fn view_focus(callback: extern "C" fn(handle: WlcView, focused: bool)) {
183    
184}
185
186/// Callback invoked when a view switches outputs.
187///
188/// Moving views between outputs is unsupported in wlc at the time of writing.
189/// Wayland mandates each output have its own memory buffer so it may take wlc
190/// some time before this is implemented.
191pub fn view_move_to_output(callback: extern "C" fn(view: WlcView,
192                                                   old_output: WlcOutput,
193                                                   new_output: WlcOutput)) {
194    
195}
196
197/// Callback invoked when a view requests geometry.
198pub fn view_request_geometry(callback: extern "C" fn(handle: WlcView,
199                                                     geometry: &Geometry)) {
200    
201}
202
203/// Callback invoked when a view requests a `ViewState`.
204pub fn view_request_state(callback: extern "C" fn(current: WlcView,
205                                                  state: ViewState,
206                                                  handled: bool)) {
207    
208}
209
210/// Callback invoked when a view requests a move.
211pub fn view_request_move(callback: extern "C" fn(handle: WlcView,
212                                                 destination: &Point)) {
213    
214}
215
216/// Callback invoked when a view requests a resize.
217pub fn view_request_resize(callback: extern "C" fn(handle: WlcView,
218                                                   edge: ResizeEdge,
219                                                   location: &Point)) {
220    
221}
222
223/// Callback invoked pre-view-render.
224pub fn view_render_pre(callback: extern "C" fn(view: WlcView)) {
225    
226}
227
228/// Callback invoked post-view-render.
229pub fn view_render_post(callback: extern "C" fn(view: WlcView)) {
230    
231}
232
233/// Callback invoked on keypresses.
234/// Return `true` to block the press from the view.
235///
236/// # Arguments
237/// The first `u32` is a timestamp, the second is the key code. The view may be
238/// the root window.
239///
240/// Proper values for `key` can be found in `input.h` or a similar library/crate
241/// - see wlc documentation on the subject, it may not support your keyboard
242/// layout at the moment.
243///
244/// # Example
245/// ```rust
246/// use rustwlc::WlcView;
247/// use rustwlc::{KeyboardModifiers, KeyState};
248///
249/// extern fn keyboard_key(view: WlcView, time: u32, mods: &KeyboardModifiers,
250///                        key: u32, state: KeyState) -> bool {
251///     println!("Key {} {:?} on {:?} at {} with modifiers {:?}",
252///              key, view, state, time, mods);
253///     return false;
254/// }
255/// # fn main() { }
256/// ```
257pub fn keyboard_key(callback: extern "C" fn(view: WlcView, time: u32,
258                                            mods: &KeyboardModifiers, key: u32,
259                                            state: KeyState) -> bool) {
260    
261}
262
263/// Callback invoked on mouse clicks.
264/// Return `true` to block the click from the view.
265///
266/// # Arguments
267/// The first u32 is a timestamp, the second is the button code.
268/// The view may be the root window. Proper values for `button`
269/// can be found in `input.h` or a similar library/crate.
270///
271/// # Example
272/// ```rust
273/// use rustwlc::WlcView;
274/// use rustwlc::{KeyboardModifiers, ButtonState, Point};
275///
276/// extern fn pointer_button(view: WlcView, time: u32,
277///                          mods: &KeyboardModifiers, button: u32,
278///                          state: ButtonState, point: &Point) -> bool {
279///     println!("Button {} {:?} at {} at {} in {:?}, keyboard mods: {:?}",
280///              button, state, time, point, view, mods);
281///     return false;
282/// }
283/// # fn main() { }
284/// ```
285pub fn pointer_button(callback: extern "C" fn(view: WlcView, time: u32,
286                                              mods: &KeyboardModifiers,
287                                              button: u32, state: ButtonState,
288                                              point: &Point) -> bool) {
289    
290}
291
292/// Callback invoked on mouse scroll.
293/// Return `true` to block the scroll from the view.
294///
295/// # Arguments
296/// * view: The WlcView (or output root) that was scrolled in
297/// * time: Timestamp
298/// * mods: Current pressed keyboard modifiers
299/// * axis: Which direction the scroll was in
300/// * amount: The first argument seems to be either 10 or -10 depending on
301/// up/down (or right/left if `axis == ScrollAxis::Horizontal`).
302/// The second one, when tested on a standard laptop trackpad, seems to be
303/// a double slightly above zero.
304pub fn pointer_scroll(callback: extern "C" fn(view: WlcView, time: u32,
305                                              mods: &KeyboardModifiers,
306                                              axis: ScrollAxis,
307                                              amount: [f64; 2]) -> bool) {
308    
309}
310
311/// Callback invoked on pointer motion.
312/// Return `true` to block the motion from the view.
313///
314/// `rustwlc::input::pointer::set_position`
315/// must be invoked to actually move the cursor!
316///
317/// # Example
318/// ```rust
319/// use rustwlc::WlcView;
320/// use rustwlc::Point;
321/// use rustwlc::input::pointer;
322///
323/// extern fn pointer_motion(view: WlcView, time: u32, point: &Point) -> bool {
324///     println!("Pointer was moved to {} in {:?} at {}", point, view, time);
325///     // This is very important.
326///     pointer::set_position(point);
327///     return false;
328/// }
329/// # fn main() { }
330/// ```
331pub fn pointer_motion(callback: extern "C" fn(view: WlcView, time: u32,
332                                              point: &Point) -> bool) {
333    
334}
335
336pub fn pointer_motion_v2(callback: extern "C" fn(view: WlcView, time: u32,
337                                              x: f64, y: f64) -> bool) {
338    
339}
340
341/// Callback invoked on touchscreen touch.
342/// Return `true` to block the touch from the view.
343///
344/// # Arguments
345/// * `mods`: Which keyboard modifiers are being pressed during the event
346/// * `touch`: What kind of event it is (a touch down, a frame being made,
347/// a touch release). In the case of `TouchType::Frame`, `slot` and `point`
348/// will both be zero.
349/// * `slot`: Which finger - in cases of multiple touches down - is causing
350/// the event
351/// * `point`: Where the touch event happened
352pub fn touch(callback: extern "C" fn(handle: WlcView, time: u32,
353                                     mods: &KeyboardModifiers, touch: TouchType,
354                                     slot: i32, point: &Point) -> bool) {
355    
356}
357
358/// Callback invoked by wlc after `rustwlc::init` is called.
359pub fn compositor_ready(callback: extern "C" fn()) {
360    
361}
362
363/// Callback invoked by wlc when a compositor is terminating
364pub fn compositor_terminate(callback: extern "C" fn()) {
365    
366}
367
368pub fn positioner_get_anchor_rect(view: WlcView) -> Option<Geometry> {
369    None
370}
371
372/// Get size requested by positioner, as defined in xdg-shell v6.
373pub fn positioner_get_size(view: WlcView) -> Option<Size> {
374    None
375}
376
377/// Get anchor requested by positioner, as defined in xdg-shell v6.
378/// Returns default value WLC_BIT_GRAVITY_NONE if view has no valid positioner
379/// or if positioner has no gravity set.
380pub fn positioner_get_anchor(view: WlcView) -> PositionerAnchorBit {
381    PositionerAnchorBit::empty()
382}
383
384pub fn positioner_get_gravity(view: WlcView) -> PositionerGravityBit {
385    PositionerGravityBit::empty()
386}
387
388pub fn positioner_get_constraint_adjustment(view: WlcView) {
389}
390
391pub fn view_properties_changed(callback: extern "C" fn(handle: WlcView, mask: ViewPropertyType)) {
392
393}