video: Add double click mouse event

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1435>
This commit is contained in:
Sebastian Dröge 2024-04-30 11:51:41 +03:00
parent 873aeff133
commit 01b32ce143

View file

@ -541,6 +541,11 @@ pub enum MouseEventType {
delta_x: f64,
delta_y: f64,
},
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
DoubleClick {
button: i32,
},
}
nav_event_builder!(
@ -583,6 +588,14 @@ nav_event_builder!(
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
modifier_state: s.modifier_state,
},
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
MouseEventType::DoubleClick { button } => NavigationEvent::MouseDoubleClick {
button,
x: s.x,
y: s.y,
modifier_state: s.modifier_state,
},
};
gst::ffi::gst_event_new_navigation(event.structure().into_glib_ptr())
}
@ -793,6 +806,14 @@ pub enum NavigationEvent {
TouchCancel {
modifier_state: NavigationModifierType,
},
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
MouseDoubleClick {
button: i32,
x: f64,
y: f64,
modifier_state: NavigationModifierType,
},
}
impl NavigationEvent {
@ -954,6 +975,18 @@ impl NavigationEvent {
}
}
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
#[doc(alias = "gst_navigation_event_new_mouse_double_click")]
pub fn new_mouse_double_click(button: i32, x: f64, y: f64) -> NavigationEvent {
assert_initialized_main_thread!();
Self::MouseDoubleClick {
button,
x,
y,
modifier_state: NavigationModifierType::empty(),
}
}
pub fn key_press_builder(key: &str) -> KeyEventBuilder {
assert_initialized_main_thread!();
KeyEventBuilder::new(KeyEventType::Press { key })
@ -1056,6 +1089,15 @@ impl NavigationEvent {
TouchMetaEventBuilder::new(TouchMetaEventType::Cancel)
}
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
pub fn mouse_double_click_builder(button: i32, x: f64, y: f64) -> MouseEventBuilder<'static> {
assert_initialized_main_thread!();
MouseEventBuilder::new(MouseEventType::DoubleClick { button })
.x(x)
.y(y)
}
#[doc(alias = "gst_navigation_event_get_type")]
pub fn type_(event: &gst::EventRef) -> NavigationEventType {
skip_assert_initialized!();
@ -1224,6 +1266,21 @@ impl NavigationEvent {
#[cfg(feature = "v1_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
NavigationEventType::TouchCancel => NavigationEvent::TouchCancel { modifier_state },
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
NavigationEventType::MouseDoubleClick => NavigationEvent::MouseDoubleClick {
button: structure
.get("button")
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
x: structure
.get("pointer_x")
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
y: structure
.get("pointer_y")
.map_err(|_| glib::bool_error!("Invalid mouse event"))?,
modifier_state,
},
NavigationEventType::Invalid | NavigationEventType::__Unknown(_) => {
return Err(glib::bool_error!("Invalid navigation event"))
}
@ -1323,10 +1380,19 @@ impl NavigationEvent {
Self::TouchCancel { .. } => {
gst::Structure::builder(NAVIGATION_EVENT_NAME).field("event", "touch-cancel")
}
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
Self::MouseDoubleClick { button, x, y, .. } => {
gst::Structure::builder(NAVIGATION_EVENT_NAME)
.field("event", "mouse-double-click")
.field("button", button)
.field("pointer_x", x)
.field("pointer_y", y)
}
};
#[cfg(feature = "v1_22")]
if true {
{
structure = match self {
Self::MouseMove { modifier_state, .. } => structure.field("state", modifier_state),
Self::MouseButtonPress { modifier_state, .. } => {
@ -1350,6 +1416,11 @@ impl NavigationEvent {
Self::TouchCancel { modifier_state, .. } => {
structure.field("state", modifier_state)
}
#[cfg(feature = "v1_26")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
Self::MouseDoubleClick { modifier_state, .. } => {
structure.field("state", modifier_state)
}
};
}