[vlc-devel] [PATCH 2/2] core: window: handle mouse events

Rémi Denis-Courmont remi at remlab.net
Mon Nov 28 10:51:07 CET 2016


On November 28, 2016 11:40:33 AM GMT+02:00, Thomas Guillem <thomas at gllm.fr> wrote:
>
>
>On Fri, Nov 25, 2016, at 19:02, Rémi Denis-Courmont wrote:
>> Le perjantaina 25. marraskuuta 2016, 17.39.35 EET Thomas Guillem a
>écrit
>> :
>> > diff --git a/src/video_output/video_output.c
>> > b/src/video_output/video_output.c index ef111ec..00036f7 100644
>> > --- a/src/video_output/video_output.c
>> > +++ b/src/video_output/video_output.c
>> > @@ -363,6 +363,17 @@ void vout_DisplayTitle(vout_thread_t *vout,
>const char
>> > *title) vout_control_PushString(&vout->p->control,
>VOUT_CONTROL_OSD_TITLE,
>> > title); }
>> > 
>> > +void vout_WindowMouseEvent(vout_thread_t *vout,
>> > +                           const vout_window_mouse_event_t *mouse)
>> > +{
>> > +    assert(mouse);
>> > +    vout_control_cmd_t cmd;
>> > +    vout_control_cmd_Init(&cmd, VOUT_CONTROL_WINDOW_MOUSE);
>> > +    cmd.u.window_mouse = *mouse;
>> > +
>> > +    vout_control_Push(&vout->p->control, &cmd);
>> > +}
>> > +
>> >  void vout_PutSubpicture( vout_thread_t *vout, subpicture_t *subpic
>)
>> >  {
>> >      vout_control_cmd_t cmd;
>> > @@ -1261,6 +1272,48 @@ static void
>ThreadChangeWindowState(vout_thread_t
>> > *vout, unsigned state) #endif
>> >  }
>> > 
>> > +static void ThreadChangeWindowMouse(vout_thread_t *vout,
>> > +                                    const
>vout_window_mouse_event_t *mouse)
>> > +{
>> > +    vout_display_t *vd = vout->p->display.vd;
>> > +    switch (mouse->type)
>> > +    {
>> > +        case VOUT_WINDOW_MOUSE_STATE:
>> > +        case VOUT_WINDOW_MOUSE_MOVED:
>> > +        {
>> > +            vout_display_place_t place;
>> > +            vout_display_PlacePicture(&place, &vd->source,
>vd->cfg, false);
>> > +
>> > +            if (place.width <= 0 || place.height <= 0)
>> > +                return;
>> > +
>> > +            const int x = vd->source.i_x_offset +
>> > +                (int64_t)(mouse->x - place.x) *
>> > +                vd->source.i_visible_width / place.width;
>> > +            const int y = vd->source.i_y_offset +
>> > +                (int64_t)(mouse->y - place.y) *
>> > +                vd->source.i_visible_height/ place.height;
>> > +
>> > +            if (mouse->type == VOUT_WINDOW_MOUSE_STATE)
>> > +                vout_display_SendEventMouseState(vd, x, y,
>> > mouse->button_mask);
>> > +            else
>> > +                vout_display_SendEventMouseMoved(vd, x, y);
>> > +            break;
>> 
>> Did you test this with orientation other than top left? I assume 
>> PlacePicture() transparently handles it?
>
>Yes, mouse coordinates are OK, even with rotated videos.
>
>By the way, I started to handle mouse events on the Qt VideoWidget and
>removed the handling in xcb and win32. Then I discovered that only the
>display could hide mouse cursors. I think we need to put mouse cursor
>handling in vout_window too.
>
>> 
>> > +        }
>> > +        case VOUT_WINDOW_MOUSE_PRESSED:
>> > +            vout_display_SendEventMousePressed(vd,
>mouse->button_mask);
>> > +            break;
>> > +        case VOUT_WINDOW_MOUSE_RELEASED:
>> > +            vout_display_SendEventMouseReleased(vd,
>mouse->button_mask);
>> > +            break;
>> > +        case VOUT_WINDOW_MOUSE_DOUBLE_CLICK:
>> > +            vout_display_SendEventMouseDoubleClick(vd);
>> > +            break;
>> > +        default: vlc_assert_unreachable();
>> > +            break;
>> > +    }
>> > +}
>> > +
>> >  static void ThreadChangeDisplayFilled(vout_thread_t *vout, bool
>is_filled)
>> >  {
>> >      vout_SetDisplayFilled(vout->p->display.vd, is_filled);
>> > @@ -1551,6 +1604,9 @@ static int ThreadControl(vout_thread_t *vout,
>> > vout_control_cmd_t cmd) case VOUT_CONTROL_WINDOW_STATE:
>> >          ThreadChangeWindowState(vout, cmd.u.integer);
>> >          break;
>> > +    case VOUT_CONTROL_WINDOW_MOUSE:
>> > +        ThreadChangeWindowMouse(vout, &cmd.u.window_mouse);
>> > +        break;
>> >      case VOUT_CONTROL_DISPLAY_FILLED:
>> >          ThreadChangeDisplayFilled(vout, cmd.u.boolean);
>> >          break;
>> > diff --git a/src/video_output/vout_control.h
>> > b/src/video_output/vout_control.h index 0be3313..e50c096 100644
>> > --- a/src/video_output/vout_control.h
>> > +++ b/src/video_output/vout_control.h
>> > @@ -25,6 +25,8 @@
>> >  #ifndef LIBVLC_VOUT_CONTROL_H
>> >  #define LIBVLC_VOUT_CONTROL_H 1
>> > 
>> > +typedef struct vout_window_mouse_event_t
>vout_window_mouse_event_t;
>> > +
>> >  /**
>> >   * This function will (un)pause the display of pictures.
>> >   * It is thread safe
>> > @@ -69,6 +71,9 @@ void vout_NextPicture( vout_thread_t *p_vout,
>mtime_t
>> > *pi_duration ); */
>> >  void vout_DisplayTitle( vout_thread_t *p_vout, const char
>*psz_title );
>> > 
>> > +void vout_WindowMouseEvent( vout_thread_t *p_vout,
>> > +                            const vout_window_mouse_event_t *mouse
>);
>> > +
>> >  /**
>> >   * This function will return true if no more pictures are to be
>displayed.
>> >   */
>> > diff --git a/src/video_output/window.c b/src/video_output/window.c
>> > index 11ed099..76d7e5a 100644
>> > --- a/src/video_output/window.c
>> > +++ b/src/video_output/window.c
>> > @@ -164,6 +164,13 @@ static void
>vout_display_window_Event(vout_window_t
>> > *window, int type, case VOUT_WINDOW_EVENT_CLOSED:
>> >              vout_display_window_CloseNotify(window);
>> >              break;
>> > +        case VOUT_WINDOW_EVENT_MOUSE:
>> > +        {
>> > +            vout_thread_t *vout = (vout_thread_t
>*)window->obj.parent;
>> > +            vout_WindowMouseEvent(vout,
>> > +                                  va_arg(args, const
>> > vout_window_mouse_event_t*)); +            break;
>> > +        }
>> >          default: vlc_assert_unreachable();
>> >      }
>> >  }
>> 
>> 
>> -- 
>> Rémi Denis-Courmont
>> https://www.remlab.net/
>> 
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

Hi,

On X11, the cursor change should indeed be managed by the window provider. I can fix the "reference" xcb_window plugin, and the Libvlc embedded code but I won't touch Qt and skins.
-- 
Rémi Denis-Courmont


More information about the vlc-devel mailing list