gtk: Translate navigation events coordinates

If the application passed down some pointer coordinates, translate those
from display coordinates to stream coordinates, so things work as
expected even if the video is resized.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/974>
This commit is contained in:
Bastien Nocera 2021-05-05 14:28:15 +02:00 committed by GStreamer Marge Bot
parent 604278a194
commit 9cd6d02cff

View file

@ -283,6 +283,19 @@ gst_gtk_base_sink_navigation_send_event (GstNavigation * navigation,
GstGtkBaseSink *sink = GST_GTK_BASE_SINK (navigation);
GstEvent *event;
GstPad *pad;
gdouble x, y;
if (gst_structure_get_double (structure, "pointer_x", &x) &&
gst_structure_get_double (structure, "pointer_y", &y)) {
GtkGstBaseWidget *widget = gst_gtk_base_sink_get_widget (sink);
gdouble stream_x, stream_y;
gtk_gst_base_widget_display_size_to_stream_size (widget,
x, y, &stream_x, &stream_y);
gst_structure_set (structure,
"pointer_x", G_TYPE_DOUBLE, (gdouble) stream_x,
"pointer_y", G_TYPE_DOUBLE, (gdouble) stream_y, NULL);
}
event = gst_event_new_navigation (structure);
pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (sink));