vulkan/window: add support for mouse/keyboard events
authorMatthew Waters <matthew@centricular.com>
Mon, 17 Feb 2020 04:03:34 +0000 (15:03 +1100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 3 Mar 2020 05:00:50 +0000 (05:00 +0000)
gst-libs/gst/vulkan/gstvkwindow.c
gst-libs/gst/vulkan/gstvkwindow.h

index d99e071..474fcfa 100644 (file)
@@ -99,6 +99,8 @@ enum
   SIGNAL_CLOSE,
   SIGNAL_DRAW,
   SIGNAL_RESIZE,
+  SIGNAL_MOUSE_EVENT,
+  SIGNAL_KEY_EVENT,
   LAST_SIGNAL
 };
 
@@ -202,6 +204,38 @@ gst_vulkan_window_class_init (GstVulkanWindowClass * klass)
       g_signal_new ("resize", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0,
       NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
 
+  /**
+   * GstVulkanWindow::mouse-event:
+   * @object: the #GstVulkanWindow
+   * @id: the name of the event
+   * @button: the id of the button
+   * @x: the x coordinate of the mouse event
+   * @y: the y coordinate of the mouse event
+   *
+   * Will be emitted when a mouse event is received by the #GstVulkanWindow.
+   *
+   * Since: 1.18
+   */
+  gst_vulkan_window_signals[SIGNAL_MOUSE_EVENT] =
+      g_signal_new ("mouse-event", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 4, G_TYPE_STRING,
+      G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+
+  /**
+   * GstVulkanWindow::key-event:
+   * @object: the #GstVulkanWindow
+   * @id: the name of the event
+   * @key: the id of the key pressed
+   *
+   * Will be emitted when a key event is received by the #GstVulkanWindow.
+   *
+   * Since: 1.18
+   */
+  gst_vulkan_window_signals[SIGNAL_KEY_EVENT] =
+      g_signal_new ("key-event", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2, G_TYPE_STRING,
+      G_TYPE_STRING);
+
   gobject_class->set_property = gst_vulkan_window_set_property;
   gobject_class->get_property = gst_vulkan_window_get_property;
   gobject_class->finalize = gst_vulkan_window_finalize;
@@ -471,6 +505,50 @@ gst_vulkan_window_get_surface_dimensions (GstVulkanWindow * window,
   }
 }
 
+void
+gst_vulkan_window_send_key_event (GstVulkanWindow * window,
+    const char *event_type, const char *key_str)
+{
+  g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
+
+  g_signal_emit (window, gst_vulkan_window_signals[SIGNAL_KEY_EVENT], 0,
+      event_type, key_str);
+}
+
+void
+gst_vulkan_window_send_mouse_event (GstVulkanWindow * window,
+    const char *event_type, int button, double posx, double posy)
+{
+  g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
+
+  g_signal_emit (window, gst_vulkan_window_signals[SIGNAL_MOUSE_EVENT], 0,
+      event_type, button, posx, posy);
+}
+
+/**
+ * gst_vulkan_window_handle_events:
+ * @window: a #GstVulkanWindow
+ * @handle_events: a #gboolean indicating if events should be handled or not.
+ *
+ * Tell a @window that it should handle events from the window system. These
+ * events are forwarded upstream as navigation events. In some window systems
+ * events are not propagated in the window hierarchy if a client is listening
+ * for them. This method allows you to disable events handling completely
+ * from the @window.
+ */
+void
+gst_vulkan_window_handle_events (GstVulkanWindow * window,
+    gboolean handle_events)
+{
+  GstVulkanWindowClass *window_class;
+
+  g_return_if_fail (GST_IS_VULKAN_WINDOW (window));
+  window_class = GST_VULKAN_WINDOW_GET_CLASS (window);
+
+  if (window_class->handle_events)
+    window_class->handle_events (window, handle_events);
+}
+
 GType gst_vulkan_dummy_window_get_type (void);
 G_DEFINE_TYPE (GstVulkanDummyWindow, gst_vulkan_dummy_window,
     GST_TYPE_VULKAN_WINDOW);
index 7e257b6..499eb35 100644 (file)
@@ -91,6 +91,8 @@ struct _GstVulkanWindowClass {
   void          (*get_surface_dimensions)       (GstVulkanWindow *window,
                                                  guint * width,
                                                  guint * height);
+  void          (*handle_events)                (GstVulkanWindow *window,
+                                                 gboolean handle_events);
 
   /*< private >*/
   gpointer _reserved[GST_PADDING];
@@ -117,6 +119,20 @@ void               gst_vulkan_window_set_window_handle              (GstVulkanWi
                                                                      guintptr handle);
 
 GST_VULKAN_API
+void                gst_vulkan_window_handle_events                 (GstVulkanWindow * window,
+                                                                     gboolean handle_events);
+GST_VULKAN_API
+void                gst_vulkan_window_send_key_event                (GstVulkanWindow * window,
+                                                                     const char * event_type,
+                                                                     const char * key_str);
+GST_VULKAN_API
+void                gst_vulkan_window_send_mouse_event              (GstVulkanWindow * window,
+                                                                     const char * event_type,
+                                                                     int button,
+                                                                     double posx,
+                                                                     double posy);
+
+GST_VULKAN_API
 gboolean           gst_vulkan_window_open                           (GstVulkanWindow *window,
                                                                      GError ** error);
 GST_VULKAN_API