[vlc-devel] [PATCH] libvlc: add API to propagate mouse move and down/up events

Felix Paul Kühne fkuehne at videolan.org
Mon May 5 22:14:36 CEST 2014


This is needed when using OSD menus with a vout which can't detect mouse movements because it doesn't have access to the window server it lives in, e.g. Android or vmem.
---
 include/vlc/libvlc_media_player.h | 36 +++++++++++++++++++++++++++++++
 lib/libvlc.sym                    |  3 +++
 lib/video.c                       | 45 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index fb91f59..43d66a5 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -951,6 +951,42 @@ void libvlc_video_set_key_input( libvlc_media_player_t *p_mi, unsigned on );
 LIBVLC_API
 void libvlc_video_set_mouse_input( libvlc_media_player_t *p_mi, unsigned on );
 
+
+/* Propagate a mouse position in coordinates relative to the video
+ *
+ * \param p_mi media player
+ * \param num number of the video (starting from, and most commonly 0)
+ * \param px to set the abscissa
+ * \param py to set the ordinate
+ * \return 0 on success, -1 if the specified video does not exist
+ * \warning it is your duty to convert screen coordinates to video coordinates
+ */
+    LIBVLC_API
+int libvlc_video_set_cursor( libvlc_media_player_t *p_mi, unsigned num,
+                             int px, int py );
+
+/* propagate a mouse down event at the last known mouse position
+ *
+ * \param p_mi media player
+ * \param num number of the video (starting from, and most commonly 0)
+ * \param buttonNumber to differenciate the clicked button
+ *        0 = left, 1 = right, >=2 = other
+ */
+LIBVLC_API
+int libvlc_video_set_mouse_down( libvlc_media_player_t *mp, unsigned num,
+                             unsigned buttonNumber );
+
+/* propagate a mouse up event at the last known mouse position
+ *
+ * \param p_mi media player
+ * \param num number of the video (starting from, and most commonly 0)
+ * \param buttonNumber to differenciate the clicked button
+ *        0 = left, 1 = right, >=2 = other
+ */
+LIBVLC_API
+int libvlc_video_set_mouse_up( libvlc_media_player_t *mp, unsigned num,
+                           unsigned buttonNumber );
+
 /**
  * Get the pixel dimensions of a video.
  *
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index fdfd164..a4ae3b9 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -225,6 +225,7 @@ libvlc_video_set_adjust_float
 libvlc_video_set_adjust_int
 libvlc_video_set_aspect_ratio
 libvlc_video_set_callbacks
+libvlc_video_set_cursor
 libvlc_video_set_crop_geometry
 libvlc_video_set_deinterlace
 libvlc_video_set_format
@@ -234,7 +235,9 @@ libvlc_video_set_logo_int
 libvlc_video_set_logo_string
 libvlc_video_set_marquee_int
 libvlc_video_set_marquee_string
+libvlc_video_set_mouse_down
 libvlc_video_set_mouse_input
+libvlc_video_set_mouse_up
 libvlc_video_set_scale
 libvlc_video_set_spu
 libvlc_video_set_spu_delay
diff --git a/lib/video.c b/lib/video.c
index 43471b9..bc4e156 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -217,6 +217,51 @@ int libvlc_video_get_cursor( libvlc_media_player_t *mp, unsigned num,
     return 0;
 }
 
+int libvlc_video_set_cursor( libvlc_media_player_t *mp, unsigned num,
+                             int px, int py )
+{
+    vout_thread_t *p_vout = GetVout (mp, num);
+    if (p_vout == NULL)
+        return -1;
+
+    var_SetCoords (p_vout, "mouse-moved", px, py);
+    vlc_object_release (p_vout);
+    return 0;
+}
+
+
+int libvlc_video_set_mouse_down( libvlc_media_player_t *mp, unsigned num,
+                              unsigned buttonNumber )
+{
+    vout_thread_t *p_vout = GetVout (mp , num);
+    if (p_vout == NULL)
+        return -1;
+
+    var_OrInteger (p_vout, "mouse-button-down", 1 << buttonNumber);
+
+    int x, y;
+    var_GetCoords (p_vout, "mouse-moved", &x, &y);
+    var_SetCoords (p_vout, "mouse-clicked", x, y);
+    vlc_object_release (p_vout);
+
+    return 0;
+}
+
+
+int libvlc_video_set_mouse_up( libvlc_media_player_t *mp, unsigned num,
+                            unsigned buttonNumber )
+{
+    vout_thread_t *p_vout = GetVout (mp , num);
+    if (p_vout == NULL)
+        return -1;
+
+    var_NAndInteger (p_vout, "mouse-button-down", 1 << buttonNumber);
+    vlc_object_release (p_vout);
+
+    return 0;
+}
+
+
 unsigned libvlc_media_player_has_vout( libvlc_media_player_t *p_mi )
 {
     size_t n;
-- 
1.8.5.2 (Apple Git-48)




More information about the vlc-devel mailing list