Changeset 5223eff99a813e93876cd87fa01a8a47a99e0aa8

Show
Ignore:
Timestamp:
03/27/08 21:11:16 (5 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1206648676 +0200
git-parent:

[3fc79afe9fcd780a3b10af5e714905c5e530d317]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1206648047 +0200
Message:

hotkeys: use key-action

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/control/hotkeys.c

    r3fc79af r5223eff  
    5252struct intf_sys_t 
    5353{ 
    54     int                 p_keys[ BUFFER_SIZE ]; /* buffer that contains 
    55                                                 * keyevents */ 
     54    int                 p_actions[ BUFFER_SIZE ]; /* buffer that contains 
     55                                                   * action events */ 
    5656    int                 i_size;        /* number of events in buffer */ 
    5757    int                 p_channels[ CHANNELS_NUMBER ]; /* contains registered 
     
    6767static void Close   ( vlc_object_t * ); 
    6868static void Run     ( intf_thread_t * ); 
    69 static int  GetKey  ( intf_thread_t *); 
    70 static int  KeyEvent( vlc_object_t *, char const *, 
    71                       vlc_value_t, vlc_value_t, void * ); 
     69static int  GetAction( intf_thread_t *); 
     70static int  ActionEvent( vlc_object_t *, char const *, 
     71                         vlc_value_t, vlc_value_t, void * ); 
     72static int  SpecialKeyEvent( vlc_object_t *, char const *, 
     73                             vlc_value_t, vlc_value_t, void * ); 
    7274static int  ActionKeyCB( vlc_object_t *, char const *, 
    7375                         vlc_value_t, vlc_value_t, void * ); 
     
    111113    p_intf->pf_run = Run; 
    112114 
    113     var_AddCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf ); 
     115    var_AddCallback( p_intf->p_libvlc, "key-pressed", SpecialKeyEvent, p_intf ); 
     116    var_AddCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf ); 
    114117    return VLC_SUCCESS; 
    115118} 
     
    122125    intf_thread_t *p_intf = (intf_thread_t *)p_this; 
    123126 
    124     var_DelCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf ); 
     127    var_DelCallback( p_intf->p_libvlc, "key-action", ActionEvent, p_intf ); 
     128    var_DelCallback( p_intf->p_libvlc, "key-pressed", SpecialKeyEvent, p_intf ); 
    125129 
    126130    /* Destroy structure */ 
     
    156160        vout_thread_t *p_last_vout; 
    157161        int i_times = 0; 
    158         int i_action = 0; 
    159         int i_key = GetKey( p_intf ); 
    160  
    161         if( i_key == -1 ) 
     162        int i_action = GetAction( p_intf ); 
     163 
     164        if( i_action == -1 ) 
    162165            break; /* die */ 
    163166 
    164         /* Special action for mouse event */ 
    165         /* FIXME: This should probably be configurable */ 
    166         /* FIXME: rework hotkeys handling to allow more than 1 event 
    167          * to trigger one same action */ 
    168         switch (i_key & KEY_SPECIAL) 
    169         { 
    170             case KEY_MOUSEWHEELUP: 
    171                 i_action = ACTIONID_VOL_UP; 
     167        for( i = 0; p_hotkeys[i].psz_action != NULL; i++ ) 
     168        { 
     169            if( p_hotkeys[i].i_action == i_action ) 
     170            { 
     171                i_times  = p_hotkeys[i].i_times; 
     172                /* times key pressed within max. delta time */ 
     173                p_hotkeys[i].i_times = 0; 
    172174                break; 
    173             case KEY_MOUSEWHEELDOWN: 
    174                 i_action = ACTIONID_VOL_DOWN; 
    175                 break; 
    176             case KEY_MOUSEWHEELLEFT: 
    177                 i_action = ACTIONID_JUMP_BACKWARD_EXTRASHORT; 
    178                 break; 
    179             case KEY_MOUSEWHEELRIGHT: 
    180                 i_action = ACTIONID_JUMP_FORWARD_EXTRASHORT; 
    181                 break; 
    182             default: break; 
    183         } 
    184  
    185         /* No mouse action, find action triggered by hotkey */ 
    186         if(!i_action) 
    187         { 
    188             for( i = 0; i_key != -1 && p_hotkeys[i].psz_action != NULL; i++ ) 
    189             { 
    190                 if( p_hotkeys[i].i_key == i_key ) 
    191                 { 
    192                     i_action = p_hotkeys[i].i_action; 
    193                     i_times  = p_hotkeys[i].i_times; 
    194                     /* times key pressed within max. delta time */ 
    195                     p_hotkeys[i].i_times = 0; 
    196                     break; 
    197                 } 
    198             } 
    199         } 
    200  
     175            } 
     176        } 
     177  
    201178        /* Update the input */ 
    202179        PL_LOCK; 
     
    858835} 
    859836 
    860 static int GetKey( intf_thread_t *p_intf ) 
     837static int GetAction( intf_thread_t *p_intf ) 
    861838{ 
    862839    intf_sys_t *p_sys = p_intf->p_sys; 
     
    871848    } 
    872849 
    873     i_ret = p_intf->p_sys->p_keys[ 0 ]; 
     850    i_ret = p_sys->p_actions[ 0 ]; 
    874851    p_sys->i_size--; 
    875852    for( int i = 0; i < p_sys->i_size; i++ ) 
    876         p_sys->p_keys[i] = p_sys->p_keys[i + 1]; 
     853        p_sys->p_actions[i] = p_sys->p_actions[i + 1]; 
    877854 
    878855out: 
     
    881858} 
    882859 
    883 static int PutKey( intf_thread_t *p_intf, int i_key
     860static int PutAction( intf_thread_t *p_intf, int i_action
    884861{ 
    885862    intf_sys_t *p_sys = p_intf->p_sys; 
     
    888865    vlc_object_lock( p_intf ); 
    889866    if ( p_sys->i_size >= BUFFER_SIZE ) 
    890         msg_Warn( p_intf, "event buffer full, dropping keypress" ); 
     867        msg_Warn( p_intf, "event buffer full, dropping key actions" ); 
    891868    else 
    892         p_sys->p_keys[p_sys->i_size++] = i_key
     869        p_sys->p_actions[p_sys->i_size++] = i_action
    893870 
    894871    vlc_object_signal_unlocked( p_intf ); 
     
    898875 
    899876/***************************************************************************** 
    900  * KeyEvent: callback for keyboard events 
     877 * SpecialKeyEvent: callback for mouse events 
    901878 *****************************************************************************/ 
    902 static int KeyEvent( vlc_object_t *p_this, char const *psz_var, 
    903                      vlc_value_t oldval, vlc_value_t newval, void *p_data ) 
    904 
    905     VLC_UNUSED(psz_var); VLC_UNUSED(oldval); 
     879static int SpecialKeyEvent( vlc_object_t *libvlc, char const *psz_var, 
     880                            vlc_value_t oldval, vlc_value_t newval, 
     881                            void *p_data ) 
     882
    906883    intf_thread_t *p_intf = (intf_thread_t *)p_data; 
    907  
    908     return PutKey( p_intf, newval.i_int ); 
     884    int i_action; 
     885 
     886    (void)libvlc; 
     887    (void)psz_var; 
     888    (void)oldval; 
     889 
     890    /* Special action for mouse event */ 
     891    /* FIXME: This should probably be configurable */ 
     892    /* FIXME: rework hotkeys handling to allow more than 1 event 
     893     * to trigger one same action */ 
     894    switch (newval.i_int & KEY_SPECIAL) 
     895    { 
     896        case KEY_MOUSEWHEELUP: 
     897            i_action = ACTIONID_VOL_UP; 
     898            break; 
     899        case KEY_MOUSEWHEELDOWN: 
     900            i_action = ACTIONID_VOL_DOWN; 
     901            break; 
     902        case KEY_MOUSEWHEELLEFT: 
     903            i_action = ACTIONID_JUMP_BACKWARD_EXTRASHORT; 
     904            break; 
     905        case KEY_MOUSEWHEELRIGHT: 
     906            i_action = ACTIONID_JUMP_FORWARD_EXTRASHORT; 
     907            break; 
     908        default: 
     909          return VLC_SUCCESS; 
     910    } 
     911 
     912    return PutAction( p_intf, i_action ); 
     913
     914 
     915/***************************************************************************** 
     916 * ActionEvent: callback for hotkey actions 
     917 *****************************************************************************/ 
     918static int ActionEvent( vlc_object_t *libvlc, char const *psz_var, 
     919                        vlc_value_t oldval, vlc_value_t newval, void *p_data ) 
     920
     921    intf_thread_t *p_intf = (intf_thread_t *)p_data; 
     922 
     923    (void)libvlc; 
     924    (void)psz_var; 
     925    (void)oldval; 
     926 
     927    return PutAction( p_intf, newval.i_int ); 
    909928} 
    910929