From: Sigmund Augdal Helberg Date: Thu, 14 Aug 2003 19:25:56 +0000 (+0000) Subject: First part of code to allow configurable hotkeys. X-Git-Tag: 0.7.0~1129 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=1b9c64b11db742480b3d8804d81d23bbcfcc04d8;p=vlc First part of code to allow configurable hotkeys. include/configuration.h, src/misc/configuration.h: * added a CONFIG_ITEM_KEY include/vlc_keys.h: * constants to identify keys src/libvlc.h: * provide a set of hotkey config options modules/gui/wxwindows/interface.cpp, wxwindows.h: * set the configured hotkeys as accelerator for the appropriate menus modules/gui/wxwindows/preferences.cpp: * start to support CONFIG_ITEM_KEY. Options are showed with the right value but any changes made have no effect yet. --- diff --git a/include/configuration.h b/include/configuration.h index 090e57d3f2..dacb6c48f6 100644 --- a/include/configuration.h +++ b/include/configuration.h @@ -4,7 +4,7 @@ * It includes functions allowing to declare, get or set configuration options. ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN - * $Id: configuration.h,v 1.30 2003/08/10 09:22:07 gbazin Exp $ + * $Id: configuration.h,v 1.31 2003/08/14 19:25:55 sigmunau Exp $ * * Authors: Gildas Bazin * @@ -44,6 +44,7 @@ #define CONFIG_ITEM_BOOL 0x0050 /* Bool option */ #define CONFIG_ITEM_FLOAT 0x0060 /* Float option */ #define CONFIG_ITEM_DIRECTORY 0x0070 /* Directory option */ +#define CONFIG_ITEM_KEY 0x0080 /* Hot key option */ #define CONFIG_ITEM 0x00F0 @@ -153,6 +154,8 @@ VLC_EXPORT( void, config_UnsetCallbacks, ( module_config_t * ) ); { static module_config_t tmp = { CONFIG_ITEM_MODULE, psz_caps, name, '\0', text, longtext, psz_value }; p_config[ i_config ] = tmp; p_config[ i_config ].pf_callback = p_callback; p_config[i_config].b_advanced = advc; } i_config++ #define add_integer( name, i_value, p_callback, text, longtext, advc ) \ { static module_config_t tmp = { CONFIG_ITEM_INTEGER, NULL, name, '\0', text, longtext, NULL, i_value }; p_config[ i_config ] = tmp; p_config[ i_config ].pf_callback = p_callback; p_config[i_config].b_advanced = advc; } i_config++ +#define add_key( name, i_value, p_callback, text, longtext, advc ) \ + { static module_config_t tmp = { CONFIG_ITEM_KEY, NULL, name, '\0', text, longtext, NULL, i_value }; p_config[ i_config ] = tmp; p_config[ i_config ].pf_callback = p_callback; p_config[i_config].b_advanced = advc; } i_config++ #define add_integer_with_range( name, i_value, i_min, i_max, p_callback, text, longtext, advc ) \ { static module_config_t tmp = { CONFIG_ITEM_INTEGER, NULL, name, '\0', text, longtext, NULL, i_value, 0, i_min, i_max }; p_config[ i_config ] = tmp; p_config[ i_config ].pf_callback = p_callback; p_config[i_config].b_advanced = advc; } i_config++ #define add_float( name, f_value, p_callback, text, longtext, advc ) \ diff --git a/include/vlc_keys.h b/include/vlc_keys.h new file mode 100644 index 0000000000..5be5c83a98 --- /dev/null +++ b/include/vlc_keys.h @@ -0,0 +1,150 @@ +/***************************************************************************** + * hotkeys.h: keycode defines + ***************************************************************************** + * Copyright (C) 2003 VideoLAN + * $Id: vlc_keys.h,v 1.1 2003/08/14 19:25:55 sigmunau Exp $ + * + * Authors: Sigmund Augdal + * + * 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. + * + * 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 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + *****************************************************************************/ + +#define KEY_MODIFIER 0xFF000000 +#define KEY_MODIFIER_ALT 0x01000000 +#define KEY_MODIFIER_SHIFT 0x02000000 +#define KEY_MODIFIER_CTRL 0x04000000 +#define KEY_MODIFIER_META 0x08000000 +#define KEY_MODIFIER_COMMAND 0x10000000 + +#define KEY_SPECIAL 0x00FF0000 +#define KEY_LEFT 0x00010000 +#define KEY_RIGHT 0x00020000 +#define KEY_UP 0x00030000 +#define KEY_DOWN 0x00040000 +#define KEY_SPACE 0x00050000 +#define KEY_ENTER 0x00060000 +#define KEY_F1 0x00070000 +#define KEY_F2 0x00080000 +#define KEY_F3 0x00090000 +#define KEY_F4 0x000A0000 +#define KEY_F5 0x000B0000 +#define KEY_F6 0x000C0000 +#define KEY_F7 0x000D0000 +#define KEY_F8 0x000E0000 +#define KEY_F9 0x000F0000 +#define KEY_F10 0x00100000 +#define KEY_F11 0x00110000 +#define KEY_F12 0x00120000 +#define KEY_HOME 0x00130000 +#define KEY_END 0x00140000 +#define KEY_MENU 0x00150000 +#define KEY_ESC 0x00160000 +#define KEY_PAGEUP 0x00170000 +#define KEY_PAGEDOWN 0x00180000 +#define KEY_TAB 0x00190000 +#define KEY_BACKSPACE 0x001A0000 + +#define KEY_ASCII 0x0000007F +#define KEY_UNSET 0 +typedef struct key_descriptor_s +{ + char *psz_key_string; + int i_key_code; +} key_descriptor_t; +#define ADD_KEY(a) { a, *a } +static const struct key_descriptor_s modifiers[] = +{ + { "Alt", KEY_MODIFIER_ALT }, + { "Shift", KEY_MODIFIER_SHIFT }, + { "Ctrl", KEY_MODIFIER_CTRL }, + { "Meta", KEY_MODIFIER_META }, + { "Command", KEY_MODIFIER_COMMAND } +}; + +static const struct key_descriptor_s keys[] = +{ + { "Unset", KEY_UNSET }, + { "Left", KEY_LEFT }, + { "Right", KEY_RIGHT }, + { "Up", KEY_UP }, + { "Down", KEY_DOWN }, + { "Space", KEY_SPACE }, + { "Enter", KEY_ENTER }, + { "F1", KEY_F1 }, + { "F2", KEY_F2 }, + { "F3", KEY_F3 }, + { "F4", KEY_F4 }, + { "F5", KEY_F5 }, + { "F6", KEY_F6 }, + { "F7", KEY_F7 }, + { "F8", KEY_F8 }, + { "F9", KEY_F9 }, + { "F10", KEY_F10 }, + { "F11", KEY_F11 }, + { "F12", KEY_F12 }, + { "Home", KEY_HOME }, + { "End", KEY_END }, + { "Menu", KEY_MENU }, + { "Esc", KEY_ESC }, + { "Page Up", KEY_PAGEUP }, + { "Page Down", KEY_PAGEDOWN }, + { "Tab", KEY_TAB }, + { "Backspace", KEY_BACKSPACE }, + { "a", 'a' }, + { "b", 'b' }, + { "c", 'c' }, + { "d", 'd' }, + { "e", 'e' }, + { "f", 'f' }, + { "g", 'g' }, + { "h", 'h' }, + { "i", 'i' }, + { "j", 'j' }, + { "k", 'k' }, + { "l", 'l' }, + { "m", 'm' }, + { "n", 'n' }, + { "o", 'o' }, + { "p", 'p' }, + { "q", 'q' }, + { "r", 'r' }, + { "s", 's' }, + { "t", 't' }, + { "u", 'u' }, + { "v", 'v' }, + { "w", 'w' }, + { "x", 'x' }, + { "y", 'y' }, + { "z", 'z' }, + { "+", '+' }, + { "-", '-' }, + { ",", ',' }, + { ".", '.' }, + { "<", '<' }, + { ">", '>' } +}; + +static char *KeyToString( int i_key ) +{ + unsigned int i = 0; + for ( i = 0; i < sizeof(keys) / sizeof(key_descriptor_t); i++ ) + { + if ( keys[i].i_key_code == i_key ) + { + return keys[i].psz_key_string; + } + } + return NULL; +} diff --git a/modules/gui/wxwindows/interface.cpp b/modules/gui/wxwindows/interface.cpp index ebf7db7e02..a3361d3479 100644 --- a/modules/gui/wxwindows/interface.cpp +++ b/modules/gui/wxwindows/interface.cpp @@ -2,7 +2,7 @@ * interface.cpp : wxWindows plugin for vlc ***************************************************************************** * Copyright (C) 2000-2001 VideoLAN - * $Id: interface.cpp,v 1.54 2003/07/29 21:14:10 gbazin Exp $ + * $Id: interface.cpp,v 1.55 2003/08/14 19:25:56 sigmunau Exp $ * * Authors: Gildas Bazin * @@ -205,6 +205,12 @@ Interface::Interface( intf_thread_t *_p_intf ): frame_sizer = new wxBoxSizer( wxHORIZONTAL ); SetSizer( frame_sizer ); + /* Create a dummy widget that can get the keyboard focus */ + wxWindow *p_dummy = new wxWindow( this, 0, wxDefaultPosition, + wxSize(0,0) ); + p_dummy->SetFocus(); + frame_sizer->Add( p_dummy ); + /* Creation of the menu bar */ CreateOurMenuBar(); @@ -236,6 +242,8 @@ Interface::Interface( intf_thread_t *_p_intf ): /* Associate drop targets with the main interface */ SetDropTarget( new DragAndDrop( p_intf ) ); #endif + + UpdateAcceleratorTable(); } Interface::~Interface() @@ -442,6 +450,43 @@ void Interface::CreateOurSlider() slider_frame->Hide(); } +void Interface::UpdateAcceleratorTable() +{ + /* Set some hotkeys */ + wxAcceleratorEntry entries[6]; + int i_key = config_GetInt( p_intf, "quit-key" ); + int i = 0; + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + Exit_Event ); + i_key = config_GetInt( p_intf, "stop-key" ); + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + StopStream_Event ); + i_key = config_GetInt( p_intf, "play-pause-key" ); + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + PlayStream_Event ); + i_key = config_GetInt( p_intf, "next-key" ); + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + NextStream_Event ); + i_key = config_GetInt( p_intf, "prev-key" ); + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + PrevStream_Event ); + i_key = config_GetInt( p_intf, "faster-key" ); + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + FastStream_Event ); + i_key = config_GetInt( p_intf, "slower-key" ); + entries[i++].Set( ConvertHotkeyModifiers( i_key ), ConvertHotkey( i_key ), + SlowStream_Event ); + + wxAcceleratorTable accel( 6, entries ); + + if( !accel.Ok() ) + msg_Err( p_intf, "invalid accelerator table" ); + + SetAcceleratorTable( accel ); + msg_Dbg( p_intf, "accelerator table loaded" ); + +} + /***************************************************************************** * Event Handlers. *****************************************************************************/ diff --git a/modules/gui/wxwindows/preferences.cpp b/modules/gui/wxwindows/preferences.cpp index 917f120c6c..8ab85c5d54 100644 --- a/modules/gui/wxwindows/preferences.cpp +++ b/modules/gui/wxwindows/preferences.cpp @@ -2,7 +2,7 @@ * preferences.cpp : wxWindows plugin for vlc ***************************************************************************** * Copyright (C) 2000-2001 VideoLAN - * $Id: preferences.cpp,v 1.24 2003/07/24 16:07:10 gbazin Exp $ + * $Id: preferences.cpp,v 1.25 2003/08/14 19:25:56 sigmunau Exp $ * * Authors: Gildas Bazin * @@ -851,7 +851,29 @@ PrefsPanel::PrefsPanel( wxWindow* parent, intf_thread_t *_p_intf, spin->SetClientData((void *)config_data); if( p_item->b_advanced ) b_has_advanced = VLC_TRUE; break; - + case CONFIG_ITEM_KEY: + { + label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); + wxCheckBox *alt = new wxCheckBox( panel, -1, wxU(_("Alt")) ); + alt->SetValue( p_item->i_value & KEY_MODIFIER_ALT ); + wxCheckBox *ctrl = new wxCheckBox( panel, -1, wxU(_("Ctrl")) ); + ctrl->SetValue( p_item->i_value & KEY_MODIFIER_CTRL ); + wxCheckBox *shift = new wxCheckBox( panel, -1, wxU(_("Shift")) ); + shift->SetValue( p_item->i_value & KEY_MODIFIER_SHIFT ); + combo = new wxComboBox( panel, -1, wxU("f"), wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT ); + for( int i = 0; i < sizeof(keys)/sizeof(key_descriptor_s); i++ ) + { + combo->Append( wxU(_(keys[i].psz_key_string)), (void*)&keys[i].i_key_code ); + } + combo->SetValue( wxU( KeyToString( p_item->i_value&~KEY_MODIFIER ))); + config_data->control.combobox = combo; + panel_sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + panel_sizer->Add( alt, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + panel_sizer->Add( ctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + panel_sizer->Add( shift, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + panel_sizer->Add( combo, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + } + break; case CONFIG_ITEM_FLOAT: label = new wxStaticText(panel, -1, wxU(p_item->psz_text)); textctrl = new wxTextCtrl( panel, -1, diff --git a/modules/gui/wxwindows/wxwindows.h b/modules/gui/wxwindows/wxwindows.h index 7875907adf..a8ab1e0874 100644 --- a/modules/gui/wxwindows/wxwindows.h +++ b/modules/gui/wxwindows/wxwindows.h @@ -2,7 +2,7 @@ * wxwindows.h: private wxWindows interface description ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN - * $Id: wxwindows.h,v 1.51 2003/08/10 09:22:07 gbazin Exp $ + * $Id: wxwindows.h,v 1.52 2003/08/14 19:25:56 sigmunau Exp $ * * Authors: Gildas Bazin * @@ -28,6 +28,8 @@ #include #include #include +#include +#include "vlc_keys.h" DECLARE_LOCAL_EVENT_TYPE( wxEVT_DIALOG, 0 ); @@ -147,6 +149,7 @@ public: wxGauge *volctrl; private: + void UpdateAcceleratorTable(); void CreateOurMenuBar(); void CreateOurToolBar(); void CreateOurSlider(); @@ -622,3 +625,52 @@ private: int i_item_id; }; + +static inline int ConvertHotkeyModifiers( int i_hotkey ) +{ + int i_accel_flags = 0; + if( i_hotkey & KEY_MODIFIER_ALT ) i_accel_flags |= wxACCEL_ALT; + if( i_hotkey & KEY_MODIFIER_CTRL ) i_accel_flags |= wxACCEL_CTRL; + if( i_hotkey & KEY_MODIFIER_SHIFT ) i_accel_flags |= wxACCEL_SHIFT; + return i_accel_flags; +} + +static inline int ConvertHotkey( int i_hotkey ) +{ + int i_key = i_hotkey & ~KEY_MODIFIER; + if( i_key & KEY_ASCII ) return i_key & KEY_ASCII; + else if( i_key & KEY_SPECIAL ) + { + switch ( i_key ) + { + case KEY_LEFT: return WXK_LEFT; + case KEY_RIGHT: return WXK_RIGHT; + case KEY_UP: return WXK_UP; + case KEY_DOWN: return WXK_DOWN; + case KEY_SPACE: return WXK_SPACE; + case KEY_ENTER: return WXK_RETURN; + case KEY_F1: return WXK_F1; + case KEY_F2: return WXK_F2; + case KEY_F3: return WXK_F3; + case KEY_F4: return WXK_F4; + case KEY_F5: return WXK_F5; + case KEY_F6: return WXK_F6; + case KEY_F7: return WXK_F7; + case KEY_F8: return WXK_F8; + case KEY_F9: return WXK_F9; + case KEY_F10: return WXK_F10; + case KEY_F11: return WXK_F11; + case KEY_F12: return WXK_F12; + case KEY_HOME: return WXK_HOME; + case KEY_END: return WXK_HOME; + case KEY_MENU: return WXK_MENU; + case KEY_ESC: return WXK_ESCAPE; + case KEY_PAGEUP: return WXK_PRIOR; + case KEY_PAGEDOWN: return WXK_NEXT; + case KEY_TAB: return WXK_TAB; + case KEY_BACKSPACE: return WXK_BACK; + default: + return 0; + } + } +} diff --git a/src/libvlc.h b/src/libvlc.h index f3dc83cb7f..3f55d35de9 100644 --- a/src/libvlc.h +++ b/src/libvlc.h @@ -2,7 +2,7 @@ * libvlc.h: main libvlc header ***************************************************************************** * Copyright (C) 1998-2002 VideoLAN - * $Id: libvlc.h,v 1.77 2003/07/20 19:48:30 hartman Exp $ + * $Id: libvlc.h,v 1.78 2003/08/14 19:25:56 sigmunau Exp $ * * Authors: Vincent Seguin * Samuel Hocevar @@ -24,6 +24,7 @@ *****************************************************************************/ #define Nothing here, this is just to prevent update-po from being stupid +#include "vlc_keys.h" static char *ppsz_sout_acodec[] = { "", "mpga", "mp3", "vorb", "a52", NULL }; static char *ppsz_sout_vcodec[] = { "", "mpgv", "mp4v", "DIV1", "DIV2", @@ -426,6 +427,41 @@ static char *ppsz_language[] = { "auto", "en", "en_GB", "de", "fr", "it", "Currently you can choose between implementation 0 (which is the " \ "default and the fastest), 1 and 2.") +#define FULLSCREEN_KEY_TEXT N_("Fullscreen") +#define FULLSCREEN_KEY_LONGTEXT N_("Select the hotkey to use to swap fullscreen state") +#define PLAY_PAUSE_KEY_TEXT N_("Pause") +#define PLAY_PAUSE_KEY_LONGTEXT N_("Select the hotkey to use to swap paused state") +#define PAUSE_KEY_TEXT N_("Pause only") +#define PAUSE_KEY_LONGTEXT N_("Select the hotkey to use to pause") +#define PLAY_KEY_TEXT N_("Play only") +#define PLAY_KEY_LONGTEXT N_("Select the hotkey to use to play") +#define FASTER_KEY_TEXT N_("Faster") +#define FASTER_KEY_LONGTEXT N_("Select the hotkey to use for fast forward playback") +#define SLOWER_KEY_TEXT N_("Slower") +#define SLOWER_KEY_LONGTEXT N_("Select the hotkey to use for slow motion playback") +#define NEXT_KEY_TEXT N_("Next") +#define NEXT_KEY_LONGTEXT N_("Select the hotkey to use to skip to the next item in the playlist") +#define PREV_KEY_TEXT N_("Previous") +#define PREV_KEY_LONGTEXT N_("Select the hotkey to use to skip to the previous item in the playlist") +#define STOP_KEY_TEXT N_("Stop") +#define STOP_KEY_LONGTEXT N_("Select the hotkey to stop the playback") +#define QUIT_KEY_TEXT N_("Quit") +#define QUIT_KEY_LONGTEXT N_("Select the hotkey to quit the application") +#define NAV_UP_KEY_TEXT N_("Navigate up") +#define NAV_UP_KEY_LONGTEXT N_("Select the key to move the selector up in dvd menus") +#define NAV_DOWN_KEY_TEXT N_("Navigate down") +#define NAV_DOWN_KEY_LONGTEXT N_("Select the key to move the selector down in dvd menus") +#define NAV_LEFT_KEY_TEXT N_("Navigate left") +#define NAV_LEFT_KEY_LONGTEXT N_("Select the key to move the selector left in dvd menus") +#define NAV_RIGHT_KEY_TEXT N_("Navigate right") +#define NAV_RIGHT_KEY_LONGTEXT N_("Select the key to move the selector right in dvd menus") +#define NAV_ACTIVATE_KEY_TEXT N_("Activate") +#define NAV_ACTIVATE_KEY_LONGTEXT N_("Select the key to activate selected item in dvd menus") +#define VOL_UP_KEY_TEXT N_("Volume up") +#define VOL_UP_KEY_LONGTEXT N_("Select the key to turn up audio volume") +#define VOL_DOWN_KEY_TEXT N_("Volume down") +#define VOL_DOWN_KEY_LONGTEXT N_("Select the key to turn down audio volume") + #define PLAYLIST_USAGE N_("\nPlaylist items:" \ "\n *.mpg, *.vob plain MPEG-1/2 files" \ "\n [dvd:][device][@raw_device][@[title][,[chapter][,angle]]]" \ @@ -593,6 +629,26 @@ vlc_module_begin(); add_integer( "win9x-cv-method", 0, NULL, WIN9X_CV_TEXT, WIN9X_CV_LONGTEXT, VLC_TRUE ); #endif + /* Hotkey options*/ + add_category_hint( N_("Hot keys"), NULL, VLC_FALSE ); + add_key( "fullscreen-key", 'f', NULL, FULLSCREEN_KEY_TEXT, FULLSCREEN_KEY_LONGTEXT, VLC_FALSE ); + add_key( "play-pause-key", KEY_SPACE, NULL, PLAY_PAUSE_KEY_TEXT, PLAY_PAUSE_KEY_LONGTEXT, VLC_FALSE ); + add_key( "pause-key", 0, NULL, PAUSE_KEY_TEXT, PAUSE_KEY_LONGTEXT, VLC_TRUE ); + add_key( "play-key", 0, NULL, PLAY_KEY_TEXT, PLAY_KEY_LONGTEXT, VLC_TRUE ); + add_key( "faster-key", '+', NULL, FASTER_KEY_TEXT, FASTER_KEY_LONGTEXT, VLC_FALSE ); + add_key( "slower-key", '-', NULL, SLOWER_KEY_TEXT, SLOWER_KEY_LONGTEXT, VLC_FALSE ); + add_key( "next-key", 'n', NULL, NEXT_KEY_TEXT, NEXT_KEY_LONGTEXT, VLC_FALSE ); + add_key( "prev-key", 'p', NULL, PREV_KEY_TEXT, PREV_KEY_LONGTEXT, VLC_FALSE ); + add_key( "stop-key", 's', NULL, STOP_KEY_TEXT, STOP_KEY_LONGTEXT, VLC_FALSE ); + add_key( "nav-activate-key", KEY_ENTER, NULL, NAV_ACTIVATE_KEY_TEXT, NAV_ACTIVATE_KEY_LONGTEXT, VLC_FALSE ); + add_key( "nav-up-key", KEY_UP, NULL, NAV_UP_KEY_TEXT, NAV_UP_KEY_LONGTEXT, VLC_FALSE ); + add_key( "nav-down-key", KEY_DOWN, NULL, NAV_DOWN_KEY_TEXT, NAV_DOWN_KEY_LONGTEXT, VLC_FALSE ); + add_key( "nav-left-key", KEY_LEFT, NULL, NAV_LEFT_KEY_TEXT, NAV_LEFT_KEY_LONGTEXT, VLC_FALSE ); + add_key( "nav-right-key", KEY_RIGHT, NULL, NAV_RIGHT_KEY_TEXT, NAV_RIGHT_KEY_LONGTEXT, VLC_FALSE ); + add_key( "quit-key", KEY_MODIFIER_CTRL|KEY_SPACE, NULL, QUIT_KEY_TEXT, QUIT_KEY_LONGTEXT, VLC_FALSE ); + add_key( "vol-up-key", 'a', NULL, VOL_UP_KEY_TEXT, VOL_UP_KEY_LONGTEXT, VLC_FALSE ); + add_key( "vol-down-key", 'z', NULL, VOL_DOWN_KEY_TEXT, VOL_DOWN_KEY_LONGTEXT, VLC_FALSE ); + /* Usage (mainly useful for cmd line stuff) */ add_usage_hint( PLAYLIST_USAGE ); diff --git a/src/misc/configuration.c b/src/misc/configuration.c index 3c2d617308..c278eac2eb 100644 --- a/src/misc/configuration.c +++ b/src/misc/configuration.c @@ -2,7 +2,7 @@ * configuration.c management of the modules configuration ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: configuration.c,v 1.61 2003/08/03 23:11:21 gbazin Exp $ + * $Id: configuration.c,v 1.62 2003/08/14 19:25:56 sigmunau Exp $ * * Authors: Gildas Bazin * @@ -22,6 +22,7 @@ *****************************************************************************/ #include +#include "vlc_keys.h" #include /* sprintf() */ #include /* free(), strtol() */ @@ -56,6 +57,9 @@ # include #endif + +static int ConfigStringToKey( char * ); + /***************************************************************************** * config_GetType: get the type of a variable (bool, int, float, string) ***************************************************************************** @@ -130,6 +134,7 @@ int __config_GetInt( vlc_object_t *p_this, const char *psz_name ) return -1; } if( (p_config->i_type!=CONFIG_ITEM_INTEGER) && + (p_config->i_type!=CONFIG_ITEM_KEY) && (p_config->i_type!=CONFIG_ITEM_BOOL) ) { msg_Err( p_this, "option %s does not refer to an int", psz_name ); @@ -280,6 +285,7 @@ void __config_PutInt( vlc_object_t *p_this, const char *psz_name, int i_value ) return; } if( (p_config->i_type!=CONFIG_ITEM_INTEGER) && + (p_config->i_type!=CONFIG_ITEM_KEY) && (p_config->i_type!=CONFIG_ITEM_BOOL) ) { msg_Err( p_this, "option %s does not refer to an int", psz_name ); @@ -761,6 +767,11 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name ) p_item->psz_name, (double)p_item->f_value ); #endif break; + case CONFIG_ITEM_KEY: + if( !*psz_option_value ) + break; /* ignore empty option */ + p_item->i_value = ConfigStringToKey( psz_option_value ); + break; default: vlc_mutex_lock( p_item->p_lock ); @@ -1007,6 +1018,7 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name ) p_item->i_type != CONFIG_HINT_END; p_item++ ) { + char *psz_key; if( p_item->i_type & CONFIG_HINT ) /* ignore hints */ continue; @@ -1023,7 +1035,16 @@ int __config_SaveConfigFile( vlc_object_t *p_this, const char *psz_module_name ) fprintf( file, "#" ); fprintf( file, "%s=%i\n", p_item->psz_name, p_item->i_value ); break; - + case CONFIG_ITEM_KEY: + if( p_item->psz_text ) + fprintf( file, "# %s (%s)\n", p_item->psz_text, + _("key") ); + psz_key = ConfigKeyToString( p_item->i_value ); + fprintf( file, "%s=%s\n", p_item->psz_name, + psz_key ? psz_key : "" ); + if ( psz_key ) free( psz_key ); + break; + case CONFIG_ITEM_FLOAT: if( p_item->psz_text ) fprintf( file, "# %s (%s)\n", p_item->psz_text, @@ -1292,6 +1313,9 @@ int __config_LoadCmdLine( vlc_object_t *p_this, int *pi_argc, char *ppsz_argv[], case CONFIG_ITEM_FLOAT: config_PutFloat( p_this, psz_name, (float)atof(optarg) ); break; + case CONFIG_ITEM_KEY: + config_PutInt( p_this, psz_name, ConfigStringToKey( optarg ) ); + break; case CONFIG_ITEM_BOOL: config_PutInt( p_this, psz_name, !flag ); break; @@ -1459,3 +1483,63 @@ char *config_GetHomeDir( void ) return p_homedir; } + + + +static int ConfigStringToKey( char *psz_key ) +{ + int i_key = 0; + unsigned int i; + char *psz_parser = strchr( psz_key, '-' ); + while( psz_parser && psz_parser != psz_key ) + { + for ( i = 0; i < sizeof(modifiers) / sizeof(key_descriptor_t); i++ ) + { + if ( !strncasecmp( modifiers[i].psz_key_string, psz_key, strlen( modifiers[i].psz_key_string ) ) ) + { + i_key |= modifiers[i].i_key_code; + } + } + psz_key = psz_parser + 1; + psz_parser = strchr( psz_key, '-' ); + } + for ( i = 0; i < sizeof(keys) / sizeof( key_descriptor_t ); i++ ) + { + if ( !strcasecmp( keys[i].psz_key_string, psz_key ) ) + { + i_key |= keys[i].i_key_code; + break; + } + } + return i_key; +} + + +static char *ConfigKeyToString( int i_key ) +{ + char *psz_key = malloc( 100 ); + char *p; + int i; + if ( !psz_key ) + { + return NULL; + } + *psz_key = '\0'; + p = psz_key; + for( i = 0; i < sizeof(modifiers) / sizeof(key_descriptor_t); i++ ) + { + if ( i_key & modifiers[i].i_key_code ) + { + p += sprintf( p, "%s-", modifiers[i].psz_key_string ); + } + } + for( i = 0; i < sizeof(keys) / sizeof( key_descriptor_t); i++) + { + if ( ( i_key & ~KEY_MODIFIER ) == keys[i].i_key_code ) + { + p += sprintf( p, "%s", keys[i].psz_key_string ); + break; + } + } + return psz_key; +}