2002-04-19 14:12:31 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
#include "button.h"
|
2002-05-28 15:05:16 +00:00
|
|
|
|
#include "kernel.h"
|
2002-04-19 14:12:31 +00:00
|
|
|
|
|
|
|
|
|
#include "X11/keysym.h"
|
|
|
|
|
|
2002-07-27 19:51:31 +00:00
|
|
|
|
static int release_mask;
|
|
|
|
|
static int repeat_mask;
|
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
/*
|
|
|
|
|
*Initialize buttons
|
|
|
|
|
*/
|
|
|
|
|
void button_init()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-27 19:51:31 +00:00
|
|
|
|
int button_set_repeat(int newmask)
|
|
|
|
|
{
|
|
|
|
|
int oldmask = repeat_mask;
|
|
|
|
|
repeat_mask = newmask;
|
|
|
|
|
return oldmask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int button_set_release(int newmask)
|
|
|
|
|
{
|
|
|
|
|
int oldmask = release_mask;
|
|
|
|
|
release_mask = newmask;
|
|
|
|
|
return oldmask;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
/*
|
2002-04-19 14:38:28 +00:00
|
|
|
|
* Translate X keys to Recorder keys
|
|
|
|
|
*
|
|
|
|
|
* We simulate recorder keys on the numeric keypad:
|
|
|
|
|
*
|
|
|
|
|
* 4,6,8,2 = Left, Right, Up, Down
|
|
|
|
|
* 5 = Play/pause
|
|
|
|
|
* Div,Mul,Sub = The tree menu keys
|
|
|
|
|
* +,Enter = On, Off
|
|
|
|
|
*
|
2002-08-05 14:11:40 +00:00
|
|
|
|
* Alternative Keys For Laptop or VNC Users
|
|
|
|
|
* Recorder:
|
|
|
|
|
* Space=Play Q=On A=Off 1,2,3 = F1,F2,F3
|
|
|
|
|
* Player:
|
2002-08-05 15:40:49 +00:00
|
|
|
|
* Q=On Return=Menu
|
2002-04-19 14:12:31 +00:00
|
|
|
|
*/
|
2002-06-14 11:00:13 +00:00
|
|
|
|
|
|
|
|
|
/* from uibasic.c */
|
|
|
|
|
extern int screenhack_handle_events (void);
|
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
static int get_raw_button (void)
|
|
|
|
|
{
|
2002-08-21 14:13:53 +00:00
|
|
|
|
int k;
|
|
|
|
|
static int next = 0;
|
|
|
|
|
if ( next ) {
|
|
|
|
|
k = next;
|
|
|
|
|
next = 0;
|
|
|
|
|
return k;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(screenhack_handle_events())
|
2002-04-19 14:12:31 +00:00
|
|
|
|
{
|
|
|
|
|
case XK_KP_Left:
|
|
|
|
|
case XK_Left:
|
|
|
|
|
case XK_KP_4:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_LEFT;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
case XK_KP_Right:
|
|
|
|
|
case XK_Right:
|
|
|
|
|
case XK_KP_6:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_RIGHT;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
case XK_KP_Up:
|
|
|
|
|
case XK_Up:
|
|
|
|
|
case XK_KP_8:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_UP;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
case XK_KP_Down:
|
|
|
|
|
case XK_Down:
|
|
|
|
|
case XK_KP_2:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_DOWN;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2002-05-16 14:46:58 +00:00
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
2002-04-19 14:38:28 +00:00
|
|
|
|
case XK_KP_Space:
|
|
|
|
|
case XK_KP_5:
|
2002-06-25 11:05:30 +00:00
|
|
|
|
case XK_KP_Begin:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_space:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_PLAY;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
|
|
|
|
case XK_KP_Enter:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_A:
|
|
|
|
|
case XK_a:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_OFF;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
|
|
|
|
case XK_KP_Add:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_Q:
|
|
|
|
|
case XK_q:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_ON;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
|
|
|
|
case XK_KP_Divide:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_1:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_F1;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
|
|
|
|
case XK_KP_Multiply:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_2:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_F2;
|
|
|
|
|
break;
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
|
|
|
|
case XK_KP_Subtract:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_3:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_F3;
|
|
|
|
|
break;
|
2002-05-21 15:02:13 +00:00
|
|
|
|
#else
|
|
|
|
|
case XK_KP_Add:
|
2002-08-05 14:11:40 +00:00
|
|
|
|
case XK_Q:
|
|
|
|
|
case XK_q:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_ON;
|
|
|
|
|
break;
|
2002-05-21 15:02:13 +00:00
|
|
|
|
|
|
|
|
|
case XK_KP_Enter:
|
2002-08-05 15:40:49 +00:00
|
|
|
|
case XK_Return:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = BUTTON_MENU;
|
|
|
|
|
break;
|
2002-05-16 14:46:58 +00:00
|
|
|
|
#endif
|
2002-04-19 14:38:28 +00:00
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
default:
|
2002-08-21 14:13:53 +00:00
|
|
|
|
k = 0;
|
|
|
|
|
break;
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
2002-08-21 14:13:53 +00:00
|
|
|
|
|
|
|
|
|
if ( k )
|
|
|
|
|
next = k | BUTTON_REL;
|
|
|
|
|
|
|
|
|
|
return k;
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-07 08:43:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* Timeout after TICKS unless a key is pressed.
|
|
|
|
|
*/
|
|
|
|
|
int button_get_w_tmo(int ticks)
|
|
|
|
|
{
|
|
|
|
|
int bits;
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
|
|
for(i=0; i< ticks; i++) {
|
|
|
|
|
bits = get_raw_button();
|
|
|
|
|
if(!bits)
|
|
|
|
|
x11_sleep(1);
|
|
|
|
|
else
|
|
|
|
|
break;
|
2002-08-21 14:13:53 +00:00
|
|
|
|
}
|
2002-08-07 08:43:55 +00:00
|
|
|
|
|
|
|
|
|
return bits;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-19 14:12:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* Get the currently pressed button.
|
|
|
|
|
* Returns one of BUTTON_xxx codes, with possibly a modifier bit set.
|
|
|
|
|
* No modifier bits are set when the button is first pressed.
|
|
|
|
|
* BUTTON_HELD bit is while the button is being held.
|
|
|
|
|
* BUTTON_REL bit is set when button has been released.
|
|
|
|
|
*/
|
2002-05-28 15:05:16 +00:00
|
|
|
|
int button_get(bool block)
|
2002-04-19 14:12:31 +00:00
|
|
|
|
{
|
2002-05-28 15:05:16 +00:00
|
|
|
|
int bits;
|
|
|
|
|
do {
|
|
|
|
|
bits = get_raw_button();
|
|
|
|
|
if(block && !bits)
|
2002-05-29 08:37:06 +00:00
|
|
|
|
x11_sleep(HZ/10);
|
2002-05-28 15:05:16 +00:00
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
} while(1);
|
|
|
|
|
|
|
|
|
|
return bits;
|
2002-04-19 14:12:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
|
* local variables:
|
|
|
|
|
* eval: (load-file "rockbox-mode.el")
|
|
|
|
|
* end:
|
|
|
|
|
*/
|