[vlc-commits] [Git][videolan/vlc][master] 8 commits: input: add input event for mouse click

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Dec 12 09:49:29 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
bde56b27 by Ayush Dey at 2024-12-12T09:35:44+00:00
input: add input event for mouse click

Store mouse data in struct vlc_input_event_mouse. This will be used
to forward the mouse event to the player.

- - - - -
56577f26 by Ayush Dey at 2024-12-12T09:35:44+00:00
player: receive and handle mouse click event

Implement handling of the INPUT_EVENT_MOUSE event in the player
to toggle play/pause functionality.

- - - - -
4dd962d4 by Ayush Dey at 2024-12-12T09:35:44+00:00
input: add oldmouse data member to store previous mouse state

- - - - -
384d6d31 by Ayush Dey at 2024-12-12T09:35:44+00:00
input: add default mouse click handler

Initialize a default mouse click handler that forwards events to the player.
Allow it to be overridden in specific cases, such as mkv, dvdnav, and bluray.

- - - - -
102e095d by Ayush Dey at 2024-12-12T09:35:44+00:00
vlc_mouse: add data member to check filters listening to mouse events

Add a new data member, b_mouse_filter, in the vlc_mouse_t structure.
This member will be set whenever a filter is listening to mouse events.

- - - - -
741cd4a6 by Ayush Dey at 2024-12-12T09:35:44+00:00
input: disable player event when a filter is listening to mouse events

- - - - -
c4076d30 by Ayush Dey at 2024-12-12T09:35:44+00:00
filter_chain: add function to check for interactive video filters

Add a function to determine if the filter chain includes any video
filters that listen for mouse events.

- - - - -
f30b631f by Ayush Dey at 2024-12-12T09:35:44+00:00
vout: modify mouse object for interactive filters

Set the b_mouse_filter member of the mouse object if any interactive
video filter is enabled. This prevents mouse event from propagating
to the player, disabling the play/pause toggling while an interactive
mouse filter is active.

- - - - -


8 changed files:

- include/vlc_filter.h
- include/vlc_mouse.h
- src/input/es_out.c
- src/input/input_internal.h
- src/libvlccore.sym
- src/misc/filter_chain.c
- src/player/input.c
- src/video_output/video_output.c


Changes:

=====================================
include/vlc_filter.h
=====================================
@@ -585,6 +585,15 @@ VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
  */
 VLC_API bool filter_chain_IsEmpty(const filter_chain_t *chain);
 
+/**
+ * Checks whether the filter chain contains any video filters listening to
+ * mouse events.
+ *
+ * \param chain pointer to filter chain
+ * \return true if at least one filter listens to mouse events
+ */
+VLC_API bool filter_chain_HasMouseFilter( const filter_chain_t *chain );
+
 /**
  * Get last output format of the last element in the filter chain.
  *


=====================================
include/vlc_mouse.h
=====================================
@@ -50,6 +50,8 @@ typedef struct vlc_mouse_t
     int i_pressed;
     /* Is double clicked */
     bool b_double_click;
+    /* Has filter listening to mouse events */
+    bool b_mouse_filter;
 } vlc_mouse_t;
 
 /**
@@ -66,6 +68,7 @@ static inline void vlc_mouse_Init( vlc_mouse_t *p_mouse )
     p_mouse->i_y = 0;
     p_mouse->i_pressed = 0;
     p_mouse->b_double_click = false;
+    p_mouse->b_mouse_filter = false;
 }
 
 /* */
@@ -86,6 +89,12 @@ static inline void vlc_mouse_SetPosition( vlc_mouse_t *p_mouse,
     p_mouse->i_y = i_y;
 }
 
+static inline void vlc_mouse_SetMouseFilter( vlc_mouse_t *p_mouse,
+                                             bool mouse_filter )
+{
+    p_mouse->b_mouse_filter = mouse_filter;
+}
+
 /* */
 static inline bool vlc_mouse_IsPressed( const vlc_mouse_t *p_mouse,
                                         int i_button )
@@ -151,5 +160,9 @@ static inline bool vlc_mouse_HasReleased( const vlc_mouse_t *p_old,
     const int i_mask = 1 << i_button;
     return (p_old->i_pressed & i_mask) && (p_new->i_pressed & i_mask) == 0;
 }
+static inline bool vlc_mouse_HasMouseFilter( const vlc_mouse_t *p_mouse )
+{
+    return p_mouse->b_mouse_filter;
+}
 #endif /* _VLC_MOUSE_H */
 


=====================================
src/input/es_out.c
=====================================
@@ -157,6 +157,7 @@ struct es_out_id_t
 
     vlc_mouse_event mouse_event_cb;
     void* mouse_event_userdata;
+    vlc_mouse_t oldmouse;
 };
 
 typedef struct
@@ -325,6 +326,35 @@ default_val:
     for( int fetes_i=0; fetes_i<2; fetes_i++ ) \
         vlc_list_foreach( pos, (!fetes_i ? &p_sys->es : &p_sys->es_slaves), node )
 
+static void MouseEventCb(const vlc_mouse_t *newmouse, void *userdata)
+{
+    es_out_id_t *id = userdata;
+    struct vlc_input_es_out *out = id->out;
+    es_out_sys_t *p_sys = PRIV(&out->out);
+
+    if(!p_sys->p_input)
+        return;
+
+    /* player event is disabled when a filter is listening to mouse events */
+    if(!newmouse || vlc_mouse_HasMouseFilter(newmouse))
+    {
+        vlc_mouse_Init(&id->oldmouse);
+        return;
+    }
+
+    struct vlc_input_event_mouse event = {
+        .oldmouse = id->oldmouse,
+        .newmouse = *newmouse
+    };
+
+    input_SendEvent(p_sys->p_input, &(struct vlc_input_event) {
+        .type = INPUT_EVENT_MOUSE,
+        .mouse_data = event,
+    });
+
+    id->oldmouse = *newmouse;
+}
+
 static void
 decoder_on_vout_started(vlc_input_decoder_t *decoder, vout_thread_t *vout,
                       enum vlc_vout_order order, void *userdata)
@@ -2190,8 +2220,9 @@ static es_out_id_t *EsOutAddLocked(es_out_sys_t *p_sys,
     es->master = false;
     vlc_vector_init(&es->sub_es_vec);
     es->p_master = p_master;
-    es->mouse_event_cb = NULL;
-    es->mouse_event_userdata = NULL;
+    vlc_mouse_Init(&es->oldmouse);
+    es->mouse_event_cb = MouseEventCb;
+    es->mouse_event_userdata = es;
     es->i_pts_level = VLC_TICK_INVALID;
     es->delay = VLC_TICK_MAX;
 
@@ -3605,9 +3636,14 @@ static int EsOutVaControlLocked(es_out_sys_t *p_sys, input_source_t *source,
         p_es->mouse_event_cb = va_arg( args, vlc_mouse_event );
         p_es->mouse_event_userdata = va_arg( args, void * );
 
-        if( p_es->p_dec )
+        if( p_es->p_dec && p_es->mouse_event_cb )
             vlc_input_decoder_SetVoutMouseEvent( p_es->p_dec,
                 p_es->mouse_event_cb, p_es->mouse_event_userdata );
+        else /* fallback to player event */
+        {
+            p_es->mouse_event_cb = MouseEventCb;
+            p_es->mouse_event_userdata = p_es;
+        }
 
         return VLC_SUCCESS;
     }


=====================================
src/input/input_internal.h
=====================================
@@ -25,6 +25,7 @@
 
 #include <vlc_demux.h>
 #include <vlc_input.h>
+#include <vlc_mouse.h>
 #include "input_interface.h"
 #include "../misc/interrupt.h"
 #include "./source.h"
@@ -149,6 +150,9 @@ typedef enum input_event_type_e
 
     /* The demux is not able to navigate */
     INPUT_EVENT_NAV_FAILED,
+
+    /* Mouse event */
+    INPUT_EVENT_MOUSE,
 } input_event_type_e;
 
 #define VLC_INPUT_CAPABILITIES_SEEKABLE (1<<0)
@@ -271,6 +275,12 @@ struct vlc_input_event_attachments
     size_t count;
 };
 
+struct vlc_input_event_mouse
+{
+    vlc_mouse_t oldmouse;
+    vlc_mouse_t newmouse;
+};
+
 struct vlc_input_event
 {
     input_event_type_e type;
@@ -318,6 +328,8 @@ struct vlc_input_event
         struct vlc_input_event_attachments attachments;
         /* INPUT_EVENT_NAV_FAILED */
         int nav_type;
+        /* INPUT_EVENT_MOUSE */
+        struct vlc_input_event_mouse mouse_data;
     };
 };
 


=====================================
src/libvlccore.sym
=====================================
@@ -125,6 +125,7 @@ filter_chain_DeleteFilter
 filter_chain_GetFmtOut
 filter_chain_GetVideoCtxOut
 filter_chain_IsEmpty
+filter_chain_HasMouseFilter
 filter_chain_MouseFilter
 filter_chain_NewVideo
 filter_chain_Reset


=====================================
src/misc/filter_chain.c
=====================================
@@ -465,6 +465,19 @@ bool filter_chain_IsEmpty(const filter_chain_t *chain)
     return vlc_list_is_empty( &chain->filter_list );
 }
 
+bool filter_chain_HasMouseFilter( const filter_chain_t *chain )
+{
+    const chained_filter_t *f;
+    vlc_list_foreach_const( f, &chain->filter_list, node )
+    {
+        const filter_t *p_filter = &f->filter;
+
+        if( p_filter->ops->video_mouse )
+            return true;
+    }
+    return false;
+}
+
 const es_format_t *filter_chain_GetFmtOut( const filter_chain_t *p_chain )
 {
     chained_filter_t *last =


=====================================
src/player/input.c
=====================================
@@ -856,6 +856,16 @@ vlc_player_input_NavigationFallback(struct vlc_player_input *input, int nav_type
     }
 }
 
+static void
+vlc_player_input_MouseFallback(struct vlc_player_input *input,
+                               const struct vlc_input_event_mouse *ev)
+{
+    vlc_player_t *player = input->player;
+
+    if (vlc_mouse_HasPressed(&ev->oldmouse, &ev->newmouse, MOUSE_BUTTON_LEFT))
+        vlc_player_TogglePause(player);
+}
+
 static void
 input_thread_Events(input_thread_t *input_thread,
                     const struct vlc_input_event *event, void *user_data)
@@ -1035,6 +1045,9 @@ input_thread_Events(input_thread_t *input_thread,
         case INPUT_EVENT_NAV_FAILED:
             vlc_player_input_NavigationFallback(input, event->nav_type);
             break;
+        case INPUT_EVENT_MOUSE:
+            vlc_player_input_MouseFallback(input, &event->mouse_data);
+            break;
         default:
             break;
     }


=====================================
src/video_output/video_output.c
=====================================
@@ -316,6 +316,10 @@ void vout_FilterMouse(vout_thread_t *vout, vlc_mouse_t *mouse)
         if (!filter_chain_MouseFilter(sys->filter.chain_static,
                                       &tmp[1], m))
             m = &tmp[1];
+
+        bool has_mouse_filter = filter_chain_HasMouseFilter(sys->filter.chain_interactive) ||
+                                filter_chain_HasMouseFilter(sys->filter.chain_static);
+        vlc_mouse_SetMouseFilter(m, has_mouse_filter);
     }
     vlc_mutex_unlock(&sys->filter.lock);
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1883d4bdae2714cdecf13730b8fd96b6fc2d7190...f30b631fe0784caa312fd6b74d30a20f8bfad533

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1883d4bdae2714cdecf13730b8fd96b6fc2d7190...f30b631fe0784caa312fd6b74d30a20f8bfad533
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list