zng_app/view_process/
raw_events.rs

1//! Events directly from the view-process targeting the app windows.
2//!
3//! These events get processed by app extensions to generate the events used in widgets, for example
4//! the `KEYBOARD` service maps the [`RAW_KEY_INPUT_EVENT`] into focus targeted events.
5//!
6//! # Synthetic Input
7//!
8//! You can [`notify`] these events to fake hardware input, please be careful that you mimic the exact sequence a real
9//! hardware would generate, [app extensions] can assume that the raw events are correct. The [`InputDeviceId`] for fake
10//! input must be unique but constant for each distinctive *synthetic event source*.
11//!
12//! [`RAW_KEY_INPUT_EVENT`]: crate::view_process::raw_events::RAW_KEY_INPUT_EVENT
13//! [`notify`]: crate::event::Event::notify
14//! [`InputDeviceId`]: crate::view_process::raw_device_events::InputDeviceId
15
16use zng_layout::unit::{DipPoint, DipSideOffsets, DipSize, Factor, Frequency, PxPoint};
17use zng_txt::Txt;
18use zng_var::WeakEq;
19use zng_view_api::{
20    AxisId, DragDropId, Ime,
21    api_extension::{ApiExtensionId, ApiExtensionPayload},
22    audio::{AudioDecoded, AudioMetadata},
23    config::{AnimationsConfig, ColorsConfig, FontAntiAliasing, KeyRepeatConfig, LocaleConfig, MultiClickConfig, TouchConfig},
24    drag_drop::{DragDropData, DragDropEffect},
25    image::{ImageDecoded, ImageMetadata},
26    keyboard::{Key, KeyCode, KeyLocation, KeyState},
27    mouse::{ButtonState, MouseButton, MouseScrollDelta},
28    touch::{TouchPhase, TouchUpdate},
29    window::{EventCause, FrameId, FrameWaitId, HeadlessOpenData, MonitorInfo, WindowStateAll},
30};
31
32use crate::{
33    event::{event, event_args},
34    view_process::{AudioOutputId, ViewImageHandle, WeakViewAudioHandle, WeakViewAudioOutput},
35    window::{MonitorId, WindowId},
36};
37
38use super::{WeakViewHeadless, WeakViewImageHandle, WeakViewWindow, WindowOpenData, raw_device_events::InputDeviceId};
39
40event_args! {
41    /// Arguments for the [`RAW_KEY_INPUT_EVENT`].
42    pub struct RawKeyInputArgs {
43        /// Window that received the event.
44        pub window_id: WindowId,
45
46        /// Keyboard device that generated the event.
47        pub device_id: InputDeviceId,
48
49        /// Physical key.
50        pub key_code: KeyCode,
51
52        /// The location of the key on the keyboard.
53        pub key_location: KeyLocation,
54
55        /// If the key was pressed or released.
56        pub state: KeyState,
57
58        /// Semantic key.
59        ///
60        /// Pressing `Shift+A` key will produce `Key::Char('a')` in QWERTY keyboards, the modifiers are not applied.
61        pub key: Key,
62        /// Semantic key modified by the current active modifiers.
63        ///
64        /// Pressing `Shift+A` key will produce `Key::Char('A')` in QWERTY keyboards, the modifiers are applied.
65        pub key_modified: Key,
66
67        /// Text typed.
68        ///
69        /// This is only set for `KeyState::Pressed` of a key that generates text.
70        ///
71        /// This is usually the `key_modified` char, but is also `'\r'` for `Key::Enter`. On Windows when a dead key was
72        /// pressed earlier but cannot be combined with the character from this key press, the produced text
73        /// will consist of two characters: the dead-key-character followed by the character resulting from this key press.
74        pub text: Txt,
75
76        ..
77
78        /// Broadcast to all widgets.
79        fn is_in_target(&self, id: WidgetId) -> bool {
80            true
81        }
82    }
83
84    /// Arguments for the [`RAW_IME_EVENT`].
85    pub struct RawImeArgs {
86        /// Window that received the event.
87        pub window_id: WindowId,
88
89        /// The IME event.
90        pub ime: Ime,
91
92        ..
93
94        /// Broadcast to all widgets.
95        fn is_in_target(&self, id: WidgetId) -> bool {
96            true
97        }
98    }
99
100    /// Arguments for the [`RAW_WINDOW_FOCUS_EVENT`].
101    pub struct RawWindowFocusArgs {
102        /// Window that load focus.
103        pub prev_focus: Option<WindowId>,
104
105        /// Window that got focus.
106        pub new_focus: Option<WindowId>,
107
108        ..
109
110        /// Broadcast to all widgets.
111        fn is_in_target(&self, id: WidgetId) -> bool {
112            true
113        }
114    }
115
116    /// Arguments for the [`RAW_FRAME_RENDERED_EVENT`].
117    pub struct RawFrameRenderedArgs {
118        /// Window that presents the rendered frame.
119        pub window_id: WindowId,
120
121        /// Frame tag.
122        pub frame_id: FrameId,
123
124        /// The frame pixels if it was requested when the frame request was sent to the view process.
125        ///
126        /// The handle can be upgraded on hook only, after it is dropped. This is so the
127        /// latest event does not keep the image alive indefinitely.
128        pub frame_image: Option<WeakEq<(ViewImageHandle, ImageDecoded)>>,
129
130        ..
131
132        /// Broadcast to all widgets.
133        fn is_in_target(&self, id: WidgetId) -> bool {
134            true
135        }
136    }
137
138    // TODO(breaking) return RawWindowChangedArgs here
139
140    /// Arguments for the [`RAW_WINDOW_OPEN_EVENT`].
141    pub struct RawWindowOpenArgs {
142        /// Window that finished opening.
143        pub window_id: WindowId,
144
145        /// Live connection to the window in the view-process.
146        ///
147        /// The handle can be upgraded on hook only, after it is dropped. This is so the
148        /// latest event does not keep the window alive indefinitely.
149        pub window: WeakViewWindow,
150
151        /// Extra data send by the view-process.
152        pub data: WindowOpenData,
153
154        ..
155
156        /// Broadcast to all widgets.
157        fn is_in_target(&self, id: WidgetId) -> bool {
158            true
159        }
160    }
161
162    /// Arguments for the [`RAW_HEADLESS_OPEN_EVENT`].
163    pub struct RawHeadlessOpenArgs {
164        /// Window id that represents the headless surface that finished opening.
165        pub window_id: WindowId,
166
167        /// Live connection to the headless surface in the view-process.
168        ///
169        /// The handle can be upgraded on hook only, after it is dropped. This is so the
170        /// latest event does not keep the surface alive indefinitely.
171        pub surface: WeakViewHeadless,
172
173        /// Extra data send by the view-process.
174        pub data: HeadlessOpenData,
175
176        ..
177
178        /// Broadcast to all widgets.
179        fn is_in_target(&self, id: WidgetId) -> bool {
180            true
181        }
182    }
183
184    /// Arguments for the [`RAW_WINDOW_OR_HEADLESS_OPEN_ERROR_EVENT`].
185    pub struct RawWindowOrHeadlessOpenErrorArgs {
186        /// Window id that failed to open.
187        pub window_id: WindowId,
188        /// Error message from the view-process.
189        pub error: Txt,
190
191        ..
192
193        /// Broadcast to all widgets.
194        fn is_in_target(&self, id: WidgetId) -> bool {
195            true
196        }
197    }
198
199    /// Arguments for the [`RAW_WINDOW_CLOSE_REQUESTED_EVENT`].
200    pub struct RawWindowCloseRequestedArgs {
201        /// Window that was requested to close.
202        pub window_id: WindowId,
203
204        ..
205
206        /// Broadcast to all widgets.
207        fn is_in_target(&self, id: WidgetId) -> bool {
208            true
209        }
210    }
211
212    /// Arguments for the [`RAW_WINDOW_CLOSE_EVENT`].
213    pub struct RawWindowCloseArgs {
214        /// Window that has closed.
215        pub window_id: WindowId,
216
217        ..
218
219        /// Broadcast to all widgets.
220        fn is_in_target(&self, id: WidgetId) -> bool {
221            true
222        }
223    }
224
225    /// Arguments for the [`RAW_DRAG_HOVERED_EVENT`].
226    pub struct RawDragHoveredArgs {
227        /// Window where it was dragged over.
228        pub window_id: WindowId,
229
230        /// Data payload.
231        pub data: Vec<DragDropData>,
232        /// Allowed effects.
233        pub allowed: DragDropEffect,
234
235        ..
236
237        /// Broadcast to all widgets.
238        fn is_in_target(&self, id: WidgetId) -> bool {
239            true
240        }
241    }
242
243    /// Arguments for the [`RAW_DRAG_MOVED_EVENT`].
244    pub struct RawDragMovedArgs {
245        /// Window that is hovered by drag&drop.
246        pub window_id: WindowId,
247
248        /// Cursor positions in between the previous event and this one.
249        ///
250        /// Drag move events can be coalesced, i.e. multiple moves packed into a single event.
251        pub coalesced_pos: Vec<DipPoint>,
252
253        /// Position of the cursor over the window, (0, 0) is the top-left.
254        pub position: DipPoint,
255
256        ..
257
258        /// Broadcast to all widgets.
259        fn is_in_target(&self, id: WidgetId) -> bool {
260            true
261        }
262    }
263
264    /// Arguments for the [`RAW_DRAG_DROPPED_EVENT`].
265    pub struct RawDragDroppedArgs {
266        /// Window where it was dropped.
267        pub window_id: WindowId,
268
269        /// Data payload.
270        pub data: Vec<DragDropData>,
271        /// Allowed effects.
272        pub allowed: DragDropEffect,
273        /// ID of this drop operation.
274        ///
275        /// Handlers must call `drag_dropped` with this ID and what effect was applied to the data.
276        pub drop_id: DragDropId,
277
278        ..
279
280        /// Broadcast to all widgets.
281        fn is_in_target(&self, id: WidgetId) -> bool {
282            true
283        }
284    }
285
286    /// Arguments for the [`RAW_DRAG_CANCELLED_EVENT`].
287    pub struct RawDragCancelledArgs {
288        /// Window where the file was previously dragged over.
289        pub window_id: WindowId,
290
291        ..
292
293        /// Broadcast to all widgets.
294        fn is_in_target(&self, id: WidgetId) -> bool {
295            true
296        }
297    }
298
299    /// Arguments for the [`RAW_APP_DRAG_ENDED_EVENT`].
300    pub struct RawAppDragEndedArgs {
301        /// Window that started the drag operation.
302        pub window_id: WindowId,
303
304        /// ID of the drag & drop operation.
305        pub id: DragDropId,
306
307        /// Effect applied to the data by the drop target.
308        ///
309        /// Is a single flag if the data was dropped in a valid drop target, or is empty if was canceled.
310        pub applied: DragDropEffect,
311
312        ..
313
314        /// Broadcast to all widgets.
315        fn is_in_target(&self, id: WidgetId) -> bool {
316            true
317        }
318    }
319
320    /// Arguments for the [`RAW_MOUSE_MOVED_EVENT`].
321    pub struct RawMouseMovedArgs {
322        /// Window the mouse was moved over.
323        pub window_id: WindowId,
324
325        /// Device that generated this event.
326        pub device_id: InputDeviceId,
327
328        /// Positions of the mouse in between the previous event and this one.
329        ///
330        /// Mouse move events can be coalesced, i.e. multiple mouse moves packed into a single event.
331        pub coalesced_pos: Vec<DipPoint>,
332
333        /// Position of the mouse over the window, (0, 0) is the top-left.
334        pub position: DipPoint,
335
336        ..
337
338        /// Broadcast to all widgets.
339        fn is_in_target(&self, id: WidgetId) -> bool {
340            true
341        }
342    }
343
344    /// Arguments for the [`RAW_MOUSE_ENTERED_EVENT`] and [`RAW_MOUSE_LEFT_EVENT`].
345    pub struct RawMouseArgs {
346        /// Window the mouse entered or left.
347        pub window_id: WindowId,
348
349        /// Device that generated this event.
350        pub device_id: InputDeviceId,
351
352        ..
353
354        /// Broadcast to all widgets.
355        fn is_in_target(&self, id: WidgetId) -> bool {
356            true
357        }
358    }
359
360    /// Arguments for the [`RAW_MOUSE_WHEEL_EVENT`].
361    pub struct RawMouseWheelArgs {
362        /// Window that is hovered by the mouse.
363        pub window_id: WindowId,
364
365        /// Device that generated this event.
366        pub device_id: InputDeviceId,
367
368        /// Wheel motion delta, value is in pixels if the *wheel* is a touchpad.
369        pub delta: MouseScrollDelta,
370
371        /// Touch state if the device that generated the event is a touchpad.
372        pub phase: TouchPhase,
373
374        ..
375
376        /// Broadcast to all widgets.
377        fn is_in_target(&self, id: WidgetId) -> bool {
378            true
379        }
380    }
381
382    /// Arguments for the [`RAW_MOUSE_INPUT_EVENT`].
383    pub struct RawMouseInputArgs {
384        /// Window that is hovered by the mouse.
385        pub window_id: WindowId,
386
387        /// Device that generated this event.
388        pub device_id: InputDeviceId,
389
390        /// If the button was pressed or released.
391        pub state: ButtonState,
392
393        /// What button was pressed or released.
394        pub button: MouseButton,
395
396        ..
397
398        /// Broadcast to all widgets.
399        fn is_in_target(&self, id: WidgetId) -> bool {
400            true
401        }
402    }
403
404    /// Arguments for the [`RAW_TOUCHPAD_PRESSURE_EVENT`].
405    pub struct RawTouchpadPressureArgs {
406        /// Window that is touched.
407        pub window_id: WindowId,
408
409        /// Device that generated this event.
410        pub device_id: InputDeviceId,
411
412        /// Pressure level between 0 and 1.
413        pub pressure: Factor,
414
415        /// Click level.
416        pub stage: i64,
417
418        ..
419
420        /// Broadcast to all widgets.
421        fn is_in_target(&self, id: WidgetId) -> bool {
422            true
423        }
424    }
425
426    /// Arguments for the [`RAW_AXIS_MOTION_EVENT`].
427    pub struct RawAxisMotionArgs {
428        /// Window that received the event.
429        pub window_id: WindowId,
430
431        /// Device that generated the event.
432        pub device_id: InputDeviceId,
433
434        /// Analog axis.
435        pub axis: AxisId,
436
437        /// Motion amount.
438        pub value: f64,
439
440        ..
441
442        /// Broadcast to all widgets.
443        fn is_in_target(&self, id: WidgetId) -> bool {
444            true
445        }
446    }
447
448    /// Arguments for the [`RAW_TOUCH_EVENT`].
449    pub struct RawTouchArgs {
450        /// Window that was touched.
451        pub window_id: WindowId,
452
453        /// Device that generated this event.
454        pub device_id: InputDeviceId,
455
456        /// Coalesced touch updates.
457        pub touches: Vec<TouchUpdate>,
458
459        ..
460
461        /// Broadcast to all widgets.
462        fn is_in_target(&self, id: WidgetId) -> bool {
463            true
464        }
465    }
466
467    /// Arguments for the [`RAW_SCALE_FACTOR_CHANGED_EVENT`].
468    pub struct RawScaleFactorChangedArgs {
469        /// Monitor that has changed.
470        pub monitor_id: MonitorId,
471
472        /// Window in the monitor that has changed.
473        pub windows: Vec<WindowId>,
474
475        /// New pixel scale factor.
476        pub scale_factor: Factor,
477
478        ..
479
480        /// Broadcast to all widgets.
481        fn is_in_target(&self, id: WidgetId) -> bool {
482            true
483        }
484    }
485
486    /// Arguments for the [`RAW_MONITORS_CHANGED_EVENT`].
487    pub struct RawMonitorsChangedArgs {
488        /// Up-to-date monitors list.
489        pub available_monitors: Vec<(MonitorId, MonitorInfo)>,
490
491        ..
492
493        /// Broadcast to all widgets.
494        fn is_in_target(&self, id: WidgetId) -> bool {
495            true
496        }
497    }
498
499    /// Arguments for [`RAW_IMAGE_METADATA_DECODED_EVENT`].
500    pub struct RawImageMetadataDecodedArgs {
501        /// Handle to the image in the view-process.
502        ///
503        /// The handle can be upgraded on hook only, after it is dropped. This is so the
504        /// latest event does not keep the image alive indefinitely.
505        pub handle: WeakViewImageHandle,
506        /// Image metadata.
507        pub meta: ImageMetadata,
508
509        ..
510
511        /// Broadcast to all widgets.
512        fn is_in_target(&self, id: WidgetId) -> bool {
513            true
514        }
515    }
516
517    /// Arguments for the [`RAW_IMAGE_DECODED_EVENT`].
518    pub struct RawImageDecodedArgs {
519        /// Handle to the image in the view-process.
520        ///
521        /// The handle can be upgraded on hook only, after it is dropped. This is so the
522        /// latest event does not keep the image alive indefinitely.
523        pub handle: WeakViewImageHandle,
524        /// Image data.
525        ///
526        /// The handle can be upgraded on hook only, after it is dropped.
527        pub image: WeakEq<ImageDecoded>,
528
529        ..
530
531        /// Broadcast to all widgets.
532        fn is_in_target(&self, id: WidgetId) -> bool {
533            true
534        }
535    }
536
537    /// Arguments for the [`RAW_IMAGE_DECODE_ERROR_EVENT`].
538    pub struct RawImageDecodeErrorArgs {
539        /// Handle that identifies the image request.
540        ///
541        /// The image data is already removed in the view-process.
542        ///
543        /// The handle can be upgraded on hook only, after it is dropped.
544        pub handle: WeakViewImageHandle,
545        /// Error message.
546        pub error: Txt,
547
548        ..
549
550        /// Broadcast to all widgets.
551        fn is_in_target(&self, id: WidgetId) -> bool {
552            true
553        }
554    }
555
556    /// Arguments for [`RAW_AUDIO_METADATA_DECODED_EVENT`].
557    pub struct RawAudioMetadataDecodedArgs {
558        /// Handle to the audio in the view-process.
559        ///
560        /// The handle can be upgraded on hook only, after it is dropped. This is so the
561        /// latest event does not keep the audio alive indefinitely.
562        pub handle: WeakViewAudioHandle,
563        /// Audio metadata.
564        pub meta: AudioMetadata,
565
566        ..
567
568        /// Broadcast to all widgets.
569        fn is_in_target(&self, id: WidgetId) -> bool {
570            true
571        }
572    }
573
574    /// Arguments for the [`RAW_AUDIO_DECODED_EVENT`].
575    pub struct RawAudioDecodedArgs {
576        /// Handle to the audio in the view-process.
577        /// The handle can be upgraded on hook only, after it is dropped. This is so the
578        /// latest event does not keep the audio alive indefinitely.
579        pub handle: WeakViewAudioHandle,
580        /// Audio data.
581        pub audio: WeakEq<AudioDecoded>,
582
583        ..
584
585        /// Broadcast to all widgets.
586        fn is_in_target(&self, id: WidgetId) -> bool {
587            true
588        }
589    }
590
591    /// Arguments for the [`RAW_AUDIO_DECODE_ERROR_EVENT`].
592    pub struct RawAudioDecodeErrorArgs {
593        /// Handle that identifies the audio request.
594        ///
595        /// The audio data is already removed in the view-process.
596        ///
597        /// The handle can be upgraded on hook only, after it is dropped. This is so the
598        /// latest event does not keep the audio alive indefinitely.
599        pub handle: WeakViewAudioHandle,
600        /// Error message.
601        pub error: Txt,
602
603        ..
604
605        /// Broadcast to all widgets.
606        fn is_in_target(&self, id: WidgetId) -> bool {
607            true
608        }
609    }
610
611    /// Arguments for the [`RAW_AUDIO_OUTPUT_OPEN_EVENT`].
612    pub struct RawAudioOutputOpenArgs {
613        /// Output that finished opening.
614        pub output_id: AudioOutputId,
615
616        /// Live connection to audio output stream.
617        ///
618        /// The handle can be upgraded on hook only, after it is dropped. This is so the
619        /// latest event does not keep the image audio indefinitely.
620        pub output: WeakViewAudioOutput,
621
622        ..
623
624        /// Broadcast to all widgets.
625        fn is_in_target(&self, id: WidgetId) -> bool {
626            true
627        }
628    }
629
630    /// Arguments for the [`RAW_AUDIO_OUTPUT_OPEN_ERROR_EVENT`].
631    pub struct RawAudioOutputOpenErrorArgs {
632        /// Output that failed to open.
633        pub output_id: AudioOutputId,
634        /// Error opening output.
635        pub error: Txt,
636
637        ..
638
639        /// Broadcast to all widgets.
640        fn is_in_target(&self, id: WidgetId) -> bool {
641            true
642        }
643    }
644
645    /// [`RAW_FONT_CHANGED_EVENT`] arguments.
646    pub struct RawFontChangedArgs {
647
648        ..
649
650        /// Broadcast to all widgets.
651        fn is_in_target(&self, id: WidgetId) -> bool {
652            true
653        }
654    }
655
656    /// Arguments for the [`RAW_FONT_AA_CHANGED_EVENT`].
657    pub struct RawFontAaChangedArgs {
658        /// The new anti-aliasing config.
659        pub aa: FontAntiAliasing,
660
661        ..
662
663        /// Broadcast to all widgets.
664        fn is_in_target(&self, id: WidgetId) -> bool {
665            true
666        }
667    }
668
669    /// Arguments for the [`RAW_MULTI_CLICK_CONFIG_CHANGED_EVENT`].
670    pub struct RawMultiClickConfigChangedArgs {
671        /// New config.
672        pub config: MultiClickConfig,
673
674        ..
675
676        /// Broadcast to all widgets.
677        fn is_in_target(&self, id: WidgetId) -> bool {
678            true
679        }
680    }
681
682    /// Arguments for the [`RAW_ANIMATIONS_CONFIG_CHANGED_EVENT`].
683    pub struct RawAnimationsConfigChangedArgs {
684        /// New config.
685        pub config: AnimationsConfig,
686
687        ..
688
689        /// Broadcast to all widgets.
690        fn is_in_target(&self, id: WidgetId) -> bool {
691            true
692        }
693    }
694
695    /// Arguments for the [`RAW_KEY_REPEAT_CONFIG_CHANGED_EVENT`].
696    pub struct RawKeyRepeatConfigChangedArgs {
697        /// New config.
698        pub config: KeyRepeatConfig,
699
700        ..
701
702        /// Broadcast to all widgets.
703        fn is_in_target(&self, id: WidgetId) -> bool {
704            true
705        }
706    }
707
708    /// Arguments for the [`RAW_TOUCH_CONFIG_CHANGED_EVENT`].
709    pub struct RawTouchConfigChangedArgs {
710        /// New config.
711        pub config: TouchConfig,
712
713        ..
714
715        /// Broadcast to all widgets.
716        fn is_in_target(&self, id: WidgetId) -> bool {
717            true
718        }
719    }
720
721    /// Arguments for the [`RAW_LOCALE_CONFIG_CHANGED_EVENT`].
722    pub struct RawLocaleChangedArgs {
723        /// New config.
724        pub config: LocaleConfig,
725
726        ..
727
728        /// Broadcast to all widgets.
729        fn is_in_target(&self, id: WidgetId) -> bool {
730            true
731        }
732    }
733
734    /// Arguments for the [`RAW_COLORS_CONFIG_CHANGED_EVENT`].
735    pub struct RawColorsConfigChangedArgs {
736        /// New config.
737        pub config: ColorsConfig,
738
739        ..
740
741        /// Broadcast to all widgets.
742        fn is_in_target(&self, id: WidgetId) -> bool {
743            true
744        }
745    }
746
747    /// Arguments for the [`RAW_EXTENSION_EVENT`].
748    pub struct RawExtensionEventArgs {
749        /// Id of the sender extension.
750        pub extension_id: ApiExtensionId,
751        /// Event payload.
752        pub payload: ApiExtensionPayload,
753
754        ..
755
756        /// Broadcast to all widgets.
757        fn is_in_target(&self, id: WidgetId) -> bool {
758            true
759        }
760    }
761
762    /// Arguments for [`LOW_MEMORY_EVENT`].
763    pub struct LowMemoryArgs {
764
765        ..
766
767        /// Broadcast to all widgets.
768        fn is_in_target(&self, id: WidgetId) -> bool {
769            true
770        }
771    }
772}
773
774/// Arguments for the [`RAW_WINDOW_CHANGED_EVENT`].
775#[derive(Debug, Clone, PartialEq)]
776pub struct RawWindowChangedArgs {
777    /// Window that has moved, resized or has a state change.
778    pub window_id: WindowId,
779
780    /// New state if any part of it has changed.
781    pub state: Option<WindowStateAll>,
782
783    /// New window position if it was moved.
784    ///
785    /// The values are `(global_position, position_in_monitor)`.
786    pub position: Option<(PxPoint, DipPoint)>,
787
788    /// New window monitor.
789    ///
790    /// The window's monitor change when it is moved enough so that most of the
791    /// client area is in the new monitor screen.
792    pub monitor: Option<MonitorId>,
793
794    /// New window size if it was resized.
795    pub size: Option<DipSize>,
796
797    /// New window safe padding.
798    pub safe_padding: Option<DipSideOffsets>,
799
800    /// If the app or operating system caused the change.
801    pub cause: EventCause,
802
803    /// If the view-process is blocking the event loop for a time waiting for a frame for the new `size` this
804    /// ID must be send with the frame to signal that it is the frame for the new size.
805    ///
806    /// Event loop implementations can use this to resize without visible artifacts
807    /// like the clear color flashing on the window corners, there is a timeout to this delay but it
808    /// can be a noticeable stutter, a [`render`] or [`render_update`] request for the window unblocks the loop early
809    /// to continue the resize operation.
810    ///
811    /// [`render`]: crate::view_process::ViewRenderer::render
812    /// [`render_update`]: crate::view_process::ViewRenderer::render_update
813    pub frame_wait_id: Option<FrameWaitId>,
814
815    /// New window scale factor, if it changed.
816    pub scale_factor: Option<Factor>,
817
818    /// New window refresh rate, if it changed.
819    pub refresh_rate: Option<Frequency>,
820
821    #[doc = r" Instant the event happened."]
822    pub timestamp: crate::DInstant,
823    #[doc = r" Propagation handle associated with this event instance."]
824    #[doc = r""]
825    #[doc = r" Cloned arguments share the same handle, some arguments may also share the handle"]
826    #[doc = r" of another event if they share the same cause."]
827    pub propagation: crate::event::EventPropagationHandle,
828}
829impl RawWindowChangedArgs {
830    #[doc = r" New args from values that convert [into](Into) the argument types."]
831    #[allow(clippy::too_many_arguments)]
832    pub fn new(
833        timestamp: impl Into<crate::DInstant>,
834        propagation: crate::event::EventPropagationHandle,
835        window_id: impl Into<WindowId>,
836        state: impl Into<Option<WindowStateAll>>,
837        position: impl Into<Option<(PxPoint, DipPoint)>>,
838        monitor: impl Into<Option<MonitorId>>,
839        size: impl Into<Option<DipSize>>,
840        safe_padding: impl Into<Option<DipSideOffsets>>,
841        cause: impl Into<EventCause>,
842        frame_wait_id: impl Into<Option<FrameWaitId>>,
843    ) -> Self {
844        RawWindowChangedArgs {
845            timestamp: timestamp.into(),
846            window_id: window_id.into(),
847            state: state.into(),
848            position: position.into(),
849            monitor: monitor.into(),
850            size: size.into(),
851            safe_padding: safe_padding.into(),
852            scale_factor: None,
853            refresh_rate: None,
854            cause: cause.into(),
855            frame_wait_id: frame_wait_id.into(),
856            propagation,
857        }
858    }
859    #[doc = r" Arguments for event that happened now (`INSTANT.now`)."]
860    #[allow(clippy::too_many_arguments)]
861    pub fn now(
862        window_id: impl Into<WindowId>,
863        state: impl Into<Option<WindowStateAll>>,
864        position: impl Into<Option<(PxPoint, DipPoint)>>,
865        monitor: impl Into<Option<MonitorId>>,
866        size: impl Into<Option<DipSize>>,
867        safe_padding: impl Into<Option<DipSideOffsets>>,
868        cause: impl Into<EventCause>,
869        frame_wait_id: impl Into<Option<FrameWaitId>>,
870    ) -> Self {
871        Self::new(
872            crate::INSTANT.now(),
873            crate::event::EventPropagationHandle::new(),
874            window_id,
875            state,
876            position,
877            monitor,
878            size,
879            safe_padding,
880            cause,
881            frame_wait_id,
882        )
883    }
884}
885impl crate::event::AnyEventArgs for RawWindowChangedArgs {
886    fn timestamp(&self) -> crate::DInstant {
887        self.timestamp
888    }
889    #[doc = r" Broadcast to all widgets."]
890    fn is_in_target(&self, id: crate::widget::WidgetId) -> bool {
891        let _ = id;
892        true
893    }
894    fn propagation(&self) -> &crate::event::EventPropagationHandle {
895        &self.propagation
896    }
897    fn clone_boxed(&self) -> std::boxed::Box<dyn crate::event::AnyEventArgs> {
898        Box::new(self.clone())
899    }
900}
901impl crate::event::EventArgs for RawWindowChangedArgs {}
902
903event! {
904    /// A key press or release targeting a window.
905    ///
906    /// This event represents a key input directly from the operating system. It is processed
907    /// by `KeyboardManager` to generate the `KEY_INPUT_EVENT` that actually targets the focused widget.
908    ///
909    /// *See also the [module level documentation](self) for details of how you can fake this event*
910    pub static RAW_KEY_INPUT_EVENT: RawKeyInputArgs;
911
912    /// An IME event was received by a window.
913    pub static RAW_IME_EVENT: RawImeArgs;
914
915    /// A window received or lost focus.
916    pub static RAW_WINDOW_FOCUS_EVENT: RawWindowFocusArgs;
917
918    /// A window was moved, resized or has a state change.
919    ///
920    /// This event aggregates events moves, resizes and other state changes into a
921    /// single event to simplify tracking composite changes, for example, the window changes size and position
922    /// when maximized, this can be trivially observed with this event.
923    pub static RAW_WINDOW_CHANGED_EVENT: RawWindowChangedArgs;
924
925    /// A frame finished rendering and was presented in a window.
926    pub static RAW_FRAME_RENDERED_EVENT: RawFrameRenderedArgs;
927
928    /// A window has finished initializing in the view-process.
929    pub static RAW_WINDOW_OPEN_EVENT: RawWindowOpenArgs;
930
931    /// A headless surface has finished initializing in the view-process.
932    pub static RAW_HEADLESS_OPEN_EVENT: RawHeadlessOpenArgs;
933
934    /// A window or headless surface initialization failed in the view-process.
935    pub static RAW_WINDOW_OR_HEADLESS_OPEN_ERROR_EVENT: RawWindowOrHeadlessOpenErrorArgs;
936
937    /// A window was requested to close.
938    pub static RAW_WINDOW_CLOSE_REQUESTED_EVENT: RawWindowCloseRequestedArgs;
939
940    /// A window was destroyed.
941    pub static RAW_WINDOW_CLOSE_EVENT: RawWindowCloseArgs;
942
943    /// Data was dragged over a window.
944    pub static RAW_DRAG_HOVERED_EVENT: RawDragHoveredArgs;
945
946    /// Data dragging over the window has moved.
947    pub static RAW_DRAG_MOVED_EVENT: RawDragMovedArgs;
948
949    /// Data was drag-dropped on a window.
950    pub static RAW_DRAG_DROPPED_EVENT: RawDragDroppedArgs;
951
952    /// Data was dragged away from the window or the operation was cancelled.
953    pub static RAW_DRAG_CANCELLED_EVENT: RawDragCancelledArgs;
954
955    /// Drag & drop operation started by the app has dropped or was cancelled.
956    pub static RAW_APP_DRAG_ENDED_EVENT: RawAppDragEndedArgs;
957
958    /// Mouse pointer moved over a window.
959    pub static RAW_MOUSE_MOVED_EVENT: RawMouseMovedArgs;
960
961    /// Mouse pointer started hovering a window.
962    pub static RAW_MOUSE_ENTERED_EVENT: RawMouseArgs;
963
964    /// Mouse pointer stopped hovering a window.
965    pub static RAW_MOUSE_LEFT_EVENT: RawMouseArgs;
966
967    /// Mouse wheel scrolled when the mouse was over a window.
968    pub static RAW_MOUSE_WHEEL_EVENT: RawMouseWheelArgs;
969
970    /// Mouse button was pressed or released when the mouse was over a window.
971    pub static RAW_MOUSE_INPUT_EVENT: RawMouseInputArgs;
972
973    /// Touchpad touched when the mouse was over a window.
974    pub static RAW_TOUCHPAD_PRESSURE_EVENT: RawTouchpadPressureArgs;
975
976    /// Motion on some analog axis send to a window.
977    pub static RAW_AXIS_MOTION_EVENT: RawAxisMotionArgs;
978
979    /// A window was touched.
980    pub static RAW_TOUCH_EVENT: RawTouchArgs;
981
982    /// Pixel scale factor for a monitor screen and its windows has changed.
983    ///
984    /// This can happen if the user change the screen settings. Note that a
985    /// window's scale factor can also change if it is moved to a different monitor,
986    /// this change can be monitored using [`RAW_WINDOW_CHANGED_EVENT`].
987    #[deprecated = "use RAW_MONITORS_CHANGED_EVENT"]
988    pub static RAW_SCALE_FACTOR_CHANGED_EVENT: RawScaleFactorChangedArgs;
989
990    /// Monitors added, removed or modified.
991    pub static RAW_MONITORS_CHANGED_EVENT: RawMonitorsChangedArgs;
992
993    /// Color scheme or accent color preference changed for a window.
994    pub static RAW_COLORS_CONFIG_CHANGED_EVENT: RawColorsConfigChangedArgs;
995
996    /// Change in system font anti-aliasing config.
997    pub static RAW_FONT_AA_CHANGED_EVENT: RawFontAaChangedArgs;
998
999    /// Change in system text fonts, install or uninstall.
1000    pub static RAW_FONT_CHANGED_EVENT: RawFontChangedArgs;
1001
1002    /// Change in system "double-click" config.
1003    pub static RAW_MULTI_CLICK_CONFIG_CHANGED_EVENT: RawMultiClickConfigChangedArgs;
1004
1005    /// Change in system animation enabled config.
1006    pub static RAW_ANIMATIONS_CONFIG_CHANGED_EVENT: RawAnimationsConfigChangedArgs;
1007
1008    /// Change in system key repeat interval config.
1009    pub static RAW_KEY_REPEAT_CONFIG_CHANGED_EVENT: RawKeyRepeatConfigChangedArgs;
1010
1011    /// Change in system touch config.
1012    pub static RAW_TOUCH_CONFIG_CHANGED_EVENT: RawTouchConfigChangedArgs;
1013
1014    /// Change in system locale config.
1015    pub static RAW_LOCALE_CONFIG_CHANGED_EVENT: RawLocaleChangedArgs;
1016
1017    /// Image metadata loaded.
1018    pub static RAW_IMAGE_METADATA_DECODED_EVENT: RawImageMetadataDecodedArgs;
1019
1020    /// Image loaded without errors.
1021    pub static RAW_IMAGE_DECODED_EVENT: RawImageDecodedArgs;
1022
1023    /// Image failed to load.
1024    pub static RAW_IMAGE_DECODE_ERROR_EVENT: RawImageDecodeErrorArgs;
1025
1026    /// Audio metadata loaded.
1027    pub static RAW_AUDIO_METADATA_DECODED_EVENT: RawAudioMetadataDecodedArgs;
1028
1029    /// Audio loaded without errors.
1030    pub static RAW_AUDIO_DECODED_EVENT: RawAudioDecodedArgs;
1031
1032    /// Image failed to load.
1033    pub static RAW_AUDIO_DECODE_ERROR_EVENT: RawAudioDecodeErrorArgs;
1034
1035    /// Audio output stream opened.
1036    pub static RAW_AUDIO_OUTPUT_OPEN_EVENT: RawAudioOutputOpenArgs;
1037
1038    /// Audio output stream failed to open.
1039    pub static RAW_AUDIO_OUTPUT_OPEN_ERROR_EVENT: RawAudioOutputOpenErrorArgs;
1040
1041    /// System low memory warning, some platforms may kill the app if it does not release memory.
1042    pub static LOW_MEMORY_EVENT: LowMemoryArgs;
1043
1044    /// Custom view-process extension event.
1045    pub static RAW_EXTENSION_EVENT: RawExtensionEventArgs;
1046}