Author: richard
Date: Mon Jan 12 08:24:09 2009
New Revision: 3773
URL: http://svn.slimdevices.com?rev=3773&root=Jive&view=rev
Log:
Bug: N/A
Description:
Don't use (or initialize) SDL timers.
Modified:
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_event.c
7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h?rev=3773&root=Jive&r1=3772&r2=3773&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive.h Mon Jan 12 08:24:09 2009
@@ -141,8 +141,8 @@
enum {
/* reserved: 0x00000001 */
- JIVE_USER_EVENT_KEY_HOLD = 0x00000002,
- JIVE_USER_EVENT_MOUSE_HOLD = 0x00000003,
+ /* reserved: 0x00000002 */
+ /* reserved: 0x00000003 */
JIVE_USER_EVENT_EVENT = 0x00000004,
};
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_event.c
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_event.c?rev=3773&root=Jive&r1=3772&r2=3773&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_event.c (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_event.c Mon Jan 12
08:24:09 2009
@@ -276,6 +276,10 @@
lua_pushfstring(L, "KEY_HOLD code=%d", event->u.key.code);
break;
+ case JIVE_EVENT_CHAR_PRESS:
+ lua_pushfstring(L, "CHAR_PRESS code=%d", event->u.text.unicode);
+ break;
+
case JIVE_ACTION:
//todo: also show actionEventName - convert index to
actionEventName by calling Framework:getActionEventNameByIndex
lua_pushfstring(L, "ACTION actionIndex=%d",
event->u.action.index);
Modified: 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
URL:
http://svn.slimdevices.com/7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c?rev=3773&root=Jive&r1=3772&r2=3773&view=diff
==============================================================================
--- 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c (original)
+++ 7.4/trunk/squeezeplay/src/squeezeplay/src/ui/jive_framework.c Mon Jan 12
08:24:09 2009
@@ -64,11 +64,12 @@
static JiveKey key_mask = 0;
-static SDL_TimerID key_timer = NULL;
-
-static SDL_TimerID mouse_timer = NULL;
-
-static SDL_TimerID pointer_timer = NULL;
+static Uint32 key_timeout = 0;
+
+static Uint32 mouse_timeout = 0;
+static Uint32 mouse_timeout_arg;
+
+static Uint32 pointer_timeout = 0;
static Uint16 mouse_origin_x, mouse_origin_y;
@@ -84,13 +85,14 @@
{ SDLK_AudioNext, JIVE_KEY_FWD },
{ SDLK_AudioRaiseVolume,JIVE_KEY_VOLUME_UP },
{ SDLK_AudioLowerVolume,JIVE_KEY_VOLUME_DOWN },
- { SDLK_PAGEUP, JIVE_KEY_PAGE_UP },
- { SDLK_PAGEDOWN, JIVE_KEY_PAGE_DOWN },
+ { SDLK_PAGEUP, JIVE_KEY_PAGE_UP },
+ { SDLK_PAGEDOWN, JIVE_KEY_PAGE_DOWN },
{ SDLK_UNKNOWN, JIVE_KEY_NONE },
};
static int process_event(lua_State *L, SDL_Event *event);
+static void process_timers(lua_State *L);
static int filter_events(const SDL_Event *event);
int jiveL_update_screen(lua_State *L);
@@ -139,7 +141,7 @@
SDL_putenv("SDL_NOMOUSE=1");
/* initialise SDL */
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_Init(V|T|A): %s\n", SDL_GetError());
SDL_Quit();
exit(-1);
@@ -266,6 +268,7 @@
}
/* process events */
+ process_timers(L);
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) > 0 ) {
r |= process_event(L, &event);
}
@@ -804,40 +807,6 @@
}
-static Uint32 keyhold_callback(Uint32 interval, void *param) {
- SDL_Event user_event;
- memset(&user_event, 0, sizeof(SDL_Event));
-
- user_event.type = SDL_USEREVENT;
- user_event.user.code = JIVE_USER_EVENT_KEY_HOLD;
- user_event.user.data1 = param;
-
- SDL_PushEvent(&user_event);
-
- return 0;
-}
-
-
-static Uint32 mousehold_callback(Uint32 interval, void *param) {
- SDL_Event user_event;
- memset(&user_event, 0, sizeof(SDL_Event));
-
- user_event.type = SDL_USEREVENT;
- user_event.user.code = JIVE_USER_EVENT_MOUSE_HOLD;
- user_event.user.data1 = param;
-
- SDL_PushEvent(&user_event);
-
- return 0;
-}
-
-static Uint32 pointer_callback(Uint32 interval, void *param) {
- SDL_ShowCursor(SDL_DISABLE);
-
- return 0;
-}
-
-
static int do_dispatch_event(lua_State *L, JiveEvent *jevent) {
int r;
@@ -857,9 +826,10 @@
static int process_event(lua_State *L, SDL_Event *event) {
JiveEvent jevent;
+ Uint32 now;
memset(&jevent, 0, sizeof(JiveEvent));
- jevent.ticks = SDL_GetTicks();
+ jevent.ticks = now = SDL_GetTicks();
switch (event->type) {
case SDL_QUIT:
@@ -898,16 +868,9 @@
if (event->type == SDL_MOUSEBUTTONDOWN) {
if (mouse_state == MOUSE_STATE_NONE) {
- unsigned int * param = malloc(sizeof(unsigned
int));
-
mouse_state = MOUSE_STATE_DOWN;
-
- if (mouse_timer) {
- SDL_RemoveTimer(mouse_timer);
- }
-
- *param = (event->button.y << 16) |
event->button.x;
- mouse_timer = SDL_AddTimer(HOLD_TIMEOUT,
&mousehold_callback, param);
+ mouse_timeout_arg = (event->button.y << 16) |
event->button.x;
+ mouse_timeout = now + HOLD_TIMEOUT;
mouse_origin_x = event->button.x;
mouse_origin_y = event->button.y;
@@ -929,11 +892,7 @@
jive_queue_event(&up);
}
- if (mouse_timer) {
- SDL_RemoveTimer(mouse_timer);
- mouse_timer = NULL;
- }
-
+ mouse_timeout = 0;
mouse_state = MOUSE_STATE_NONE;
}
break;
@@ -941,11 +900,10 @@
case SDL_MOUSEMOTION:
/* show mouse cursor */
- if (pointer_timer) {
- SDL_RemoveTimer(pointer_timer);
- }
- SDL_ShowCursor(SDL_ENABLE);
- SDL_AddTimer(POINTER_TIMEOUT, &pointer_callback, NULL);
+ if (pointer_timeout == 0) {
+ SDL_ShowCursor(SDL_ENABLE);
+ }
+ pointer_timeout = now + POINTER_TIMEOUT;
if (event->motion.state & SDL_BUTTON(1)) {
if ( ( (mouse_state == MOUSE_STATE_DOWN || mouse_state
== MOUSE_STATE_SENT)
@@ -992,37 +950,26 @@
if (entry->keysym == SDLK_UNKNOWN) {
// handle regular character keys ('a', 't', etc..)
if (event->type == SDL_KEYDOWN &&
event->key.keysym.unicode != 0) {
- JiveEvent textEvent;
-
- memset(&textEvent, 0, sizeof(JiveEvent));
- textEvent.type = JIVE_EVENT_CHAR_PRESS;
- textEvent.ticks = SDL_GetTicks();
+ jevent.type = JIVE_EVENT_CHAR_PRESS;
if (event->key.keysym.sym == SDLK_BACKSPACE) {
//special case for Backspace, where
value set is not ascii value, instead pass backspace ascii value
- textEvent.u.text.unicode = 8;
+ jevent.u.text.unicode = 8;
} else {
- textEvent.u.text.unicode =
event->key.keysym.unicode;
+ jevent.u.text.unicode =
event->key.keysym.unicode;
}
- jive_queue_event(&textEvent);
- }
- return 0;
+ }
}
/* handle pgup/upgn as repeatable keys */
- if (entry->keysym == SDLK_PAGEUP || entry->keysym ==
SDLK_PAGEDOWN) {
+ else if (entry->keysym == SDLK_PAGEUP || entry->keysym ==
SDLK_PAGEDOWN) {
if (event->type == SDL_KEYDOWN) {
- JiveEvent keypress;
-
- memset(&keypress, 0, sizeof(JiveEvent));
- keypress.type = JIVE_EVENT_KEY_PRESS;
- keypress.ticks = SDL_GetTicks();
- keypress.u.key.code = entry->keycode;
- jive_queue_event(&keypress);
- }
- return 0;
+ jevent.type = JIVE_EVENT_KEY_PRESS;
+ jevent.ticks = SDL_GetTicks();
+ jevent.u.key.code = entry->keycode;
+ }
}
- if (event->type == SDL_KEYDOWN) {
+ else if (event->type == SDL_KEYDOWN) {
if (key_mask & entry->keycode) {
// ignore key repeats
return 0;
@@ -1042,11 +989,7 @@
jevent.type = JIVE_EVENT_KEY_DOWN;
jevent.u.key.code = entry->keycode;
- if (key_timer) {
- SDL_RemoveTimer(key_timer);
- }
-
- key_timer = SDL_AddTimer(HOLD_TIMEOUT,
&keyhold_callback, (void *)key_mask);
+ key_timeout = now + HOLD_TIMEOUT;
break;
}
@@ -1093,11 +1036,7 @@
}
}
- if (key_timer) {
- SDL_RemoveTimer(key_timer);
- key_timer = NULL;
- }
-
+ key_timeout = 0;
key_mask &= ~(entry->keycode);
if (key_mask == 0) {
key_state = KEY_STATE_NONE;
@@ -1107,28 +1046,10 @@
}
case SDL_USEREVENT:
- switch ( (int) event->user.code) {
- case JIVE_USER_EVENT_KEY_HOLD:
- jevent.type = JIVE_EVENT_KEY_HOLD;
- jevent.u.key.code = (JiveKey) event->user.data1;
- key_state = KEY_STATE_SENT;
- break;
-
- case JIVE_USER_EVENT_MOUSE_HOLD:
- if (mouse_state == MOUSE_STATE_DOWN) {
- jevent.type = JIVE_EVENT_MOUSE_HOLD;
- jevent.u.mouse.x = *((unsigned int *)
event->user.data1) & 0xFFFF;
- jevent.u.mouse.y = ( *((unsigned int *)
event->user.data1) >> 16) & 0xFFFF;
- mouse_state = MOUSE_STATE_SENT;
- free(event->user.data1);
- }
- break;
-
- case JIVE_USER_EVENT_EVENT:
- memcpy(&jevent, event->user.data1, sizeof(JiveEvent));
- free(event->user.data1);
- break;
- }
+ assert(event->user.code == JIVE_USER_EVENT_EVENT);
+
+ memcpy(&jevent, event->user.data1, sizeof(JiveEvent));
+ free(event->user.data1);
break;
case SDL_VIDEORESIZE: {
@@ -1169,6 +1090,42 @@
}
return do_dispatch_event(L, &jevent);
+}
+
+
+static void process_timers(lua_State *L) {
+ JiveEvent jevent;
+ Uint32 now;
+
+ memset(&jevent, 0, sizeof(JiveEvent));
+ jevent.ticks = now = SDL_GetTicks();
+
+ if (pointer_timeout && pointer_timeout < now) {
+ SDL_ShowCursor(SDL_DISABLE);
+ pointer_timeout = 0;
+ }
+
+ if (mouse_timeout && mouse_timeout < now) {
+ if (mouse_state == MOUSE_STATE_DOWN) {
+ jevent.type = JIVE_EVENT_MOUSE_HOLD;
+ jevent.u.mouse.x = (mouse_timeout_arg >> 0) & 0xFFFF;
+ jevent.u.mouse.y = (mouse_timeout_arg >> 16) & 0xFFFF;
+ mouse_state = MOUSE_STATE_SENT;
+
+ do_dispatch_event(L, &jevent);
+ }
+ mouse_timeout = 0;
+ }
+
+ if (key_timeout && key_timeout < now) {
+ jevent.type = JIVE_EVENT_KEY_HOLD;
+ jevent.u.key.code = key_mask;
+ key_state = KEY_STATE_SENT;
+
+ do_dispatch_event(L, &jevent);
+
+ key_timeout = 0;
+ }
}
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins