gl/navigation: Scroll events dispatch support
authorPhilippe Normand <philn@igalia.com>
Mon, 10 Feb 2020 18:05:01 +0000 (18:05 +0000)
committerPhilippe Normand <philn@igalia.com>
Thu, 19 Mar 2020 09:59:47 +0000 (09:59 +0000)
ext/gl/gstglimagesink.c
ext/gl/gstglimagesink.h
gst-libs/gst/gl/gstglwindow.c
gst-libs/gst/gl/gstglwindow.h

index fb70a74..a5c7571 100644 (file)
@@ -916,6 +916,17 @@ gst_glimage_sink_mouse_event_cb (GstGLWindow * window, char *event_name,
       event_name, button, posx, posy);
 }
 
+
+static void
+gst_glimage_sink_mouse_scroll_event_cb (GstGLWindow * window,
+    double posx, double posy, double delta_x, double delta_y,
+    GstGLImageSink * gl_sink)
+{
+  GST_DEBUG_OBJECT (gl_sink, "event scroll at %g, %g", posx, posy);
+  gst_navigation_send_mouse_scroll_event (GST_NAVIGATION (gl_sink),
+      posx, posy, delta_x, delta_y);
+}
+
 static gboolean
 _ensure_gl_setup (GstGLImageSink * gl_sink)
 {
@@ -991,6 +1002,9 @@ _ensure_gl_setup (GstGLImageSink * gl_sink)
       gl_sink->mouse_sig_id =
           g_signal_connect (window, "mouse-event",
           G_CALLBACK (gst_glimage_sink_mouse_event_cb), gl_sink);
+      gl_sink->mouse_scroll_sig_id =
+          g_signal_connect (window, "scroll-event",
+          G_CALLBACK (gst_glimage_sink_mouse_scroll_event_cb), gl_sink);
 
       gst_gl_window_set_render_rectangle (window, gl_sink->x, gl_sink->y,
           gl_sink->width, gl_sink->height);
@@ -1241,6 +1255,10 @@ gst_glimage_sink_change_state (GstElement * element, GstStateChange transition)
         if (glimage_sink->mouse_sig_id)
           g_signal_handler_disconnect (window, glimage_sink->mouse_sig_id);
         glimage_sink->mouse_sig_id = 0;
+        if (glimage_sink->mouse_scroll_sig_id)
+          g_signal_handler_disconnect (window,
+              glimage_sink->mouse_scroll_sig_id);
+        glimage_sink->mouse_scroll_sig_id = 0;
 
         gst_object_unref (window);
         gst_object_unref (glimage_sink->context);
@@ -2353,6 +2371,9 @@ gst_glimage_sink_on_close (GstGLImageSink * gl_sink)
   if (gl_sink->mouse_sig_id)
     g_signal_handler_disconnect (window, gl_sink->mouse_sig_id);
   gl_sink->mouse_sig_id = 0;
+  if (gl_sink->mouse_scroll_sig_id)
+    g_signal_handler_disconnect (window, gl_sink->mouse_scroll_sig_id);
+  gl_sink->mouse_scroll_sig_id = 0;
 
   g_atomic_int_set (&gl_sink->to_quit, 1);
 
index 12166ec..1a75fb9 100644 (file)
@@ -69,6 +69,7 @@ struct _GstGLImageSink
     guintptr new_window_id;
     gulong mouse_sig_id;
     gulong key_sig_id;
+    gulong mouse_scroll_sig_id;
 
     /* GstVideoOverlay::set_render_rectangle() cache */
     gint x;
index da7f498..3b5df55 100644 (file)
@@ -128,6 +128,7 @@ enum
   SIGNAL_0,
   EVENT_MOUSE_SIGNAL,
   EVENT_KEY_SIGNAL,
+  EVENT_SCROLL_SIGNAL,
   LAST_SIGNAL
 };
 
@@ -236,6 +237,24 @@ gst_gl_window_class_init (GstGLWindowClass * klass)
       G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_STRING,
       G_TYPE_STRING);
 
+  /**
+   * GstGLWindow::scroll-event:
+   * @object: the #GstGLWindow
+   * @x: the x coordinate of the mouse event
+   * @y: the y coordinate of the mouse event
+   * @delta_x: the x offset of the scroll event
+   * @delta_y: the y offset of the scroll event
+   *
+   * Will be emitted when a mouse scroll event is received by the GstGLwindow.
+   *
+   * Since: 1.18
+   */
+  gst_gl_window_signals[EVENT_SCROLL_SIGNAL] =
+      g_signal_new ("scroll-event", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
+      G_TYPE_NONE, 4, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE,
+      G_TYPE_DOUBLE);
+
   _init_debug ();
 }
 
@@ -921,6 +940,15 @@ gst_gl_window_send_mouse_event (GstGLWindow * window, const char *event_type,
       event_type, button, posx, posy);
 }
 
+void
+gst_gl_window_send_scroll_event (GstGLWindow * window,
+    double posx, double posy, double delta_x, double delta_y)
+{
+  g_signal_emit (window, gst_gl_window_signals[EVENT_SCROLL_SIGNAL], 0,
+      posx, posy, delta_x, delta_y);
+}
+
+
 /**
  * gst_gl_window_handle_events:
  * @window: a #GstGLWindow
index 562f2a5..6e70597 100644 (file)
@@ -234,6 +234,13 @@ void     gst_gl_window_send_mouse_event     (GstGLWindow * window,
                                              double posx,
                                              double posy);
 
+GST_GL_API
+void     gst_gl_window_send_scroll_event    (GstGLWindow * window,
+                                             double posx,
+                                             double posy,
+                                             double delta_x,
+                                             double delta_y);
+
 /* surfaces/rendering */
 GST_GL_API
 void     gst_gl_window_queue_resize         (GstGLWindow *window);