1 /* Copyright (C) 2007-2008 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 #ifndef _ANDROID_SKIN_KEYSET_H_ 13 #define _ANDROID_SKIN_KEYSET_H_ 14 15 #include "android/config.h" 16 17 /* A SkinKeySet maps keystrokes to specific commands. we have a few hard-coded 18 * keysets in the emulator binary, and the user can define its own if he wants 19 * to... 20 */ 21 typedef struct SkinKeyset SkinKeyset; 22 23 #define SKIN_KEY_COMMAND_LIST \ 24 _SKIN_KEY_COMMAND(NONE,"no key") \ 25 _SKIN_KEY_COMMAND(BUTTON_HOME,"Home button") \ 26 _SKIN_KEY_COMMAND(BUTTON_MENU,"Menu (Soft-Left) button") \ 27 _SKIN_KEY_COMMAND(BUTTON_STAR,"Star (Soft-Right) button") \ 28 _SKIN_KEY_COMMAND(BUTTON_BACK,"Back button") \ 29 _SKIN_KEY_COMMAND(BUTTON_CALL,"Call/Dial button") \ 30 _SKIN_KEY_COMMAND(BUTTON_HANGUP,"Hangup/EndCall button") \ 31 _SKIN_KEY_COMMAND(BUTTON_POWER,"Power button") \ 32 _SKIN_KEY_COMMAND(BUTTON_SEARCH,"Search button") \ 33 _SKIN_KEY_COMMAND(BUTTON_VOLUME_UP,"Volume up button") \ 34 _SKIN_KEY_COMMAND(BUTTON_VOLUME_DOWN,"Volume down button") \ 35 _SKIN_KEY_COMMAND(BUTTON_CAMERA,"Camera button") \ 36 _SKIN_KEY_COMMAND(CHANGE_LAYOUT_PREV,"switch to previous layout") \ 37 _SKIN_KEY_COMMAND(CHANGE_LAYOUT_NEXT,"switch to next layout") \ 38 _SKIN_KEY_COMMAND(TOGGLE_NETWORK,"toggle cell network on/off") \ 39 _SKIN_KEY_COMMAND(TOGGLE_TRACING,"toggle code profiling") \ 40 _SKIN_KEY_COMMAND(TOGGLE_FULLSCREEN,"toggle fullscreen mode") \ 41 _SKIN_KEY_COMMAND(TOGGLE_TRACKBALL,"toggle trackball mode") \ 42 _SKIN_KEY_COMMAND(SHOW_TRACKBALL,"show trackball") \ 43 _SKIN_KEY_COMMAND(BUTTON_DPAD_CENTER,"DPad center") \ 44 _SKIN_KEY_COMMAND(BUTTON_DPAD_LEFT,"DPad left") \ 45 _SKIN_KEY_COMMAND(BUTTON_DPAD_RIGHT,"DPad right") \ 46 _SKIN_KEY_COMMAND(BUTTON_DPAD_UP,"DPad up") \ 47 _SKIN_KEY_COMMAND(BUTTON_DPAD_DOWN,"DPad down") \ 48 _SKIN_KEY_COMMAND(ONION_ALPHA_UP,"increase onion alpha") \ 49 _SKIN_KEY_COMMAND(ONION_ALPHA_DOWN,"decrease onion alpha") \ 50 51 52 /* the list of commands in the emulator */ 53 #define _SKIN_KEY_COMMAND(x,y) SKIN_KEY_COMMAND_##x, 54 typedef enum { 55 SKIN_KEY_COMMAND_LIST 56 SKIN_KEY_COMMAND_MAX // do not remove 57 } SkinKeyCommand; 58 #undef _SKIN_KEY_COMMAND 59 60 /* retrieve the textual name of a given command, this is the command name without 61 * the "SKIN_KEY_COMMAND_" prefix. returns NULL if command is NONE or invalid 62 * the result is a static constant string that must not be freed 63 */ 64 extern const char* skin_key_command_to_str ( SkinKeyCommand command ); 65 66 /* convert a string into a SkinKeyCommand. returns SKIN_COMMAND_NONE if the string 67 * is unknown 68 */ 69 extern SkinKeyCommand skin_key_command_from_str( const char* str, int len ); 70 71 /* returns a short human-friendly description of the command */ 72 extern const char* skin_key_command_description( SkinKeyCommand cmd ); 73 74 /* returns the number of keysym string descriptors */ 75 extern int skin_keysym_str_count( void ); 76 77 /* return the n-th keysym string descriptor */ 78 extern const char* skin_keysym_str( int index ); 79 80 /* convert a (sym,mod) pair into a descriptive string. e.g. "Ctrl-K" or "Alt-A", etc.. 81 * result is a static string that is overwritten on each call 82 */ 83 extern const char* skin_key_symmod_to_str ( int sym, int mod ); 84 85 /* convert a key binding description into a (sym,mod) pair. returns 0 on success, -1 86 * if the string cannot be parsed. 87 */ 88 extern int skin_key_symmod_from_str ( const char* str, int *psym, int *pmod ); 89 90 /* create a new keyset from a configuration tree node */ 91 extern SkinKeyset* skin_keyset_new ( AConfig* root ); 92 extern SkinKeyset* skin_keyset_new_from_text( const char* text ); 93 94 /* destroy a given keyset */ 95 extern void skin_keyset_free( SkinKeyset* kset ); 96 97 /* maximum number of key bindings per command. one command can be bound to several 98 * key bindings for convenience 99 */ 100 #define SKIN_KEY_COMMAND_MAX_BINDINGS 3 101 102 /* a structure that describe a key binding */ 103 typedef struct { 104 int sym; // really a SDL key symbol 105 int mod; // really a SDL key modifier 106 } SkinKeyBinding; 107 108 /* return the number of keyboard bindings for a given command. results are placed in the 'bindings' array 109 * which must have at least SKIN_KEY_MAX_BINDINGS items */ 110 extern int skin_keyset_get_bindings( SkinKeyset* kset, 111 SkinKeyCommand command, 112 SkinKeyBinding* bindings ); 113 114 /* return the command for a given keypress - SKIN_KEY_COMMAND_NONE is returned if unknown */ 115 extern SkinKeyCommand skin_keyset_get_command( SkinKeyset* kset, int sym, int mod ); 116 117 extern const char* skin_keyset_get_default( void ); 118 119 /* in android_main.c */ 120 extern SkinKeyset* android_keyset; 121 122 #endif /* _ANDROID_SKIN_KEYSET_H_ */ 123