Home | History | Annotate | Download | only in skin
      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     _SKIN_KEY_COMMAND(BUTTON_TV,"TV button")         \
     51     _SKIN_KEY_COMMAND(BUTTON_EPG,"EPG button")         \
     52     _SKIN_KEY_COMMAND(BUTTON_DVR,"DVR button")         \
     53     _SKIN_KEY_COMMAND(BUTTON_PREV,"Previous button")         \
     54     _SKIN_KEY_COMMAND(BUTTON_NEXT,"Next button")         \
     55     _SKIN_KEY_COMMAND(BUTTON_PLAY,"Play button")         \
     56     _SKIN_KEY_COMMAND(BUTTON_PAUSE,"Pause button")         \
     57     _SKIN_KEY_COMMAND(BUTTON_STOP,"Stop button")         \
     58     _SKIN_KEY_COMMAND(BUTTON_REWIND,"Rewind button")         \
     59     _SKIN_KEY_COMMAND(BUTTON_FFWD,"Fast forward button")         \
     60     _SKIN_KEY_COMMAND(BUTTON_BOOKMARKS,"Bookmarks button")         \
     61     _SKIN_KEY_COMMAND(BUTTON_WINDOW,"Window button")         \
     62     _SKIN_KEY_COMMAND(BUTTON_CHANNELUP,"Channel up button")         \
     63     _SKIN_KEY_COMMAND(BUTTON_CHANNELDOWN,"Channel down button")         \
     64 
     65 
     66 /* the list of commands in the emulator */
     67 #define _SKIN_KEY_COMMAND(x,y)  SKIN_KEY_COMMAND_##x,
     68 typedef enum {
     69     SKIN_KEY_COMMAND_LIST
     70     SKIN_KEY_COMMAND_MAX  // do not remove
     71 } SkinKeyCommand;
     72 #undef _SKIN_KEY_COMMAND
     73 
     74 /* retrieve the textual name of a given command, this is the command name without
     75  * the "SKIN_KEY_COMMAND_" prefix. returns NULL if command is NONE or invalid
     76  * the result is a static constant string that must not be freed
     77  */
     78 extern const char*      skin_key_command_to_str  ( SkinKeyCommand  command );
     79 
     80 /* convert a string into a SkinKeyCommand. returns SKIN_COMMAND_NONE if the string
     81  * is unknown
     82  */
     83 extern SkinKeyCommand   skin_key_command_from_str( const char*  str, int  len );
     84 
     85 /* returns a short human-friendly description of the command */
     86 extern const char*      skin_key_command_description( SkinKeyCommand  cmd );
     87 
     88 /* returns the number of keysym string descriptors */
     89 extern int              skin_keysym_str_count( void );
     90 
     91 /* return the n-th keysym string descriptor */
     92 extern const char*      skin_keysym_str( int  index );
     93 
     94 /* convert a (sym,mod) pair into a descriptive string. e.g. "Ctrl-K" or "Alt-A", etc..
     95  * result is a static string that is overwritten on each call
     96  */
     97 extern const char*      skin_key_symmod_to_str   ( int  sym, int  mod );
     98 
     99 /* convert a key binding description into a (sym,mod) pair. returns 0 on success, -1
    100  * if the string cannot be parsed.
    101  */
    102 extern int              skin_key_symmod_from_str ( const char*  str, int  *psym, int  *pmod );
    103 
    104 /* create a new keyset from a configuration tree node */
    105 extern SkinKeyset*      skin_keyset_new ( AConfig*  root );
    106 extern SkinKeyset*      skin_keyset_new_from_text( const char*  text );
    107 
    108 /* destroy a given keyset */
    109 extern void             skin_keyset_free( SkinKeyset*  kset );
    110 
    111 /* maximum number of key bindings per command. one command can be bound to several
    112  * key bindings for convenience
    113  */
    114 #define  SKIN_KEY_COMMAND_MAX_BINDINGS  3
    115 
    116 /* a structure that describe a key binding */
    117 typedef struct {
    118     int  sym;   // really a SDL key symbol
    119     int  mod;   // really a SDL key modifier
    120 } SkinKeyBinding;
    121 
    122 /* return the number of keyboard bindings for a given command. results are placed in the 'bindings' array
    123  * which must have at least SKIN_KEY_MAX_BINDINGS items */
    124 extern int              skin_keyset_get_bindings( SkinKeyset*      kset,
    125                                                   SkinKeyCommand   command,
    126                                                   SkinKeyBinding*  bindings );
    127 
    128 /* return the command for a given keypress - SKIN_KEY_COMMAND_NONE is returned if unknown */
    129 extern SkinKeyCommand   skin_keyset_get_command( SkinKeyset*  kset, int  sym, int  mod );
    130 
    131 extern const char*      skin_keyset_get_default( void );
    132 
    133 /* in android_main.c */
    134 extern SkinKeyset*      android_keyset;
    135 
    136 #endif /* _ANDROID_SKIN_KEYSET_H_ */
    137