2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2021-12-23 14:25:20 +00:00
|
|
|
use std::mem;
|
2017-12-10 09:57:11 +00:00
|
|
|
|
2023-01-04 16:11:27 +00:00
|
|
|
use glib::{translate::*, ToSendValue};
|
2023-01-03 18:58:25 +00:00
|
|
|
use gst::EventType;
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
use crate::NavigationModifierType;
|
2023-01-03 18:58:25 +00:00
|
|
|
use crate::{NavigationCommand, NavigationEventType};
|
2022-03-15 13:18:08 +00:00
|
|
|
|
2017-12-10 10:26:16 +00:00
|
|
|
// FIXME: Copy from gstreamer/src/event.rs
|
|
|
|
macro_rules! event_builder_generic_impl {
|
|
|
|
($new_fn:expr) => {
|
|
|
|
pub fn seqnum(self, seqnum: gst::Seqnum) -> Self {
|
|
|
|
Self {
|
|
|
|
seqnum: Some(seqnum),
|
2020-04-24 09:46:16 +00:00
|
|
|
..self
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn running_time_offset(self, running_time_offset: i64) -> Self {
|
|
|
|
Self {
|
|
|
|
running_time_offset: Some(running_time_offset),
|
2020-04-24 09:46:16 +00:00
|
|
|
..self
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
pub fn other_fields(
|
|
|
|
self,
|
|
|
|
other_fields: &[(&'a str, &'a (dyn ToSendValue + Sync))],
|
|
|
|
) -> Self {
|
2017-12-10 10:26:16 +00:00
|
|
|
Self {
|
2020-04-24 09:46:16 +00:00
|
|
|
other_fields: self
|
|
|
|
.other_fields
|
|
|
|
.iter()
|
|
|
|
.cloned()
|
2017-12-10 10:26:16 +00:00
|
|
|
.chain(other_fields.iter().cloned())
|
|
|
|
.collect(),
|
2020-04-24 09:46:16 +00:00
|
|
|
..self
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "Building the event without using it has no effect"]
|
2023-08-22 07:00:35 +00:00
|
|
|
#[allow(clippy::redundant_closure_call)]
|
2017-12-10 10:26:16 +00:00
|
|
|
pub fn build(mut self) -> gst::Event {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2017-12-10 10:26:16 +00:00
|
|
|
unsafe {
|
|
|
|
let event = $new_fn(&mut self);
|
|
|
|
if let Some(seqnum) = self.seqnum {
|
2021-04-27 15:15:46 +00:00
|
|
|
gst::ffi::gst_event_set_seqnum(event, seqnum.into_glib());
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(running_time_offset) = self.running_time_offset {
|
2020-11-22 09:53:17 +00:00
|
|
|
gst::ffi::gst_event_set_running_time_offset(event, running_time_offset);
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let s = gst::StructureRef::from_glib_borrow_mut(
|
2020-11-22 09:53:17 +00:00
|
|
|
gst::ffi::gst_event_writable_structure(event),
|
2017-12-10 10:26:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
for (k, v) in self.other_fields {
|
|
|
|
s.set_value(k, v.to_send_value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
from_glib_full(event)
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 09:46:16 +00:00
|
|
|
};
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "The builder must be built to be used"]
|
2017-12-10 10:26:16 +00:00
|
|
|
pub struct DownstreamForceKeyUnitEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
2021-04-20 07:19:02 +00:00
|
|
|
other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>,
|
2021-04-28 22:29:13 +00:00
|
|
|
timestamp: Option<gst::ClockTime>,
|
|
|
|
stream_time: Option<gst::ClockTime>,
|
|
|
|
running_time: Option<gst::ClockTime>,
|
2017-12-10 10:26:16 +00:00
|
|
|
all_headers: bool,
|
|
|
|
count: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> DownstreamForceKeyUnitEventBuilder<'a> {
|
2017-12-10 20:43:28 +00:00
|
|
|
fn new() -> Self {
|
2017-12-10 10:26:16 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
2021-04-28 22:29:13 +00:00
|
|
|
timestamp: gst::ClockTime::NONE,
|
|
|
|
stream_time: gst::ClockTime::NONE,
|
|
|
|
running_time: gst::ClockTime::NONE,
|
2017-12-10 20:43:28 +00:00
|
|
|
all_headers: true,
|
|
|
|
count: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn timestamp(self, timestamp: impl Into<Option<gst::ClockTime>>) -> Self {
|
|
|
|
Self {
|
|
|
|
timestamp: timestamp.into(),
|
|
|
|
..self
|
|
|
|
}
|
2017-12-10 20:43:28 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn stream_time(self, stream_time: impl Into<Option<gst::ClockTime>>) -> Self {
|
2017-12-10 20:43:28 +00:00
|
|
|
Self {
|
2021-04-28 22:29:13 +00:00
|
|
|
stream_time: stream_time.into(),
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn running_time(self, running_time: impl Into<Option<gst::ClockTime>>) -> Self {
|
2017-12-10 20:43:28 +00:00
|
|
|
Self {
|
2021-04-28 22:29:13 +00:00
|
|
|
running_time: running_time.into(),
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all_headers(self, all_headers: bool) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
all_headers,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn count(self, count: u32) -> Self {
|
2018-07-27 10:36:40 +00:00
|
|
|
Self { count, ..self }
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
2017-12-10 10:26:16 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
event_builder_generic_impl!(|s: &mut Self| {
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_event_new_downstream_force_key_unit(
|
2021-04-27 15:15:46 +00:00
|
|
|
s.timestamp.into_glib(),
|
|
|
|
s.stream_time.into_glib(),
|
|
|
|
s.running_time.into_glib(),
|
|
|
|
s.all_headers.into_glib(),
|
2017-12-10 10:26:16 +00:00
|
|
|
s.count,
|
|
|
|
)
|
2019-03-19 07:58:20 +00:00
|
|
|
});
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct DownstreamForceKeyUnitEvent {
|
2021-04-28 22:29:13 +00:00
|
|
|
pub timestamp: Option<gst::ClockTime>,
|
|
|
|
pub stream_time: Option<gst::ClockTime>,
|
|
|
|
pub running_time: Option<gst::ClockTime>,
|
2017-12-10 09:57:11 +00:00
|
|
|
pub all_headers: bool,
|
|
|
|
pub count: u32,
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:22:25 +00:00
|
|
|
impl DownstreamForceKeyUnitEvent {
|
|
|
|
pub fn builder<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> {
|
2022-12-25 10:47:02 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-06-25 16:22:25 +00:00
|
|
|
DownstreamForceKeyUnitEventBuilder::new()
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_event_parse_downstream_force_key_unit")]
|
2021-04-29 20:49:40 +00:00
|
|
|
pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
|
2020-06-25 16:22:25 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let mut timestamp = mem::MaybeUninit::uninit();
|
|
|
|
let mut stream_time = mem::MaybeUninit::uninit();
|
|
|
|
let mut running_time = mem::MaybeUninit::uninit();
|
|
|
|
let mut all_headers = mem::MaybeUninit::uninit();
|
|
|
|
let mut count = mem::MaybeUninit::uninit();
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let res: bool = from_glib(ffi::gst_video_event_parse_downstream_force_key_unit(
|
|
|
|
event.as_mut_ptr(),
|
|
|
|
timestamp.as_mut_ptr(),
|
|
|
|
stream_time.as_mut_ptr(),
|
|
|
|
running_time.as_mut_ptr(),
|
|
|
|
all_headers.as_mut_ptr(),
|
|
|
|
count.as_mut_ptr(),
|
|
|
|
));
|
2020-06-25 16:22:25 +00:00
|
|
|
if res {
|
2021-04-29 20:49:40 +00:00
|
|
|
Ok(Self {
|
2020-06-25 16:22:25 +00:00
|
|
|
timestamp: from_glib(timestamp.assume_init()),
|
|
|
|
stream_time: from_glib(stream_time.assume_init()),
|
|
|
|
running_time: from_glib(running_time.assume_init()),
|
|
|
|
all_headers: from_glib(all_headers.assume_init()),
|
|
|
|
count: count.assume_init(),
|
|
|
|
})
|
|
|
|
} else {
|
2020-12-17 22:38:06 +00:00
|
|
|
Err(glib::bool_error!("Failed to parse GstEvent"))
|
2020-06-25 16:22:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "The builder must be built to be used"]
|
2017-12-10 10:26:16 +00:00
|
|
|
pub struct UpstreamForceKeyUnitEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
2021-04-20 07:19:02 +00:00
|
|
|
other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>,
|
2021-04-28 22:29:13 +00:00
|
|
|
running_time: Option<gst::ClockTime>,
|
2017-12-10 10:26:16 +00:00
|
|
|
all_headers: bool,
|
|
|
|
count: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> UpstreamForceKeyUnitEventBuilder<'a> {
|
2017-12-10 20:43:28 +00:00
|
|
|
fn new() -> Self {
|
2017-12-10 10:26:16 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
2021-04-28 22:29:13 +00:00
|
|
|
running_time: gst::ClockTime::NONE,
|
2017-12-10 20:43:28 +00:00
|
|
|
all_headers: true,
|
|
|
|
count: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn running_time(self, running_time: impl Into<Option<gst::ClockTime>>) -> Self {
|
2017-12-10 20:43:28 +00:00
|
|
|
Self {
|
2021-04-28 22:29:13 +00:00
|
|
|
running_time: running_time.into(),
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all_headers(self, all_headers: bool) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
all_headers,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn count(self, count: u32) -> Self {
|
2018-07-27 10:36:40 +00:00
|
|
|
Self { count, ..self }
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
2017-12-10 10:26:16 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
event_builder_generic_impl!(|s: &mut Self| {
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_event_new_upstream_force_key_unit(
|
2021-04-27 15:15:46 +00:00
|
|
|
s.running_time.into_glib(),
|
|
|
|
s.all_headers.into_glib(),
|
2017-12-10 10:26:16 +00:00
|
|
|
s.count,
|
|
|
|
)
|
2019-03-19 07:58:20 +00:00
|
|
|
});
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct UpstreamForceKeyUnitEvent {
|
2021-04-28 22:29:13 +00:00
|
|
|
pub running_time: Option<gst::ClockTime>,
|
2017-12-10 09:57:11 +00:00
|
|
|
pub all_headers: bool,
|
|
|
|
pub count: u32,
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:22:25 +00:00
|
|
|
impl UpstreamForceKeyUnitEvent {
|
|
|
|
pub fn builder<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> {
|
2022-12-25 10:47:02 +00:00
|
|
|
assert_initialized_main_thread!();
|
2020-06-25 16:22:25 +00:00
|
|
|
UpstreamForceKeyUnitEventBuilder::new()
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_event_parse_upstream_force_key_unit")]
|
2021-04-29 20:49:40 +00:00
|
|
|
pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
|
2020-06-25 16:22:25 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let mut running_time = mem::MaybeUninit::uninit();
|
|
|
|
let mut all_headers = mem::MaybeUninit::uninit();
|
|
|
|
let mut count = mem::MaybeUninit::uninit();
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let res: bool = from_glib(ffi::gst_video_event_parse_upstream_force_key_unit(
|
|
|
|
event.as_mut_ptr(),
|
|
|
|
running_time.as_mut_ptr(),
|
|
|
|
all_headers.as_mut_ptr(),
|
|
|
|
count.as_mut_ptr(),
|
|
|
|
));
|
2020-06-25 16:22:25 +00:00
|
|
|
if res {
|
2021-04-29 20:49:40 +00:00
|
|
|
Ok(Self {
|
2020-06-25 16:22:25 +00:00
|
|
|
running_time: from_glib(running_time.assume_init()),
|
|
|
|
all_headers: from_glib(all_headers.assume_init()),
|
|
|
|
count: count.assume_init(),
|
|
|
|
})
|
|
|
|
} else {
|
2020-12-17 22:38:06 +00:00
|
|
|
Err(glib::bool_error!("Failed to parse GstEvent"))
|
2020-06-25 16:22:25 +00:00
|
|
|
}
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub enum ForceKeyUnitEvent {
|
|
|
|
Downstream(DownstreamForceKeyUnitEvent),
|
|
|
|
Upstream(UpstreamForceKeyUnitEvent),
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:22:25 +00:00
|
|
|
impl ForceKeyUnitEvent {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_event_is_force_key_unit")]
|
2020-06-25 16:22:25 +00:00
|
|
|
pub fn is(event: &gst::EventRef) -> bool {
|
|
|
|
skip_assert_initialized!();
|
2020-11-22 09:53:17 +00:00
|
|
|
unsafe { from_glib(ffi::gst_video_event_is_force_key_unit(event.as_mut_ptr())) }
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 20:49:40 +00:00
|
|
|
pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
|
2020-06-25 16:22:25 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
if event.is_upstream() {
|
2021-04-29 20:49:40 +00:00
|
|
|
UpstreamForceKeyUnitEvent::parse(event).map(Self::Upstream)
|
2020-06-25 16:22:25 +00:00
|
|
|
} else {
|
2021-04-29 20:49:40 +00:00
|
|
|
DownstreamForceKeyUnitEvent::parse(event).map(Self::Downstream)
|
2020-06-25 16:22:25 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-03 23:17:29 +00:00
|
|
|
#[must_use = "The builder must be built to be used"]
|
2017-12-10 10:26:16 +00:00
|
|
|
pub struct StillFrameEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
2021-04-20 07:19:02 +00:00
|
|
|
other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>,
|
2017-12-10 10:26:16 +00:00
|
|
|
in_still: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> StillFrameEventBuilder<'a> {
|
|
|
|
fn new(in_still: bool) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
2018-07-20 07:21:06 +00:00
|
|
|
in_still,
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
event_builder_generic_impl!(|s: &mut Self| ffi::gst_video_event_new_still_frame(
|
2021-04-27 15:15:46 +00:00
|
|
|
s.in_still.into_glib()
|
2020-11-22 09:53:17 +00:00
|
|
|
));
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct StillFrameEvent {
|
|
|
|
pub in_still: bool,
|
|
|
|
}
|
|
|
|
|
2020-06-25 16:22:25 +00:00
|
|
|
impl StillFrameEvent {
|
|
|
|
pub fn builder<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
StillFrameEventBuilder::new(in_still)
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_video_event_parse_still_frame")]
|
2021-04-29 20:49:40 +00:00
|
|
|
pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
|
2020-06-25 16:22:25 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let mut in_still = mem::MaybeUninit::uninit();
|
|
|
|
|
2020-11-22 09:53:17 +00:00
|
|
|
let res: bool = from_glib(ffi::gst_video_event_parse_still_frame(
|
2020-06-25 16:22:25 +00:00
|
|
|
event.as_mut_ptr(),
|
|
|
|
in_still.as_mut_ptr(),
|
|
|
|
));
|
|
|
|
if res {
|
2021-04-29 20:49:40 +00:00
|
|
|
Ok(Self {
|
2020-06-25 16:22:25 +00:00
|
|
|
in_still: from_glib(in_still.assume_init()),
|
|
|
|
})
|
|
|
|
} else {
|
2020-12-17 22:38:06 +00:00
|
|
|
Err(glib::bool_error!("Invalid still-frame event"))
|
2020-06-25 16:22:25 +00:00
|
|
|
}
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
|
2022-03-24 14:58:57 +00:00
|
|
|
macro_rules! nav_event_builder {
|
|
|
|
($builder:ident, $($event_field:ident: $event_type:ty,)? [$( $field_names:ident : $field_types:ty),*], $new_fn: expr) => {
|
|
|
|
#[must_use = "The builder must be built to be used"]
|
|
|
|
pub struct $builder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
|
|
|
other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>,
|
|
|
|
$($field_names: $field_types,)*
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
$($event_field: $event_type,)?
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> $builder<'a> {
|
2022-12-25 10:47:02 +00:00
|
|
|
fn new($($event_field: $event_type)?) -> Self {
|
2022-03-24 14:58:57 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
|
|
|
$($field_names: <$field_types>::default(),)*
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
$($event_field,)?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(pub fn $field_names(self, $field_names: $field_types) -> Self {
|
|
|
|
Self { $field_names, ..self }
|
|
|
|
})*
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn modifier_state(self, modifier_state: NavigationModifierType) -> Self {
|
|
|
|
Self { modifier_state, ..self }
|
|
|
|
}
|
|
|
|
|
|
|
|
event_builder_generic_impl!($new_fn);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum KeyEventType<'a> {
|
|
|
|
Press { key: &'a str },
|
|
|
|
Release { key: &'a str },
|
|
|
|
}
|
|
|
|
|
|
|
|
nav_event_builder!(
|
|
|
|
KeyEventBuilder,
|
|
|
|
kind: KeyEventType<'a>,
|
|
|
|
[],
|
|
|
|
|s: &mut Self| {
|
|
|
|
let event = match s.kind {
|
|
|
|
KeyEventType::Press { key } => NavigationEvent::KeyPress {
|
|
|
|
key: key.to_owned(),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
KeyEventType::Release { key } => NavigationEvent::KeyRelease {
|
|
|
|
key: key.to_owned(),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
};
|
2023-01-04 16:11:27 +00:00
|
|
|
gst::ffi::gst_event_new_navigation(event.structure().into_glib_ptr())
|
2022-03-24 14:58:57 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
pub enum MouseEventType {
|
|
|
|
Move,
|
|
|
|
Press {
|
|
|
|
button: i32,
|
|
|
|
},
|
|
|
|
Release {
|
|
|
|
button: i32,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
Scroll {
|
|
|
|
delta_x: f64,
|
|
|
|
delta_y: f64,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
nav_event_builder!(
|
|
|
|
MouseEventBuilder,
|
|
|
|
kind: MouseEventType,
|
|
|
|
[x: f64, y: f64],
|
|
|
|
|s: &mut Self| {
|
|
|
|
let event = match s.kind {
|
|
|
|
MouseEventType::Move => NavigationEvent::MouseMove {
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
MouseEventType::Press { button } => NavigationEvent::MouseButtonPress {
|
|
|
|
button,
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
MouseEventType::Release { button } => NavigationEvent::MouseButtonRelease {
|
|
|
|
button,
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
MouseEventType::Scroll { delta_x, delta_y } => NavigationEvent::MouseScroll {
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
};
|
2023-01-04 16:11:27 +00:00
|
|
|
gst::ffi::gst_event_new_navigation(event.structure().into_glib_ptr())
|
2022-03-24 14:58:57 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
#[must_use = "The builder must be built to be used"]
|
|
|
|
pub struct CommandEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
|
|
|
other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>,
|
|
|
|
command: NavigationCommand,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> CommandEventBuilder<'a> {
|
2022-12-25 10:47:02 +00:00
|
|
|
fn new(command: NavigationCommand) -> Self {
|
2022-03-24 14:58:57 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
|
|
|
command,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn modifier_state(self, modifier_state: NavigationModifierType) -> Self {
|
|
|
|
Self {
|
|
|
|
modifier_state,
|
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event_builder_generic_impl!(|s: &mut Self| {
|
|
|
|
let event = NavigationEvent::Command {
|
|
|
|
command: s.command,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
};
|
2023-01-04 16:11:27 +00:00
|
|
|
gst::ffi::gst_event_new_navigation(event.structure().into_glib_ptr())
|
2022-03-24 14:58:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub enum TouchEventType {
|
|
|
|
Down { pressure: f64 },
|
|
|
|
Motion { pressure: f64 },
|
|
|
|
Up,
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
nav_event_builder!(
|
|
|
|
TouchEventBuilder,
|
|
|
|
kind: TouchEventType,
|
|
|
|
[identifier: u32, x: f64, y: f64],
|
|
|
|
|s: &mut Self| {
|
|
|
|
let event = match s.kind {
|
|
|
|
TouchEventType::Down { pressure } => NavigationEvent::TouchDown {
|
|
|
|
identifier: s.identifier,
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
pressure,
|
|
|
|
},
|
|
|
|
TouchEventType::Motion { pressure } => NavigationEvent::TouchMotion {
|
|
|
|
identifier: s.identifier,
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
pressure,
|
|
|
|
},
|
|
|
|
TouchEventType::Up => NavigationEvent::TouchUp {
|
|
|
|
identifier: s.identifier,
|
|
|
|
x: s.x,
|
|
|
|
y: s.y,
|
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
};
|
2023-01-04 16:11:27 +00:00
|
|
|
gst::ffi::gst_event_new_navigation(event.structure().into_glib_ptr())
|
2022-03-24 14:58:57 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub enum TouchMetaEventType {
|
|
|
|
Frame,
|
|
|
|
Cancel,
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
nav_event_builder!(
|
|
|
|
TouchMetaEventBuilder,
|
|
|
|
kind: TouchMetaEventType,
|
|
|
|
[],
|
|
|
|
|s: &mut Self| {
|
|
|
|
let event = match s.kind {
|
|
|
|
TouchMetaEventType::Frame => NavigationEvent::TouchFrame {
|
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
TouchMetaEventType::Cancel => NavigationEvent::TouchCancel {
|
|
|
|
modifier_state: s.modifier_state,
|
|
|
|
},
|
|
|
|
};
|
2023-01-04 16:11:27 +00:00
|
|
|
gst::ffi::gst_event_new_navigation(event.structure().into_glib_ptr())
|
2022-03-24 14:58:57 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-12-23 14:25:20 +00:00
|
|
|
const NAVIGATION_EVENT_NAME: &str = "application/x-gst-navigation";
|
2022-09-12 16:32:16 +00:00
|
|
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
|
|
|
#[cfg_attr(feature = "serde", serde(tag = "event"))]
|
2021-12-22 01:26:20 +00:00
|
|
|
#[derive(Clone, PartialEq, Debug)]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub enum NavigationEvent {
|
|
|
|
KeyPress {
|
|
|
|
key: String,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
|
|
|
KeyRelease {
|
|
|
|
key: String,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
|
|
|
MouseMove {
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
|
|
|
MouseButtonPress {
|
|
|
|
button: i32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
|
|
|
MouseButtonRelease {
|
|
|
|
button: i32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
|
|
|
Command {
|
|
|
|
command: NavigationCommand,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2021-12-23 14:25:20 +00:00
|
|
|
MouseScroll {
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
delta_x: f64,
|
|
|
|
delta_y: f64,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
TouchDown {
|
|
|
|
identifier: u32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
pressure: f64,
|
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
TouchMotion {
|
|
|
|
identifier: u32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
pressure: f64,
|
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
TouchUp {
|
|
|
|
identifier: u32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
TouchFrame {
|
|
|
|
modifier_state: NavigationModifierType,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
TouchCancel {
|
|
|
|
modifier_state: NavigationModifierType,
|
2021-12-23 14:25:20 +00:00
|
|
|
},
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-23 14:25:20 +00:00
|
|
|
impl NavigationEvent {
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_key_press")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_key_press(key: &str) -> NavigationEvent {
|
2021-12-22 01:26:20 +00:00
|
|
|
assert_initialized_main_thread!();
|
2021-12-23 14:25:20 +00:00
|
|
|
Self::KeyPress {
|
|
|
|
key: key.to_string(),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_key_release")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_key_release(key: &str) -> NavigationEvent {
|
2021-12-22 01:26:20 +00:00
|
|
|
assert_initialized_main_thread!();
|
2021-12-23 14:25:20 +00:00
|
|
|
Self::KeyRelease {
|
|
|
|
key: key.to_string(),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_mouse_move")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_mouse_move(x: f64, y: f64) -> NavigationEvent {
|
2021-12-22 01:26:20 +00:00
|
|
|
assert_initialized_main_thread!();
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::MouseMove {
|
|
|
|
x,
|
|
|
|
y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_mouse_button_press")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_mouse_button_press(button: i32, x: f64, y: f64) -> NavigationEvent {
|
2021-12-22 01:26:20 +00:00
|
|
|
assert_initialized_main_thread!();
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::MouseButtonPress {
|
|
|
|
button,
|
|
|
|
x,
|
|
|
|
y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_mouse_button_release")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_mouse_button_release(button: i32, x: f64, y: f64) -> NavigationEvent {
|
2021-12-22 01:26:20 +00:00
|
|
|
assert_initialized_main_thread!();
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::MouseButtonRelease {
|
|
|
|
button,
|
|
|
|
x,
|
|
|
|
y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_mouse_scroll")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_mouse_scroll(x: f64, y: f64, delta_x: f64, delta_y: f64) -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Self::MouseScroll {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
2021-12-23 14:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 13:25:30 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_command")]
|
2021-12-23 14:25:20 +00:00
|
|
|
pub fn new_command(command: NavigationCommand) -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::Command {
|
|
|
|
command,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_touch_down")]
|
|
|
|
pub fn new_touch_down(identifier: u32, x: f64, y: f64, pressure: f64) -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Self::TouchDown {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pressure,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_touch_motion")]
|
|
|
|
pub fn new_touch_motion(identifier: u32, x: f64, y: f64, pressure: f64) -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Self::TouchMotion {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pressure,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_touch_up")]
|
|
|
|
pub fn new_touch_up(identifier: u32, x: f64, y: f64) -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Self::TouchUp {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_touch_frame")]
|
|
|
|
pub fn new_touch_frame() -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Self::TouchFrame {
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_new_touch_cancel")]
|
|
|
|
pub fn new_touch_cancel() -> NavigationEvent {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
Self::TouchCancel {
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state: NavigationModifierType::empty(),
|
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn key_press_builder(key: &str) -> KeyEventBuilder {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
KeyEventBuilder::new(KeyEventType::Press { key })
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn key_release_builder(key: &str) -> KeyEventBuilder {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
KeyEventBuilder::new(KeyEventType::Release { key })
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mouse_move_builder(x: f64, y: f64) -> MouseEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
MouseEventBuilder::new(MouseEventType::Move {}).x(x).y(y)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mouse_button_press_builder(button: i32, x: f64, y: f64) -> MouseEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
MouseEventBuilder::new(MouseEventType::Press { button })
|
|
|
|
.x(x)
|
|
|
|
.y(y)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mouse_button_release_builder(button: i32, x: f64, y: f64) -> MouseEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
MouseEventBuilder::new(MouseEventType::Press { button })
|
|
|
|
.x(x)
|
|
|
|
.y(y)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn mouse_scroll_builder(
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
delta_x: f64,
|
|
|
|
delta_y: f64,
|
|
|
|
) -> MouseEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
MouseEventBuilder::new(MouseEventType::Scroll { delta_x, delta_y })
|
|
|
|
.x(x)
|
|
|
|
.y(y)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn command_builder(command: NavigationCommand) -> CommandEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
CommandEventBuilder::new(command)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn touch_down_builder(
|
|
|
|
identifier: u32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
pressure: f64,
|
|
|
|
) -> TouchEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
TouchEventBuilder::new(TouchEventType::Down { pressure })
|
|
|
|
.identifier(identifier)
|
|
|
|
.x(x)
|
|
|
|
.y(y)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn touch_motion_builder(
|
|
|
|
identifier: u32,
|
|
|
|
x: f64,
|
|
|
|
y: f64,
|
|
|
|
pressure: f64,
|
|
|
|
) -> TouchEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
TouchEventBuilder::new(TouchEventType::Motion { pressure })
|
|
|
|
.identifier(identifier)
|
|
|
|
.x(x)
|
|
|
|
.y(y)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn touch_up_builder(identifier: u32, x: f64, y: f64) -> TouchEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
TouchEventBuilder::new(TouchEventType::Up)
|
|
|
|
.identifier(identifier)
|
|
|
|
.x(x)
|
|
|
|
.y(y)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn touch_frame_builder() -> TouchMetaEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
TouchMetaEventBuilder::new(TouchMetaEventType::Frame)
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-24 14:58:57 +00:00
|
|
|
pub fn touch_cancel_builder() -> TouchMetaEventBuilder<'static> {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
TouchMetaEventBuilder::new(TouchMetaEventType::Cancel)
|
|
|
|
}
|
|
|
|
|
2021-12-22 01:26:20 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_get_type")]
|
|
|
|
pub fn type_(event: &gst::EventRef) -> NavigationEventType {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2021-12-22 01:26:20 +00:00
|
|
|
unsafe { from_glib(ffi::gst_navigation_event_get_type(event.as_mut_ptr())) }
|
|
|
|
}
|
|
|
|
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_parse_key_event")]
|
2021-12-23 14:25:20 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_parse_mouse_button_event")]
|
|
|
|
#[doc(alias = "gst_navigation_event_parse_mouse_scroll_event")]
|
|
|
|
#[doc(alias = "gst_navigation_event_parse_mouse_move_event")]
|
2022-03-15 13:18:08 +00:00
|
|
|
#[doc(alias = "gst_navigation_event_parse_touch_event")]
|
|
|
|
#[doc(alias = "gst_navigation_event_parse_touch_up_event")]
|
|
|
|
#[doc(alias = "gst_navigation_event_parse_command")]
|
2021-12-22 01:26:20 +00:00
|
|
|
pub fn parse(event: &gst::EventRef) -> Result<Self, glib::error::BoolError> {
|
|
|
|
skip_assert_initialized!();
|
2022-03-15 13:18:08 +00:00
|
|
|
if event.type_() != EventType::Navigation {
|
|
|
|
return Err(glib::bool_error!("Invalid navigation event"));
|
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
|
2021-12-23 14:25:20 +00:00
|
|
|
let structure = event
|
|
|
|
.structure()
|
2022-03-15 13:18:08 +00:00
|
|
|
.ok_or_else(|| glib::bool_error!("Invalid navigation event"))?;
|
|
|
|
if structure.name() != NAVIGATION_EVENT_NAME {
|
|
|
|
return Err(glib::bool_error!("Invalid navigation event"));
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
let modifier_state = structure
|
|
|
|
.get("state")
|
|
|
|
.unwrap_or(NavigationModifierType::empty());
|
|
|
|
let event = match Self::type_(event) {
|
|
|
|
NavigationEventType::MouseMove => NavigationEvent::MouseMove {
|
|
|
|
x: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
y: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
|
|
|
NavigationEventType::MouseButtonPress => NavigationEvent::MouseButtonPress {
|
|
|
|
button: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("button")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
x: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
y: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
|
|
|
NavigationEventType::MouseButtonRelease => NavigationEvent::MouseButtonRelease {
|
|
|
|
button: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("button")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
x: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
y: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
NavigationEventType::MouseScroll => NavigationEvent::MouseScroll {
|
|
|
|
x: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
y: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
delta_x: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("delta_pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2022-03-15 13:18:08 +00:00
|
|
|
delta_y: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("delta_pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
|
|
|
NavigationEventType::KeyPress => NavigationEvent::KeyPress {
|
|
|
|
key: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("key")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid key press event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
|
|
|
NavigationEventType::KeyRelease => NavigationEvent::KeyRelease {
|
|
|
|
key: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("key")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid key press event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
|
|
|
NavigationEventType::Command => NavigationEvent::Command {
|
|
|
|
command: structure
|
2021-12-23 14:25:20 +00:00
|
|
|
.get("command-code")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid key press event"))?,
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
modifier_state,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
NavigationEventType::TouchDown => NavigationEvent::TouchDown {
|
|
|
|
identifier: structure
|
|
|
|
.get("identifier")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
x: structure
|
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
y: structure
|
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
pressure: structure
|
|
|
|
.get("pressure")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
modifier_state,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
NavigationEventType::TouchMotion => NavigationEvent::TouchMotion {
|
|
|
|
identifier: structure
|
|
|
|
.get("identifier")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
x: structure
|
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
y: structure
|
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
pressure: structure
|
|
|
|
.get("pressure")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
modifier_state,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
NavigationEventType::TouchUp => NavigationEvent::TouchUp {
|
|
|
|
identifier: structure
|
|
|
|
.get("identifier")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
x: structure
|
|
|
|
.get("pointer_x")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
y: structure
|
|
|
|
.get("pointer_y")
|
|
|
|
.map_err(|_| glib::bool_error!("Invalid touch event"))?,
|
|
|
|
modifier_state,
|
|
|
|
},
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
NavigationEventType::TouchFrame => NavigationEvent::TouchFrame { modifier_state },
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
NavigationEventType::TouchCancel => NavigationEvent::TouchCancel { modifier_state },
|
2021-12-23 14:25:20 +00:00
|
|
|
NavigationEventType::Invalid | NavigationEventType::__Unknown(_) => {
|
|
|
|
return Err(glib::bool_error!("Invalid navigation event"))
|
|
|
|
}
|
2022-03-15 13:18:08 +00:00
|
|
|
};
|
|
|
|
Ok(event)
|
2021-12-23 14:25:20 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 14:47:54 +00:00
|
|
|
pub fn structure(&self) -> gst::Structure {
|
2021-12-23 14:25:20 +00:00
|
|
|
skip_assert_initialized!();
|
2022-03-15 13:18:08 +00:00
|
|
|
#[allow(unused_mut)]
|
|
|
|
let mut structure = match self {
|
|
|
|
Self::MouseMove { x, y, .. } => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
2021-12-23 14:25:20 +00:00
|
|
|
.field("event", "mouse-move")
|
|
|
|
.field("pointer_x", x)
|
2022-03-15 13:18:08 +00:00
|
|
|
.field("pointer_y", y),
|
|
|
|
Self::MouseButtonPress { button, x, y, .. } => {
|
2021-12-23 14:25:20 +00:00
|
|
|
gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
|
|
|
.field("event", "mouse-button-press")
|
|
|
|
.field("button", button)
|
|
|
|
.field("pointer_x", x)
|
|
|
|
.field("pointer_y", y)
|
|
|
|
}
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::MouseButtonRelease { button, x, y, .. } => {
|
2021-12-23 14:25:20 +00:00
|
|
|
gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
|
|
|
.field("event", "mouse-button-release")
|
|
|
|
.field("button", button)
|
|
|
|
.field("pointer_x", x)
|
|
|
|
.field("pointer_y", y)
|
|
|
|
}
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_18")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
|
2021-12-23 14:25:20 +00:00
|
|
|
Self::MouseScroll {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
2022-03-15 13:18:08 +00:00
|
|
|
..
|
2021-12-23 14:25:20 +00:00
|
|
|
} => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
|
|
|
.field("event", "mouse-scroll")
|
|
|
|
.field("pointer_x", x)
|
|
|
|
.field("pointer_y", y)
|
|
|
|
.field("delta_pointer_x", delta_x)
|
2022-03-15 13:18:08 +00:00
|
|
|
.field("delta_pointer_y", delta_y),
|
|
|
|
Self::KeyPress { key, .. } => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
2021-12-23 14:25:20 +00:00
|
|
|
.field("event", "key-press")
|
2022-03-15 13:18:08 +00:00
|
|
|
.field("key", key),
|
|
|
|
Self::KeyRelease { key, .. } => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
2021-12-23 14:25:20 +00:00
|
|
|
.field("event", "key-release")
|
2022-03-15 13:18:08 +00:00
|
|
|
.field("key", key),
|
|
|
|
Self::Command { command, .. } => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
2021-12-23 14:25:20 +00:00
|
|
|
.field("event", "command")
|
2022-03-15 13:18:08 +00:00
|
|
|
.field("command-code", command),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::TouchDown {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pressure,
|
|
|
|
..
|
|
|
|
} => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
|
|
|
.field("event", "touch-down")
|
|
|
|
.field("identifier", identifier)
|
|
|
|
.field("pointer_x", x)
|
|
|
|
.field("pointer_y", y)
|
|
|
|
.field("pressure", pressure),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::TouchMotion {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pressure,
|
|
|
|
..
|
|
|
|
} => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
|
|
|
.field("event", "touch-motion")
|
|
|
|
.field("identifier", identifier)
|
|
|
|
.field("pointer_x", x)
|
|
|
|
.field("pointer_y", y)
|
|
|
|
.field("pressure", pressure),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::TouchUp {
|
|
|
|
identifier, x, y, ..
|
|
|
|
} => gst::Structure::builder(NAVIGATION_EVENT_NAME)
|
|
|
|
.field("event", "touch-up")
|
|
|
|
.field("identifier", identifier)
|
|
|
|
.field("pointer_x", x)
|
|
|
|
.field("pointer_y", y),
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::TouchFrame { .. } => {
|
|
|
|
gst::Structure::builder(NAVIGATION_EVENT_NAME).field("event", "touch-frame")
|
|
|
|
}
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2022-03-15 13:18:08 +00:00
|
|
|
Self::TouchCancel { .. } => {
|
|
|
|
gst::Structure::builder(NAVIGATION_EVENT_NAME).field("event", "touch-cancel")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
2022-03-15 13:18:08 +00:00
|
|
|
if true {
|
|
|
|
structure = match self {
|
|
|
|
Self::MouseMove { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::MouseButtonPress { modifier_state, .. } => {
|
|
|
|
structure.field("state", modifier_state)
|
|
|
|
}
|
|
|
|
Self::MouseButtonRelease { modifier_state, .. } => {
|
|
|
|
structure.field("state", modifier_state)
|
|
|
|
}
|
|
|
|
Self::MouseScroll { modifier_state, .. } => {
|
|
|
|
structure.field("state", modifier_state)
|
|
|
|
}
|
|
|
|
Self::KeyPress { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::KeyRelease { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::Command { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::TouchDown { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::TouchMotion { modifier_state, .. } => {
|
|
|
|
structure.field("state", modifier_state)
|
|
|
|
}
|
|
|
|
Self::TouchUp { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::TouchFrame { modifier_state, .. } => structure.field("state", modifier_state),
|
|
|
|
Self::TouchCancel { modifier_state, .. } => {
|
|
|
|
structure.field("state", modifier_state)
|
|
|
|
}
|
|
|
|
};
|
2021-12-27 14:47:54 +00:00
|
|
|
}
|
2022-03-15 13:18:08 +00:00
|
|
|
|
|
|
|
structure.build()
|
2021-12-27 14:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build(&self) -> gst::Event {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
|
|
|
|
gst::event::Navigation::new(self.structure())
|
2021-12-23 14:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
2022-09-12 16:32:16 +00:00
|
|
|
#[cfg(feature = "serde")]
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_22")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
|
2021-12-23 14:25:20 +00:00
|
|
|
fn serialize_navigation_events() {
|
2022-04-01 15:30:14 +00:00
|
|
|
use crate::{NavigationEvent, NavigationModifierType};
|
2021-12-23 14:25:20 +00:00
|
|
|
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
2022-04-01 15:30:14 +00:00
|
|
|
let mods = NavigationModifierType::SHIFT_MASK | NavigationModifierType::CONTROL_MASK;
|
|
|
|
let ev = NavigationEvent::mouse_scroll_builder(1.0, 2.0, 3.0, 4.0)
|
|
|
|
.modifier_state(mods)
|
|
|
|
.build();
|
2021-12-23 14:25:20 +00:00
|
|
|
let navigation_event = NavigationEvent::parse(&ev).unwrap();
|
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::MouseScroll {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
2022-04-01 15:30:14 +00:00
|
|
|
modifier_state,
|
2021-12-23 14:25:20 +00:00
|
|
|
} => {
|
2022-04-01 15:30:14 +00:00
|
|
|
assert!(
|
|
|
|
*x == 1.0
|
|
|
|
&& *y == 2.0
|
|
|
|
&& *delta_x == 3.0
|
|
|
|
&& *delta_y == 4.0
|
|
|
|
&& *modifier_state == mods
|
|
|
|
);
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
let json_event = serde_json::to_string(&navigation_event).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
json_event,
|
2022-04-01 15:30:14 +00:00
|
|
|
r#"{"event":"MouseScroll","x":1.0,"y":2.0,"delta_x":3.0,"delta_y":4.0,"modifier_state":"shift-mask+control-mask"}"#
|
2021-12-23 14:25:20 +00:00
|
|
|
);
|
|
|
|
let navigation_event: NavigationEvent = serde_json::from_str(&json_event).unwrap();
|
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::MouseScroll {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
2022-04-01 15:30:14 +00:00
|
|
|
modifier_state,
|
2021-12-23 14:25:20 +00:00
|
|
|
} => {
|
2022-04-01 15:30:14 +00:00
|
|
|
assert!(
|
|
|
|
*x == 1.0
|
|
|
|
&& *y == 2.0
|
|
|
|
&& *delta_x == 3.0
|
|
|
|
&& *delta_y == 4.0
|
|
|
|
&& *modifier_state == mods
|
|
|
|
);
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
let ev = NavigationEvent::new_mouse_button_press(1, 1.0, 2.0).build();
|
|
|
|
let navigation_event = NavigationEvent::parse(&ev).unwrap();
|
|
|
|
match &navigation_event {
|
2022-04-01 15:30:14 +00:00
|
|
|
NavigationEvent::MouseButtonPress {
|
|
|
|
button,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
modifier_state,
|
|
|
|
} => {
|
|
|
|
assert!(
|
|
|
|
*button == 1
|
|
|
|
&& *x == 1.0
|
|
|
|
&& *y == 2.0
|
|
|
|
&& *modifier_state == NavigationModifierType::empty()
|
|
|
|
);
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
let json_event = serde_json::to_string(&navigation_event).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
json_event,
|
2022-04-14 15:34:42 +00:00
|
|
|
r#"{"event":"MouseButtonPress","button":1,"x":1.0,"y":2.0,"modifier_state":""}"#
|
2021-12-23 14:25:20 +00:00
|
|
|
);
|
2022-04-14 15:34:42 +00:00
|
|
|
let navigation_event: NavigationEvent = serde_json::from_str(&json_event).unwrap();
|
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::MouseButtonPress {
|
|
|
|
button,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
modifier_state,
|
|
|
|
} => {
|
|
|
|
assert!(
|
|
|
|
*button == 1
|
|
|
|
&& *x == 1.0
|
|
|
|
&& *y == 2.0
|
|
|
|
&& *modifier_state == NavigationModifierType::empty()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
|
2022-04-01 15:30:14 +00:00
|
|
|
let mods = NavigationModifierType::META_MASK;
|
|
|
|
let ev = NavigationEvent::key_release_builder("a")
|
|
|
|
.modifier_state(mods)
|
|
|
|
.build();
|
2021-12-23 14:25:20 +00:00
|
|
|
let navigation_event = NavigationEvent::parse(&ev).unwrap();
|
|
|
|
match &navigation_event {
|
2022-04-01 15:30:14 +00:00
|
|
|
NavigationEvent::KeyRelease {
|
|
|
|
key,
|
|
|
|
modifier_state,
|
|
|
|
} => {
|
|
|
|
assert!(*key == "a" && *modifier_state == mods);
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
_ => unreachable!(),
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
2021-12-23 14:25:20 +00:00
|
|
|
|
|
|
|
let json_event = serde_json::to_string(&navigation_event).unwrap();
|
2022-04-01 15:30:14 +00:00
|
|
|
assert_eq!(
|
|
|
|
json_event,
|
|
|
|
r#"{"event":"KeyRelease","key":"a","modifier_state":"meta-mask"}"#
|
|
|
|
);
|
2022-04-14 15:34:42 +00:00
|
|
|
let navigation_event: NavigationEvent = serde_json::from_str(&json_event).unwrap();
|
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::KeyRelease {
|
|
|
|
key,
|
|
|
|
modifier_state,
|
|
|
|
} => {
|
|
|
|
assert!(*key == "a" && *modifier_state == mods);
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2022-03-15 13:18:08 +00:00
|
|
|
|
|
|
|
let ev = NavigationEvent::new_touch_motion(0, 1.0, 2.0, 0.5).build();
|
|
|
|
let navigation_event = NavigationEvent::parse(&ev).unwrap();
|
|
|
|
match &navigation_event {
|
2022-04-01 15:30:14 +00:00
|
|
|
NavigationEvent::TouchMotion {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pressure,
|
|
|
|
modifier_state,
|
|
|
|
} => {
|
|
|
|
assert!(
|
|
|
|
*identifier == 0
|
|
|
|
&& *x == 1.0
|
|
|
|
&& *y == 2.0
|
|
|
|
&& *pressure == 0.5
|
|
|
|
&& *modifier_state == NavigationModifierType::empty()
|
|
|
|
);
|
2022-03-15 13:18:08 +00:00
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
let json_event = serde_json::to_string(&navigation_event).unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
json_event,
|
2022-04-14 15:34:42 +00:00
|
|
|
r#"{"event":"TouchMotion","identifier":0,"x":1.0,"y":2.0,"pressure":0.5,"modifier_state":""}"#
|
2022-03-15 13:18:08 +00:00
|
|
|
);
|
2022-04-14 15:34:42 +00:00
|
|
|
let navigation_event: NavigationEvent = serde_json::from_str(&json_event).unwrap();
|
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::TouchMotion {
|
|
|
|
identifier,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
pressure,
|
|
|
|
modifier_state,
|
|
|
|
} => {
|
|
|
|
assert!(
|
|
|
|
*identifier == 0
|
|
|
|
&& *x == 1.0
|
|
|
|
&& *y == 2.0
|
|
|
|
&& *pressure == 0.5
|
|
|
|
&& *modifier_state == NavigationModifierType::empty()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2022-03-15 13:18:08 +00:00
|
|
|
|
2022-04-01 15:30:14 +00:00
|
|
|
let ev = NavigationEvent::touch_cancel_builder().build();
|
2022-03-15 13:18:08 +00:00
|
|
|
let navigation_event = NavigationEvent::parse(&ev).unwrap();
|
2022-04-01 15:30:14 +00:00
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::TouchCancel { modifier_state } => {
|
|
|
|
assert!(*modifier_state == NavigationModifierType::empty());
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2022-03-15 13:18:08 +00:00
|
|
|
|
|
|
|
let json_event = serde_json::to_string(&navigation_event).unwrap();
|
2022-04-14 15:34:42 +00:00
|
|
|
assert_eq!(json_event, r#"{"event":"TouchCancel","modifier_state":""}"#);
|
|
|
|
let navigation_event: NavigationEvent = serde_json::from_str(&json_event).unwrap();
|
|
|
|
match &navigation_event {
|
|
|
|
NavigationEvent::TouchCancel { modifier_state } => {
|
|
|
|
assert!(*modifier_state == NavigationModifierType::empty());
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
2021-12-22 01:26:20 +00:00
|
|
|
}
|
|
|
|
}
|