Key repeat is handled by the OS, since text input is now decoupled from physical key events.
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402368
This commit is contained in:
parent
278c83218c
commit
80dcd123dc
7 changed files with 38 additions and 158 deletions
|
@ -64,6 +64,9 @@ extern "C" {
|
||||||
#define SDL_BUTTON_WHEELUP 4
|
#define SDL_BUTTON_WHEELUP 4
|
||||||
#define SDL_BUTTON_WHEELDOWN 5
|
#define SDL_BUTTON_WHEELDOWN 5
|
||||||
|
|
||||||
|
#define SDL_DEFAULT_REPEAT_DELAY 500
|
||||||
|
#define SDL_DEFAULT_REPEAT_INTERVAL 30
|
||||||
|
|
||||||
typedef struct SDL_VideoInfo
|
typedef struct SDL_VideoInfo
|
||||||
{
|
{
|
||||||
Uint32 hw_available:1;
|
Uint32 hw_available:1;
|
||||||
|
@ -173,6 +176,8 @@ extern DECLSPEC int SDLCALL SDL_DisplayYUVOverlay(SDL_Overlay * overlay,
|
||||||
SDL_Rect * dstrect);
|
SDL_Rect * dstrect);
|
||||||
extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
|
extern DECLSPEC void SDLCALL SDL_FreeYUVOverlay(SDL_Overlay * overlay);
|
||||||
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
|
extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
|
||||||
|
extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
|
||||||
|
extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
|
||||||
|
|
||||||
/* Ends C function definitions when using C++ */
|
/* Ends C function definitions when using C++ */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -92,32 +92,6 @@ extern DECLSPEC int SDLCALL SDL_SelectKeyboard(int index);
|
||||||
*/
|
*/
|
||||||
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
|
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
|
||||||
|
|
||||||
/**
|
|
||||||
* \fn int SDL_EnableKeyRepeat(int delay, int interval)
|
|
||||||
*
|
|
||||||
* \brief Enable keyboard repeat for the selected keyboard.
|
|
||||||
*
|
|
||||||
* \param delay The initial delay in milliseconds between the time when a
|
|
||||||
* key is pressed and keyboard repeat begins. Setting a delay
|
|
||||||
* of 0 will disable keyboard repeat.
|
|
||||||
* \param interval The time in milliseconds between keyboard repeat events.
|
|
||||||
*
|
|
||||||
* \return 0 on success, or -1 if there was an error.
|
|
||||||
*
|
|
||||||
* \note Keyboard repeat defaults to off.
|
|
||||||
*/
|
|
||||||
#define SDL_DEFAULT_REPEAT_DELAY 500
|
|
||||||
#define SDL_DEFAULT_REPEAT_INTERVAL 30
|
|
||||||
/**/
|
|
||||||
extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \fn void SDL_GetKeyRepeat(int *delay, int *interval)
|
|
||||||
*
|
|
||||||
* \brief Get the current keyboard repeat setting for the selected keyboard.
|
|
||||||
*/
|
|
||||||
extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn Uint8 *SDL_GetKeyState(int *numkeys)
|
* \fn Uint8 *SDL_GetKeyState(int *numkeys)
|
||||||
*
|
*
|
||||||
|
|
|
@ -240,6 +240,12 @@ SDL_CompatEventFilter(void *userdata, SDL_Event * event)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
{
|
||||||
|
/* FIXME: Generate an old style key repeat event if needed */
|
||||||
|
printf("TEXTINPUT: '%s'\n", event->text.text);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
Uint8 button;
|
Uint8 button;
|
||||||
|
@ -1447,4 +1453,22 @@ SDL_GL_SwapBuffers(void)
|
||||||
SDL_GL_SwapWindow(SDL_VideoWindow);
|
SDL_GL_SwapWindow(SDL_VideoWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
SDL_EnableKeyRepeat(int delay, int interval)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SDL_GetKeyRepeat(int *delay, int *interval)
|
||||||
|
{
|
||||||
|
if (delay) {
|
||||||
|
*delay = SDL_DEFAULT_REPEAT_DELAY;
|
||||||
|
}
|
||||||
|
if (interval) {
|
||||||
|
*interval = SDL_DEFAULT_REPEAT_INTERVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -111,10 +111,6 @@ SDL_GobbleEvents(void *unused)
|
||||||
if (_this) {
|
if (_this) {
|
||||||
_this->PumpEvents(_this);
|
_this->PumpEvents(_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Queue pending key-repeat events */
|
|
||||||
SDL_CheckKeyRepeat();
|
|
||||||
|
|
||||||
#if !SDL_JOYSTICK_DISABLED
|
#if !SDL_JOYSTICK_DISABLED
|
||||||
/* Check for joystick state change */
|
/* Check for joystick state change */
|
||||||
if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
|
if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
|
||||||
|
@ -386,10 +382,6 @@ SDL_PumpEvents(void)
|
||||||
if (_this) {
|
if (_this) {
|
||||||
_this->PumpEvents(_this);
|
_this->PumpEvents(_this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Queue pending key-repeat events */
|
|
||||||
SDL_CheckKeyRepeat();
|
|
||||||
|
|
||||||
#if !SDL_JOYSTICK_DISABLED
|
#if !SDL_JOYSTICK_DISABLED
|
||||||
/* Check for joystick state change */
|
/* Check for joystick state change */
|
||||||
if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
|
if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
|
||||||
|
|
|
@ -349,7 +349,6 @@ SDL_ResetKeyboard(int index)
|
||||||
SDL_SendKeyboardKey(index, SDL_RELEASED, 0, key);
|
SDL_SendKeyboardKey(index, SDL_RELEASED, 0, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
keyboard->repeat.timestamp = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -515,7 +514,7 @@ int
|
||||||
SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
|
SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
|
||||||
{
|
{
|
||||||
SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
|
SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
|
||||||
int posted, repeatable;
|
int posted;
|
||||||
Uint16 modstate;
|
Uint16 modstate;
|
||||||
Uint8 type;
|
Uint8 type;
|
||||||
|
|
||||||
|
@ -526,7 +525,6 @@ SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
|
||||||
printf("The '%s' key has been %s\n", SDL_GetKeyName(key),
|
printf("The '%s' key has been %s\n", SDL_GetKeyName(key),
|
||||||
state == SDL_PRESSED ? "pressed" : "released");
|
state == SDL_PRESSED ? "pressed" : "released");
|
||||||
#endif
|
#endif
|
||||||
repeatable = 0;
|
|
||||||
if (state == SDL_PRESSED) {
|
if (state == SDL_PRESSED) {
|
||||||
modstate = keyboard->modstate;
|
modstate = keyboard->modstate;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
@ -566,7 +564,6 @@ SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
|
||||||
keyboard->modstate |= KMOD_MODE;
|
keyboard->modstate |= KMOD_MODE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
repeatable = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -616,13 +613,6 @@ SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
|
||||||
break;
|
break;
|
||||||
case SDL_RELEASED:
|
case SDL_RELEASED:
|
||||||
type = SDL_KEYUP;
|
type = SDL_KEYUP;
|
||||||
/*
|
|
||||||
* jk 991215 - Added
|
|
||||||
*/
|
|
||||||
if (keyboard->repeat.timestamp &&
|
|
||||||
keyboard->repeat.evt.key.keysym.sym == key) {
|
|
||||||
keyboard->repeat.timestamp = 0;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Invalid state -- bail */
|
/* Invalid state -- bail */
|
||||||
|
@ -654,19 +644,6 @@ SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
|
||||||
event.key.keysym.mod = modstate;
|
event.key.keysym.mod = modstate;
|
||||||
event.key.keysym.unicode = 0;
|
event.key.keysym.unicode = 0;
|
||||||
event.key.windowID = keyboard->focus;
|
event.key.windowID = keyboard->focus;
|
||||||
/* FIXME: This doesn't make sense anymore... */
|
|
||||||
/*
|
|
||||||
* jk 991215 - Added
|
|
||||||
*/
|
|
||||||
if (repeatable && (keyboard->repeat.delay != 0)) {
|
|
||||||
Uint32 timestamp = SDL_GetTicks();
|
|
||||||
if (!timestamp) {
|
|
||||||
timestamp = 1;
|
|
||||||
}
|
|
||||||
keyboard->repeat.evt = event;
|
|
||||||
keyboard->repeat.firsttime = 1;
|
|
||||||
keyboard->repeat.timestamp = 1;
|
|
||||||
}
|
|
||||||
posted = (SDL_PushEvent(&event) > 0);
|
posted = (SDL_PushEvent(&event) > 0);
|
||||||
}
|
}
|
||||||
return (posted);
|
return (posted);
|
||||||
|
@ -695,84 +672,4 @@ SDL_SendKeyboardText(int index, const char *text)
|
||||||
return (posted);
|
return (posted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* jk 991215 - Added
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
SDL_CheckKeyRepeat(void)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < SDL_num_keyboards; ++i) {
|
|
||||||
SDL_Keyboard *keyboard = SDL_keyboards[i];
|
|
||||||
|
|
||||||
if (!keyboard) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyboard->repeat.timestamp) {
|
|
||||||
Uint32 now, interval;
|
|
||||||
|
|
||||||
now = SDL_GetTicks();
|
|
||||||
interval = (now - keyboard->repeat.timestamp);
|
|
||||||
if (keyboard->repeat.firsttime) {
|
|
||||||
if (interval > (Uint32) keyboard->repeat.delay) {
|
|
||||||
keyboard->repeat.timestamp = now;
|
|
||||||
keyboard->repeat.firsttime = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (interval > (Uint32) keyboard->repeat.interval) {
|
|
||||||
keyboard->repeat.timestamp = now;
|
|
||||||
SDL_PushEvent(&keyboard->repeat.evt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
SDL_EnableKeyRepeat(int delay, int interval)
|
|
||||||
{
|
|
||||||
SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
|
|
||||||
|
|
||||||
if (!keyboard) {
|
|
||||||
SDL_SetError("No keyboard is currently selected");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((delay < 0) || (interval < 0)) {
|
|
||||||
SDL_SetError("keyboard repeat value less than zero");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
keyboard->repeat.firsttime = 0;
|
|
||||||
keyboard->repeat.delay = delay;
|
|
||||||
keyboard->repeat.interval = interval;
|
|
||||||
keyboard->repeat.timestamp = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SDL_GetKeyRepeat(int *delay, int *interval)
|
|
||||||
{
|
|
||||||
SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
|
|
||||||
|
|
||||||
if (!keyboard) {
|
|
||||||
if (delay) {
|
|
||||||
*delay = 0;
|
|
||||||
}
|
|
||||||
if (interval) {
|
|
||||||
*interval = 0;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (delay) {
|
|
||||||
*delay = keyboard->repeat.delay;
|
|
||||||
}
|
|
||||||
if (interval) {
|
|
||||||
*interval = keyboard->repeat.interval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -39,16 +39,6 @@ struct SDL_Keyboard
|
||||||
Uint16 modstate;
|
Uint16 modstate;
|
||||||
Uint8 keystate[SDLK_LAST];
|
Uint8 keystate[SDLK_LAST];
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
int firsttime; /* if we check against the delay or repeat value */
|
|
||||||
int delay; /* the delay before we start repeating */
|
|
||||||
int interval; /* the delay between key repeat events */
|
|
||||||
Uint32 timestamp; /* the time the first keydown event occurred */
|
|
||||||
|
|
||||||
SDL_Event evt; /* the event we are supposed to repeat */
|
|
||||||
} repeat;
|
|
||||||
|
|
||||||
void *driverdata;
|
void *driverdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,9 +75,6 @@ extern int SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode,
|
||||||
/* Send keyboard text input for a keyboard at an index */
|
/* Send keyboard text input for a keyboard at an index */
|
||||||
extern int SDL_SendKeyboardText(int index, const char *text);
|
extern int SDL_SendKeyboardText(int index, const char *text);
|
||||||
|
|
||||||
/* Used by the event loop to queue pending keyboard repeat events */
|
|
||||||
extern void SDL_CheckKeyRepeat(void);
|
|
||||||
|
|
||||||
/* Shutdown the keyboard subsystem */
|
/* Shutdown the keyboard subsystem */
|
||||||
extern void SDL_KeyboardQuit(void);
|
extern void SDL_KeyboardQuit(void);
|
||||||
|
|
||||||
|
|
|
@ -532,15 +532,16 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
|
||||||
|
|
||||||
switch ([event type]) {
|
switch ([event type]) {
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
if ([event isARepeat]) {
|
if (![event isARepeat]) {
|
||||||
break;
|
|
||||||
}
|
|
||||||
SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode,
|
SDL_SendKeyboardKey(data->keyboard, SDL_PRESSED, (Uint8)scancode,
|
||||||
data->keymap[scancode]);
|
data->keymap[scancode]);
|
||||||
|
}
|
||||||
|
if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
|
||||||
text = [[event characters] UTF8String];
|
text = [[event characters] UTF8String];
|
||||||
if(text && *text) {
|
if(text && *text) {
|
||||||
SDL_SendKeyboardText(data->keyboard, text);
|
SDL_SendKeyboardText(data->keyboard, text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case NSKeyUp:
|
case NSKeyUp:
|
||||||
SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode,
|
SDL_SendKeyboardKey(data->keyboard, SDL_RELEASED, (Uint8)scancode,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue