[vlc-devel] [PATCH v4 23/23] display: don't use empty mouse coordinates if TranslateMouseState fails

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 21 11:59:41 CEST 2020


If there's no display module or the video placement is not done yet, don't use
0,0 coordinates as video coordinates; just use the old video coordinates.
---
 include/vlc_vout_display.h      |  2 +-
 src/video_output/display.c      |  5 ++---
 src/video_output/video_output.c | 14 +++++++++++---
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/vlc_vout_display.h b/include/vlc_vout_display.h
index b6282b052b4..fbc4886186e 100644
--- a/include/vlc_vout_display.h
+++ b/include/vlc_vout_display.h
@@ -522,7 +522,7 @@ VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_
  * video coordinates.
  * @note @c video and @c window pointers may alias.
  */
-void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
+bool vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
                                       const vlc_mouse_t *window);
 
 /** @} */
diff --git a/src/video_output/display.c b/src/video_output/display.c
index 84284e8f41d..ae273b6cdd8 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -225,7 +225,7 @@ void vout_display_PlacePicture(vout_display_place_t *place,
     }
 }
 
-void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
+bool vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
                                       const vlc_mouse_t *window)
 {
     vout_display_place_t place;
@@ -234,8 +234,7 @@ void vout_display_TranslateMouseState(vout_display_t *vd, vlc_mouse_t *video,
     vout_display_PlacePicture(&place, &vd->source, vd->cfg);
 
     if (place.width <= 0 || place.height <= 0) {
-        memset(video, 0, sizeof (*video));
-        return;
+        return false;
     }
 
     const int wx = window->i_x, wy = window->i_y;
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 041be46a28a..f16c4c57c95 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -395,10 +395,18 @@ void vout_MouseState(vout_thread_t *vout, const vlc_mouse_t *mouse)
     /* Translate window coordinates to video coordinates */
     vlc_mouse_t m;
     vlc_mutex_lock(&sys->display_lock);
-    if (sys->display)
-        vout_display_TranslateMouseState(sys->display, &m, mouse);
-    else
+
+    if (!sys->display)
         m = *mouse;
+    else if (!vout_display_TranslateMouseState(sys->display, &m, mouse))
+    {
+        // we don't have coordinates relative to the video, we shouldn't pass
+        // on the value as if they were video coordinates, keep the old values
+        // for now, when we have a functional display module we can detect
+        // video coordinates based movement based on real video coordinates
+        m.i_x = sys->mouse.i_x;
+        m.i_y = sys->mouse.i_y;
+    }
 
     bool moved = vlc_mouse_HasMoved(&sys->mouse, &m);
     bool button = vlc_mouse_HasButton(&sys->mouse, &m);
-- 
2.26.2



More information about the vlc-devel mailing list