Added some debug logging to print out every event added to the SDL queue.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 03 Nov 2016 01:29:56 -0400
changeset 10573422723a6efc3
parent 10572 8b8a45c000f9
child 10574 3cc0fe7f98d7
Added some debug logging to print out every event added to the SDL queue.
src/events/SDL_events.c
     1.1 --- a/src/events/SDL_events.c	Wed Nov 02 02:56:54 2016 -0700
     1.2 +++ b/src/events/SDL_events.c	Thu Nov 03 01:29:56 2016 -0400
     1.3 @@ -33,6 +33,8 @@
     1.4  #endif
     1.5  #include "../video/SDL_sysvideo.h"
     1.6  
     1.7 +/*#define SDL_DEBUG_EVENTS 1*/
     1.8 +
     1.9  /* An arbitrary limit so we don't have unbounded growth */
    1.10  #define SDL_MAX_QUEUED_EVENTS   65535
    1.11  
    1.12 @@ -84,6 +86,230 @@
    1.13  } SDL_EventQ = { NULL, { 1 }, { 0 }, 0, NULL, NULL, NULL, NULL, NULL };
    1.14  
    1.15  
    1.16 +#ifdef SDL_DEBUG_EVENTS
    1.17 +
    1.18 +/* this is to make printf() calls cleaner. */
    1.19 +#define uint unsigned int
    1.20 +
    1.21 +static void
    1.22 +SDL_DebugPrintEvent(const SDL_Event *event)
    1.23 +{
    1.24 +    /* !!! FIXME: This code is kinda ugly, sorry. */
    1.25 +    printf("SDL EVENT: ");
    1.26 +
    1.27 +    if ((event->type >= SDL_USEREVENT) && (event->type <= SDL_LASTEVENT)) {
    1.28 +        printf("SDL_USEREVENT");
    1.29 +        if (event->type > SDL_USEREVENT) {
    1.30 +            printf("+%u", ((uint) event->type) - SDL_USEREVENT);
    1.31 +        }
    1.32 +        printf(" (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
    1.33 +                (uint) event->user.timestamp, (uint) event->user.windowID,
    1.34 +                (int) event->user.code, event->user.data1, event->user.data2);
    1.35 +        return;
    1.36 +    }
    1.37 +
    1.38 +    switch (event->type) {
    1.39 +        #define SDL_EVENT_CASE(x) case x: printf("%s", #x);
    1.40 +        SDL_EVENT_CASE(SDL_FIRSTEVENT) printf("(THIS IS PROBABLY A BUG!)"); break;
    1.41 +        SDL_EVENT_CASE(SDL_QUIT) printf("(timestamp=%u)", (uint) event->quit.timestamp); break;
    1.42 +        SDL_EVENT_CASE(SDL_APP_TERMINATING) break;
    1.43 +        SDL_EVENT_CASE(SDL_APP_LOWMEMORY) break;
    1.44 +        SDL_EVENT_CASE(SDL_APP_WILLENTERBACKGROUND) break;
    1.45 +        SDL_EVENT_CASE(SDL_APP_DIDENTERBACKGROUND) break;
    1.46 +        SDL_EVENT_CASE(SDL_APP_WILLENTERFOREGROUND) break;
    1.47 +        SDL_EVENT_CASE(SDL_APP_DIDENTERFOREGROUND) break;
    1.48 +        SDL_EVENT_CASE(SDL_KEYMAPCHANGED) break;
    1.49 +        SDL_EVENT_CASE(SDL_CLIPBOARDUPDATE); break;
    1.50 +        SDL_EVENT_CASE(SDL_RENDER_TARGETS_RESET) break;
    1.51 +        SDL_EVENT_CASE(SDL_RENDER_DEVICE_RESET) break;
    1.52 +        #undef SDL_EVENT_CASE
    1.53 +
    1.54 +        #define SDL_EVENT_CASE(x) case x: printf("%s ", #x);
    1.55 +
    1.56 +        SDL_EVENT_CASE(SDL_WINDOWEVENT)
    1.57 +            printf("(timestamp=%u windowid=%u event=", (uint) event->window.timestamp, (uint) event->window.windowID);
    1.58 +            switch(event->window.event) {
    1.59 +                case SDL_WINDOWEVENT_NONE: printf("none(THIS IS PROBABLY A BUG!)"); break;
    1.60 +                #define SDL_WINDOWEVENT_CASE(x) case x: printf("%s", #x); break
    1.61 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_SHOWN);
    1.62 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_HIDDEN);
    1.63 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_EXPOSED);
    1.64 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_MOVED);
    1.65 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_RESIZED);
    1.66 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_SIZE_CHANGED);
    1.67 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_MINIMIZED);
    1.68 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_MAXIMIZED);
    1.69 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_RESTORED);
    1.70 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_ENTER);
    1.71 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_LEAVE);
    1.72 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_FOCUS_GAINED);
    1.73 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_FOCUS_LOST);
    1.74 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_CLOSE);
    1.75 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_TAKE_FOCUS);
    1.76 +                SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_HIT_TEST);
    1.77 +                #undef SDL_WINDOWEVENT_CASE
    1.78 +                default: printf("UNKNOWN(bug? fixme?)"); break;
    1.79 +            }
    1.80 +            printf(" data1=%d data2=%d)", (int) event->window.data1, (int) event->window.data2);
    1.81 +            break;
    1.82 +
    1.83 +        SDL_EVENT_CASE(SDL_SYSWMEVENT)
    1.84 +            printf("(timestamp=%u)", (uint) event->syswm.timestamp);
    1.85 +            /* !!! FIXME: we don't delve further at the moment. */
    1.86 +            break;
    1.87 +
    1.88 +        #define PRINT_KEY_EVENT(event) \
    1.89 +            printf("(timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
    1.90 +                (uint) event->key.timestamp, (uint) event->key.windowID, \
    1.91 +                event->key.state == SDL_PRESSED ? "pressed" : "released", \
    1.92 +                event->key.repeat ? "true" : "false", \
    1.93 +                (uint) event->key.keysym.scancode, \
    1.94 +                (uint) event->key.keysym.sym, \
    1.95 +                (uint) event->key.keysym.mod)
    1.96 +        SDL_EVENT_CASE(SDL_KEYDOWN) PRINT_KEY_EVENT(event); break;
    1.97 +        SDL_EVENT_CASE(SDL_KEYUP) PRINT_KEY_EVENT(event); break;
    1.98 +        #undef PRINT_KEY_EVENT
    1.99 +
   1.100 +        SDL_EVENT_CASE(SDL_TEXTEDITING)
   1.101 +            printf("(timestamp=%u windowid=%u text='%s' start=%d length=%d)",
   1.102 +                (uint) event->edit.timestamp, (uint) event->edit.windowID,
   1.103 +                event->edit.text, (int) event->edit.start, (int) event->edit.length);
   1.104 +            break;
   1.105 +
   1.106 +        SDL_EVENT_CASE(SDL_TEXTINPUT)
   1.107 +            printf("(timestamp=%u windowid=%u text='%s')", (uint) event->text.timestamp, (uint) event->text.windowID, event->text.text);
   1.108 +            break;
   1.109 +
   1.110 +
   1.111 +        SDL_EVENT_CASE(SDL_MOUSEMOTION)
   1.112 +            printf("(timestamp=%u windowid=%u which=%u state=%u x=%d y=%d xrel=%d yrel=%d)",
   1.113 +                    (uint) event->motion.timestamp, (uint) event->motion.windowID,
   1.114 +                    (uint) event->motion.which, (uint) event->motion.state,
   1.115 +                    (int) event->motion.x, (int) event->motion.y,
   1.116 +                    (int) event->motion.xrel, (int) event->motion.yrel);
   1.117 +            break;
   1.118 +
   1.119 +        #define PRINT_MBUTTON_EVENT(event) \
   1.120 +            printf("(timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
   1.121 +                    (uint) event->button.timestamp, (uint) event->button.windowID, \
   1.122 +                    (uint) event->button.which, (uint) event->button.button, \
   1.123 +                    event->button.state == SDL_PRESSED ? "pressed" : "released", \
   1.124 +                    (uint) event->button.clicks, (int) event->button.x, (int) event->button.y)
   1.125 +        SDL_EVENT_CASE(SDL_MOUSEBUTTONDOWN) PRINT_MBUTTON_EVENT(event); break;
   1.126 +        SDL_EVENT_CASE(SDL_MOUSEBUTTONUP) PRINT_MBUTTON_EVENT(event); break;
   1.127 +        #undef PRINT_MBUTTON_EVENT
   1.128 +
   1.129 +
   1.130 +        SDL_EVENT_CASE(SDL_MOUSEWHEEL)
   1.131 +            printf("(timestamp=%u windowid=%u which=%u x=%d y=%d direction=%s)",
   1.132 +                    (uint) event->wheel.timestamp, (uint) event->wheel.windowID,
   1.133 +                    (uint) event->wheel.which, (int) event->wheel.x, (int) event->wheel.y,
   1.134 +                    event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
   1.135 +            break;
   1.136 +
   1.137 +        SDL_EVENT_CASE(SDL_JOYAXISMOTION)
   1.138 +            printf("(timestamp=%u which=%d axis=%u value=%d)",
   1.139 +                (uint) event->jaxis.timestamp, (int) event->jaxis.which,
   1.140 +                (uint) event->jaxis.axis, (int) event->jaxis.value);
   1.141 +            break;
   1.142 +
   1.143 +        SDL_EVENT_CASE(SDL_JOYBALLMOTION)
   1.144 +            printf("(timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
   1.145 +                (uint) event->jball.timestamp, (int) event->jball.which,
   1.146 +                (uint) event->jball.ball, (int) event->jball.xrel, (int) event->jball.yrel);
   1.147 +            break;
   1.148 +
   1.149 +        SDL_EVENT_CASE(SDL_JOYHATMOTION)
   1.150 +            printf("(timestamp=%u which=%d hat=%u value=%u)",
   1.151 +                (uint) event->jhat.timestamp, (int) event->jhat.which,
   1.152 +                (uint) event->jhat.hat, (uint) event->jhat.value);
   1.153 +            break;
   1.154 +
   1.155 +        #define PRINT_JBUTTON_EVENT(event) \
   1.156 +            printf("(timestamp=%u which=%d button=%u state=%s)", \
   1.157 +                (uint) event->jbutton.timestamp, (int) event->jbutton.which, \
   1.158 +                (uint) event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
   1.159 +        SDL_EVENT_CASE(SDL_JOYBUTTONDOWN) PRINT_JBUTTON_EVENT(event); break;
   1.160 +        SDL_EVENT_CASE(SDL_JOYBUTTONUP) PRINT_JBUTTON_EVENT(event); break;
   1.161 +        #undef PRINT_JBUTTON_EVENT
   1.162 +
   1.163 +        #define PRINT_JOYDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which)
   1.164 +        SDL_EVENT_CASE(SDL_JOYDEVICEADDED) PRINT_JOYDEV_EVENT(event); break;
   1.165 +        SDL_EVENT_CASE(SDL_JOYDEVICEREMOVED) PRINT_JOYDEV_EVENT(event); break;
   1.166 +        #undef PRINT_JOYDEV_EVENT
   1.167 +
   1.168 +        SDL_EVENT_CASE(SDL_CONTROLLERAXISMOTION)
   1.169 +            printf("(timestamp=%u which=%d axis=%u value=%d)",
   1.170 +                (uint) event->caxis.timestamp, (int) event->caxis.which,
   1.171 +                (uint) event->caxis.axis, (int) event->caxis.value);
   1.172 +            break;
   1.173 +
   1.174 +        #define PRINT_CBUTTON_EVENT(event) \
   1.175 +            printf("(timestamp=%u which=%d button=%u state=%s)", \
   1.176 +                (uint) event->cbutton.timestamp, (int) event->cbutton.which, \
   1.177 +                (uint) event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
   1.178 +        SDL_EVENT_CASE(SDL_CONTROLLERBUTTONDOWN) PRINT_CBUTTON_EVENT(event); break;
   1.179 +        SDL_EVENT_CASE(SDL_CONTROLLERBUTTONUP) PRINT_CBUTTON_EVENT(event); break;
   1.180 +        #undef PRINT_CBUTTON_EVENT
   1.181 +
   1.182 +        #define PRINT_CONTROLLERDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which)
   1.183 +        SDL_EVENT_CASE(SDL_CONTROLLERDEVICEADDED) PRINT_CONTROLLERDEV_EVENT(event); break;
   1.184 +        SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMOVED) PRINT_CONTROLLERDEV_EVENT(event); break;
   1.185 +        SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMAPPED) PRINT_CONTROLLERDEV_EVENT(event); break;
   1.186 +        #undef PRINT_CONTROLLERDEV_EVENT
   1.187 +
   1.188 +        #define PRINT_FINGER_EVENT(event) \
   1.189 +            printf("(timestamp=%u touchid=%lld fingerid=%lld x=%f y=%f dx=%f dy=%f pressure=%f)", \
   1.190 +                (uint) event->tfinger.timestamp, (long long) event->tfinger.touchId, \
   1.191 +                (long long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, \
   1.192 +                event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
   1.193 +        SDL_EVENT_CASE(SDL_FINGERDOWN) PRINT_FINGER_EVENT(event); break;
   1.194 +        SDL_EVENT_CASE(SDL_FINGERUP) PRINT_FINGER_EVENT(event); break;
   1.195 +        SDL_EVENT_CASE(SDL_FINGERMOTION) PRINT_FINGER_EVENT(event); break;
   1.196 +        #undef PRINT_FINGER_EVENT
   1.197 +
   1.198 +        #define PRINT_DOLLAR_EVENT(event) \
   1.199 +            printf("(timestamp=%u touchid=%lld gestureid=%lld numfingers=%u error=%f x=%f y=%f)", \
   1.200 +                (uint) event->dgesture.timestamp, (long long) event->dgesture.touchId, \
   1.201 +                (long long) event->dgesture.gestureId, (uint) event->dgesture.numFingers, \
   1.202 +                event->dgesture.error, event->dgesture.x, event->dgesture.y);
   1.203 +        SDL_EVENT_CASE(SDL_DOLLARGESTURE) PRINT_DOLLAR_EVENT(event); break;
   1.204 +        SDL_EVENT_CASE(SDL_DOLLARRECORD) PRINT_DOLLAR_EVENT(event); break;
   1.205 +        #undef PRINT_DOLLAR_EVENT
   1.206 +
   1.207 +        SDL_EVENT_CASE(SDL_MULTIGESTURE)
   1.208 +            printf("(timestamp=%u touchid=%lld dtheta=%f ddist=%f x=%f y=%f numfingers=%u)",
   1.209 +                (uint) event->mgesture.timestamp, (long long) event->mgesture.touchId,
   1.210 +                event->mgesture.dTheta, event->mgesture.dDist,
   1.211 +                event->mgesture.x, event->mgesture.y, (uint) event->mgesture.numFingers);
   1.212 +            break;
   1.213 +
   1.214 +        #define PRINT_DROP_EVENT(event) printf("(file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID)
   1.215 +        SDL_EVENT_CASE(SDL_DROPFILE) PRINT_DROP_EVENT(event); break;
   1.216 +        SDL_EVENT_CASE(SDL_DROPTEXT) PRINT_DROP_EVENT(event); break;
   1.217 +        SDL_EVENT_CASE(SDL_DROPBEGIN) PRINT_DROP_EVENT(event); break;
   1.218 +        SDL_EVENT_CASE(SDL_DROPCOMPLETE) PRINT_DROP_EVENT(event); break;
   1.219 +        #undef PRINT_DROP_EVENT
   1.220 +
   1.221 +        #define PRINT_AUDIODEV_EVENT(event) printf("(timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false");
   1.222 +        SDL_EVENT_CASE(SDL_AUDIODEVICEADDED) PRINT_AUDIODEV_EVENT(event); break;
   1.223 +        SDL_EVENT_CASE(SDL_AUDIODEVICEREMOVED) PRINT_AUDIODEV_EVENT(event); break;
   1.224 +        #undef PRINT_AUDIODEV_EVENT
   1.225 +
   1.226 +        #undef SDL_EVENT_CASE
   1.227 +
   1.228 +        default:
   1.229 +            printf("UNKNOWN SDL EVENT #%u! (Bug? FIXME?)", (uint) event->type);
   1.230 +            break;
   1.231 +    }
   1.232 +
   1.233 +    printf("\n");
   1.234 +}
   1.235 +#undef uint
   1.236 +#endif
   1.237 +
   1.238 +
   1.239 +
   1.240  /* Public functions */
   1.241  
   1.242  void
   1.243 @@ -209,6 +435,10 @@
   1.244          SDL_EventQ.free = entry->next;
   1.245      }
   1.246  
   1.247 +    #ifdef SDL_DEBUG_EVENTS
   1.248 +    SDL_DebugPrintEvent(event);
   1.249 +    #endif
   1.250 +
   1.251      entry->event = *event;
   1.252      if (event->type == SDL_SYSWMEVENT) {
   1.253          entry->msg = *event->syswm.msg;