gestures.c 18.6 KB
Newer Older
1
/*****************************************************************************
Anil Daoud's avatar
Anil Daoud committed
2
 * gestures.c: control vlc with mouse gestures
3
 *****************************************************************************
4
 * Copyright (C) 2004-2009 the VideoLAN team
Laurent Aimar's avatar
Laurent Aimar committed
5
 * $Id$
6
 *
7
 * Authors: Sigmund Augdal Helberg <dnumgis@videolan.org>
8 9 10 11 12
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
Clément Stenac's avatar
Clément Stenac committed
13
 *
14 15 16 17 18 19 20
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include <vlc_common.h>
33
#include <vlc_plugin.h>
Clément Stenac's avatar
Clément Stenac committed
34 35
#include <vlc_interface.h>
#include <vlc_vout.h>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
36
#include <vlc_aout.h>
Clément Stenac's avatar
Clément Stenac committed
37
#include <vlc_playlist.h>
38

39 40 41 42
#ifdef HAVE_UNISTD_H
#    include <unistd.h>
#endif

43 44 45 46 47
/*****************************************************************************
 * intf_sys_t: description and status of interface
 *****************************************************************************/
struct intf_sys_t
{
48
    vlc_mutex_t         lock;
49
    vout_thread_t      *p_vout;
50 51
    bool                b_got_gesture;
    bool                b_button_pressed;
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    int                 i_mouse_x, i_mouse_y;
    int                 i_last_x, i_last_y;
    unsigned int        i_pattern;
    int                 i_num_gestures;
    int                 i_threshold;
    int                 i_button_mask;
};

/*****************************************************************************
 * Local prototypes.
 *****************************************************************************/
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define NONE 0
#define GESTURE( a, b, c, d ) (a | ( b << 4 ) | ( c << 8 ) | ( d << 12 ))

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
70 71
int  Open   ( vlc_object_t * );
void Close  ( vlc_object_t * );
72 73 74 75 76 77 78 79 80
static int  MouseEvent     ( vlc_object_t *, char const *,
                             vlc_value_t, vlc_value_t, void * );

/* Exported functions */
static void RunIntf        ( intf_thread_t *p_intf );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
Anil Daoud's avatar
Anil Daoud committed
81
#define THRESHOLD_TEXT N_( "Motion threshold (10-100)" )
82
#define THRESHOLD_LONGTEXT N_( \
83
    "Amount of movement required for a mouse gesture to be recorded." )
84

Anil Daoud's avatar
Anil Daoud committed
85
#define BUTTON_TEXT N_( "Trigger button" )
86
#define BUTTON_LONGTEXT N_( \
87
    "Trigger button for mouse gestures." )
88

89 90
static const char *const button_list[] = { "left", "middle", "right" };
static const char *const button_list_text[] =
Clément Stenac's avatar
Clément Stenac committed
91
                                   { N_("Left"), N_("Middle"), N_("Right") };
92

93 94 95 96
vlc_module_begin ()
    set_shortname( N_("Gestures"))
    set_category( CAT_INTERFACE )
    set_subcategory( SUBCAT_INTERFACE_CONTROL )
97
    add_integer( "gestures-threshold", 30, NULL,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
98
                 THRESHOLD_TEXT, THRESHOLD_LONGTEXT, true )
99
    add_string( "gestures-button", "right", NULL,
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
100
                BUTTON_TEXT, BUTTON_LONGTEXT, false )
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
101
        change_string_list( button_list, button_list_text, 0 )
102
    set_description( N_("Mouse gestures control interface") )
103

104 105 106
    set_capability( "interface", 0 )
    set_callbacks( Open, Close )
vlc_module_end ()
107 108 109 110

/*****************************************************************************
 * OpenIntf: initialize interface
 *****************************************************************************/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
111
int Open ( vlc_object_t *p_this )
112 113 114 115
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

    /* Allocate instance and initialize some members */
116
    intf_sys_t *p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
117
    if( p_intf->p_sys == NULL )
118
        return VLC_ENOMEM;
119

120
    // Configure the module
121 122
    p_intf->pf_run = RunIntf;

123
    vlc_mutex_init( &p_sys->lock );
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    p_sys->p_vout = NULL;
    p_sys->b_got_gesture = false;
    p_sys->b_button_pressed = false;
    p_sys->i_threshold = config_GetInt( p_intf, "gestures-threshold" );

    // Choose the tight button to use
    char *psz_button = config_GetPsz( p_intf, "gestures-button" );
    if( !strcmp( psz_button, "left" ) )
        p_sys->i_button_mask = 1;
    else if( !strcmp( psz_button, "middle" ) )
        p_sys->i_button_mask = 2;
    else // psz_button == "right"
        p_sys->i_button_mask = 4;
    free( psz_button );

    p_sys->i_pattern = 0;
    p_sys->i_num_gestures = 0;

142
    return VLC_SUCCESS;
143 144 145 146 147 148 149 150 151
}

/*****************************************************************************
 * gesture: return a subpattern within a pattern
 *****************************************************************************/
static int gesture( int i_pattern, int i_num )
{
    return ( i_pattern >> ( i_num * 4 ) ) & 0xF;
}
152

153 154 155
/*****************************************************************************
 * CloseIntf: destroy dummy interface
 *****************************************************************************/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
156
void Close ( vlc_object_t *p_this )
157 158 159
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;

160 161 162 163 164 165 166 167 168 169
    // Destroy the callbacks
    if( p_intf->p_sys->p_vout )
    {
        var_DelCallback( p_intf->p_sys->p_vout, "mouse-moved",
                         MouseEvent, p_intf );
        var_DelCallback( p_intf->p_sys->p_vout, "mouse-button-down",
                         MouseEvent, p_intf );
        vlc_object_release( p_intf->p_sys->p_vout );
    }

170
    /* Destroy structure */
171
    vlc_mutex_destroy( &p_intf->p_sys->lock );
172 173 174 175 176 177 178 179 180
    free( p_intf->p_sys );
}


/*****************************************************************************
 * RunIntf: main loop
 *****************************************************************************/
static void RunIntf( intf_thread_t *p_intf )
{
181
    intf_sys_t *p_sys = p_intf->p_sys;
182
    playlist_t * p_playlist = NULL;
183
    int canc = vlc_savecancel();
184
    input_thread_t *p_input;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
185

186
    /* Main loop */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
187
    while( vlc_object_alive( p_intf ) )
188
    {
189
        vlc_mutex_lock( &p_sys->lock );
190

191
        /*
192 193
         * mouse cursor
         */
194
        if( p_sys->b_got_gesture )
195
        {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
196 197
            vlc_value_t val;
            int i_interval = 0;
198
            /* Do something */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
199 200 201
            /* If you modify this, please try to follow this convention:
               Start with LEFT, RIGHT for playback related commands
               and UP, DOWN, for other commands */
202
            switch( p_sys->i_pattern )
203 204
            {
            case LEFT:
Rémi Duraffort's avatar
Rémi Duraffort committed
205
                msg_Dbg( p_intf, "Go backward in the movie!" );
206 207 208
                p_playlist = pl_Hold( p_intf );
                p_input = playlist_CurrentInput( p_playlist );
                pl_Release( p_intf );
Rémi Duraffort's avatar
Rémi Duraffort committed
209
                if( p_input )
210
                {
Rémi Duraffort's avatar
Rémi Duraffort committed
211 212 213 214 215 216 217
                    i_interval = config_GetInt( p_intf , "short-jump-size" );
                    if ( i_interval > 0 )
                    {
                        val.i_time = ( (mtime_t)( -i_interval ) * 1000000L);
                        var_Set( p_input, "time-offset", val );
                    }
                    vlc_object_release( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
218 219
                }
                break;
220

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
221
            case RIGHT:
Rémi Duraffort's avatar
Rémi Duraffort committed
222
                msg_Dbg( p_intf, "Go forward in the movie!" );
223 224 225 226
                p_playlist = pl_Hold( p_intf );
                p_input = playlist_CurrentInput( p_playlist );
                pl_Release( p_intf );

Rémi Duraffort's avatar
Rémi Duraffort committed
227
                if( p_input )
228
                {
Rémi Duraffort's avatar
Rémi Duraffort committed
229 230 231 232 233 234 235
                    i_interval = config_GetInt( p_intf , "short-jump-size" );
                    if ( i_interval > 0 )
                    {
                        val.i_time = ( (mtime_t)( i_interval ) * 1000000L);
                        var_Set( p_input, "time-offset", val );
                    }
                    vlc_object_release( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
236 237
                }
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
238

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
239
            case GESTURE(LEFT,UP,NONE,NONE):
Rémi Duraffort's avatar
Rémi Duraffort committed
240 241 242 243 244 245 246 247 248
                msg_Dbg( p_intf, "Going slower." );
                p_playlist = pl_Hold( p_intf );
                p_input = playlist_CurrentInput( p_playlist );
                pl_Release( p_intf );
                if( p_input )
                {
                    var_SetVoid( p_input, "rate-slower" );
                    vlc_object_release( p_input );
                }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
249
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
250

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
251
            case GESTURE(RIGHT,UP,NONE,NONE):
Rémi Duraffort's avatar
Rémi Duraffort committed
252 253 254 255 256 257 258 259 260
                msg_Dbg( p_intf, "Going faster." );
                p_playlist = pl_Hold( p_intf );
                p_input = playlist_CurrentInput( p_playlist );
                pl_Release( p_intf );
                if( p_input )
                {
                    var_SetVoid( p_input, "rate-faster" );
                    vlc_object_release( p_input );
                }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
261
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
262

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
263 264
            case GESTURE(LEFT,RIGHT,NONE,NONE):
            case GESTURE(RIGHT,LEFT,NONE,NONE):
Rémi Duraffort's avatar
Rémi Duraffort committed
265 266 267 268
                msg_Dbg( p_intf, "Play/Pause" );
                p_playlist = pl_Hold( p_intf );
                p_input = playlist_CurrentInput( p_playlist );
                pl_Release( p_intf );
269
 
Rémi Duraffort's avatar
Rémi Duraffort committed
270 271 272 273 274
                if( p_input )
                {
                    var_Get( p_input, "state", &val);
                    val.i_int = ( val.i_int != PLAYING_S ) ? PLAYING_S : PAUSE_S;
                    var_Set( p_input, "state", val);
275
                    vlc_object_release( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
276 277
                }
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
278

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
279
            case GESTURE(LEFT,DOWN,NONE,NONE):
Antoine Cellerier's avatar
Antoine Cellerier committed
280
                p_playlist = pl_Hold( p_intf );
281
                playlist_Prev( p_playlist );
282
                pl_Release( p_intf );
283
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
284

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
285
            case GESTURE(RIGHT,DOWN,NONE,NONE):
Antoine Cellerier's avatar
Antoine Cellerier committed
286
                p_playlist = pl_Hold( p_intf );
287
                playlist_Next( p_playlist );
288
                pl_Release( p_intf );
289
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
290

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
291
            case UP:
Rémi Duraffort's avatar
Rémi Duraffort committed
292 293
                msg_Dbg(p_intf, "Louder");
                aout_VolumeUp( p_intf, 1, NULL );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
294
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
295

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
296
            case DOWN:
Rémi Duraffort's avatar
Rémi Duraffort committed
297 298
                msg_Dbg(p_intf, "Quieter");
                aout_VolumeDown( p_intf, 1, NULL );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
299
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
300

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
301 302
            case GESTURE(UP,DOWN,NONE,NONE):
            case GESTURE(DOWN,UP,NONE,NONE):
303
                msg_Dbg( p_intf, "Mute sound" );
Rémi Duraffort's avatar
Rémi Duraffort committed
304
                aout_VolumeMute( p_intf, NULL );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
305
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
306

307
            case GESTURE(UP,RIGHT,NONE,NONE):
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
308 309 310
                {
                   vlc_value_t val, list, list2;
                   int i_count, i;
311

Antoine Cellerier's avatar
Antoine Cellerier committed
312
                    p_playlist = pl_Hold( p_intf );
313 314
                    p_input = playlist_CurrentInput( p_playlist );
                    pl_Release( p_intf );
315

316 317 318
                    if( !p_input )
                        break;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
319 320 321 322 323 324
                   var_Get( p_input, "audio-es", &val );
                   var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
                               &list, &list2 );
                   i_count = list.p_list->i_count;
                   if( i_count <= 1 )
                   {
325
                       vlc_object_release( p_input );
326
                       break;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
327 328 329 330 331 332
                   }
                   for( i = 0; i < i_count; i++ )
                   {
                       if( val.i_int == list.p_list->p_values[i].i_int )
                           break;
                   }
Rémi Duraffort's avatar
Rémi Duraffort committed
333 334 335 336 337 338 339 340 341 342 343 344 345
                    /* value of audio-es was not in choices list */
                    if( i == i_count )
                    {
                        msg_Warn( p_input,
                                  "invalid current audio track, selecting 0" );
                        i = 0;
                    }
                    else if( i == i_count - 1 )
                        i = 1;
                    else
                        i++;
                    var_Set( p_input, "audio-es", list.p_list->p_values[i] );
                    vlc_object_release( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
346 347 348 349 350 351
                }
                break;
            case GESTURE(DOWN,RIGHT,NONE,NONE):
                {
                    vlc_value_t val, list, list2;
                    int i_count, i;
352

Antoine Cellerier's avatar
Antoine Cellerier committed
353
                    p_playlist = pl_Hold( p_intf );
354 355
                    p_input = playlist_CurrentInput( p_playlist );
                    pl_Release( p_intf );
356 357 358

                    if( !p_input )
                        break;
359

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
360 361 362 363 364 365 366
                    var_Get( p_input, "spu-es", &val );

                    var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
                            &list, &list2 );
                    i_count = list.p_list->i_count;
                    if( i_count <= 1 )
                    {
367
                        vlc_object_release( p_input );
368
                        break;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
                    }
                    for( i = 0; i < i_count; i++ )
                    {
                        if( val.i_int == list.p_list->p_values[i].i_int )
                        {
                            break;
                        }
                    }
                    /* value of spu-es was not in choices list */
                    if( i == i_count )
                    {
                        msg_Warn( p_input,
                                "invalid current subtitle track, selecting 0" );
                        i = 0;
                    }
                    else if( i == i_count - 1 )
                        i = 0;
                    else
Rémi Duraffort's avatar
Rémi Duraffort committed
387 388
                        i++;
                    var_Set( p_input, "spu-es", list.p_list->p_values[i] );
389
                    vlc_object_release( p_input );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
390 391
                }
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
392

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
393
            case GESTURE(UP,LEFT,NONE,NONE):
394
                if( p_sys->p_vout )
395
                {
396
                    var_Get( p_sys->p_vout, "fullscreen", &val );
Rémi Duraffort's avatar
Rémi Duraffort committed
397
                    val.b_bool = !val.b_bool;
398
                    var_Set( p_sys->p_vout, "fullscreen", val );
399 400
                }
                break;
Rémi Duraffort's avatar
Rémi Duraffort committed
401

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
402
            case GESTURE(DOWN,LEFT,NONE,NONE):
403
                /* FIXME: Should close the vout!"*/
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
404
                libvlc_Quit( p_intf->p_libvlc );
405
                break;
406
            case GESTURE(DOWN,LEFT,UP,RIGHT):
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
407
            case GESTURE(UP,RIGHT,DOWN,LEFT):
408
                msg_Dbg( p_intf, "a square was drawn!" );
409 410 411 412
                break;
            default:
                break;
            }
413 414 415
            p_sys->i_num_gestures = 0;
            p_sys->i_pattern = 0;
            p_sys->b_got_gesture = false;
416
        }
417 418

        /*
419 420
         * video output
         */
421
        if( p_sys->p_vout && !vlc_object_alive( p_sys->p_vout ) )
422
        {
423
            var_DelCallback( p_sys->p_vout, "mouse-moved",
424
                             MouseEvent, p_intf );
425
            var_DelCallback( p_sys->p_vout, "mouse-button-down",
426
                             MouseEvent, p_intf );
427 428
            vlc_object_release( p_sys->p_vout );
            p_sys->p_vout = NULL;
429 430
        }

431
        if( p_sys->p_vout == NULL )
432
        {
Rémi Duraffort's avatar
Rémi Duraffort committed
433 434 435 436 437
            p_playlist = pl_Hold( p_intf );
            p_input = playlist_CurrentInput( p_playlist );
            pl_Release( p_intf );
            if( p_input )
            {
438
                p_sys->p_vout = input_GetVout( p_input );
Rémi Duraffort's avatar
Rémi Duraffort committed
439 440
                vlc_object_release( p_input );
            }
441
            if( p_sys->p_vout )
442
            {
443
                var_AddCallback( p_sys->p_vout, "mouse-moved",
444
                                 MouseEvent, p_intf );
445
                var_AddCallback( p_sys->p_vout, "mouse-button-down",
446 447 448 449
                                 MouseEvent, p_intf );
            }
        }

450
        vlc_mutex_unlock( &p_sys->lock );
451

452 453 454 455
        /* Wait a bit */
        msleep( INTF_IDLE_SLEEP );
    }

456
    vlc_restorecancel( canc );
457 458 459 460 461 462 463 464
}

/*****************************************************************************
 * MouseEvent: callback for mouse events
 *****************************************************************************/
static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
Rafaël Carré's avatar
Rafaël Carré committed
465
    VLC_UNUSED(p_this); VLC_UNUSED(oldval);
466
    int pattern = 0;
467

468 469
    signed int i_horizontal, i_vertical;
    intf_thread_t *p_intf = (intf_thread_t *)p_data;
470
    intf_sys_t    *p_sys = p_intf->p_sys;
471

472
    vlc_mutex_lock( &p_sys->lock );
473

474
    /* don't process new gestures before the last events are processed */
475
    if( p_sys->b_got_gesture )
476
    {
477
        vlc_mutex_unlock( &p_sys->lock );
478 479 480
        return VLC_SUCCESS;
    }

481
    if( !strcmp( psz_var, "mouse-moved" ) && p_sys->b_button_pressed )
482
    {
483 484 485 486 487 488
        p_sys->i_mouse_x = var_GetInteger( p_sys->p_vout, "mouse-x" );
        p_sys->i_mouse_y = var_GetInteger( p_sys->p_vout, "mouse-y" );
        i_horizontal = p_sys->i_mouse_x - p_sys->i_last_x;
        i_horizontal = i_horizontal / p_sys->i_threshold;
        i_vertical = p_sys->i_mouse_y - p_sys->i_last_y;
        i_vertical = i_vertical / p_sys->i_threshold;
489 490

        if( i_horizontal < 0 )
491
        {
492
            msg_Dbg( p_intf, "left gesture (%d)", i_horizontal );
493 494
            pattern = LEFT;
        }
495
        else if( i_horizontal > 0 )
496
        {
497
            msg_Dbg( p_intf, "right gesture (%d)", i_horizontal );
498 499
            pattern = RIGHT;
        }
500
        if( i_vertical < 0 )
501
        {
502
            msg_Dbg( p_intf, "up gesture (%d)", i_vertical );
503 504
            pattern = UP;
        }
505
        else if( i_vertical > 0 )
506
        {
507
            msg_Dbg( p_intf, "down gesture (%d)", i_vertical );
508 509
            pattern = DOWN;
        }
510
        if( pattern )
511
        {
512 513 514 515
            p_sys->i_last_y = p_sys->i_mouse_y;
            p_sys->i_last_x = p_sys->i_mouse_x;
            if( gesture( p_sys->i_pattern, p_sys->i_num_gestures - 1 )
                    != pattern )
516
            {
517 518
                p_sys->i_pattern |= pattern << ( p_sys->i_num_gestures * 4 );
                p_sys->i_num_gestures++;
519 520 521 522
            }
        }

    }
523
    else if( !strcmp( psz_var, "mouse-button-down" ) )
524
    {
525 526 527 528 529 530 531 532 533 534 535
        if( (newval.i_int & p_sys->i_button_mask) && !p_sys->b_button_pressed )
        {
            p_sys->b_button_pressed = true;
            p_sys->i_last_x = var_GetInteger( p_sys->p_vout, "mouse-x" );
            p_sys->i_last_y = var_GetInteger( p_sys->p_vout, "mouse-y" );
        }
        else if( !( newval.i_int & p_sys->i_button_mask ) && p_sys->b_button_pressed )
        {
            p_sys->b_button_pressed = false;
            p_sys->b_got_gesture = true;
        }
536 537
    }

538
    vlc_mutex_unlock( &p_sys->lock );
539 540 541

    return VLC_SUCCESS;
}