X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=4c9ecc8b569b0629a879f0e41746c163f299d343;hp=ebcb5e1d1ee1427fb767c0f8583182e5935abca0;hb=a8816d6e5319f9ec26a45346b08250f61e95c011;hpb=8848a001bf529a3e06710b80b928094e48f25aa8 diff --git a/src/events.c b/src/events.c index ebcb5e1d..4c9ecc8b 100644 --- a/src/events.c +++ b/src/events.c @@ -29,17 +29,28 @@ static boolean cursor_inside_playfield = FALSE; static boolean playfield_cursor_set = FALSE; -static unsigned long playfield_cursor_delay = 0; +static unsigned int playfield_cursor_delay = 0; /* event filter especially needed for SDL event filtering due to delay problems with lots of mouse motion events when mouse button not pressed (X11 can handle this with 'PointerMotionHintMask') */ -int FilterMouseMotionEvents(const Event *event) +/* event filter addition for SDL2: as SDL2 does not have a function to enable + or disable keyboard auto-repeat, filter repeated keyboard events instead */ + +static int FilterEventsExt(const Event *event) { MotionEvent *motion; +#if defined(TARGET_SDL2) + /* skip repeated key press events if keyboard auto-repeat is disabled */ + if (event->type == EVENT_KEYPRESS && + event->key.repeat && + !keyrepeat_status) + return 0; +#endif + /* non-motion events are directly passed to event handler functions */ if (event->type != EVENT_MOTIONNOTIFY) return 1; @@ -59,9 +70,21 @@ int FilterMouseMotionEvents(const Event *event) if (button_status == MB_RELEASED && game_status != GAME_MODE_EDITOR && game_status != GAME_MODE_PLAYING) return 0; - else - return 1; + + return 1; +} + +#if defined(TARGET_SDL2) +int FilterEvents(void *userdata, Event *event) +{ + return FilterEventsExt(event); +} +#else +int FilterEvents(const Event *event) +{ + return FilterEventsExt(event); } +#endif /* to prevent delay problems, skip mouse motion events if the very next event is also a mouse motion event (and therefore effectively only @@ -104,7 +127,7 @@ static boolean NextValidEvent(Event *event) NextEvent(event); - if (FilterMouseMotionEvents(event)) + if (FilterEventsExt(event)) handle_this_event = TRUE; if (SkipPressedMouseMotionEvent(event)) @@ -137,7 +160,15 @@ void EventLoop(void) case EVENT_MOTIONNOTIFY: HandleMotionEvent((MotionEvent *) &event); break; - + +#if defined(TARGET_SDL2) + case EVENT_FINGERPRESS: + case EVENT_FINGERRELEASE: + case EVENT_FINGERMOTION: + HandleFingerEvent((FingerEvent *) &event); + break; +#endif + case EVENT_KEYPRESS: case EVENT_KEYRELEASE: HandleKeyEvent((KeyEvent *) &event); @@ -318,7 +349,7 @@ void SleepWhileUnmapped() void HandleExposeEvent(ExposeEvent *event) { -#ifndef TARGET_SDL +#if !defined(TARGET_SDL) RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height); FlushDisplay(); #endif @@ -354,6 +385,33 @@ void HandleMotionEvent(MotionEvent *event) HandleButton(event->x, event->y, button_status, button_status); } +#if defined(TARGET_SDL2) +void HandleFingerEvent(FingerEvent *event) +{ + // #if DEBUG_EVENTS + Error(ERR_DEBUG, "FINGER EVENT: finger was %s, touch ID %lld, finger ID %lld, x/y %f/%f, dx/dy %f/%f, pressure %f", + (event->type == EVENT_FINGERPRESS ? "pressed" : + event->type == EVENT_FINGERRELEASE ? "released" : "moved"), + event->touchId, + event->fingerId, + event->x, event->y, + event->dx, event->dy, + event->pressure); + // #endif + +#if 1 + CloseAllAndExit(0); +#else + if (event->type == EVENT_FINGERPRESS) + button_status = event->button; + else + button_status = MB_RELEASED; + + HandleButton(event->x, event->y, button_status, event->button); +#endif +} +#endif + void HandleKeyEvent(KeyEvent *event) { int key_status = (event->type==EVENT_KEYPRESS ? KEY_PRESSED : KEY_RELEASED); @@ -1012,7 +1070,7 @@ void HandleKey(Key key, int key_status) } break; - case KSYM_S: + case KSYM_s: if (!global.fps_slowdown) { global.fps_slowdown = TRUE; @@ -1141,7 +1199,7 @@ void HandleJoystick() case GAME_MODE_SETUP: case GAME_MODE_INFO: { - static unsigned long joystickmove_delay = 0; + static unsigned int joystickmove_delay = 0; if (joystick && !button && !DelayReached(&joystickmove_delay, GADGET_FRAME_DELAY))