[vlc-devel] [PATCH 15/16] vout: xcb: handle 360 user-interaction

Thomas Guillem thomas at gllm.fr
Wed Nov 9 18:33:09 CET 2016


These changes make sure that we handle mouse-dragging inside xcb for projection
modes that are not RECTANGULAR. We will swallow events that are to be
interpreted as viewpoint-change-requests, while making sure that others are
propagated to the core so that others can react to them.
---
 modules/video_output/xcb/events.c | 54 +++++++++++++++++++++++++++++++--------
 modules/video_output/xcb/events.h |  1 +
 2 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/modules/video_output/xcb/events.c b/modules/video_output/xcb/events.c
index 0fa5d92..9e890a4 100644
--- a/modules/video_output/xcb/events.c
+++ b/modules/video_output/xcb/events.c
@@ -31,6 +31,7 @@
 
 #include <vlc_common.h>
 #include <vlc_vout_display.h>
+#include <vlc_vout_wrapper.h>
 
 #include "events.h"
 
@@ -74,7 +75,7 @@ static vlc_xcb_handle_t Connect (vlc_object_t *obj, const char *display)
     msg_Dbg (obj, " vendor : %.*s", (int)setup->vendor_len,
              xcb_setup_vendor (setup));
     msg_Dbg (obj, " version: %"PRIu32, setup->release_number);
-    return ( vlc_xcb_handle_t ) { .conn = conn };
+    return ( vlc_xcb_handle_t ) { .conn = conn, .mouse = { } };
 }
 
 /**
@@ -175,6 +176,25 @@ xcb_cursor_t vlc_xcb_cursor_Create(vlc_xcb_handle_t *vx,
     return cur;
 }
 
+static int GetCursorCoords (vout_display_t *vd, int* x, int* y,
+                            int ev_x, int ev_y )
+{
+    /* TODO it could be saved */
+    vout_display_place_t pl;
+    vout_display_PlacePicture (&pl, &vd->source, vd->cfg, false);
+
+    if (pl.width <= 0 || pl.height <= 0)
+        return VLC_EGENERIC;
+
+    *x = vd->source.i_x_offset +
+        (int64_t)(ev_x - pl.x) * vd->source.i_visible_width / pl.width;
+
+    *y = vd->source.i_y_offset +
+        (int64_t)(ev_y - pl.y) * vd->source.i_visible_height/ pl.height;
+
+    return VLC_SUCCESS;
+}
+
 /* NOTE: we assume no other thread will be _setting_ our video output events
  * variables. Afterall, only this plugin is supposed to know when these occur.
   * Otherwise, we'd var_OrInteger() and var_NandInteger() functions...
@@ -186,6 +206,12 @@ static void HandleButtonPress (vout_display_t *vd, vlc_xcb_handle_t* vx,
 {
     VLC_UNUSED( vx );
     vout_display_SendEventMousePressed (vd, ev->detail - 1);
+
+    if( GetCursorCoords (vd, &vx->mouse.i_x, &vx->mouse.i_y,
+                             ev->event_x, ev->event_y ) )
+        return;
+
+    vx->mouse.i_pressed = 1;
 }
 
 static void HandleButtonRelease (vout_display_t *vd, vlc_xcb_handle_t* vx,
@@ -193,12 +219,12 @@ static void HandleButtonRelease (vout_display_t *vd, vlc_xcb_handle_t* vx,
 {
     VLC_UNUSED( vx );
     vout_display_SendEventMouseReleased (vd, ev->detail - 1);
+    vx->mouse.i_pressed = 0;
 }
 
 static void HandleMotionNotify (vout_display_t *vd, vlc_xcb_handle_t *vx,
                                 const xcb_motion_notify_event_t *ev)
 {
-    vout_display_place_t place;
     xcb_connection_t* conn = vx->conn;
 
     /* show the default cursor */
@@ -206,18 +232,26 @@ static void HandleMotionNotify (vout_display_t *vd, vlc_xcb_handle_t *vx,
                                   &(uint32_t) { XCB_CURSOR_NONE });
     xcb_flush (conn);
 
-    /* TODO it could be saved */
-    vout_display_PlacePicture (&place, &vd->source, vd->cfg, false);
+    int x, y;
 
-    if (place.width <= 0 || place.height <= 0)
+    if( GetCursorCoords (vd, &x, &y, ev->event_x, ev->event_y) )
         return;
 
-    const int x = vd->source.i_x_offset +
-        (int64_t)(ev->event_x - place.x) * vd->source.i_visible_width / place.width;
-    const int y = vd->source.i_y_offset +
-        (int64_t)(ev->event_y - place.y) * vd->source.i_visible_height/ place.height;
+    if( vd->fmt.projection_mode == PROJECTION_MODE_RECTANGULAR
+     || vx->mouse.i_pressed == false )
+        vout_display_SendEventMouseMoved (vd, x, y);
+    else
+    {
+        int i_horizontal = x - vx->mouse.i_x;
+        int i_vertical   = y - vx->mouse.i_y;
+
+        vout_display_UpdateViewpoint( vd, &( vlc_viewpoint_t ) {
+            .yaw   = -i_horizontal * 33,
+            .pitch = -i_vertical * 25}, false );
 
-    vout_display_SendEventMouseMoved (vd, x, y);
+        vx->mouse.i_x = x;
+        vx->mouse.i_y = y;
+    }
 }
 
 static void HandleVisibilityNotify (vout_display_t *vd, bool *visible,
diff --git a/modules/video_output/xcb/events.h b/modules/video_output/xcb/events.h
index 3f1b57f..c928577 100644
--- a/modules/video_output/xcb/events.h
+++ b/modules/video_output/xcb/events.h
@@ -31,6 +31,7 @@
 
 struct vlc_xcb_handle_t {
     xcb_connection_t* conn;
+    vlc_mouse_t mouse;
 };
 
 typedef struct vlc_xcb_handle_t vlc_xcb_handle_t;
-- 
2.9.3



More information about the vlc-devel mailing list