Move to a proper sdl key config instead of using the d2 pad. make the mouse wheel work, middle click is "select" and right click is "back"

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27891 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2010-08-26 11:43:51 +00:00
parent 1d613bee0f
commit aaa1636a8b
11 changed files with 335 additions and 29 deletions

View file

@ -295,4 +295,6 @@ keymaps/keymap-vibe500.c
keymaps/keymap-mpio-hd200.c
#elif CONFIG_KEYPAD == ANDROID_PAD
keymaps/keymap-android.c
#elif CONFIG_KEYPAD == SDL_PAD
keymaps/keymap-sdl.c
#endif

216
apps/keymaps/keymap-sdl.c Normal file
View file

@ -0,0 +1,216 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 Maurus Cuelenaere
*
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
/* Button Code Definitions for Android targets */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "config.h"
#include "action.h"
#include "button.h"
#include "settings.h"
/*
* The format of the list is as follows
* { Action Code, Button code, Prereq button code }
* if there's no need to check the previous button's value, use BUTTON_NONE
* Insert LAST_ITEM_IN_LIST at the end of each mapping
*/
static const struct button_mapping button_context_standard[] = {
{ ACTION_STD_PREV, BUTTON_SCROLL_BACK, BUTTON_NONE },
{ ACTION_STD_PREVREPEAT, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_NEXT, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_STD_NEXTREPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_PREV, BUTTON_UP, BUTTON_NONE },
{ ACTION_STD_PREVREPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_NEXT, BUTTON_DOWN, BUTTON_NONE },
{ ACTION_STD_NEXTREPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_OK, BUTTON_CENTER|BUTTON_REL, BUTTON_CENTER },
{ ACTION_STD_OK, BUTTON_RIGHT|BUTTON_REL, BUTTON_RIGHT },
{ ACTION_STD_CANCEL, BUTTON_LEFT, BUTTON_NONE },
{ ACTION_STD_CANCEL, BUTTON_LEFT|BUTTON_REL, BUTTON_LEFT },
{ ACTION_STD_CONTEXT, BUTTON_MENU, BUTTON_NONE },
LAST_ITEM_IN_LIST
}; /* button_context_standard */
static const struct button_mapping button_context_wps[] = {
{ ACTION_WPS_BROWSE, BUTTON_BACK, BUTTON_NONE },
{ ACTION_WPS_MENU, BUTTON_MENU|BUTTON_REL, BUTTON_MENU },
{ ACTION_WPS_CONTEXT, BUTTON_MENU|BUTTON_REPEAT, BUTTON_MENU },
{ ACTION_WPS_VOLUP, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_WPS_VOLUP, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_WPS_VOLDOWN, BUTTON_SCROLL_BACK, BUTTON_NONE },
{ ACTION_WPS_VOLDOWN, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
LAST_ITEM_IN_LIST
}; /* button_context_wps */
static const struct button_mapping button_context_list[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_list */
static const struct button_mapping button_context_tree[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST)
}; /* button_context_tree */
static const struct button_mapping button_context_listtree_scroll_with_combo[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE),
};
static const struct button_mapping button_context_listtree_scroll_without_combo[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_TREE),
};
static const struct button_mapping button_context_settings[] = {
{ ACTION_SETTINGS_INC, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_SETTINGS_INCREPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_SETTINGS_DEC, BUTTON_LEFT, BUTTON_NONE },
{ ACTION_SETTINGS_DECREPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_STD_OK, BUTTON_CENTER, BUTTON_NONE },
{ ACTION_STD_CANCEL, BUTTON_BACK, BUTTON_NONE },
{ ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_SETTINGS_INCREPEAT,BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE },
{ ACTION_SETTINGS_DECREPEAT,BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_settings */
static const struct button_mapping button_context_settings_right_is_inc[] = {
{ ACTION_SETTINGS_INC, BUTTON_SCROLL_FWD, BUTTON_NONE },
{ ACTION_SETTINGS_INCREPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_SETTINGS_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE },
{ ACTION_SETTINGS_DECREPEAT, BUTTON_SCROLL_BACK|BUTTON_REPEAT,BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_settingsgraphical */
static const struct button_mapping button_context_yesno[] = {
{ ACTION_YESNO_ACCEPT, BUTTON_CENTER, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_settings_yesno */
static const struct button_mapping button_context_colorchooser[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS),
}; /* button_context_colorchooser */
static const struct button_mapping button_context_eq[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_CUSTOM|CONTEXT_SETTINGS),
}; /* button_context_eq */
/** Bookmark Screen **/
static const struct button_mapping button_context_bmark[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_LIST),
}; /* button_context_bmark */
static const struct button_mapping button_context_time[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS),
}; /* button_context_time */
static const struct button_mapping button_context_quickscreen[] = {
{ ACTION_STD_CANCEL, BUTTON_BACK|BUTTON_REL, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_quickscreen */
static const struct button_mapping button_context_pitchscreen[] = {
{ ACTION_PS_INC_SMALL, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_PS_INC_BIG, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_PS_DEC_SMALL, BUTTON_LEFT, BUTTON_NONE },
{ ACTION_PS_DEC_BIG, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_PS_EXIT, BUTTON_BACK, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_pitchcreen */
static const struct button_mapping button_context_keyboard[] = {
{ ACTION_KBD_PAGE_FLIP, BUTTON_MENU, BUTTON_NONE },
{ ACTION_KBD_CURSOR_LEFT, BUTTON_LEFT, BUTTON_NONE },
{ ACTION_KBD_CURSOR_LEFT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE },
{ ACTION_KBD_CURSOR_RIGHT, BUTTON_RIGHT, BUTTON_NONE },
{ ACTION_KBD_CURSOR_RIGHT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE },
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_STD)
}; /* button_context_keyboard */
static const struct button_mapping button_context_radio[] = {
LAST_ITEM_IN_LIST__NEXTLIST(CONTEXT_SETTINGS)
}; /* button_context_radio */
const struct button_mapping* target_get_context_mapping(int context)
{
switch (context)
{
case CONTEXT_STD:
return button_context_standard;
case CONTEXT_WPS:
return button_context_wps;
case CONTEXT_LIST:
return button_context_list;
case CONTEXT_MAINMENU:
case CONTEXT_TREE:
if (global_settings.hold_lr_for_scroll_in_list)
return button_context_listtree_scroll_without_combo;
else
return button_context_listtree_scroll_with_combo;
case CONTEXT_CUSTOM|CONTEXT_TREE:
return button_context_tree;
case CONTEXT_SETTINGS:
return button_context_settings;
case CONTEXT_CUSTOM|CONTEXT_SETTINGS:
case CONTEXT_SETTINGS_RECTRIGGER:
return button_context_settings_right_is_inc;
case CONTEXT_SETTINGS_COLOURCHOOSER:
return button_context_colorchooser;
case CONTEXT_SETTINGS_EQ:
return button_context_eq;
case CONTEXT_SETTINGS_TIME:
return button_context_time;
case CONTEXT_YESNOSCREEN:
return button_context_yesno;
case CONTEXT_FM:
return button_context_radio;
case CONTEXT_BOOKMARKSCREEN:
return button_context_bmark;
case CONTEXT_QUICKSCREEN:
return button_context_quickscreen;
case CONTEXT_PITCHSCREEN:
return button_context_pitchscreen;
case CONTEXT_KEYBOARD:
return button_context_keyboard;
}
return button_context_standard;
}

View file

@ -129,6 +129,7 @@
#define PBELL_VIBE500_PAD 43
#define MPIO_HD200_PAD 44
#define ANDROID_PAD 45
#define SDL_PAD 46
/* CONFIG_REMOTE_KEYPAD */
#define H100_REMOTE 1

View file

@ -75,10 +75,13 @@
/* Define this if you do software codec */
#define CONFIG_CODEC SWCODEC
#ifdef ANDROID
#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
#define CONFIG_KEYPAD ANDROID_PAD
#elif (CONFIG_PLATFORM & PLATFORM_SDL)
#define HAVE_SCROLLWHEEL
#define CONFIG_KEYPAD SDL_PAD
#else
#define CONFIG_KEYPAD COWON_D2_PAD
#error unknown platform
#endif
#if (CONFIG_PLATFORM & PLATFORM_SDL)

View file

@ -20,10 +20,62 @@
***************************************************9*************************/
#include <stdio.h>
#include <SDL.h>
#include "button.h"
#include "buttonmap.h"
int key_to_button(int keyboard_key)
{
(void)keyboard_key;
return BUTTON_NONE;
int new_btn = BUTTON_NONE;
switch (keyboard_key)
{
case SDLK_KP7:
new_btn = BUTTON_TOPLEFT;
break;
case SDLK_KP8:
new_btn = BUTTON_TOPMIDDLE;
break;
case SDLK_KP9:
new_btn = BUTTON_TOPRIGHT;
break;
case SDLK_KP4:
case SDLK_LEFT:
new_btn = BUTTON_MIDLEFT;
break;
case SDLK_KP5:
new_btn = BUTTON_CENTER;
break;
case SDLK_KP6:
case SDLK_RIGHT:
new_btn = BUTTON_MIDRIGHT;
break;
case SDLK_KP1:
new_btn = BUTTON_BOTTOMLEFT;
break;
case SDLK_KP2:
case SDLK_DOWN:
new_btn = BUTTON_BOTTOMMIDDLE;
break;
case SDLK_KP3:
new_btn = BUTTON_BOTTOMRIGHT;
break;
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELUP:
new_btn = BUTTON_SCROLL_BACK;
break;
case SDL_BUTTON_WHEELDOWN:
new_btn = BUTTON_SCROLL_FWD;
break;
#endif
case SDL_BUTTON_RIGHT:
new_btn = BUTTON_MIDLEFT;
break;
case SDL_BUTTON_MIDDLE:
new_btn = BUTTON_MIDRIGHT;
break;
default:
break;
}
return new_btn;
}

View file

@ -34,27 +34,26 @@ void button_init_device(void);
int button_read_device(int *data);
/* Main unit's buttons */
#define BUTTON_POWER 0x00000001
#define BUTTON_PLUS 0x00000002
#define BUTTON_MINUS 0x00000004
#define BUTTON_MENU 0x00000008
/* Compatibility hacks for flipping. Needs a somewhat better fix. */
#define BUTTON_LEFT BUTTON_MIDLEFT
#define BUTTON_RIGHT BUTTON_MIDRIGHT
#define BUTTON_UP BUTTON_TOPMIDDLE
#define BUTTON_DOWN BUTTON_BOTTOMMIDDLE
#define BUTTON_UP 0x00000001
#define BUTTON_DOWN 0x00000002
#define BUTTON_LEFT 0x00000004
#define BUTTON_RIGHT 0x00000008
#define BUTTON_SELECT 0x00000010
#define BUTTON_MENU 0x00000020
#define BUTTON_BACK 0x00000040
#define BUTTON_SCROLL_FWD 0x00000100
#define BUTTON_SCROLL_BACK 0x00000200
/* Touch Screen Area Buttons */
#define BUTTON_TOPLEFT 0x00000010
#define BUTTON_TOPMIDDLE 0x00000020
#define BUTTON_TOPRIGHT 0x00000040
#define BUTTON_MIDLEFT 0x00000080
#define BUTTON_CENTER 0x00000100
#define BUTTON_MIDRIGHT 0x00000200
#define BUTTON_BOTTOMLEFT 0x00000400
#define BUTTON_BOTTOMMIDDLE 0x00000800
#define BUTTON_BOTTOMRIGHT 0x00001000
#define BUTTON_TOPLEFT 0x00001000
#define BUTTON_TOPMIDDLE 0x00002000
#define BUTTON_TOPRIGHT 0x00004000
#define BUTTON_MIDLEFT 0x00008000
#define BUTTON_CENTER 0x00010000
#define BUTTON_MIDRIGHT 0x00020000
#define BUTTON_BOTTOMLEFT 0x00040000
#define BUTTON_BOTTOMMIDDLE 0x00080000
#define BUTTON_BOTTOMRIGHT 0x00100000
#define BUTTON_MAIN 0x1FFF

View file

@ -112,9 +112,16 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
if(button_up) {
switch ( event->button )
{
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELUP:
case SDL_BUTTON_WHEELDOWN:
#endif
case SDL_BUTTON_MIDDLE:
case SDL_BUTTON_RIGHT:
button_event( event->button, false );
break;
/* The scrollwheel button up events are ignored as they are queued immediately */
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
if ( mapping && background ) {
printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y,
(int)sqrt( SQUARE(x-(int)event->x) + SQUARE(y-(int)event->y))
@ -137,14 +144,13 @@ static void mouse_event(SDL_MouseButtonEvent *event, bool button_up)
{
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELUP:
button_event( SDLK_UP, true );
break;
case SDL_BUTTON_WHEELDOWN:
button_event( SDLK_DOWN, true );
break;
#endif
case SDL_BUTTON_LEFT:
case SDL_BUTTON_MIDDLE:
case SDL_BUTTON_RIGHT:
button_event( event->button, true );
break;
case SDL_BUTTON_LEFT:
if ( mapping && background ) {
x = event->x;
y = event->y;

View file

@ -51,6 +51,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
}
}
break;
#ifndef CONFIG_PLATFORM
case SDLK_KP7:
case SDLK_7:
new_btn = BUTTON_TOPLEFT;
@ -58,6 +59,9 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
case SDLK_KP8:
case SDLK_8:
case SDLK_UP:
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELDOWN:
#endif
new_btn = BUTTON_TOPMIDDLE;
break;
case SDLK_KP9:
@ -71,6 +75,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
break;
case SDLK_KP5:
case SDLK_i:
case SDL_BUTTON_MIDDLE:
new_btn = BUTTON_CENTER;
break;
case SDLK_KP6:
@ -84,6 +89,9 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
break;
case SDLK_KP2:
case SDLK_k:
#ifdef HAVE_SCROLLWHEEL
case SDL_BUTTON_WHEELDOWN:
#endif
case SDLK_DOWN:
new_btn = BUTTON_BOTTOMMIDDLE;
break;
@ -91,6 +99,7 @@ int key_to_touch(int keyboard_button, unsigned int mouse_coords)
case SDLK_l:
new_btn = BUTTON_BOTTOMRIGHT;
break;
#endif
}
return new_btn;
}

View file

@ -58,6 +58,12 @@ int key_to_button(int keyboard_button)
case SDLK_INSERT:
new_btn = BUTTON_MENU;
break;
case SDL_BUTTON_WHEELUP:
new_btn = BUTTON_SCROLL_BACK;
break;
case SDL_BUTTON_WHEELDOWN:
new_btn = BUTTON_SCROLL_FWD;
break;
}
return new_btn;
}

View file

@ -65,6 +65,12 @@ int key_to_button(int keyboard_button)
case SDLK_SPACE:
new_btn = BUTTON_SELECT;
break;
case SDL_BUTTON_WHEELUP:
new_btn = BUTTON_SCROLL_BACK;
break;
case SDL_BUTTON_WHEELDOWN:
new_btn = BUTTON_SCROLL_FWD;
break;
}
return new_btn;
}

View file

@ -66,6 +66,12 @@ int key_to_button(int keyboard_button)
case SDLK_RETURN:
new_btn = BUTTON_SELECT;
break;
case SDL_BUTTON_WHEELUP:
new_btn = BUTTON_SCROLL_BACK;
break;
case SDL_BUTTON_WHEELDOWN:
new_btn = BUTTON_SCROLL_FWD;
break;
}
return new_btn;
}