Changeset 5223eff99a813e93876cd87fa01a8a47a99e0aa8
- 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
| r3fc79af |
r5223eff |
|
| 52 | 52 | struct intf_sys_t |
|---|
| 53 | 53 | { |
|---|
| 54 | | int p_keys[ BUFFER_SIZE ]; /* buffer that contains |
|---|
| 55 | | * keyevents */ |
|---|
| | 54 | int p_actions[ BUFFER_SIZE ]; /* buffer that contains |
|---|
| | 55 | * action events */ |
|---|
| 56 | 56 | int i_size; /* number of events in buffer */ |
|---|
| 57 | 57 | int p_channels[ CHANNELS_NUMBER ]; /* contains registered |
|---|
| … | … | |
| 67 | 67 | static void Close ( vlc_object_t * ); |
|---|
| 68 | 68 | static 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 * ); |
|---|
| | 69 | static int GetAction( intf_thread_t *); |
|---|
| | 70 | static int ActionEvent( vlc_object_t *, char const *, |
|---|
| | 71 | vlc_value_t, vlc_value_t, void * ); |
|---|
| | 72 | static int SpecialKeyEvent( vlc_object_t *, char const *, |
|---|
| | 73 | vlc_value_t, vlc_value_t, void * ); |
|---|
| 72 | 74 | static int ActionKeyCB( vlc_object_t *, char const *, |
|---|
| 73 | 75 | vlc_value_t, vlc_value_t, void * ); |
|---|
| … | … | |
| 111 | 113 | p_intf->pf_run = Run; |
|---|
| 112 | 114 | |
|---|
| 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 ); |
|---|
| 114 | 117 | return VLC_SUCCESS; |
|---|
| 115 | 118 | } |
|---|
| … | … | |
| 122 | 125 | intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 123 | 126 | |
|---|
| 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 ); |
|---|
| 125 | 129 | |
|---|
| 126 | 130 | /* Destroy structure */ |
|---|
| … | … | |
| 156 | 160 | vout_thread_t *p_last_vout; |
|---|
| 157 | 161 | 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 ) |
|---|
| 162 | 165 | break; /* die */ |
|---|
| 163 | 166 | |
|---|
| 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; |
|---|
| 172 | 174 | 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 | |
|---|
| 201 | 178 | /* Update the input */ |
|---|
| 202 | 179 | PL_LOCK; |
|---|
| … | … | |
| 858 | 835 | } |
|---|
| 859 | 836 | |
|---|
| 860 | | static int GetKey( intf_thread_t *p_intf ) |
|---|
| | 837 | static int GetAction( intf_thread_t *p_intf ) |
|---|
| 861 | 838 | { |
|---|
| 862 | 839 | intf_sys_t *p_sys = p_intf->p_sys; |
|---|
| … | … | |
| 871 | 848 | } |
|---|
| 872 | 849 | |
|---|
| 873 | | i_ret = p_intf->p_sys->p_keys[ 0 ]; |
|---|
| | 850 | i_ret = p_sys->p_actions[ 0 ]; |
|---|
| 874 | 851 | p_sys->i_size--; |
|---|
| 875 | 852 | 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]; |
|---|
| 877 | 854 | |
|---|
| 878 | 855 | out: |
|---|
| … | … | |
| 881 | 858 | } |
|---|
| 882 | 859 | |
|---|
| 883 | | static int PutKey( intf_thread_t *p_intf, int i_key ) |
|---|
| | 860 | static int PutAction( intf_thread_t *p_intf, int i_action ) |
|---|
| 884 | 861 | { |
|---|
| 885 | 862 | intf_sys_t *p_sys = p_intf->p_sys; |
|---|
| … | … | |
| 888 | 865 | vlc_object_lock( p_intf ); |
|---|
| 889 | 866 | 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" ); |
|---|
| 891 | 868 | else |
|---|
| 892 | | p_sys->p_keys[p_sys->i_size++] = i_key; |
|---|
| | 869 | p_sys->p_actions[p_sys->i_size++] = i_action; |
|---|
| 893 | 870 | |
|---|
| 894 | 871 | vlc_object_signal_unlocked( p_intf ); |
|---|
| … | … | |
| 898 | 875 | |
|---|
| 899 | 876 | /***************************************************************************** |
|---|
| 900 | | * KeyEvent: callback for keyboard events |
|---|
| | 877 | * SpecialKeyEvent: callback for mouse events |
|---|
| 901 | 878 | *****************************************************************************/ |
|---|
| 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); |
|---|
| | 879 | static int SpecialKeyEvent( vlc_object_t *libvlc, char const *psz_var, |
|---|
| | 880 | vlc_value_t oldval, vlc_value_t newval, |
|---|
| | 881 | void *p_data ) |
|---|
| | 882 | { |
|---|
| 906 | 883 | 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 | *****************************************************************************/ |
|---|
| | 918 | static 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 ); |
|---|
| 909 | 928 | } |
|---|
| 910 | 929 | |
|---|