indent
authorSam Lantinga <slouken@libsdl.org>
Sat, 23 May 2009 22:41:08 +0000
changeset 3139 7f684f249ec9
parent 3125 d71d8ceda8b3
child 3140 9ef99b844c60
child 3160 210e209b87cc
child 3710 8600c345cd77
indent
XCodeiPhoneOS/Demos/src/keyboard.c
XCodeiPhoneOS/Demos/src/mixer.c
include/SDL_opengles.h
include/SDL_video.h
src/SDL_compat.c
src/audio/SDL_audio.c
src/audio/qsa/SDL_qsa_audio.c
src/audio/qsa/SDL_qsa_audio.h
src/video/SDL_renderer_gles.c
src/video/SDL_video.c
src/video/nds/SDL_ndsrender.c
src/video/photon/SDL_photon.c
src/video/photon/SDL_photon.h
src/video/photon/SDL_photon_input.c
src/video/photon/SDL_photon_input.h
src/video/photon/SDL_photon_keycodes.h
src/video/photon/SDL_photon_pixelfmt.c
src/video/photon/SDL_photon_render.c
src/video/photon/SDL_photon_render.h
src/video/qnxgf/SDL_gf_input.c
src/video/qnxgf/SDL_gf_input.h
src/video/qnxgf/SDL_gf_opengles.c
src/video/qnxgf/SDL_gf_opengles.h
src/video/qnxgf/SDL_gf_pixelfmt.c
src/video/qnxgf/SDL_gf_pixelfmt.h
src/video/qnxgf/SDL_gf_render.c
src/video/qnxgf/SDL_gf_render.h
src/video/qnxgf/SDL_hiddi_keyboard.h
src/video/qnxgf/SDL_hiddi_mouse.h
src/video/qnxgf/SDL_qnxgf.c
src/video/qnxgf/SDL_qnxgf.h
src/video/win32/SDL_gdirender.c
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32gamma.c
src/video/win32/SDL_win32modes.c
src/video/win32/SDL_win32opengl.c
src/video/win32/SDL_win32window.c
src/video/x11/SDL_x11opengl.c
test/testdyngles.c
test/testgl2.c
test/testgles.c
--- a/XCodeiPhoneOS/Demos/src/keyboard.c	Fri May 15 15:47:37 2009 +0000
+++ b/XCodeiPhoneOS/Demos/src/keyboard.c	Sat May 23 22:41:08 2009 +0000
@@ -174,7 +174,8 @@
 drawBlank(int x, int y)
 {
     SDL_Rect rect = { x, y, GLYPH_SIZE_SCREEN, GLYPH_SIZE_SCREEN };
-    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused);
+    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
+                           bg_color.unused);
     SDL_RenderFill(&rect);
 }
 
@@ -254,7 +255,8 @@
     loadFont();
 
     /* draw the background, we'll just paint over it */
-    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused);
+    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
+                           bg_color.unused);
     SDL_RenderFill(NULL);
     SDL_RenderPresent();
 
--- a/XCodeiPhoneOS/Demos/src/mixer.c	Fri May 15 15:47:37 2009 +0000
+++ b/XCodeiPhoneOS/Demos/src/mixer.c	Sat May 23 22:41:08 2009 +0000
@@ -168,7 +168,7 @@
 {
     int i;
     SDL_SetRenderDrawColor(50, 50, 50, 255);
-    SDL_RenderFill(NULL);      /* draw background (gray) */
+    SDL_RenderFill(NULL);       /* draw background (gray) */
     /* draw the drum buttons */
     for (i = 0; i < NUM_DRUMS; i++) {
         SDL_Color color =
--- a/include/SDL_opengles.h	Fri May 15 15:47:37 2009 +0000
+++ b/include/SDL_opengles.h	Sat May 23 22:41:08 2009 +0000
@@ -50,7 +50,7 @@
 
 #ifndef GL_API
 #define GL_API
-#endif /* GL_API */
+#endif                          /* GL_API */
 
 /*
 ** License Applicability. Except to the extent portions of this file are
@@ -347,10 +347,10 @@
 /* OpenGL ES 1.0 defines, they gone in 1.1 and 2.0 */
 #ifndef GL_MAX_ELEMENTS_VERTICES
 #define GL_MAX_ELEMENTS_VERTICES          0x80E8
-#endif /* GL_MAX_ELEMENTS_VERTICES */
+#endif                          /* GL_MAX_ELEMENTS_VERTICES */
 #ifndef GL_MAX_ELEMENTS_INDICES
 #define GL_MAX_ELEMENTS_INDICES           0x80E9
-#endif /* GL_MAX_ELEMENTS_INDICES */
+#endif                          /* GL_MAX_ELEMENTS_INDICES */
 
 /* GetTextureParameter */
 /*      GL_TEXTURE_MAG_FILTER */
@@ -669,7 +669,7 @@
 /* GL_OES_draw_texture */
 #ifndef GL_OES_draw_texture
 #define GL_TEXTURE_CROP_RECT_OES                                0x8B9D
-#endif /* GL_OES_draw_texture */
+#endif                          /* GL_OES_draw_texture */
 
 /*  GL_OES_vertex_buffer_object */
 #ifndef GL_OES_vertex_buffer_object
@@ -687,7 +687,7 @@
 #define GL_BUFFER_SIZE_OES                                      0x8764
 #define GL_BUFFER_USAGE_OES                                     0x8765
 #define GL_BUFFER_ACCESS_OES                                    0x88BB
-#endif /* GL_OES_vertex_buffer_object */
+#endif                          /* GL_OES_vertex_buffer_object */
 
 /*************************************************************/
 
@@ -973,8 +973,9 @@
 /* GL_OES_query_matrix */
 #ifndef GL_OES_query_matrix
 #define GL_OES_query_matrix 1
-    GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]);
-#endif /* GL_OES_query_matrix */
+    GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16],
+                                                    GLint exponent[16]);
+#endif                          /* GL_OES_query_matrix */
 
 /* GL_OES_point_sprite */
 #ifndef GL_OES_point_sprite
@@ -984,26 +985,35 @@
 /* GL_OES_draw_texture */
 #ifndef GL_OES_draw_texture
 #define GL_OES_draw_texture 1
-    GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height);
-    GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height);
-    GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height);
-    GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort *coords);
-    GL_API void GL_APIENTRY glDrawTexivOES (const GLint *coords);
-    GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed *coords);
-    GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
-    GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat *coords);
-#endif /* GL_OES_draw_texture */
+    GL_API void GL_APIENTRY glDrawTexsOES(GLshort x, GLshort y, GLshort z,
+                                          GLshort width, GLshort height);
+    GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z,
+                                          GLint width, GLint height);
+    GL_API void GL_APIENTRY glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z,
+                                          GLfixed width, GLfixed height);
+    GL_API void GL_APIENTRY glDrawTexsvOES(const GLshort * coords);
+    GL_API void GL_APIENTRY glDrawTexivOES(const GLint * coords);
+    GL_API void GL_APIENTRY glDrawTexxvOES(const GLfixed * coords);
+    GL_API void GL_APIENTRY glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z,
+                                          GLfloat width, GLfloat height);
+    GL_API void GL_APIENTRY glDrawTexfvOES(const GLfloat * coords);
+#endif                          /* GL_OES_draw_texture */
 
 /* GL_OES_single_precision */
 #ifndef GL_OES_single_precision
 #define GL_OES_single_precision 1
-    GL_API void GL_APIENTRY glDepthRangefOES (GLclampf zNear, GLclampf zFar);
-    GL_API void GL_APIENTRY glFrustumfOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
-    GL_API void GL_APIENTRY glOrthofOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
-    GL_API void GL_APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation);
-    GL_API void GL_APIENTRY glGetClipPlanefOES (GLenum pname, GLfloat eqn[4]);
-    GL_API void GL_APIENTRY glClearDepthfOES (GLclampf depth);
-#endif /* GL_OES_single_precision */
+    GL_API void GL_APIENTRY glDepthRangefOES(GLclampf zNear, GLclampf zFar);
+    GL_API void GL_APIENTRY glFrustumfOES(GLfloat left, GLfloat right,
+                                          GLfloat bottom, GLfloat top,
+                                          GLfloat zNear, GLfloat zFar);
+    GL_API void GL_APIENTRY glOrthofOES(GLfloat left, GLfloat right,
+                                        GLfloat bottom, GLfloat top,
+                                        GLfloat zNear, GLfloat zFar);
+    GL_API void GL_APIENTRY glClipPlanefOES(GLenum plane,
+                                            const GLfloat * equation);
+    GL_API void GL_APIENTRY glGetClipPlanefOES(GLenum pname, GLfloat eqn[4]);
+    GL_API void GL_APIENTRY glClearDepthfOES(GLclampf depth);
+#endif                          /* GL_OES_single_precision */
 
 /* GL_OES_vertex_buffer_object */
 #ifndef GL_OES_vertex_buffer_object
@@ -1012,10 +1022,12 @@
     GL_API void APIENTRY glDeleteBuffersOES(GLsizei, const GLuint *);
     GL_API void APIENTRY glGenBuffersOES(GLsizei, GLuint *);
     GL_API GLboolean APIENTRY glIsBufferOES(GLuint);
-    GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *, GLenum);
-    GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr, const GLvoid *);
+    GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *,
+                                         GLenum);
+    GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr,
+                                            const GLvoid *);
     GL_API void APIENTRY glGetBufferParameterivOES(GLenum, GLenum, GLint *);
-#endif /* GL_OES_vertex_buffer_object */
+#endif                          /* GL_OES_vertex_buffer_object */
 
 #ifdef __cplusplus
 }
--- a/include/SDL_video.h	Fri May 15 15:47:37 2009 +0000
+++ b/include/SDL_video.h	Sat May 23 22:41:08 2009 +0000
@@ -271,8 +271,8 @@
     SDL_GL_MULTISAMPLESAMPLES,
     SDL_GL_ACCELERATED_VISUAL,
     SDL_GL_RETAINED_BACKING,
-	SDL_GL_CONTEXT_MAJOR_VERSION,
-	SDL_GL_CONTEXT_MINOR_VERSION
+    SDL_GL_CONTEXT_MAJOR_VERSION,
+    SDL_GL_CONTEXT_MINOR_VERSION
 } SDL_GLattr;
 
 
--- a/src/SDL_compat.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/SDL_compat.c	Sat May 23 22:41:08 2009 +0000
@@ -494,7 +494,7 @@
             return NULL;
         }
     }
-    
+
     SDL_GetDesktopDisplayMode(&desktop_mode);
 
     if (width == 0) {
--- a/src/audio/SDL_audio.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/audio/SDL_audio.c	Sat May 23 22:41:08 2009 +0000
@@ -477,7 +477,8 @@
                     /* Wait for an audio buffer to become available */
                     current_audio.impl.WaitDevice(device);
                 } else {
-                    SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
+                    SDL_Delay((device->spec.samples * 1000) /
+                              device->spec.freq);
                 }
             }
 
@@ -525,7 +526,7 @@
                 /* Wait for an audio buffer to become available */
                 current_audio.impl.WaitDevice(device);
             } else {
-            	SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
+                SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
             }
         }
     }
--- a/src/audio/qsa/SDL_qsa_audio.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/audio/qsa/SDL_qsa_audio.c	Sat May 23 22:41:08 2009 +0000
@@ -59,888 +59,840 @@
 
 struct BuggyCards
 {
-    char* cardname;
+    char *cardname;
     unsigned long bugtype;
 };
 
 #define QSA_WA_CARDS             3
 #define QSA_MAX_CARD_NAME_LENGTH 33
 
-struct BuggyCards buggycards[QSA_WA_CARDS]=
-{
-   {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
-   {"Vortex 8820", QSA_MMAP_WORKAROUND},
-   {"Vortex 8830", QSA_MMAP_WORKAROUND},
+struct BuggyCards buggycards[QSA_WA_CARDS] = {
+    {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
+    {"Vortex 8820", QSA_MMAP_WORKAROUND},
+    {"Vortex 8830", QSA_MMAP_WORKAROUND},
 };
 
 /* List of found devices */
 #define QSA_MAX_DEVICES       32
-#define QSA_MAX_NAME_LENGTH   81+16 /* Hardcoded in QSA, can't be changed */
+#define QSA_MAX_NAME_LENGTH   81+16     /* Hardcoded in QSA, can't be changed */
 
 typedef struct _QSA_Device
 {
-   char  name[QSA_MAX_NAME_LENGTH];   /* Long audio device name for SDL  */
-   int   cardno;
-   int   deviceno;
+    char name[QSA_MAX_NAME_LENGTH];     /* Long audio device name for SDL  */
+    int cardno;
+    int deviceno;
 } QSA_Device;
 
 QSA_Device qsa_playback_device[QSA_MAX_DEVICES];
-uint32_t   qsa_playback_devices;
+uint32_t qsa_playback_devices;
 
 QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
-uint32_t   qsa_capture_devices;
+uint32_t qsa_capture_devices;
 
-static inline void QSA_SetError(const char* fn, int status)
+static inline void
+QSA_SetError(const char *fn, int status)
 {
-   SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
+    SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
 }
 
 /* card names check to apply the workarounds */
-static int QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
+static int
+QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
 {
-   char scardname[QSA_MAX_CARD_NAME_LENGTH];
-   int it;
-
-   if (snd_card_get_name(this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH-1)<0)
-   {
-      return 0;
-   }
+    char scardname[QSA_MAX_CARD_NAME_LENGTH];
+    int it;
 
-   for (it=0; it<QSA_WA_CARDS; it++)
-   {
-      if (SDL_strcmp(buggycards[it].cardname, scardname)==0)
-      {
-         if (buggycards[it].bugtype==checkfor)
-         {
-            return 1;
-         }
-      }
-   }
+    if (snd_card_get_name
+        (this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH - 1) < 0) {
+        return 0;
+    }
 
-   return 0;
+    for (it = 0; it < QSA_WA_CARDS; it++) {
+        if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
+            if (buggycards[it].bugtype == checkfor) {
+                return 1;
+            }
+        }
+    }
+
+    return 0;
 }
 
-static void QSA_ThreadInit(_THIS)
+static void
+QSA_ThreadInit(_THIS)
 {
-   struct sched_param param;
-   int status;
+    struct sched_param param;
+    int status;
 
-   /* Increase default 10 priority to 25 to avoid jerky sound */
-   status=SchedGet(0, 0, &param);
-   param.sched_priority=param.sched_curpriority + 15;
-   status=SchedSet(0, 0, SCHED_NOCHANGE, &param);
+    /* Increase default 10 priority to 25 to avoid jerky sound */
+    status = SchedGet(0, 0, &param);
+    param.sched_priority = param.sched_curpriority + 15;
+    status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
 }
 
 /* PCM channel parameters initialize function */
-static void QSA_InitAudioParams(snd_pcm_channel_params_t* cpars)
+static void
+QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
 {
-   SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
+    SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
 
-   cpars->channel=SND_PCM_CHANNEL_PLAYBACK;
-   cpars->mode=SND_PCM_MODE_BLOCK;
-   cpars->start_mode=SND_PCM_START_DATA;
-   cpars->stop_mode=SND_PCM_STOP_STOP;
-   cpars->format.format=SND_PCM_SFMT_S16_LE;
-   cpars->format.interleave=1;
-   cpars->format.rate=DEFAULT_CPARAMS_RATE;
-   cpars->format.voices=DEFAULT_CPARAMS_VOICES;
-   cpars->buf.block.frag_size=DEFAULT_CPARAMS_FRAG_SIZE;
-   cpars->buf.block.frags_min=DEFAULT_CPARAMS_FRAGS_MIN;
-   cpars->buf.block.frags_max=DEFAULT_CPARAMS_FRAGS_MAX;
+    cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
+    cpars->mode = SND_PCM_MODE_BLOCK;
+    cpars->start_mode = SND_PCM_START_DATA;
+    cpars->stop_mode = SND_PCM_STOP_STOP;
+    cpars->format.format = SND_PCM_SFMT_S16_LE;
+    cpars->format.interleave = 1;
+    cpars->format.rate = DEFAULT_CPARAMS_RATE;
+    cpars->format.voices = DEFAULT_CPARAMS_VOICES;
+    cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
+    cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
+    cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
 }
 
 /* This function waits until it is possible to write a full sound buffer */
-static void QSA_WaitDevice(_THIS)
+static void
+QSA_WaitDevice(_THIS)
 {
-   fd_set wfds;
-   fd_set rfds;
-   int selectret;
-   struct timeval timeout;
-
-   if (!this->hidden->iscapture)
-   {
-      FD_ZERO(&wfds);
-      FD_SET(this->hidden->audio_fd, &wfds);
-   }
-   else
-   {
-      FD_ZERO(&rfds);
-      FD_SET(this->hidden->audio_fd, &rfds);
-   }
+    fd_set wfds;
+    fd_set rfds;
+    int selectret;
+    struct timeval timeout;
 
-   do {
-      /* Setup timeout for playing one fragment equal to 2 seconds          */
-      /* If timeout occured than something wrong with hardware or driver    */
-      /* For example, Vortex 8820 audio driver stucks on second DAC because */
-      /* it doesn't exist !                                                 */
-      timeout.tv_sec=2;
-      timeout.tv_usec=0;
-      this->hidden->timeout_on_wait=0;
+    if (!this->hidden->iscapture) {
+        FD_ZERO(&wfds);
+        FD_SET(this->hidden->audio_fd, &wfds);
+    } else {
+        FD_ZERO(&rfds);
+        FD_SET(this->hidden->audio_fd, &rfds);
+    }
 
-      if (!this->hidden->iscapture)
-      {
-         selectret=select(this->hidden->audio_fd+1, NULL, &wfds, NULL, &timeout);
-      }
-      else
-      {
-         selectret=select(this->hidden->audio_fd+1, &rfds, NULL, NULL, &timeout);
-      }
+    do {
+        /* Setup timeout for playing one fragment equal to 2 seconds          */
+        /* If timeout occured than something wrong with hardware or driver    */
+        /* For example, Vortex 8820 audio driver stucks on second DAC because */
+        /* it doesn't exist !                                                 */
+        timeout.tv_sec = 2;
+        timeout.tv_usec = 0;
+        this->hidden->timeout_on_wait = 0;
 
-      switch(selectret)
-      {
-         case -1:
-              {
-                 SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
-                 return;
-              }
-              break;
-         case 0:
-              {
-                 SDL_SetError("QSA: timeout on buffer waiting occured\n");
-                 this->hidden->timeout_on_wait=1;
-                 return;
-              }
-              break;
-         default:
-              {
-                 if (!this->hidden->iscapture)
-                 {
-                    if (FD_ISSET(this->hidden->audio_fd, &wfds))
-                    {
-                       return;
+        if (!this->hidden->iscapture) {
+            selectret =
+                select(this->hidden->audio_fd + 1, NULL, &wfds, NULL,
+                       &timeout);
+        } else {
+            selectret =
+                select(this->hidden->audio_fd + 1, &rfds, NULL, NULL,
+                       &timeout);
+        }
+
+        switch (selectret) {
+        case -1:
+            {
+                SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
+                return;
+            }
+            break;
+        case 0:
+            {
+                SDL_SetError("QSA: timeout on buffer waiting occured\n");
+                this->hidden->timeout_on_wait = 1;
+                return;
+            }
+            break;
+        default:
+            {
+                if (!this->hidden->iscapture) {
+                    if (FD_ISSET(this->hidden->audio_fd, &wfds)) {
+                        return;
                     }
-                 }
-                 else
-                 {
-                    if (FD_ISSET(this->hidden->audio_fd, &rfds))
-                    {
-                       return;
+                } else {
+                    if (FD_ISSET(this->hidden->audio_fd, &rfds)) {
+                        return;
                     }
-                 }
-              }
-              break;
-      }
-   } while (1);
+                }
+            }
+            break;
+        }
+    } while (1);
 }
 
-static void QSA_PlayDevice(_THIS)
+static void
+QSA_PlayDevice(_THIS)
 {
-   snd_pcm_channel_status_t cstatus;
-   int   written;
-   int   status;
-   int   towrite;
-   void* pcmbuffer;
+    snd_pcm_channel_status_t cstatus;
+    int written;
+    int status;
+    int towrite;
+    void *pcmbuffer;
 
-   if ((!this->enabled) || (!this->hidden))
-   {
-      return;
-   }
+    if ((!this->enabled) || (!this->hidden)) {
+        return;
+    }
 
-   towrite = this->spec.size;
-   pcmbuffer = this->hidden->pcm_buf;
+    towrite = this->spec.size;
+    pcmbuffer = this->hidden->pcm_buf;
 
-   /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
-   do {
-      written=snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer, towrite);
-      if (written!=towrite)
-      {
-         /* Check if samples playback got stuck somewhere in hardware or in */
-         /* the audio device driver */
-         if ((errno==EAGAIN) && (written==0))
-         {
-            if (this->hidden->timeout_on_wait!=0)
-            {
-               SDL_SetError("QSA: buffer playback timeout\n");
-               return;
+    /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
+    do {
+        written =
+            snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer,
+                                 towrite);
+        if (written != towrite) {
+            /* Check if samples playback got stuck somewhere in hardware or in */
+            /* the audio device driver */
+            if ((errno == EAGAIN) && (written == 0)) {
+                if (this->hidden->timeout_on_wait != 0) {
+                    SDL_SetError("QSA: buffer playback timeout\n");
+                    return;
+                }
             }
-         }
 
-         /* Check for errors or conditions */
-         if ((errno==EAGAIN)||(errno==EWOULDBLOCK))
-         {
-            /* Let a little CPU time go by and try to write again */
-            SDL_Delay(1);
+            /* Check for errors or conditions */
+            if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
+                /* Let a little CPU time go by and try to write again */
+                SDL_Delay(1);
 
-            /* if we wrote some data */
-            towrite-=written;
-            pcmbuffer+=written*this->spec.channels;
-            continue;
-         }
-         else
-         {
-            if ((errno==EINVAL)||(errno==EIO))
-            {
-               SDL_memset(&cstatus, 0, sizeof(cstatus));
-               if (!this->hidden->iscapture)
-               {
-                  cstatus.channel=SND_PCM_CHANNEL_PLAYBACK;
-               }
-               else
-               {
-                  cstatus.channel=SND_PCM_CHANNEL_CAPTURE;
-               }
+                /* if we wrote some data */
+                towrite -= written;
+                pcmbuffer += written * this->spec.channels;
+                continue;
+            } else {
+                if ((errno == EINVAL) || (errno == EIO)) {
+                    SDL_memset(&cstatus, 0, sizeof(cstatus));
+                    if (!this->hidden->iscapture) {
+                        cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
+                    } else {
+                        cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
+                    }
 
-               status=snd_pcm_plugin_status(this->hidden->audio_handle, &cstatus);
-               if (status<0)
-               {
-                  QSA_SetError("snd_pcm_plugin_status", status);
-                  return;
-               }
+                    status =
+                        snd_pcm_plugin_status(this->hidden->audio_handle,
+                                              &cstatus);
+                    if (status < 0) {
+                        QSA_SetError("snd_pcm_plugin_status", status);
+                        return;
+                    }
 
-               if ((cstatus.status==SND_PCM_STATUS_UNDERRUN) ||
-                   (cstatus.status==SND_PCM_STATUS_READY))
-               {
-                  if (!this->hidden->iscapture)
-                  {
-                     status=snd_pcm_plugin_prepare(this->hidden->audio_handle,
-                                                   SND_PCM_CHANNEL_PLAYBACK);
-                  }
-                  else
-                  {
-                     status=snd_pcm_plugin_prepare(this->hidden->audio_handle,
-                                                   SND_PCM_CHANNEL_CAPTURE);
-                  }
-                  if (status<0)
-                  {
-                     QSA_SetError("snd_pcm_plugin_prepare", status);
-                     return;
-                  }
-               }
-               continue;
+                    if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
+                        (cstatus.status == SND_PCM_STATUS_READY)) {
+                        if (!this->hidden->iscapture) {
+                            status =
+                                snd_pcm_plugin_prepare(this->hidden->
+                                                       audio_handle,
+                                                       SND_PCM_CHANNEL_PLAYBACK);
+                        } else {
+                            status =
+                                snd_pcm_plugin_prepare(this->hidden->
+                                                       audio_handle,
+                                                       SND_PCM_CHANNEL_CAPTURE);
+                        }
+                        if (status < 0) {
+                            QSA_SetError("snd_pcm_plugin_prepare", status);
+                            return;
+                        }
+                    }
+                    continue;
+                } else {
+                    return;
+                }
             }
-            else
-            {
-                return;
-            }
-         }
-      }
-      else
-      {
-         /* we wrote all remaining data */
-         towrite -= written;
-         pcmbuffer += written * this->spec.channels;
-      }
-   } while ((towrite>0) && (this->enabled));
+        } else {
+            /* we wrote all remaining data */
+            towrite -= written;
+            pcmbuffer += written * this->spec.channels;
+        }
+    } while ((towrite > 0) && (this->enabled));
 
-   /* If we couldn't write, assume fatal error for now */
-   if (towrite!=0)
-   {
-      this->enabled=0;
-   }
+    /* If we couldn't write, assume fatal error for now */
+    if (towrite != 0) {
+        this->enabled = 0;
+    }
 }
 
-static Uint8* QSA_GetDeviceBuf(_THIS)
+static Uint8 *
+QSA_GetDeviceBuf(_THIS)
 {
-   return this->hidden->pcm_buf;
+    return this->hidden->pcm_buf;
 }
 
-static void QSA_CloseDevice(_THIS)
+static void
+QSA_CloseDevice(_THIS)
 {
-   if (this->hidden!=NULL)
-   {
-      if (this->hidden->audio_handle!=NULL)
-      {
-         if (!this->hidden->iscapture)
-         {
-            /* Finish playing available samples */
-            snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
-         }
-         else
-         {
-            /* Cancel unread samples during capture */
-            snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
-         }
-         snd_pcm_close(this->hidden->audio_handle);
-         this->hidden->audio_handle=NULL;
-      }
+    if (this->hidden != NULL) {
+        if (this->hidden->audio_handle != NULL) {
+            if (!this->hidden->iscapture) {
+                /* Finish playing available samples */
+                snd_pcm_plugin_flush(this->hidden->audio_handle,
+                                     SND_PCM_CHANNEL_PLAYBACK);
+            } else {
+                /* Cancel unread samples during capture */
+                snd_pcm_plugin_flush(this->hidden->audio_handle,
+                                     SND_PCM_CHANNEL_CAPTURE);
+            }
+            snd_pcm_close(this->hidden->audio_handle);
+            this->hidden->audio_handle = NULL;
+        }
 
-      if (this->hidden->pcm_buf!=NULL)
-      {
-         SDL_FreeAudioMem(this->hidden->pcm_buf);
-         this->hidden->pcm_buf=NULL;
-      }
+        if (this->hidden->pcm_buf != NULL) {
+            SDL_FreeAudioMem(this->hidden->pcm_buf);
+            this->hidden->pcm_buf = NULL;
+        }
 
-      SDL_free(this->hidden);
-      this->hidden=NULL;
-   }
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+    }
 }
 
-static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
+static int
+QSA_OpenDevice(_THIS, const char *devname, int iscapture)
 {
-   int status=0;
-   int format=0;
-   SDL_AudioFormat test_format=0;
-   int found=0;
-   snd_pcm_channel_setup_t  csetup;
-   snd_pcm_channel_params_t cparams;
+    int status = 0;
+    int format = 0;
+    SDL_AudioFormat test_format = 0;
+    int found = 0;
+    snd_pcm_channel_setup_t csetup;
+    snd_pcm_channel_params_t cparams;
 
-   /* Initialize all variables that we clean on shutdown */
-   this->hidden=(struct SDL_PrivateAudioData*)SDL_calloc(1, (sizeof(struct SDL_PrivateAudioData)));
-   if (this->hidden==NULL)
-   {
-      SDL_OutOfMemory();
-      return 0;
-   }
-   SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden =
+        (struct SDL_PrivateAudioData *) SDL_calloc(1,
+                                                   (sizeof
+                                                    (struct
+                                                     SDL_PrivateAudioData)));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
 
-   /* Initialize channel transfer parameters to default */
-   QSA_InitAudioParams(&cparams);
+    /* Initialize channel transfer parameters to default */
+    QSA_InitAudioParams(&cparams);
 
-   /* Initialize channel direction: capture or playback */
-   this->hidden->iscapture=iscapture;
+    /* Initialize channel direction: capture or playback */
+    this->hidden->iscapture = iscapture;
 
-   /* Find deviceid and cardid by device name for playback */
-   if ((!this->hidden->iscapture) && (devname!=NULL))
-   {
-      uint32_t device;
-      int32_t  status;
+    /* Find deviceid and cardid by device name for playback */
+    if ((!this->hidden->iscapture) && (devname != NULL)) {
+        uint32_t device;
+        int32_t status;
 
-      /* Search in the playback devices */
-      device=0;
-      do {
-         status=SDL_strcmp(qsa_playback_device[device].name, devname);
-         if (status==0)
-         {
-            /* Found requested device */
-            this->hidden->deviceno=qsa_playback_device[device].deviceno;
-            this->hidden->cardno=qsa_playback_device[device].cardno;
-            break;
-         }
-         device++;
-         if (device>=qsa_playback_devices)
-         {
-            QSA_CloseDevice(this);
-            SDL_SetError("No such playback device");
-            return 0;
-         }
-      } while(1);
-   }
+        /* Search in the playback devices */
+        device = 0;
+        do {
+            status = SDL_strcmp(qsa_playback_device[device].name, devname);
+            if (status == 0) {
+                /* Found requested device */
+                this->hidden->deviceno = qsa_playback_device[device].deviceno;
+                this->hidden->cardno = qsa_playback_device[device].cardno;
+                break;
+            }
+            device++;
+            if (device >= qsa_playback_devices) {
+                QSA_CloseDevice(this);
+                SDL_SetError("No such playback device");
+                return 0;
+            }
+        } while (1);
+    }
 
-   /* Find deviceid and cardid by device name for capture */
-   if ((this->hidden->iscapture) && (devname!=NULL))
-   {
-      /* Search in the capture devices */
-      uint32_t device;
-      int32_t  status;
+    /* Find deviceid and cardid by device name for capture */
+    if ((this->hidden->iscapture) && (devname != NULL)) {
+        /* Search in the capture devices */
+        uint32_t device;
+        int32_t status;
 
-      /* Searching in the playback devices */
-      device=0;
-      do {
-         status=SDL_strcmp(qsa_capture_device[device].name, devname);
-         if (status==0)
-         {
-            /* Found requested device */
-            this->hidden->deviceno=qsa_capture_device[device].deviceno;
-            this->hidden->cardno=qsa_capture_device[device].cardno;
-            break;
-         }
-         device++;
-         if (device>=qsa_capture_devices)
-         {
-            QSA_CloseDevice(this);
-            SDL_SetError("No such capture device");
-            return 0;
-         }
-      } while(1);
-   }
+        /* Searching in the playback devices */
+        device = 0;
+        do {
+            status = SDL_strcmp(qsa_capture_device[device].name, devname);
+            if (status == 0) {
+                /* Found requested device */
+                this->hidden->deviceno = qsa_capture_device[device].deviceno;
+                this->hidden->cardno = qsa_capture_device[device].cardno;
+                break;
+            }
+            device++;
+            if (device >= qsa_capture_devices) {
+                QSA_CloseDevice(this);
+                SDL_SetError("No such capture device");
+                return 0;
+            }
+        } while (1);
+    }
 
-   /* Check if SDL requested default audio device */
-   if (devname==NULL)
-   {
-      /* Open system default audio device */
-      if (!this->hidden->iscapture)
-      {
-         status=snd_pcm_open_preferred(&this->hidden->audio_handle,
-                                       &this->hidden->cardno,
-                                       &this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK);
-      }
-      else
-      {
-         status=snd_pcm_open_preferred(&this->hidden->audio_handle,
-                                       &this->hidden->cardno,
-                                       &this->hidden->deviceno, SND_PCM_OPEN_CAPTURE);
-      }
-   }
-   else
-   {
-      /* Open requested audio device */
-      if (!this->hidden->iscapture)
-      {
-         status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno,
-                              this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK);
-      }
-      else
-      {
-         status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno,
-                              this->hidden->deviceno, SND_PCM_OPEN_CAPTURE);
-      }
-   }
+    /* Check if SDL requested default audio device */
+    if (devname == NULL) {
+        /* Open system default audio device */
+        if (!this->hidden->iscapture) {
+            status = snd_pcm_open_preferred(&this->hidden->audio_handle,
+                                            &this->hidden->cardno,
+                                            &this->hidden->deviceno,
+                                            SND_PCM_OPEN_PLAYBACK);
+        } else {
+            status = snd_pcm_open_preferred(&this->hidden->audio_handle,
+                                            &this->hidden->cardno,
+                                            &this->hidden->deviceno,
+                                            SND_PCM_OPEN_CAPTURE);
+        }
+    } else {
+        /* Open requested audio device */
+        if (!this->hidden->iscapture) {
+            status =
+                snd_pcm_open(&this->hidden->audio_handle,
+                             this->hidden->cardno, this->hidden->deviceno,
+                             SND_PCM_OPEN_PLAYBACK);
+        } else {
+            status =
+                snd_pcm_open(&this->hidden->audio_handle,
+                             this->hidden->cardno, this->hidden->deviceno,
+                             SND_PCM_OPEN_CAPTURE);
+        }
+    }
 
-   /* Check if requested device is opened */
-   if (status<0)
-   {
-      this->hidden->audio_handle=NULL;
-      QSA_CloseDevice(this);
-      QSA_SetError("snd_pcm_open", status);
-      return 0;
-   }
+    /* Check if requested device is opened */
+    if (status < 0) {
+        this->hidden->audio_handle = NULL;
+        QSA_CloseDevice(this);
+        QSA_SetError("snd_pcm_open", status);
+        return 0;
+    }
 
-   if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND))
-   {
-      /* Disable QSA MMAP plugin for buggy audio drivers */
-      status=snd_pcm_plugin_set_disable(this->hidden->audio_handle, PLUGIN_DISABLE_MMAP);
-      if (status<0)
-      {
-         QSA_CloseDevice(this);
-         QSA_SetError("snd_pcm_plugin_set_disable", status);
-         return 0;
-      }
-   }
+    if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
+        /* Disable QSA MMAP plugin for buggy audio drivers */
+        status =
+            snd_pcm_plugin_set_disable(this->hidden->audio_handle,
+                                       PLUGIN_DISABLE_MMAP);
+        if (status < 0) {
+            QSA_CloseDevice(this);
+            QSA_SetError("snd_pcm_plugin_set_disable", status);
+            return 0;
+        }
+    }
 
-   /* Try for a closest match on audio format */
-   format = 0;
-   /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
-   found = 0;
+    /* Try for a closest match on audio format */
+    format = 0;
+    /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
+    found = 0;
 
-   for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;)
-   {
-      /* if match found set format to equivalent QSA format */
-      switch (test_format)
-      {
-         case AUDIO_U8:
-              {
-                 format=SND_PCM_SFMT_U8;
-                 found=1;
-              }
-              break;
-         case AUDIO_S8:
-              {
-                 format=SND_PCM_SFMT_S8;
-                 found=1;
-              }
-              break;
-         case AUDIO_S16LSB:
-              {
-                 format=SND_PCM_SFMT_S16_LE;
-                 found=1;
-              }
-              break;
-         case AUDIO_S16MSB:
-              {
-                 format=SND_PCM_SFMT_S16_BE;
-                 found=1;
-              }
-              break;
-         case AUDIO_U16LSB:
-              {
-                 format=SND_PCM_SFMT_U16_LE;
-                 found=1;
-              }
-              break;
-         case AUDIO_U16MSB:
-              {
-                 format=SND_PCM_SFMT_U16_BE;
-                 found=1;
-              }
-              break;
-         case AUDIO_S32LSB:
-              {
-                 format=SND_PCM_SFMT_S32_LE;
-                 found=1;
-              }
-              break;
-         case AUDIO_S32MSB:
-              {
-                 format=SND_PCM_SFMT_S32_BE;
-                 found=1;
-              }
-              break;
-         case AUDIO_F32LSB:
-              {
-                 format=SND_PCM_SFMT_FLOAT_LE;
-                 found=1;
-              }
-              break;
-         case AUDIO_F32MSB:
-              {
-                 format=SND_PCM_SFMT_FLOAT_BE;
-                 found=1;
-              }
-              break;
-         default:
-              {
-                 break;
-              }
-      }
+    for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
+        /* if match found set format to equivalent QSA format */
+        switch (test_format) {
+        case AUDIO_U8:
+            {
+                format = SND_PCM_SFMT_U8;
+                found = 1;
+            }
+            break;
+        case AUDIO_S8:
+            {
+                format = SND_PCM_SFMT_S8;
+                found = 1;
+            }
+            break;
+        case AUDIO_S16LSB:
+            {
+                format = SND_PCM_SFMT_S16_LE;
+                found = 1;
+            }
+            break;
+        case AUDIO_S16MSB:
+            {
+                format = SND_PCM_SFMT_S16_BE;
+                found = 1;
+            }
+            break;
+        case AUDIO_U16LSB:
+            {
+                format = SND_PCM_SFMT_U16_LE;
+                found = 1;
+            }
+            break;
+        case AUDIO_U16MSB:
+            {
+                format = SND_PCM_SFMT_U16_BE;
+                found = 1;
+            }
+            break;
+        case AUDIO_S32LSB:
+            {
+                format = SND_PCM_SFMT_S32_LE;
+                found = 1;
+            }
+            break;
+        case AUDIO_S32MSB:
+            {
+                format = SND_PCM_SFMT_S32_BE;
+                found = 1;
+            }
+            break;
+        case AUDIO_F32LSB:
+            {
+                format = SND_PCM_SFMT_FLOAT_LE;
+                found = 1;
+            }
+            break;
+        case AUDIO_F32MSB:
+            {
+                format = SND_PCM_SFMT_FLOAT_BE;
+                found = 1;
+            }
+            break;
+        default:
+            {
+                break;
+            }
+        }
 
-      if (!found)
-      {
-         test_format = SDL_NextAudioFormat();
-      }
-   }
+        if (!found) {
+            test_format = SDL_NextAudioFormat();
+        }
+    }
 
-   /* assumes test_format not 0 on success */
-   if (test_format==0)
-   {
-      QSA_CloseDevice(this);
-      SDL_SetError("QSA: Couldn't find any hardware audio formats");
-      return 0;
-   }
+    /* assumes test_format not 0 on success */
+    if (test_format == 0) {
+        QSA_CloseDevice(this);
+        SDL_SetError("QSA: Couldn't find any hardware audio formats");
+        return 0;
+    }
 
-   this->spec.format=test_format;
+    this->spec.format = test_format;
 
-   /* Set the audio format */
-   cparams.format.format=format;
+    /* Set the audio format */
+    cparams.format.format = format;
 
-   /* Set mono/stereo/4ch/6ch/8ch audio */
-   cparams.format.voices=this->spec.channels;
+    /* Set mono/stereo/4ch/6ch/8ch audio */
+    cparams.format.voices = this->spec.channels;
 
-   /* Set rate */
-   cparams.format.rate=this->spec.freq;
+    /* Set rate */
+    cparams.format.rate = this->spec.freq;
 
-   /* Setup the transfer parameters according to cparams */
-   status=snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
-   if (status<0)
-   {
-      QSA_CloseDevice(this);
-      QSA_SetError("snd_pcm_channel_params", status);
-      return 0;
-   }
+    /* Setup the transfer parameters according to cparams */
+    status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
+    if (status < 0) {
+        QSA_CloseDevice(this);
+        QSA_SetError("snd_pcm_channel_params", status);
+        return 0;
+    }
 
-   /* Make sure channel is setup right one last time */
-   SDL_memset(&csetup, '\0', sizeof(csetup));
-   if (!this->hidden->iscapture)
-   {
-      csetup.channel=SND_PCM_CHANNEL_PLAYBACK;
-   }
-   else
-   {
-      csetup.channel=SND_PCM_CHANNEL_CAPTURE;
-   }
+    /* Make sure channel is setup right one last time */
+    SDL_memset(&csetup, '\0', sizeof(csetup));
+    if (!this->hidden->iscapture) {
+        csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
+    } else {
+        csetup.channel = SND_PCM_CHANNEL_CAPTURE;
+    }
 
-   /* Setup an audio channel */
-   if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0)
-   {
-      QSA_CloseDevice(this);
-      SDL_SetError("QSA: Unable to setup channel\n");
-      return 0;
-   }
+    /* Setup an audio channel */
+    if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
+        QSA_CloseDevice(this);
+        SDL_SetError("QSA: Unable to setup channel\n");
+        return 0;
+    }
 
-   /* Calculate the final parameters for this audio specification */
-   SDL_CalculateAudioSpec(&this->spec);
+    /* Calculate the final parameters for this audio specification */
+    SDL_CalculateAudioSpec(&this->spec);
 
-   this->hidden->pcm_len = this->spec.size;
+    this->hidden->pcm_len = this->spec.size;
 
-   if (this->hidden->pcm_len==0)
-   {
-      this->hidden->pcm_len=csetup.buf.block.frag_size * this->spec.channels *
-                           (snd_pcm_format_width(format) / 8);
-   }
+    if (this->hidden->pcm_len == 0) {
+        this->hidden->pcm_len =
+            csetup.buf.block.frag_size * this->spec.channels *
+            (snd_pcm_format_width(format) / 8);
+    }
 
-   /*
-    * Allocate memory to the audio buffer and initialize with silence
-    *  (Note that buffer size must be a multiple of fragment size, so find
-    *  closest multiple)
-    */
-   this->hidden->pcm_buf=(Uint8*)SDL_AllocAudioMem(this->hidden->pcm_len);
-   if (this->hidden->pcm_buf==NULL)
-   {
-      QSA_CloseDevice(this);
-      SDL_OutOfMemory();
-      return 0;
-   }
-   SDL_memset(this->hidden->pcm_buf, this->spec.silence, this->hidden->pcm_len);
+    /*
+     * Allocate memory to the audio buffer and initialize with silence
+     *  (Note that buffer size must be a multiple of fragment size, so find
+     *  closest multiple)
+     */
+    this->hidden->pcm_buf =
+        (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
+    if (this->hidden->pcm_buf == NULL) {
+        QSA_CloseDevice(this);
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden->pcm_buf, this->spec.silence,
+               this->hidden->pcm_len);
 
-   /* get the file descriptor */
-   if (!this->hidden->iscapture)
-   {
-      this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
-                                                     SND_PCM_CHANNEL_PLAYBACK);
-   }
-   else
-   {
-      this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
-                                                     SND_PCM_CHANNEL_CAPTURE);
-   }
+    /* get the file descriptor */
+    if (!this->hidden->iscapture) {
+        this->hidden->audio_fd =
+            snd_pcm_file_descriptor(this->hidden->audio_handle,
+                                    SND_PCM_CHANNEL_PLAYBACK);
+    } else {
+        this->hidden->audio_fd =
+            snd_pcm_file_descriptor(this->hidden->audio_handle,
+                                    SND_PCM_CHANNEL_CAPTURE);
+    }
 
-   if (this->hidden->audio_fd<0)
-   {
-      QSA_CloseDevice(this);
-      QSA_SetError("snd_pcm_file_descriptor", status);
-      return 0;
-   }
+    if (this->hidden->audio_fd < 0) {
+        QSA_CloseDevice(this);
+        QSA_SetError("snd_pcm_file_descriptor", status);
+        return 0;
+    }
 
-   /* Prepare an audio channel */
-   if (!this->hidden->iscapture)
-   {
-      /* Prepare audio playback */
-      status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
-   }
-   else
-   {
-      /* Prepare audio capture */
-      status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
-   }
+    /* Prepare an audio channel */
+    if (!this->hidden->iscapture) {
+        /* Prepare audio playback */
+        status =
+            snd_pcm_plugin_prepare(this->hidden->audio_handle,
+                                   SND_PCM_CHANNEL_PLAYBACK);
+    } else {
+        /* Prepare audio capture */
+        status =
+            snd_pcm_plugin_prepare(this->hidden->audio_handle,
+                                   SND_PCM_CHANNEL_CAPTURE);
+    }
 
-   if (status<0)
-   {
-      QSA_CloseDevice(this);
-      QSA_SetError("snd_pcm_plugin_prepare", status);
-      return 0;
-   }
+    if (status < 0) {
+        QSA_CloseDevice(this);
+        QSA_SetError("snd_pcm_plugin_prepare", status);
+        return 0;
+    }
 
-   /* We're really ready to rock and roll. :-) */
-   return 1;
+    /* We're really ready to rock and roll. :-) */
+    return 1;
 }
 
-int QSA_DetectDevices(int iscapture)
+int
+QSA_DetectDevices(int iscapture)
 {
-   uint32_t it;
-   uint32_t cards;
-   uint32_t devices;
-   int32_t  status;
+    uint32_t it;
+    uint32_t cards;
+    uint32_t devices;
+    int32_t status;
+
+    /* Detect amount of available devices       */
+    /* this value can be changed in the runtime */
+    cards = snd_cards();
 
-   /* Detect amount of available devices       */
-   /* this value can be changed in the runtime */
-   cards=snd_cards();
+    /* If io-audio manager is not running we will get 0 as number */
+    /* of available audio devices                                 */
+    if (cards == 0) {
+        /* We have no any available audio devices */
+        return 0;
+    }
 
-   /* If io-audio manager is not running we will get 0 as number */
-   /* of available audio devices                                 */
-   if (cards==0)
-   {
-      /* We have no any available audio devices */
-      return 0;
-   }
+    /* Find requested devices by type */
+    if (!iscapture) {
+        /* Playback devices enumeration requested */
+        for (it = 0; it < cards; it++) {
+            devices = 0;
+            do {
+                status =
+                    snd_card_get_longname(it,
+                                          qsa_playback_device
+                                          [qsa_playback_devices].name,
+                                          QSA_MAX_NAME_LENGTH);
+                if (status == EOK) {
+                    snd_pcm_t *handle;
 
-   /* Find requested devices by type */
-   if (!iscapture)
-   {
-      /* Playback devices enumeration requested */
-      for(it=0; it<cards; it++)
-      {
-         devices=0;
-         do {
-            status=snd_card_get_longname(it, qsa_playback_device[qsa_playback_devices].name, QSA_MAX_NAME_LENGTH);
-            if (status==EOK)
-            {
-               snd_pcm_t* handle;
+                    /* Add device number to device name */
+                    sprintf(qsa_playback_device[qsa_playback_devices].name +
+                            SDL_strlen(qsa_playback_device
+                                       [qsa_playback_devices].name), " d%d",
+                            devices);
 
-               /* Add device number to device name */
-               sprintf(qsa_playback_device[qsa_playback_devices].name + SDL_strlen(qsa_playback_device[qsa_playback_devices].name), " d%d", devices);
-
-               /* Store associated card number id */
-               qsa_playback_device[qsa_playback_devices].cardno=it;
+                    /* Store associated card number id */
+                    qsa_playback_device[qsa_playback_devices].cardno = it;
 
-               /* Check if this device id could play anything */
-               status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_PLAYBACK);
-               if (status==EOK)
-               {
-                  qsa_playback_device[qsa_playback_devices].deviceno=devices;
-                  status=snd_pcm_close(handle);
-                  if (status==EOK)
-                  {
-                     qsa_playback_devices++;
-                  }
-               }
-               else
-               {
-                  /* Check if we got end of devices list */
-                  if (status==-ENOENT)
-                  {
-                     break;
-                  }
-               }
-            }
-            else
-            {
-               break;
-            }
+                    /* Check if this device id could play anything */
+                    status =
+                        snd_pcm_open(&handle, it, devices,
+                                     SND_PCM_OPEN_PLAYBACK);
+                    if (status == EOK) {
+                        qsa_playback_device[qsa_playback_devices].deviceno =
+                            devices;
+                        status = snd_pcm_close(handle);
+                        if (status == EOK) {
+                            qsa_playback_devices++;
+                        }
+                    } else {
+                        /* Check if we got end of devices list */
+                        if (status == -ENOENT) {
+                            break;
+                        }
+                    }
+                } else {
+                    break;
+                }
+
+                /* Check if we reached maximum devices count */
+                if (qsa_playback_devices >= QSA_MAX_DEVICES) {
+                    break;
+                }
+                devices++;
+            } while (1);
 
             /* Check if we reached maximum devices count */
-            if (qsa_playback_devices>=QSA_MAX_DEVICES)
-            {
-               break;
+            if (qsa_playback_devices >= QSA_MAX_DEVICES) {
+                break;
             }
-            devices++;
-         } while(1);
+        }
+    } else {
+        /* Capture devices enumeration requested */
+        for (it = 0; it < cards; it++) {
+            devices = 0;
+            do {
+                status =
+                    snd_card_get_longname(it,
+                                          qsa_capture_device
+                                          [qsa_capture_devices].name,
+                                          QSA_MAX_NAME_LENGTH);
+                if (status == EOK) {
+                    snd_pcm_t *handle;
 
-         /* Check if we reached maximum devices count */
-         if (qsa_playback_devices>=QSA_MAX_DEVICES)
-         {
-            break;
-         }
-      }
-   }
-   else
-   {
-      /* Capture devices enumeration requested */
-      for(it=0; it<cards; it++)
-      {
-         devices=0;
-         do {
-            status=snd_card_get_longname(it, qsa_capture_device[qsa_capture_devices].name, QSA_MAX_NAME_LENGTH);
-            if (status==EOK)
-            {
-               snd_pcm_t* handle;
+                    /* Add device number to device name */
+                    sprintf(qsa_capture_device[qsa_capture_devices].name +
+                            SDL_strlen(qsa_capture_device
+                                       [qsa_capture_devices].name), " d%d",
+                            devices);
 
-               /* Add device number to device name */
-               sprintf(qsa_capture_device[qsa_capture_devices].name + SDL_strlen(qsa_capture_device[qsa_capture_devices].name), " d%d", devices);
-
-               /* Store associated card number id */
-               qsa_capture_device[qsa_capture_devices].cardno=it;
+                    /* Store associated card number id */
+                    qsa_capture_device[qsa_capture_devices].cardno = it;
 
-               /* Check if this device id could play anything */
-               status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_CAPTURE);
-               if (status==EOK)
-               {
-                  qsa_capture_device[qsa_capture_devices].deviceno=devices;
-                  status=snd_pcm_close(handle);
-                  if (status==EOK)
-                  {
-                     qsa_capture_devices++;
-                  }
-               }
-               else
-               {
-                  /* Check if we got end of devices list */
-                  if (status==-ENOENT)
-                  {
-                     break;
-                  }
-               }
+                    /* Check if this device id could play anything */
+                    status =
+                        snd_pcm_open(&handle, it, devices,
+                                     SND_PCM_OPEN_CAPTURE);
+                    if (status == EOK) {
+                        qsa_capture_device[qsa_capture_devices].deviceno =
+                            devices;
+                        status = snd_pcm_close(handle);
+                        if (status == EOK) {
+                            qsa_capture_devices++;
+                        }
+                    } else {
+                        /* Check if we got end of devices list */
+                        if (status == -ENOENT) {
+                            break;
+                        }
+                    }
 
-               /* Check if we reached maximum devices count */
-               if (qsa_capture_devices>=QSA_MAX_DEVICES)
-               {
-                  break;
-               }
-            }
-            else
-            {
-               break;
-            }
-            devices++;
-         } while(1);
+                    /* Check if we reached maximum devices count */
+                    if (qsa_capture_devices >= QSA_MAX_DEVICES) {
+                        break;
+                    }
+                } else {
+                    break;
+                }
+                devices++;
+            } while (1);
 
-         /* Check if we reached maximum devices count */
-         if (qsa_capture_devices>=QSA_MAX_DEVICES)
-         {
-            break;
-         }
-      }
-   }
+            /* Check if we reached maximum devices count */
+            if (qsa_capture_devices >= QSA_MAX_DEVICES) {
+                break;
+            }
+        }
+    }
 
-   /* Return amount of available playback or capture devices */
-   if (!iscapture)
-   {
-      return qsa_playback_devices;
-   }
-   else
-   {
-      return qsa_capture_devices;
-   }
+    /* Return amount of available playback or capture devices */
+    if (!iscapture) {
+        return qsa_playback_devices;
+    } else {
+        return qsa_capture_devices;
+    }
 }
 
-const char* QSA_GetDeviceName(int index, int iscapture)
+const char *
+QSA_GetDeviceName(int index, int iscapture)
 {
-   if (!iscapture)
-   {
-      if (index>=qsa_playback_devices)
-      {
-         return "No such playback device";
-      }
+    if (!iscapture) {
+        if (index >= qsa_playback_devices) {
+            return "No such playback device";
+        }
 
-      return qsa_playback_device[index].name;
-   }
-   else
-   {
-      if (index>=qsa_capture_devices)
-      {
-         return "No such capture device";
-      }
+        return qsa_playback_device[index].name;
+    } else {
+        if (index >= qsa_capture_devices) {
+            return "No such capture device";
+        }
 
-      return qsa_capture_device[index].name;
-   }
+        return qsa_capture_device[index].name;
+    }
 }
 
-void QSA_WaitDone(_THIS)
+void
+QSA_WaitDone(_THIS)
 {
-   if (!this->hidden->iscapture)
-   {
-      if (this->hidden->audio_handle!=NULL)
-      {
-         /* Wait till last fragment is played and stop channel */
-         snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
-      }
-   }
-   else
-   {
-      if (this->hidden->audio_handle!=NULL)
-      {
-         /* Discard all unread data and stop channel */
-         snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
-      }
-   }
+    if (!this->hidden->iscapture) {
+        if (this->hidden->audio_handle != NULL) {
+            /* Wait till last fragment is played and stop channel */
+            snd_pcm_plugin_flush(this->hidden->audio_handle,
+                                 SND_PCM_CHANNEL_PLAYBACK);
+        }
+    } else {
+        if (this->hidden->audio_handle != NULL) {
+            /* Discard all unread data and stop channel */
+            snd_pcm_plugin_flush(this->hidden->audio_handle,
+                                 SND_PCM_CHANNEL_CAPTURE);
+        }
+    }
+}
+
+void
+QSA_Deinitialize(void)
+{
+    /* Clear devices array on shutdown */
+    SDL_memset(qsa_playback_device, 0x00,
+               sizeof(QSA_Device) * QSA_MAX_DEVICES);
+    SDL_memset(qsa_capture_device, 0x00,
+               sizeof(QSA_Device) * QSA_MAX_DEVICES);
+    qsa_playback_devices = 0;
+    qsa_capture_devices = 0;
 }
 
-void QSA_Deinitialize(void)
+static int
+QSA_Init(SDL_AudioDriverImpl * impl)
 {
-   /* Clear devices array on shutdown */
-   SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
-   SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
-   qsa_playback_devices=0;
-   qsa_capture_devices=0;
+    snd_pcm_t *handle = NULL;
+    int32_t status = 0;
+
+    /* Clear devices array */
+    SDL_memset(qsa_playback_device, 0x00,
+               sizeof(QSA_Device) * QSA_MAX_DEVICES);
+    SDL_memset(qsa_capture_device, 0x00,
+               sizeof(QSA_Device) * QSA_MAX_DEVICES);
+    qsa_playback_devices = 0;
+    qsa_capture_devices = 0;
+
+    /* Set function pointers                                     */
+    /* DeviceLock and DeviceUnlock functions are used default,   */
+    /* provided by SDL, which uses pthread_mutex for lock/unlock */
+    impl->DetectDevices = QSA_DetectDevices;
+    impl->GetDeviceName = QSA_GetDeviceName;
+    impl->OpenDevice = QSA_OpenDevice;
+    impl->ThreadInit = QSA_ThreadInit;
+    impl->WaitDevice = QSA_WaitDevice;
+    impl->PlayDevice = QSA_PlayDevice;
+    impl->GetDeviceBuf = QSA_GetDeviceBuf;
+    impl->CloseDevice = QSA_CloseDevice;
+    impl->WaitDone = QSA_WaitDone;
+    impl->Deinitialize = QSA_Deinitialize;
+    impl->LockDevice = NULL;
+    impl->UnlockDevice = NULL;
+
+    impl->OnlyHasDefaultOutputDevice = 0;
+    impl->ProvidesOwnCallbackThread = 0;
+    impl->SkipMixerLock = 0;
+    impl->HasCaptureSupport = 1;
+    impl->OnlyHasDefaultOutputDevice = 0;
+    impl->OnlyHasDefaultInputDevice = 0;
+
+    /* Check if io-audio manager is running or not */
+    status = snd_cards();
+    if (status == 0) {
+        /* if no, return immediately */
+        return 1;
+    }
+
+    /* At this point we are definitely has an audio device */
+    return 2;
 }
 
-static int QSA_Init(SDL_AudioDriverImpl* impl)
-{
-   snd_pcm_t* handle=NULL;
-   int32_t    status=0;
-
-   /* Clear devices array */
-   SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
-   SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
-   qsa_playback_devices=0;
-   qsa_capture_devices=0;
-
-   /* Set function pointers                                     */
-   /* DeviceLock and DeviceUnlock functions are used default,   */
-   /* provided by SDL, which uses pthread_mutex for lock/unlock */
-   impl->DetectDevices=QSA_DetectDevices;
-   impl->GetDeviceName=QSA_GetDeviceName;
-   impl->OpenDevice=QSA_OpenDevice;
-   impl->ThreadInit=QSA_ThreadInit;
-   impl->WaitDevice=QSA_WaitDevice;
-   impl->PlayDevice=QSA_PlayDevice;
-   impl->GetDeviceBuf=QSA_GetDeviceBuf;
-   impl->CloseDevice=QSA_CloseDevice;
-   impl->WaitDone=QSA_WaitDone;
-   impl->Deinitialize=QSA_Deinitialize;
-   impl->LockDevice=NULL;
-   impl->UnlockDevice=NULL;
-
-   impl->OnlyHasDefaultOutputDevice=0;
-   impl->ProvidesOwnCallbackThread=0;
-   impl->SkipMixerLock=0;
-   impl->HasCaptureSupport=1;
-   impl->OnlyHasDefaultOutputDevice=0;
-   impl->OnlyHasDefaultInputDevice=0;
-
-   /* Check if io-audio manager is running or not */
-   status=snd_cards();
-   if (status==0)
-   {
-      /* if no, return immediately */
-      return 1;
-   }
-
-   /* At this point we are definitely has an audio device */
-   return 2;
-}
-
-AudioBootStrap QSAAUDIO_bootstrap=
-{
-   DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
+AudioBootStrap QSAAUDIO_bootstrap = {
+    DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
 };
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/qsa/SDL_qsa_audio.h	Fri May 15 15:47:37 2009 +0000
+++ b/src/audio/qsa/SDL_qsa_audio.h	Sat May 23 22:41:08 2009 +0000
@@ -44,7 +44,7 @@
     /* The audio device handle */
     int cardno;
     int deviceno;
-    snd_pcm_t* audio_handle;
+    snd_pcm_t *audio_handle;
 
     /* The audio file descriptor */
     int audio_fd;
@@ -53,7 +53,7 @@
     uint32_t timeout_on_wait;
 
     /* Raw mixing buffer */
-    Uint8* pcm_buf;
+    Uint8 *pcm_buf;
     Uint32 pcm_len;
 };
 
--- a/src/video/SDL_renderer_gles.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/SDL_renderer_gles.c	Sat May 23 22:41:08 2009 +0000
@@ -34,9 +34,10 @@
 
 /* Empty function stub to get OpenGL ES 1.0 support without  */
 /* OpenGL ES extension GL_OES_draw_texture_supported         */
-GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
+GL_API void GL_APIENTRY
+glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
 {
-   return;
+    return;
 }
 
 #endif /* __QNXNTO__ */
@@ -105,8 +106,7 @@
      {
       /* OpenGL ES 1.x supported formats list */
       SDL_PIXELFORMAT_BGR24,
-      SDL_PIXELFORMAT_ABGR8888
-     },
+      SDL_PIXELFORMAT_ABGR8888},
      0,
      0}
 };
@@ -351,7 +351,7 @@
 }
 
 static int
-GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
+GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
     GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
     SDL_Window *window = SDL_GetWindowFromID(renderer->window);
@@ -363,15 +363,15 @@
 
     switch (texture->format) {
     case SDL_PIXELFORMAT_BGR24:
-         internalFormat = GL_RGB;
-         format = GL_RGB;
-         type = GL_UNSIGNED_BYTE;
-         break;
+        internalFormat = GL_RGB;
+        format = GL_RGB;
+        type = GL_UNSIGNED_BYTE;
+        break;
     case SDL_PIXELFORMAT_ABGR8888:
-         internalFormat = GL_RGBA;
-         format = GL_RGBA;
-         type = GL_UNSIGNED_BYTE;
-         break;
+        internalFormat = GL_RGBA;
+        format = GL_RGBA;
+        type = GL_UNSIGNED_BYTE;
+        break;
         /*
            These formats would be supported if SDL had the necessary pixel formats
            case SDL_PIXELFORMAT_BGR565:
@@ -389,7 +389,7 @@
            format = GL_RGBA;
            type = GL_UNSIGNED_SHORT_4_4_4_4;
            break;
-        */
+         */
     default:
         SDL_SetError("Unsupported texture format");
         return -1;
@@ -533,8 +533,8 @@
 }
 
 static int
-GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
-                   const SDL_Rect *rect, const void *pixels, int pitch)
+GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
+                   const SDL_Rect * rect, const void *pixels, int pitch)
 {
     GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
     GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
@@ -858,7 +858,7 @@
 }
 
 static void
-GLES_RenderPresent(SDL_Renderer *renderer)
+GLES_RenderPresent(SDL_Renderer * renderer)
 {
     SDL_GL_SwapWindow(renderer->window);
 }
--- a/src/video/SDL_video.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/SDL_video.c	Sat May 23 22:41:08 2009 +0000
@@ -1496,10 +1496,9 @@
     window->renderer = SDL_CurrentDisplay.render_drivers[index]
         .CreateRenderer(window, flags);
 
-    if (window->renderer==NULL)
-    {
-       /* Assuming renderer set its error */
-       return -1;
+    if (window->renderer == NULL) {
+        /* Assuming renderer set its error */
+        return -1;
     }
 
     SDL_SelectRenderer(window->id);
@@ -2719,7 +2718,7 @@
 {
 #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
     void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
-    GLenum (APIENTRY * glGetErrorFunc) (void);
+    GLenum(APIENTRY * glGetErrorFunc) (void);
     GLenum attrib = 0;
     GLenum error = 0;
 
@@ -2734,7 +2733,7 @@
     }
 
     /* Clear value in any case */
-    *value=0;
+    *value = 0;
 
     switch (attr) {
     case SDL_GL_RETAINED_BACKING:
@@ -2842,28 +2841,26 @@
     }
 
     glGetIntegervFunc(attrib, (GLint *) value);
-    error=glGetErrorFunc();
-    if (error!=GL_NO_ERROR)
-    {
-       switch (error)
-       {
-          case GL_INVALID_ENUM:
-               {
-                  SDL_SetError("OpenGL error: GL_INVALID_ENUM");
-               }
-               break;
-          case GL_INVALID_VALUE:
-               {
-                  SDL_SetError("OpenGL error: GL_INVALID_VALUE");
-               }
-               break;
-          default:
-               {
-                  SDL_SetError("OpenGL error: %08X", error);
-               }
-               break;
-       }
-       return -1;
+    error = glGetErrorFunc();
+    if (error != GL_NO_ERROR) {
+        switch (error) {
+        case GL_INVALID_ENUM:
+            {
+                SDL_SetError("OpenGL error: GL_INVALID_ENUM");
+            }
+            break;
+        case GL_INVALID_VALUE:
+            {
+                SDL_SetError("OpenGL error: GL_INVALID_VALUE");
+            }
+            break;
+        default:
+            {
+                SDL_SetError("OpenGL error: %08X", error);
+            }
+            break;
+        }
+        return -1;
     }
     return 0;
 #else
--- a/src/video/nds/SDL_ndsrender.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/nds/SDL_ndsrender.c	Sat May 23 22:41:08 2009 +0000
@@ -88,7 +88,7 @@
       SDL_PIXELFORMAT_INDEX8,
       SDL_PIXELFORMAT_ABGR1555,
       SDL_PIXELFORMAT_BGR555,
-     },                         /* u32 texture_formats[20] */
+      },                        /* u32 texture_formats[20] */
      (256),                     /* int max_texture_width */
      (256),                     /* int max_texture_height */
      }
@@ -107,8 +107,14 @@
     { NDSTX_BG, NDSTX_SPR } type;       /* represented in a bg or sprite. */
     int hw_index;               /* index of sprite in OAM or bg from libnds */
     int pitch, bpp;             /* useful information about the texture */
-    struct { int x,y; } scale;  /* x/y stretch (24.8 fixed point) */
-    struct { int x,y; } scroll; /* x/y offset */
+    struct
+    {
+        int x, y;
+    } scale;                    /* x/y stretch (24.8 fixed point) */
+    struct
+    {
+        int x, y;
+    } scroll;                   /* x/y offset */
     int rotate;                 /* -32768 to 32767, texture rotation */
     u16 *vram_pixels;           /* where the pixel data is stored (a pointer into VRAM) */
     u16 *vram_palette;          /* where the palette data is stored if it's indexed. */
@@ -197,9 +203,9 @@
     renderer->info.max_texture_height =
         NDS_RenderDriver.info.max_texture_height;
 
-    data->sub = 0;           /* TODO: this is hard-coded to the "main" screen.
-                                figure out how to detect whether to set it to
-                                "sub" screen.  window->id, perhaps? */
+    data->sub = 0;              /* TODO: this is hard-coded to the "main" screen.
+                                   figure out how to detect whether to set it to
+                                   "sub" screen.  window->id, perhaps? */
     data->bg_taken[2] = data->bg_taken[3] = 0;
 
     return renderer;
@@ -310,9 +316,10 @@
             txdat->dim.vdy = 0x100;
             txdat->dim.pitch = pitch;
             txdat->dim.bpp = bpp;
-            txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
+            txdat->vram_pixels =
+                (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
             /* FIXME: use tileIdx*boundary
-                      to point to proper location */
+               to point to proper location */
         } else {
             SDL_SetError("Out of NDS sprites.");
         }
@@ -332,20 +339,26 @@
                 SDL_OutOfMemory();
                 return -1;
             }
-
 // hard-coded for 256x256 for now...
 // TODO: a series of if-elseif-else's to find the closest but larger size.
-            if(!data->sub) {
-                if(bpp==8) {
-                    txdat->hw_index = bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
+            if (!data->sub) {
+                if (bpp == 8) {
+                    txdat->hw_index =
+                        bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
                 } else {
-                    txdat->hw_index = bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
+                    txdat->hw_index =
+                        bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0,
+                               0);
                 }
             } else {
-                if(bpp==8) {
-                    txdat->hw_index = bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
+                if (bpp == 8) {
+                    txdat->hw_index =
+                        bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0,
+                                  0);
                 } else {
-                    txdat->hw_index = bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
+                    txdat->hw_index =
+                        bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256,
+                                  0, 0);
                 }
             }
 
@@ -357,14 +370,14 @@
 		bgUpdate(bg3);
 */
             txdat->type = NDSTX_BG;
-            txdat->pitch = (texture->w)*(bpp/8);
+            txdat->pitch = (texture->w) * (bpp / 8);
             txdat->bpp = bpp;
             txdat->rotate = 0;
             txdat->scale.x = 0x100;
             txdat->scale.y = 0x100;
             txdat->scroll.x = 0;
             txdat->scroll.y = 0;
-            txdat->vram_pixels = (u16*)bgGetGfxPtr(txdat->hw_index);
+            txdat->vram_pixels = (u16 *) bgGetGfxPtr(txdat->hw_index);
 
             bgSetCenter(txdat->hw_index, 0, 0);
             bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x,
@@ -458,7 +471,7 @@
     int i, j;
 
     printf("NDS_RenderFill: stub\n");
-    color = RGB8(r, g, b);  /* macro in libnds that makes an ARGB1555 pixel */
+    color = RGB8(r, g, b);      /* macro in libnds that makes an ARGB1555 pixel */
     /* TODO: make a single-color sprite and stretch it.
        calculate the "HDX" width modifier of the sprite by:
        let S be the actual sprite's width (like, 32 pixels for example)
--- a/src/video/photon/SDL_photon.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon.c	Sat May 23 22:41:08 2009 +0000
@@ -42,2541 +42,2509 @@
 
 /* Use GF's pixel format functions for OpenGL ES context creation */
 #if defined(SDL_VIDEO_OPENGL_ES)
-   #include "../qnxgf/SDL_gf_pixelfmt.h"
+#include "../qnxgf/SDL_gf_pixelfmt.h"
 
    /* If GF driver is not compiled in, include some of usefull functions */
-   #if !defined(SDL_VIDEO_DRIVER_QNXGF)
-      #include "../qnxgf/SDL_gf_pixelfmt.c"
-   #endif /* SDL_VIDEO_DRIVER_QNXGF */
+#if !defined(SDL_VIDEO_DRIVER_QNXGF)
+#include "../qnxgf/SDL_gf_pixelfmt.c"
+#endif /* SDL_VIDEO_DRIVER_QNXGF */
 #endif /* SDL_VIDEO_OPENGL_ES */
 
 /* Use GF's OpenGL ES 1.1 functions emulation */
 #if defined(SDL_VIDEO_OPENGL_ES)
-   #include "../qnxgf/SDL_gf_opengles.h"
+#include "../qnxgf/SDL_gf_opengles.h"
 
    /* If GF driver is not compiled in, include some of usefull functions */
-   #if !defined(SDL_VIDEO_DRIVER_QNXGF)
-      #include "../qnxgf/SDL_gf_opengles.c"
-   #endif /* SDL_VIDEO_DRIVER_QNXGF */
+#if !defined(SDL_VIDEO_DRIVER_QNXGF)
+#include "../qnxgf/SDL_gf_opengles.c"
+#endif /* SDL_VIDEO_DRIVER_QNXGF */
 #endif /* SDL_VIDEO_OPENGL_ES */
 
 /* Low level device graphics driver names, which they are reporting */
-Photon_DeviceCaps photon_devicename[]=
-{
-   /* ATI Rage 128 graphics driver (devg-ati_rage128)      */
-   {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Fujitsu Carmine graphics driver (devg-carmine.so)    */
-   {"carmine",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
-   /* C&T graphics driver (devg-chips.so)                  */
-   {"chips",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Fujitsu Coral graphics driver (devg-coral.so)        */
-   {"coral",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
-   /* Intel integrated graphics driver (devg-extreme2.so)  */
-   {"extreme2",    SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
-   /* Unaccelerated FB driver (devg-flat.so)               */
-   {"flat",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* NS Geode graphics driver (devg-geode.so)             */
-   {"geode",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Geode LX graphics driver (devg-geodelx.so)           */
-   {"geodelx",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Intel integrated graphics driver (devg-gma9xx.so)    */
-   {"gma",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
-   /* Intel integrated graphics driver (devg-i810.so)      */
-   {"i810",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Intel integrated graphics driver (devg-i830.so)      */
-   {"i830",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Geode LX graphics driver (devg-lx800.so)             */
-   {"lx800",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Matrox Gxx graphics driver (devg-matroxg.so)         */
-   {"matroxg",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Intel Poulsbo graphics driver (devg-poulsbo.so)      */
-   {"poulsbo",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
-   /* ATI Radeon driver (devg-radeon.so)                   */
-   {"radeon",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* ATI Rage driver (devg-rage.so)                       */
-   {"rage",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* S3 Savage graphics driver (devg-s3_savage.so)        */
-   {"s3_savage",   SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* SiS630 integrated graphics driver (devg-sis630.so)   */
-   {"sis630",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* PowerVR SGX 535 graphics driver (devg-poulsbo.so)    */
-   {"sgx",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
-   /* SM Voyager GX graphics driver (devg-smi5xx.so)       */
-   {"smi5xx",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* Silicon Motion graphics driver (devg-smi7xx.so)      */
-   {"smi7xx",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* SVGA unaccelerated gfx driver (devg-svga.so)         */
-   {"svga",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* nVidia TNT graphics driver (devg-tnt.so)             */
-   {"tnt",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* VIA integrated graphics driver (devg-tvia.so)        */
-   {"tvia",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* VIA UniChrome graphics driver (devg-unichrome.so)    */
-   {"unichrome",   SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* VESA unaccelerated gfx driver (devg-vesa.so)         */
-   {"vesa",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* VmWare graphics driver (devg-volari.so)              */
-   {"vmware",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5*/
-   {"volari",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
-   /* End of list */
-   {NULL,          0x00000000}
+Photon_DeviceCaps photon_devicename[] = {
+    /* ATI Rage 128 graphics driver (devg-ati_rage128)      */
+    {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Fujitsu Carmine graphics driver (devg-carmine.so)    */
+    {"carmine", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
+    ,
+    /* C&T graphics driver (devg-chips.so)                  */
+    {"chips", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Fujitsu Coral graphics driver (devg-coral.so)        */
+    {"coral", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
+    ,
+    /* Intel integrated graphics driver (devg-extreme2.so)  */
+    {"extreme2", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
+    ,
+    /* Unaccelerated FB driver (devg-flat.so)               */
+    {"flat", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* NS Geode graphics driver (devg-geode.so)             */
+    {"geode", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Geode LX graphics driver (devg-geodelx.so)           */
+    {"geodelx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Intel integrated graphics driver (devg-gma9xx.so)    */
+    {"gma", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
+    ,
+    /* Intel integrated graphics driver (devg-i810.so)      */
+    {"i810", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Intel integrated graphics driver (devg-i830.so)      */
+    {"i830", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Geode LX graphics driver (devg-lx800.so)             */
+    {"lx800", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Matrox Gxx graphics driver (devg-matroxg.so)         */
+    {"matroxg", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Intel Poulsbo graphics driver (devg-poulsbo.so)      */
+    {"poulsbo", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
+    ,
+    /* ATI Radeon driver (devg-radeon.so)                   */
+    {"radeon", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* ATI Rage driver (devg-rage.so)                       */
+    {"rage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* S3 Savage graphics driver (devg-s3_savage.so)        */
+    {"s3_savage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* SiS630 integrated graphics driver (devg-sis630.so)   */
+    {"sis630", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* PowerVR SGX 535 graphics driver (devg-poulsbo.so)    */
+    {"sgx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
+    ,
+    /* SM Voyager GX graphics driver (devg-smi5xx.so)       */
+    {"smi5xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* Silicon Motion graphics driver (devg-smi7xx.so)      */
+    {"smi7xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* SVGA unaccelerated gfx driver (devg-svga.so)         */
+    {"svga", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* nVidia TNT graphics driver (devg-tnt.so)             */
+    {"tnt", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* VIA integrated graphics driver (devg-tvia.so)        */
+    {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* VIA UniChrome graphics driver (devg-unichrome.so)    */
+    {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* VESA unaccelerated gfx driver (devg-vesa.so)         */
+    {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* VmWare graphics driver (devg-volari.so)              */
+    {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5 */
+    {"volari", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
+    ,
+    /* End of list */
+    {NULL, 0x00000000}
 };
 
-static SDL_bool photon_initialized=SDL_FALSE;
+static SDL_bool photon_initialized = SDL_FALSE;
 
-static int photon_available(void)
+static int
+photon_available(void)
 {
-   int status;
+    int status;
 
-   /* Check if Photon was initialized before */
-   if (photon_initialized==SDL_FALSE)
-   {
-      /* Initialize Photon widget library and open channel to Photon */
-      status=PtInit(NULL);
-      if (status==0)
-      {
-         photon_initialized=SDL_TRUE;
-         return 1;
-      }
-      else
-      {
-         photon_initialized=SDL_FALSE;
-         return 0;
-      }
-   }
+    /* Check if Photon was initialized before */
+    if (photon_initialized == SDL_FALSE) {
+        /* Initialize Photon widget library and open channel to Photon */
+        status = PtInit(NULL);
+        if (status == 0) {
+            photon_initialized = SDL_TRUE;
+            return 1;
+        } else {
+            photon_initialized = SDL_FALSE;
+            return 0;
+        }
+    }
 
-   return 1;
-}
-
-static void photon_destroy(SDL_VideoDevice* device)
-{
-   SDL_VideoData* phdata=(SDL_VideoData*) device->driverdata;
-
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      if (phdata->gfinitialized!=SDL_FALSE)
-      {
-         gf_dev_detach(phdata->gfdev);
-      }
-   #endif /* SDL_VIDEO_OPENGL_ES */
-
-   if (device->driverdata!=NULL)
-   {
-      device->driverdata=NULL;
-   }
+    return 1;
 }
 
-static SDL_VideoDevice* photon_create(int devindex)
+static void
+photon_destroy(SDL_VideoDevice * device)
 {
-   SDL_VideoDevice*  device;
-   SDL_VideoData*    phdata;
-   int               status;
-
-   /* Check if photon could be initialized */
-   status=photon_available();
-   if (status==0)
-   {
-      /* Photon could not be used */
-      return NULL;
-   }
-
-   /* Photon agregates all video devices to one with multiple heads */
-   if (devindex!=0)
-   {
-      /* devindex could be zero only in Photon SDL driver */
-      return NULL;
-   }
-
-   /* Initialize SDL_VideoDevice structure */
-   device=(SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice));
-   if (device==NULL)
-   {
-      SDL_OutOfMemory();
-      return NULL;
-   }
-
-   /* Initialize internal photon specific data */
-   phdata=(SDL_VideoData*)SDL_calloc(1, sizeof(SDL_VideoData));
-   if (phdata==NULL)
-   {
-      SDL_OutOfMemory();
-      SDL_free(device);
-      return NULL;
-   }
-   device->driverdata=phdata;
-
-   /* Get all photon display devices */
-   phdata->avail_rids=PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
-   if (phdata->avail_rids>SDL_VIDEO_PHOTON_MAX_RIDS)
-   {
-      phdata->avail_rids=SDL_VIDEO_PHOTON_MAX_RIDS;
-   }
+    SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
 
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      /* TODO: add real device detection versus multiple heads */
-      status=gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0), &phdata->gfdev_info);
-      if (status!=GF_ERR_OK)
-      {
-         /* Do not fail right now, if GF can't be attached */
-         phdata->gfinitialized=SDL_FALSE;
-      }
-      else
-      {
-         phdata->gfinitialized=SDL_TRUE;
-      }
-   #endif /* SDL_VIDEO_OPENGL_ES */
-
-   /* Set default target device */
-   status=PdSetTargetDevice(NULL, phdata->rid[0]);
-   if (status==-1)
-   {
-      SDL_SetError("Photon: Can't set default target device");
-      #if defined(SDL_VIDEO_OPENGL_ES)
-         gf_dev_detach(phdata->gfdev);
-      #endif /* SDL_VIDEO_OPENGL_ES */
-      SDL_free(phdata);
-      SDL_free(device);
-      return NULL;
-   }
-   phdata->current_device_id=0;
-
-   /* Setup amount of available displays and current display */
-   device->num_displays=0;
-   device->current_display=0;
-
-   /* Set device free function */
-   device->free=photon_destroy;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    if (phdata->gfinitialized != SDL_FALSE) {
+        gf_dev_detach(phdata->gfdev);
+    }
+#endif /* SDL_VIDEO_OPENGL_ES */
 
-   /* Setup all functions which we can handle */
-   device->VideoInit=photon_videoinit;
-   device->VideoQuit=photon_videoquit;
-   device->GetDisplayModes=photon_getdisplaymodes;
-   device->SetDisplayMode=photon_setdisplaymode;
-   device->SetDisplayPalette=photon_setdisplaypalette;
-   device->GetDisplayPalette=photon_getdisplaypalette;
-   device->SetDisplayGammaRamp=photon_setdisplaygammaramp;
-   device->GetDisplayGammaRamp=photon_getdisplaygammaramp;
-   device->CreateWindow=photon_createwindow;
-   device->CreateWindowFrom=photon_createwindowfrom;
-   device->SetWindowTitle=photon_setwindowtitle;
-   device->SetWindowIcon=photon_setwindowicon;
-   device->SetWindowPosition=photon_setwindowposition;
-   device->SetWindowSize=photon_setwindowsize;
-   device->ShowWindow=photon_showwindow;
-   device->HideWindow=photon_hidewindow;
-   device->RaiseWindow=photon_raisewindow;
-   device->MaximizeWindow=photon_maximizewindow;
-   device->MinimizeWindow=photon_minimizewindow;
-   device->RestoreWindow=photon_restorewindow;
-   device->SetWindowGrab=photon_setwindowgrab;
-   device->DestroyWindow=photon_destroywindow;
-   device->GetWindowWMInfo=photon_getwindowwminfo;
-   device->GL_LoadLibrary=photon_gl_loadlibrary;
-   device->GL_GetProcAddress=photon_gl_getprocaddres;
-   device->GL_UnloadLibrary=photon_gl_unloadlibrary;
-   device->GL_CreateContext=photon_gl_createcontext;
-   device->GL_MakeCurrent=photon_gl_makecurrent;
-   device->GL_SetSwapInterval=photon_gl_setswapinterval;
-   device->GL_GetSwapInterval=photon_gl_getswapinterval;
-   device->GL_SwapWindow=photon_gl_swapwindow;
-   device->GL_DeleteContext=photon_gl_deletecontext;
-   device->PumpEvents=photon_pumpevents;
-   device->SuspendScreenSaver=photon_suspendscreensaver;
-
-   return device;
+    if (device->driverdata != NULL) {
+        device->driverdata = NULL;
+    }
 }
 
-VideoBootStrap photon_bootstrap=
+static SDL_VideoDevice *
+photon_create(int devindex)
 {
-   "photon",
-   "SDL QNX Photon video driver",
-   photon_available,
-   photon_create
+    SDL_VideoDevice *device;
+    SDL_VideoData *phdata;
+    int status;
+
+    /* Check if photon could be initialized */
+    status = photon_available();
+    if (status == 0) {
+        /* Photon could not be used */
+        return NULL;
+    }
+
+    /* Photon agregates all video devices to one with multiple heads */
+    if (devindex != 0) {
+        /* devindex could be zero only in Photon SDL driver */
+        return NULL;
+    }
+
+    /* Initialize SDL_VideoDevice structure */
+    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+    if (device == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    /* Initialize internal photon specific data */
+    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+    if (phdata == NULL) {
+        SDL_OutOfMemory();
+        SDL_free(device);
+        return NULL;
+    }
+    device->driverdata = phdata;
+
+    /* Get all photon display devices */
+    phdata->avail_rids =
+        PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
+    if (phdata->avail_rids > SDL_VIDEO_PHOTON_MAX_RIDS) {
+        phdata->avail_rids = SDL_VIDEO_PHOTON_MAX_RIDS;
+    }
+#if defined(SDL_VIDEO_OPENGL_ES)
+    /* TODO: add real device detection versus multiple heads */
+    status =
+        gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0),
+                      &phdata->gfdev_info);
+    if (status != GF_ERR_OK) {
+        /* Do not fail right now, if GF can't be attached */
+        phdata->gfinitialized = SDL_FALSE;
+    } else {
+        phdata->gfinitialized = SDL_TRUE;
+    }
+#endif /* SDL_VIDEO_OPENGL_ES */
+
+    /* Set default target device */
+    status = PdSetTargetDevice(NULL, phdata->rid[0]);
+    if (status == -1) {
+        SDL_SetError("Photon: Can't set default target device");
+#if defined(SDL_VIDEO_OPENGL_ES)
+        gf_dev_detach(phdata->gfdev);
+#endif /* SDL_VIDEO_OPENGL_ES */
+        SDL_free(phdata);
+        SDL_free(device);
+        return NULL;
+    }
+    phdata->current_device_id = 0;
+
+    /* Setup amount of available displays and current display */
+    device->num_displays = 0;
+    device->current_display = 0;
+
+    /* Set device free function */
+    device->free = photon_destroy;
+
+    /* Setup all functions which we can handle */
+    device->VideoInit = photon_videoinit;
+    device->VideoQuit = photon_videoquit;
+    device->GetDisplayModes = photon_getdisplaymodes;
+    device->SetDisplayMode = photon_setdisplaymode;
+    device->SetDisplayPalette = photon_setdisplaypalette;
+    device->GetDisplayPalette = photon_getdisplaypalette;
+    device->SetDisplayGammaRamp = photon_setdisplaygammaramp;
+    device->GetDisplayGammaRamp = photon_getdisplaygammaramp;
+    device->CreateWindow = photon_createwindow;
+    device->CreateWindowFrom = photon_createwindowfrom;
+    device->SetWindowTitle = photon_setwindowtitle;
+    device->SetWindowIcon = photon_setwindowicon;
+    device->SetWindowPosition = photon_setwindowposition;
+    device->SetWindowSize = photon_setwindowsize;
+    device->ShowWindow = photon_showwindow;
+    device->HideWindow = photon_hidewindow;
+    device->RaiseWindow = photon_raisewindow;
+    device->MaximizeWindow = photon_maximizewindow;
+    device->MinimizeWindow = photon_minimizewindow;
+    device->RestoreWindow = photon_restorewindow;
+    device->SetWindowGrab = photon_setwindowgrab;
+    device->DestroyWindow = photon_destroywindow;
+    device->GetWindowWMInfo = photon_getwindowwminfo;
+    device->GL_LoadLibrary = photon_gl_loadlibrary;
+    device->GL_GetProcAddress = photon_gl_getprocaddres;
+    device->GL_UnloadLibrary = photon_gl_unloadlibrary;
+    device->GL_CreateContext = photon_gl_createcontext;
+    device->GL_MakeCurrent = photon_gl_makecurrent;
+    device->GL_SetSwapInterval = photon_gl_setswapinterval;
+    device->GL_GetSwapInterval = photon_gl_getswapinterval;
+    device->GL_SwapWindow = photon_gl_swapwindow;
+    device->GL_DeleteContext = photon_gl_deletecontext;
+    device->PumpEvents = photon_pumpevents;
+    device->SuspendScreenSaver = photon_suspendscreensaver;
+
+    return device;
+}
+
+VideoBootStrap photon_bootstrap = {
+    "photon",
+    "SDL QNX Photon video driver",
+    photon_available,
+    photon_create
 };
 
 /*****************************************************************************/
 /* SDL Video and Display initialization/handling functions                   */
 /*****************************************************************************/
-int photon_videoinit(_THIS)
+int
+photon_videoinit(_THIS)
 {
-   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
-   PgHWCaps_t        hwcaps;
-   PgVideoModeInfo_t modeinfo;
-   int32_t           status;
-   SDL_VideoDisplay  display;
-   SDL_DisplayMode   current_mode;
-   SDL_DisplayData*  didata;
-   uint32_t          it;
-   uint32_t          jt;
-   char*             override;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    PgHWCaps_t hwcaps;
+    PgVideoModeInfo_t modeinfo;
+    int32_t status;
+    SDL_VideoDisplay display;
+    SDL_DisplayMode current_mode;
+    SDL_DisplayData *didata;
+    uint32_t it;
+    uint32_t jt;
+    char *override;
+
+    /* By default Photon do not uses swap on VSYNC */
+    phdata->swapinterval = 0;
 
-   /* By default Photon do not uses swap on VSYNC */
-   phdata->swapinterval=0;
+    for (it = 0; it < phdata->avail_rids; it++) {
+        didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
+        if (didata == NULL) {
+            /* memory allocation error */
+            SDL_OutOfMemory();
+            return -1;
+        }
 
-   for (it=0; it<phdata->avail_rids; it++)
-   {
-      didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData));
-      if (didata==NULL)
-      {
-         /* memory allocation error */
-         SDL_OutOfMemory();
-         return -1;
-      }
+        /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
+        /* and 128 bytes of spare place                                    */
+        didata->cursor_size =
+            ((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE * 4) >> 3) + 128;
+        didata->cursor = (PhCursorDef_t *) SDL_calloc(1, didata->cursor_size);
+        if (didata->cursor == NULL) {
+            /* memory allocation error */
+            SDL_OutOfMemory();
+            SDL_free(didata);
+            return -1;
+        }
 
-      /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
-      /* and 128 bytes of spare place                                    */
-      didata->cursor_size=((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE*4)>>3)+128;
-      didata->cursor=(PhCursorDef_t*)SDL_calloc(1, didata->cursor_size);
-      if (didata->cursor==NULL)
-      {
-         /* memory allocation error */
-         SDL_OutOfMemory();
-         SDL_free(didata);
-         return -1;
-      }
+        /* Initialize GF in case of OpenGL ES support is compiled in */
+#if defined(SDL_VIDEO_OPENGL_ES)
+        /* TODO: add real device detection versus multiple heads */
+        if (phdata->gfinitialized == SDL_TRUE) {
+            status =
+                gf_display_attach(&didata->display, phdata->gfdev, it,
+                                  &didata->display_info);
+            if (status != GF_ERR_OK) {
+                /* Just shutdown GF, do not fail */
+                gf_dev_detach(phdata->gfdev);
+                phdata->gfinitialized = SDL_FALSE;
+            }
+        }
+#endif /* SDL_VIDEO_OPENGL_ES */
 
-      /* Initialize GF in case of OpenGL ES support is compiled in */
-      #if defined(SDL_VIDEO_OPENGL_ES)
-         /* TODO: add real device detection versus multiple heads */
-         if (phdata->gfinitialized==SDL_TRUE)
-         {
-            status=gf_display_attach(&didata->display, phdata->gfdev, it, &didata->display_info);
-            if (status!=GF_ERR_OK)
-            {
-               /* Just shutdown GF, do not fail */
-               gf_dev_detach(phdata->gfdev);
-               phdata->gfinitialized=SDL_FALSE;
+        /* Check if current device is not the same as target */
+        if (phdata->current_device_id != it) {
+            /* Set target device as default for Pd and Pg functions */
+            status = PdSetTargetDevice(NULL, phdata->rid[it]);
+            if (status != 0) {
+                SDL_SetError("Photon: Can't set default target device\n");
+                SDL_free(didata->cursor);
+                SDL_free(didata);
+                return -1;
             }
-         }
-      #endif /* SDL_VIDEO_OPENGL_ES */
+            phdata->current_device_id = it;
+        }
+
+        /* Store device id */
+        didata->device_id = it;
 
-      /* Check if current device is not the same as target */
-      if (phdata->current_device_id!=it)
-      {
-         /* Set target device as default for Pd and Pg functions */
-         status=PdSetTargetDevice(NULL, phdata->rid[it]);
-         if (status!=0)
-         {
-            SDL_SetError("Photon: Can't set default target device\n");
+        /* Query photon about graphics hardware caps and current video mode */
+        status = PgGetGraphicsHWCaps(&hwcaps);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't get graphics capabilities");
+            SDL_free(didata->cursor);
+            SDL_free(didata);
+            return -1;
+        }
+
+        /* Get current video mode details */
+        status = PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't get current video mode information");
             SDL_free(didata->cursor);
             SDL_free(didata);
             return -1;
-         }
-         phdata->current_device_id=it;
-      }
-
-      /* Store device id */
-      didata->device_id=it;
+        }
 
-      /* Query photon about graphics hardware caps and current video mode */
-      status=PgGetGraphicsHWCaps(&hwcaps);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't get graphics capabilities");
-         SDL_free(didata->cursor);
-         SDL_free(didata);
-         return -1;
-      }
+        /* Setup current desktop mode for SDL */
+        SDL_zero(current_mode);
+        current_mode.w = modeinfo.width;
+        current_mode.h = modeinfo.height;
+        current_mode.refresh_rate = hwcaps.current_rrate;
+        current_mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
+        current_mode.driverdata = NULL;
+
+        /* Copy device name */
+        SDL_strlcpy(didata->description, hwcaps.chip_name,
+                    SDL_VIDEO_PHOTON_DEVICENAME_MAX - 1);
 
-      /* Get current video mode details */
-      status=PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't get current video mode information");
-         SDL_free(didata->cursor);
-         SDL_free(didata);
-         return -1;
-      }
-
-      /* Setup current desktop mode for SDL */
-      SDL_zero(current_mode);
-      current_mode.w=modeinfo.width;
-      current_mode.h=modeinfo.height;
-      current_mode.refresh_rate=hwcaps.current_rrate;
-      current_mode.format=photon_image_to_sdl_pixelformat(modeinfo.type);
-      current_mode.driverdata=NULL;
-
-      /* Copy device name */
-      SDL_strlcpy(didata->description, hwcaps.chip_name, SDL_VIDEO_PHOTON_DEVICENAME_MAX-1);
+        /* Search device capabilities and possible workarounds */
+        jt = 0;
+        do {
+            if (photon_devicename[jt].name == NULL) {
+                break;
+            }
+            if (SDL_strncmp
+                (photon_devicename[jt].name, didata->description,
+                 SDL_strlen(photon_devicename[jt].name)) == 0) {
+                didata->caps = photon_devicename[jt].caps;
+            }
+            jt++;
+        } while (1);
 
-      /* Search device capabilities and possible workarounds */
-      jt=0;
-      do {
-         if (photon_devicename[jt].name==NULL)
-         {
-            break;
-         }
-         if (SDL_strncmp(photon_devicename[jt].name, didata->description, SDL_strlen(photon_devicename[jt].name))==0)
-         {
-            didata->caps=photon_devicename[jt].caps;
-         }
-         jt++;
-      } while(1);
-
-      /* Initialize display structure */
-      SDL_zero(display);
-      display.desktop_mode=current_mode;
-      display.current_mode=current_mode;
-      display.driverdata=didata;
-      didata->current_mode=current_mode;
-      SDL_AddVideoDisplay(&display);
+        /* Initialize display structure */
+        SDL_zero(display);
+        display.desktop_mode = current_mode;
+        display.current_mode = current_mode;
+        display.driverdata = didata;
+        didata->current_mode = current_mode;
+        SDL_AddVideoDisplay(&display);
 
-      /* Check for environment variables which could override some SDL settings */
-      didata->custom_refresh=0;
-      override=SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
-      if (override!=NULL)
-      {
-         if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1)
-         {
-            didata->custom_refresh=0;
-         }
-      }
-   }
+        /* Check for environment variables which could override some SDL settings */
+        didata->custom_refresh = 0;
+        override = SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
+        if (override != NULL) {
+            if (SDL_sscanf(override, "%u", &didata->custom_refresh) != 1) {
+                didata->custom_refresh = 0;
+            }
+        }
+    }
 
-   /* Add photon input devices */
-   status=photon_addinputdevices(_this);
-   if (status!=0)
-   {
-      /* SDL error is set by photon_addinputdevices() function */
-      return -1;
-   }
+    /* Add photon input devices */
+    status = photon_addinputdevices(_this);
+    if (status != 0) {
+        /* SDL error is set by photon_addinputdevices() function */
+        return -1;
+    }
 
-   /* Add photon renderer to SDL */
-   photon_addrenderdriver(_this);
+    /* Add photon renderer to SDL */
+    photon_addrenderdriver(_this);
 
-   /* video has been initialized successfully */
-   return 1;
+    /* video has been initialized successfully */
+    return 1;
 }
 
-void photon_videoquit(_THIS)
+void
+photon_videoquit(_THIS)
 {
-   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData* didata;
-   uint32_t it;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata;
+    uint32_t it;
 
-   /* SDL will restore our desktop mode on exit */
-   for(it=0; it<_this->num_displays; it++)
-   {
-      didata=_this->displays[it].driverdata;
+    /* SDL will restore our desktop mode on exit */
+    for (it = 0; it < _this->num_displays; it++) {
+        didata = _this->displays[it].driverdata;
 
-      if (didata->cursor!=NULL)
-      {
-         SDL_free(didata->cursor);
-      }
-
-      #if defined(SDL_VIDEO_OPENGL_ES)
-         if (phdata->gfinitialized==SDL_TRUE)
-         {
+        if (didata->cursor != NULL) {
+            SDL_free(didata->cursor);
+        }
+#if defined(SDL_VIDEO_OPENGL_ES)
+        if (phdata->gfinitialized == SDL_TRUE) {
             /* Detach GF display */
             gf_display_detach(didata->display);
-         }
-      #endif /* SDL_VIDEO_OPENGL_ES */
-   }
+        }
+#endif /* SDL_VIDEO_OPENGL_ES */
+    }
 }
 
-void photon_getdisplaymodes(_THIS)
+void
+photon_getdisplaymodes(_THIS)
 {
-   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData*  didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-   SDL_DisplayMode   mode;
-   PgVideoModes_t    modes;
-   PgVideoModeInfo_t modeinfo;
-   int32_t           status;
-   uint32_t          it;
-   uint32_t          jt;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    SDL_DisplayMode mode;
+    PgVideoModes_t modes;
+    PgVideoModeInfo_t modeinfo;
+    int32_t status;
+    uint32_t it;
+    uint32_t jt;
 
-   /* Check if current device is not the same as target */
-   if (phdata->current_device_id!=didata->device_id)
-   {
-      /* Set target device as default for Pd and Pg functions */
-      status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't set default target device\n");
-         return;
-      }
-      phdata->current_device_id=didata->device_id;
-   }
+    /* Check if current device is not the same as target */
+    if (phdata->current_device_id != didata->device_id) {
+        /* Set target device as default for Pd and Pg functions */
+        status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't set default target device\n");
+            return;
+        }
+        phdata->current_device_id = didata->device_id;
+    }
 
-   /* Get array of available video modes */
-   status=PgGetVideoModeList(&modes);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't get video mode list");
-      return;
-   }
+    /* Get array of available video modes */
+    status = PgGetVideoModeList(&modes);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't get video mode list");
+        return;
+    }
 
-   for (it=0; it<modes.num_modes; it++)
-   {
-      status=PgGetVideoModeInfo(modes.modes[it], &modeinfo);
-      if (status!=0)
-      {
-         /* Maybe something wrong with this particular mode, skip it */
-         continue;
-      }
+    for (it = 0; it < modes.num_modes; it++) {
+        status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
+        if (status != 0) {
+            /* Maybe something wrong with this particular mode, skip it */
+            continue;
+        }
 
-      jt=0;
-      do {
-         if (modeinfo.refresh_rates[jt]!=0)
-         {
-            mode.w=modeinfo.width;
-            mode.h=modeinfo.height;
-            mode.refresh_rate=modeinfo.refresh_rates[jt];
-            mode.format=photon_image_to_sdl_pixelformat(modeinfo.type);
-            mode.driverdata=NULL;
-            SDL_AddDisplayMode(_this->current_display, &mode);
-            jt++;
-         }
-         else
-         {
-            break;
-         }
-      } while(1);
-   }
+        jt = 0;
+        do {
+            if (modeinfo.refresh_rates[jt] != 0) {
+                mode.w = modeinfo.width;
+                mode.h = modeinfo.height;
+                mode.refresh_rate = modeinfo.refresh_rates[jt];
+                mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
+                mode.driverdata = NULL;
+                SDL_AddDisplayMode(_this->current_display, &mode);
+                jt++;
+            } else {
+                break;
+            }
+        } while (1);
+    }
 }
 
-int photon_setdisplaymode(_THIS, SDL_DisplayMode* mode)
+int
+photon_setdisplaymode(_THIS, SDL_DisplayMode * mode)
 {
-   SDL_VideoData*      phdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData*    didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-   PgVideoModes_t      modes;
-   PgVideoModeInfo_t   modeinfo;
-   PgDisplaySettings_t modesettings;
-   uint32_t refresh_rate=0;
-   int32_t  status;
-   uint32_t it;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    PgVideoModes_t modes;
+    PgVideoModeInfo_t modeinfo;
+    PgDisplaySettings_t modesettings;
+    uint32_t refresh_rate = 0;
+    int32_t status;
+    uint32_t it;
 
-   /* Check if current device is not the same as target */
-   if (phdata->current_device_id!=didata->device_id)
-   {
-      /* Set target device as default for Pd and Pg functions */
-      status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't set default target device\n");
-         return;
-      }
-      phdata->current_device_id=didata->device_id;
-   }
+    /* Check if current device is not the same as target */
+    if (phdata->current_device_id != didata->device_id) {
+        /* Set target device as default for Pd and Pg functions */
+        status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't set default target device\n");
+            return;
+        }
+        phdata->current_device_id = didata->device_id;
+    }
 
-   /* Get array of available video modes */
-   status=PgGetVideoModeList(&modes);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't get video mode list");
-      return;
-   }
+    /* Get array of available video modes */
+    status = PgGetVideoModeList(&modes);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't get video mode list");
+        return;
+    }
 
-   /* Current display dimension and bpp are no more valid */
-   didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
-   didata->current_mode.w=0;
-   didata->current_mode.h=0;
+    /* Current display dimension and bpp are no more valid */
+    didata->current_mode.format = SDL_PIXELFORMAT_UNKNOWN;
+    didata->current_mode.w = 0;
+    didata->current_mode.h = 0;
 
-   /* Check if custom refresh rate requested */
-   if (didata->custom_refresh!=0)
-   {
-      refresh_rate=didata->custom_refresh;
-   }
-   else
-   {
-      refresh_rate=mode->refresh_rate;
-   }
+    /* Check if custom refresh rate requested */
+    if (didata->custom_refresh != 0) {
+        refresh_rate = didata->custom_refresh;
+    } else {
+        refresh_rate = mode->refresh_rate;
+    }
 
-   /* Check if SDL GF driver needs to find appropriate refresh rate itself */
-   if (refresh_rate==0)
-   {
-      SDL_DisplayMode tempmode;
+    /* Check if SDL GF driver needs to find appropriate refresh rate itself */
+    if (refresh_rate == 0) {
+        SDL_DisplayMode tempmode;
 
-      /* Clear display mode structure */
-      SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
-      tempmode.refresh_rate=0x0000FFFF;
+        /* Clear display mode structure */
+        SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
+        tempmode.refresh_rate = 0x0000FFFF;
 
-      /* Check if window width and height matches one of our modes */
-      for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
-      {
-         if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
-             (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
-             (SDL_CurrentDisplay.display_modes[it].format==mode->format))
-         {
-            /* Find the lowest refresh rate available */
-            if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
+        /* Check if window width and height matches one of our modes */
+        for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
+            if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
+                (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
+                (SDL_CurrentDisplay.display_modes[it].format == mode->format))
             {
-               tempmode=SDL_CurrentDisplay.display_modes[it];
+                /* Find the lowest refresh rate available */
+                if (tempmode.refresh_rate >
+                    SDL_CurrentDisplay.display_modes[it].refresh_rate) {
+                    tempmode = SDL_CurrentDisplay.display_modes[it];
+                }
             }
-         }
-      }
-      if (tempmode.refresh_rate!=0x0000FFFF)
-      {
-         refresh_rate=tempmode.refresh_rate;
-      }
-      else
-      {
-         /* Let video driver decide what to do with this */
-         refresh_rate=0;
-      }
-   }
+        }
+        if (tempmode.refresh_rate != 0x0000FFFF) {
+            refresh_rate = tempmode.refresh_rate;
+        } else {
+            /* Let video driver decide what to do with this */
+            refresh_rate = 0;
+        }
+    }
 
-   /* Check if SDL GF driver needs to check custom refresh rate */
-   if (didata->custom_refresh!=0)
-   {
-      SDL_DisplayMode tempmode;
+    /* Check if SDL GF driver needs to check custom refresh rate */
+    if (didata->custom_refresh != 0) {
+        SDL_DisplayMode tempmode;
 
-      /* Clear display mode structure */
-      SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
-      tempmode.refresh_rate=0x0000FFFF;
+        /* Clear display mode structure */
+        SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
+        tempmode.refresh_rate = 0x0000FFFF;
 
-      /* Check if window width and height matches one of our modes */
-      for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
-      {
-         if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
-             (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
-             (SDL_CurrentDisplay.display_modes[it].format==mode->format))
-         {
-            /* Find the lowest refresh rate available */
-            if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
+        /* Check if window width and height matches one of our modes */
+        for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
+            if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
+                (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
+                (SDL_CurrentDisplay.display_modes[it].format == mode->format))
             {
-               tempmode=SDL_CurrentDisplay.display_modes[it];
-            }
+                /* Find the lowest refresh rate available */
+                if (tempmode.refresh_rate >
+                    SDL_CurrentDisplay.display_modes[it].refresh_rate) {
+                    tempmode = SDL_CurrentDisplay.display_modes[it];
+                }
 
-            /* Check if requested refresh rate found */
-            if (refresh_rate==SDL_CurrentDisplay.display_modes[it].refresh_rate)
-            {
-               tempmode=SDL_CurrentDisplay.display_modes[it];
-               break;
+                /* Check if requested refresh rate found */
+                if (refresh_rate ==
+                    SDL_CurrentDisplay.display_modes[it].refresh_rate) {
+                    tempmode = SDL_CurrentDisplay.display_modes[it];
+                    break;
+                }
             }
-         }
-      }
-      if (tempmode.refresh_rate!=0x0000FFFF)
-      {
-         refresh_rate=tempmode.refresh_rate;
-      }
-      else
-      {
-         /* Let video driver decide what to do with this */
-         refresh_rate=0;
-      }
-   }
+        }
+        if (tempmode.refresh_rate != 0x0000FFFF) {
+            refresh_rate = tempmode.refresh_rate;
+        } else {
+            /* Let video driver decide what to do with this */
+            refresh_rate = 0;
+        }
+    }
 
-   /* Find photon's video mode number */
-   for (it=0; it<modes.num_modes; it++)
-   {
-      uint32_t jt;
-      uint32_t foundrefresh;
+    /* Find photon's video mode number */
+    for (it = 0; it < modes.num_modes; it++) {
+        uint32_t jt;
+        uint32_t foundrefresh;
 
-      /* Get current video mode details */
-      status=PgGetVideoModeInfo(modes.modes[it], &modeinfo);
-      if (status!=0)
-      {
-         /* Maybe something wrong with this particular mode, skip it */
-         continue;
-      }
-      if ((modeinfo.width==mode->w) && (modeinfo.height==mode->h) &&
-          (modeinfo.type==photon_sdl_to_image_pixelformat(mode->format)))
-      {
-         /* Mode is found, find requested refresh rate, this case is for */
-         /* video drivers, which provide non-generic video modes.        */
-         jt=0;
-         foundrefresh=0;
-         do {
-            if (modeinfo.refresh_rates[jt]!=0)
-            {
-               if (modeinfo.refresh_rates[jt]==refresh_rate)
-               {
-                  foundrefresh=1;
-                  break;
-               }
-               jt++;
-            }
-            else
-            {
-               break;
+        /* Get current video mode details */
+        status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
+        if (status != 0) {
+            /* Maybe something wrong with this particular mode, skip it */
+            continue;
+        }
+        if ((modeinfo.width == mode->w) && (modeinfo.height == mode->h) &&
+            (modeinfo.type == photon_sdl_to_image_pixelformat(mode->format)))
+        {
+            /* Mode is found, find requested refresh rate, this case is for */
+            /* video drivers, which provide non-generic video modes.        */
+            jt = 0;
+            foundrefresh = 0;
+            do {
+                if (modeinfo.refresh_rates[jt] != 0) {
+                    if (modeinfo.refresh_rates[jt] == refresh_rate) {
+                        foundrefresh = 1;
+                        break;
+                    }
+                    jt++;
+                } else {
+                    break;
+                }
+            } while (1);
+            if (foundrefresh != 0) {
+                break;
             }
-         } while(1);
-         if (foundrefresh!=0)
-         {
-            break;
-         }
-      }
-   }
+        }
+    }
 
-   /* Check if video mode has not been found */
-   if (it==modes.num_modes)
-   {
-      SDL_SetError("Photon: Can't find appropriate video mode");
-      return -1;
-   }
+    /* Check if video mode has not been found */
+    if (it == modes.num_modes) {
+        SDL_SetError("Photon: Can't find appropriate video mode");
+        return -1;
+    }
 
-   /* Fill mode settings */
-   modesettings.flags=0x00000000;
-   modesettings.mode=modes.modes[it];
-   modesettings.refresh=refresh_rate;
+    /* Fill mode settings */
+    modesettings.flags = 0x00000000;
+    modesettings.mode = modes.modes[it];
+    modesettings.refresh = refresh_rate;
 
-   /* Finally set new video mode */
-   status=PgSetVideoMode(&modesettings);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't set new video mode");
-      return -1;
-   }
+    /* Finally set new video mode */
+    status = PgSetVideoMode(&modesettings);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't set new video mode");
+        return -1;
+    }
 
-   /* Store new video mode parameters */
-   didata->current_mode=*mode;
-   didata->current_mode.refresh_rate=refresh_rate;
+    /* Store new video mode parameters */
+    didata->current_mode = *mode;
+    didata->current_mode.refresh_rate = refresh_rate;
 
-   return 0;
+    return 0;
 }
 
-int photon_setdisplaypalette(_THIS, SDL_Palette* palette)
+int
+photon_setdisplaypalette(_THIS, SDL_Palette * palette)
 {
-   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 
-   /* Setting display palette operation has been failed */
-   return -1;
+    /* Setting display palette operation has been failed */
+    return -1;
 }
 
-int photon_getdisplaypalette(_THIS, SDL_Palette* palette)
+int
+photon_getdisplaypalette(_THIS, SDL_Palette * palette)
 {
-   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 
-   /* Getting display palette operation has been failed */
-   return -1;
+    /* Getting display palette operation has been failed */
+    return -1;
 }
 
-int photon_setdisplaygammaramp(_THIS, Uint16* ramp)
+int
+photon_setdisplaygammaramp(_THIS, Uint16 * ramp)
 {
-   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 
-   /* Setting display gamma ramp operation has been failed */
-   return -1;
+    /* Setting display gamma ramp operation has been failed */
+    return -1;
 }
 
-int photon_getdisplaygammaramp(_THIS, Uint16* ramp)
+int
+photon_getdisplaygammaramp(_THIS, Uint16 * ramp)
 {
-   /* Getting display gamma ramp operation has been failed */
-   return -1;
+    /* Getting display gamma ramp operation has been failed */
+    return -1;
 }
 
-int photon_createwindow(_THIS, SDL_Window* window)
+int
+photon_createwindow(_THIS, SDL_Window * window)
 {
-   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-   SDL_WindowData*  wdata;
-   PhDim_t          winsize;
-   PhPoint_t        winpos;
-   PtArg_t          winargs[32];
-   uint32_t         winargc=0;
-   int32_t          status;
-   PhRegion_t       wregion;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    SDL_WindowData *wdata;
+    PhDim_t winsize;
+    PhPoint_t winpos;
+    PtArg_t winargs[32];
+    uint32_t winargc = 0;
+    int32_t status;
+    PhRegion_t wregion;
 
-   /* Allocate window internal data */
-   wdata=(SDL_WindowData*)SDL_calloc(1, sizeof(SDL_WindowData));
-   if (wdata==NULL)
-   {
-      SDL_OutOfMemory();
-      return -1;
-   }
+    /* Allocate window internal data */
+    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+    if (wdata == NULL) {
+        SDL_OutOfMemory();
+        return -1;
+    }
 
-   /* Setup driver data for this window */
-   window->driverdata=wdata;
+    /* Setup driver data for this window */
+    window->driverdata = wdata;
+
+    /* Set initial window title */
+    if (window->title != NULL) {
+        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
+    } else {
+        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0);
+    }
 
-   /* Set initial window title */
-   if (window->title!=NULL)
-   {
-      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
-   }
-   else
-   {
-      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0);
-   }
+    /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
+
+    /* Disable default window filling on redraw */
+    PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
+             Pt_BASIC_PREVENT_FILL);
 
-   /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
-
-   /* Disable default window filling on redraw */
-   PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
+    /* Reset default managed flags to disabled state */
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
+             Ph_WM_APP_DEF_MANAGED);
+    /* Set which events we will not handle, let WM to handle them */
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
+             Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT |
+             Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX |
+             Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR |
+             Ph_WM_TOBACK | Ph_WM_RESIZE);
 
-   /* Reset default managed flags to disabled state */
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
-            Ph_WM_APP_DEF_MANAGED);
-   /* Set which events we will not handle, let WM to handle them */
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
-            Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT  |
-            Ph_WM_FOCUS    | Ph_WM_HELP    | Ph_WM_HIDE     | Ph_WM_MAX     |
-            Ph_WM_MENU     | Ph_WM_MOVE    | Ph_WM_RESTORE  | Ph_WM_TASKBAR |
-            Ph_WM_TOBACK   | Ph_WM_RESIZE);
+    /* Reset default notify events to disable */
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
+             Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
+    /* Set which events we will handle */
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
+             Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS | Ph_WM_MAX |
+             Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | Ph_WM_HIDE);
 
-   /* Reset default notify events to disable */
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
-            Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
-   /* Set which events we will handle */
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
-            Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS   | Ph_WM_MAX  |
-            Ph_WM_MOVE  | Ph_WM_RESIZE   | Ph_WM_RESTORE | Ph_WM_HIDE);
+    /* Borderless window can't be resizeable */
+    if ((window->flags & SDL_WINDOW_BORDERLESS) == SDL_WINDOW_BORDERLESS) {
+        window->flags &= ~(SDL_WINDOW_RESIZABLE);
+    }
 
-   /* Borderless window can't be resizeable */
-   if ((window->flags & SDL_WINDOW_BORDERLESS)==SDL_WINDOW_BORDERLESS)
-   {
-      window->flags&=~(SDL_WINDOW_RESIZABLE);
-   }
-
-   /* Reset all default decorations */
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_APP_DEF_RENDER);
+    /* Reset all default decorations */
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE,
+             Ph_WM_APP_DEF_RENDER);
 
-   /* Fullscreen window has its own decorations */
-   if ((window->flags & SDL_WINDOW_FULLSCREEN)==SDL_WINDOW_FULLSCREEN)
-   {
-      window->flags|=SDL_WINDOW_BORDERLESS;
-      window->flags&=~(SDL_WINDOW_RESIZABLE);
-      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
-               Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
-   }
-   else
-   {
-      uint32_t decorations=Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
-                           Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
+    /* Fullscreen window has its own decorations */
+    if ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) {
+        window->flags |= SDL_WINDOW_BORDERLESS;
+        window->flags &= ~(SDL_WINDOW_RESIZABLE);
+        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
+                 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
+    } else {
+        uint32_t decorations =
+            Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
+            Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
 
-      if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE)
-      {
-         decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
-         PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
-      }
-      if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS)
-      {
-         decorations|=Ph_WM_RENDER_BORDER;
-      }
-      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, decorations);
-   }
+        if ((window->flags & SDL_WINDOW_RESIZABLE) == SDL_WINDOW_RESIZABLE) {
+            decorations |=
+                Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
+            PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
+                     Pt_RESIZE_XY_AS_REQUIRED);
+        }
+        if ((window->flags & SDL_WINDOW_BORDERLESS) != SDL_WINDOW_BORDERLESS) {
+            decorations |= Ph_WM_RENDER_BORDER;
+        }
+        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
+                 decorations);
+    }
 
-   /* Set initial window state */
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS);
-   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
+    /* Set initial window state */
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
+             Ph_WM_STATE_ISFOCUS);
+    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
+             Ph_WM_STATE_ISALTKEY);
 
-   /* Set window dimension */
-   winsize.w=window->w;
-   winsize.h=window->h;
-   PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
+    /* Set window dimension */
+    winsize.w = window->w;
+    winsize.h = window->h;
+    PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
 
-   /* Check if upper level requests WM to position window */
-   if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
-   {
-      /* Do not set widget position, let WM to set it */
-   }
-   else
-   {
-      if (window->x==SDL_WINDOWPOS_UNDEFINED)
-      {
-         window->x=0;
-      }
-      if (window->y==SDL_WINDOWPOS_UNDEFINED)
-      {
-         window->y=0;
-      }
-      if (window->x==SDL_WINDOWPOS_CENTERED)
-      {
-         window->x=(didata->current_mode.w-window->w)/2;
-      }
-      if (window->y==SDL_WINDOWPOS_CENTERED)
-      {
-         window->y=(didata->current_mode.h-window->h)/2;
-      }
+    /* Check if upper level requests WM to position window */
+    if ((window->x == SDL_WINDOWPOS_UNDEFINED)
+        && (window->y == SDL_WINDOWPOS_UNDEFINED)) {
+        /* Do not set widget position, let WM to set it */
+    } else {
+        if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+            window->x = 0;
+        }
+        if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+            window->y = 0;
+        }
+        if (window->x == SDL_WINDOWPOS_CENTERED) {
+            window->x = (didata->current_mode.w - window->w) / 2;
+        }
+        if (window->y == SDL_WINDOWPOS_CENTERED) {
+            window->y = (didata->current_mode.h - window->h) / 2;
+        }
 
-      /* Now set window position */
-      winpos.x=window->x;
-      winpos.y=window->y;
-      PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
-   }
+        /* Now set window position */
+        winpos.x = window->x;
+        winpos.y = window->y;
+        PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
+    }
 
-   /* Check if window must support OpenGL ES rendering */
-   if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
-   {
-      #if defined(SDL_VIDEO_OPENGL_ES)
-         EGLBoolean initstatus;
+    /* Check if window must support OpenGL ES rendering */
+    if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
+#if defined(SDL_VIDEO_OPENGL_ES)
+        EGLBoolean initstatus;
 
-         /* Check if GF was initialized correctly */
-         if (phdata->gfinitialized==SDL_FALSE)
-         {
-            SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
+        /* Check if GF was initialized correctly */
+        if (phdata->gfinitialized == SDL_FALSE) {
+            SDL_SetError
+                ("Photon: GF initialization failed, no OpenGL ES support");
             return -1;
-         }
+        }
 
-         /* Mark this window as OpenGL ES compatible */
-         wdata->uses_gles=SDL_TRUE;
+        /* Mark this window as OpenGL ES compatible */
+        wdata->uses_gles = SDL_TRUE;
 
-         /* Create connection to OpenGL ES */
-         if (phdata->egldisplay==EGL_NO_DISPLAY)
-         {
-            phdata->egldisplay=eglGetDisplay(phdata->gfdev);
-            if (phdata->egldisplay==EGL_NO_DISPLAY)
-            {
-               SDL_SetError("Photon: Can't get connection to OpenGL ES");
-               return -1;
+        /* Create connection to OpenGL ES */
+        if (phdata->egldisplay == EGL_NO_DISPLAY) {
+            phdata->egldisplay = eglGetDisplay(phdata->gfdev);
+            if (phdata->egldisplay == EGL_NO_DISPLAY) {
+                SDL_SetError("Photon: Can't get connection to OpenGL ES");
+                return -1;
             }
 
             /* Initialize OpenGL ES library, ignore EGL version */
-            initstatus=eglInitialize(phdata->egldisplay, NULL, NULL);
-            if (initstatus!=EGL_TRUE)
-            {
-               SDL_SetError("Photon: Can't init OpenGL ES library");
-               return -1;
+            initstatus = eglInitialize(phdata->egldisplay, NULL, NULL);
+            if (initstatus != EGL_TRUE) {
+                SDL_SetError("Photon: Can't init OpenGL ES library");
+                return -1;
             }
-         }
+        }
 
-         /* Increment GL ES reference count usage */
-         phdata->egl_refcount++;
-      #else
-         SDL_SetError("Photon: OpenGL ES support is not compiled in");
-         return -1;
-      #endif /* SDL_VIDEO_OPENGL_ES */
-   }
+        /* Increment GL ES reference count usage */
+        phdata->egl_refcount++;
+#else
+        SDL_SetError("Photon: OpenGL ES support is not compiled in");
+        return -1;
+#endif /* SDL_VIDEO_OPENGL_ES */
+    }
 
-   /* Finally create the window */
-   wdata->window=PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
-   if (wdata->window==NULL)
-   {
-      SDL_SetError("Photon: Can't create window widget");
-      SDL_free(wdata);
-      return -1;
-   }
+    /* Finally create the window */
+    wdata->window = PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
+    if (wdata->window == NULL) {
+        SDL_SetError("Photon: Can't create window widget");
+        SDL_free(wdata);
+        return -1;
+    }
 
-   /* Show widget */
-   status=PtRealizeWidget(wdata->window);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't realize window widget");
-      PtDestroyWidget(wdata->window);
-      SDL_free(wdata);
-      return;
-   }
+    /* Show widget */
+    status = PtRealizeWidget(wdata->window);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't realize window widget");
+        PtDestroyWidget(wdata->window);
+        SDL_free(wdata);
+        return;
+    }
 
-   /* Just created SDL window always gets focus */
-   window->flags|=SDL_WINDOW_INPUT_FOCUS;
+    /* Just created SDL window always gets focus */
+    window->flags |= SDL_WINDOW_INPUT_FOCUS;
 
-   /* Create window-specific cursor after creation */
-   if (didata->cursor_visible==SDL_TRUE)
-   {
-      /* Setup cursor type. shape and default color */
-      PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
-      PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
-      PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor, didata->cursor->hdr.len+sizeof(PhRegionDataHdr_t));
-   }
-   else
-   {
-      PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
-   }
+    /* Create window-specific cursor after creation */
+    if (didata->cursor_visible == SDL_TRUE) {
+        /* Setup cursor type. shape and default color */
+        PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
+                      Ph_CURSOR_DEFAULT_COLOR, 0);
+        PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
+        PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor,
+                      didata->cursor->hdr.len + sizeof(PhRegionDataHdr_t));
+    } else {
+        PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
+    }
 
-   /* Set window region sensible to mouse motion events */
-   status=PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't set region sensivity to mouse motion events");
-      PtDestroyWidget(wdata->window);
-      SDL_free(wdata);
-      return -1;
-   }
-   wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
-   status=PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
-   if (status<0)
-   {
-      SDL_SetError("Photon: Can't change region sensivity");
-      PtDestroyWidget(wdata->window);
-      SDL_free(wdata);
-      return -1;
-   }
+    /* Set window region sensible to mouse motion events */
+    status =
+        PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
+    if (status != 0) {
+        SDL_SetError
+            ("Photon: Can't set region sensivity to mouse motion events");
+        PtDestroyWidget(wdata->window);
+        SDL_free(wdata);
+        return -1;
+    }
+    wregion.events_sense |=
+        Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
+    status = PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
+    if (status < 0) {
+        SDL_SetError("Photon: Can't change region sensivity");
+        PtDestroyWidget(wdata->window);
+        SDL_free(wdata);
+        return -1;
+    }
 
-   /* Flush all widget operations again */
-   PtFlush();
+    /* Flush all widget operations again */
+    PtFlush();
 
-   /* By default last created window got a input focus */
-   SDL_SetKeyboardFocus(0, window->id);
+    /* By default last created window got a input focus */
+    SDL_SetKeyboardFocus(0, window->id);
 
-   /* Window has been successfully created */
-   return 0;
+    /* Window has been successfully created */
+    return 0;
 }
 
-int photon_createwindowfrom(_THIS, SDL_Window* window, const void* data)
+int
+photon_createwindowfrom(_THIS, SDL_Window * window, const void *data)
 {
-   /* TODO: it is possible */
+    /* TODO: it is possible */
 
-   /* Failed to create window from another window */
-   return -1;
+    /* Failed to create window from another window */
+    return -1;
 }
 
-void photon_setwindowtitle(_THIS, SDL_Window* window)
+void
+photon_setwindowtitle(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   int32_t status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    int32_t status;
 
-   /* Set window title */
-   if (window->title!=NULL)
-   {
-      status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title, 0);
-   }
-   else
-   {
-      status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
-   }
+    /* Set window title */
+    if (window->title != NULL) {
+        status =
+            PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title,
+                          0);
+    } else {
+        status = PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
+    }
 
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't set window title");
-   }
+    if (status != 0) {
+        SDL_SetError("Photon: Can't set window title");
+    }
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon)
+void
+photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   int32_t   status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    int32_t status;
 
-   /* TODO: Use iconify ? */
+    /* TODO: Use iconify ? */
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_setwindowposition(_THIS, SDL_Window* window)
+void
+photon_setwindowposition(_THIS, SDL_Window * window)
 {
-   SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
-   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-   PhPoint_t winpos;
-   int32_t   status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    PhPoint_t winpos;
+    int32_t status;
 
-   /* Check if upper level requests WM to position window */
-   if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
-   {
-      /* Do not set widget position, let WM to set it */
-   }
-   else
-   {
-      if (window->x==SDL_WINDOWPOS_UNDEFINED)
-      {
-         window->x=0;
-      }
-      if (window->y==SDL_WINDOWPOS_UNDEFINED)
-      {
-         window->y=0;
-      }
-      if (window->x==SDL_WINDOWPOS_CENTERED)
-      {
-         window->x=(didata->current_mode.w-window->w)/2;
-      }
-      if (window->y==SDL_WINDOWPOS_CENTERED)
-      {
-         window->y=(didata->current_mode.h-window->h)/2;
-      }
+    /* Check if upper level requests WM to position window */
+    if ((window->x == SDL_WINDOWPOS_UNDEFINED)
+        && (window->y == SDL_WINDOWPOS_UNDEFINED)) {
+        /* Do not set widget position, let WM to set it */
+    } else {
+        if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+            window->x = 0;
+        }
+        if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+            window->y = 0;
+        }
+        if (window->x == SDL_WINDOWPOS_CENTERED) {
+            window->x = (didata->current_mode.w - window->w) / 2;
+        }
+        if (window->y == SDL_WINDOWPOS_CENTERED) {
+            window->y = (didata->current_mode.h - window->h) / 2;
+        }
 
-      /* Now set window position */
-      winpos.x=window->x;
-      winpos.y=window->y;
-      status=PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't set window position");
-      }
-   }
+        /* Now set window position */
+        winpos.x = window->x;
+        winpos.y = window->y;
+        status = PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't set window position");
+        }
+    }
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_setwindowsize(_THIS, SDL_Window* window)
+void
+photon_setwindowsize(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhDim_t winsize;
-   int32_t status;
-
-   winsize.w=window->w;
-   winsize.h=window->h;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhDim_t winsize;
+    int32_t status;
 
-   status=PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't set window size");
-   }
+    winsize.w = window->w;
+    winsize.h = window->h;
 
-   /* Flush all widget operations */
-   PtFlush();
+    status = PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't set window size");
+    }
+
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_showwindow(_THIS, SDL_Window* window)
+void
+photon_showwindow(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   int32_t status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    int32_t status;
+
+    /* Bring focus to window and put it in front of others */
+    PtWindowToFront(wdata->window);
+
+    /* Flush all widget operations */
+    PtFlush();
+}
 
-   /* Bring focus to window and put it in front of others */
-   PtWindowToFront(wdata->window);
+void
+photon_hidewindow(_THIS, SDL_Window * window)
+{
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhWindowEvent_t winevent;
+    int32_t status;
 
-   /* Flush all widget operations */
-   PtFlush();
+    SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
+    winevent.event_f = Ph_WM_HIDE;
+    winevent.rid = PtWidgetRid(wdata->window);
+    winevent.event_state = Ph_WM_EVSTATE_HIDE;
+
+    status = PtForwardWindowEvent(&winevent);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't hide window");
+    }
+
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_hidewindow(_THIS, SDL_Window* window)
+void
+photon_raisewindow(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhWindowEvent_t winevent;
-   int32_t status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhWindowEvent_t winevent;
+    int32_t status;
 
-   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
-   winevent.event_f=Ph_WM_HIDE;
-   winevent.rid=PtWidgetRid(wdata->window);
-   winevent.event_state=Ph_WM_EVSTATE_HIDE;
+    SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
+    winevent.event_f = Ph_WM_HIDE;
+    winevent.rid = PtWidgetRid(wdata->window);
+    winevent.event_state = Ph_WM_EVSTATE_UNHIDE;
 
-   status=PtForwardWindowEvent(&winevent);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't hide window");
-   }
+    status = PtForwardWindowEvent(&winevent);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't hide window");
+    }
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_raisewindow(_THIS, SDL_Window* window)
+void
+photon_maximizewindow(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhWindowEvent_t winevent;
-   int32_t status;
-
-   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
-   winevent.event_f=Ph_WM_HIDE;
-   winevent.rid=PtWidgetRid(wdata->window);
-   winevent.event_state=Ph_WM_EVSTATE_UNHIDE;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhWindowEvent_t winevent;
+    int32_t status;
 
-   status=PtForwardWindowEvent(&winevent);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't hide window");
-   }
-
-   /* Flush all widget operations */
-   PtFlush();
-}
-
-void photon_maximizewindow(_THIS, SDL_Window* window)
-{
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhWindowEvent_t winevent;
-   int32_t status;
-
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_minimizewindow(_THIS, SDL_Window* window)
+void
+photon_minimizewindow(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhWindowEvent_t winevent;
-   int32_t status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhWindowEvent_t winevent;
+    int32_t status;
 
-   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
-   winevent.event_f=Ph_WM_HIDE;
-   winevent.rid=PtWidgetRid(wdata->window);
-   winevent.event_state=Ph_WM_EVSTATE_HIDE;
+    SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
+    winevent.event_f = Ph_WM_HIDE;
+    winevent.rid = PtWidgetRid(wdata->window);
+    winevent.event_state = Ph_WM_EVSTATE_HIDE;
 
-   status=PtForwardWindowEvent(&winevent);
-   if (status!=0)
-   {
-      SDL_SetError("Photon: Can't hide window");
-   }
+    status = PtForwardWindowEvent(&winevent);
+    if (status != 0) {
+        SDL_SetError("Photon: Can't hide window");
+    }
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_restorewindow(_THIS, SDL_Window* window)
+void
+photon_restorewindow(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhWindowEvent_t winevent;
-   int32_t status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhWindowEvent_t winevent;
+    int32_t status;
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_setwindowgrab(_THIS, SDL_Window* window)
+void
+photon_setwindowgrab(_THIS, SDL_Window * window)
 {
-   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
-   PhWindowEvent_t winevent;
-   int32_t status;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    PhWindowEvent_t winevent;
+    int32_t status;
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
-void photon_destroywindow(_THIS, SDL_Window* window)
+void
+photon_destroywindow(_THIS, SDL_Window * window)
 {
-   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-   SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
-   int32_t status;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    int32_t status;
 
-   if (wdata!=NULL)
-   {
-      status=PtDestroyWidget(wdata->window);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't destroy window widget");
-      }
-      wdata->window=NULL;
+    if (wdata != NULL) {
+        status = PtDestroyWidget(wdata->window);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't destroy window widget");
+        }
+        wdata->window = NULL;
 
-      #if defined(SDL_VIDEO_OPENGL_ES)
-         if (phdata->gfinitialized==SDL_TRUE)
-         {
+#if defined(SDL_VIDEO_OPENGL_ES)
+        if (phdata->gfinitialized == SDL_TRUE) {
             /* Destroy OpenGL ES surface if it was created */
-            if (wdata->gles_surface!=EGL_NO_SURFACE)
-            {
-               eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
+            if (wdata->gles_surface != EGL_NO_SURFACE) {
+                eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
             }
 
             /* Free OpenGL ES target surface */
-            if (wdata->gfsurface!=NULL)
-            {
-               gf_surface_free(wdata->gfsurface);
+            if (wdata->gfsurface != NULL) {
+                gf_surface_free(wdata->gfsurface);
             }
 
             phdata->egl_refcount--;
-            if (phdata->egl_refcount==0)
-            {
-               /* Terminate connection to OpenGL ES */
-               if (phdata->egldisplay!=EGL_NO_DISPLAY)
-               {
-                  eglTerminate(phdata->egldisplay);
-                  phdata->egldisplay=EGL_NO_DISPLAY;
-               }
+            if (phdata->egl_refcount == 0) {
+                /* Terminate connection to OpenGL ES */
+                if (phdata->egldisplay != EGL_NO_DISPLAY) {
+                    eglTerminate(phdata->egldisplay);
+                    phdata->egldisplay = EGL_NO_DISPLAY;
+                }
             }
-         }
-      #endif /* SDL_VIDEO_OPENGL_ES */
-   }
+        }
+#endif /* SDL_VIDEO_OPENGL_ES */
+    }
 
-   /* Flush all widget operations */
-   PtFlush();
+    /* Flush all widget operations */
+    PtFlush();
 }
 
 /*****************************************************************************/
 /* SDL Window Manager function                                               */
 /*****************************************************************************/
-SDL_bool photon_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info)
+SDL_bool
+photon_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
 {
-   if (info->version.major<=SDL_MAJOR_VERSION)
-   {
-      return SDL_TRUE;
-   }
-   else
-   {
-      SDL_SetError("application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
-      return SDL_FALSE;
-   }
+    if (info->version.major <= SDL_MAJOR_VERSION) {
+        return SDL_TRUE;
+    } else {
+        SDL_SetError("application not compiled with SDL %d.%d\n",
+                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+        return SDL_FALSE;
+    }
 
-   /* Failed to get window manager information */
-   return SDL_FALSE;
+    /* Failed to get window manager information */
+    return SDL_FALSE;
 }
 
 /*****************************************************************************/
 /* SDL OpenGL/OpenGL ES functions                                            */
 /*****************************************************************************/
-int photon_gl_loadlibrary(_THIS, const char* path)
+int
+photon_gl_loadlibrary(_THIS, const char *path)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return NULL;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return NULL;
+    }
 
-      /* Check if OpenGL ES library is specified for GF driver */
-      if (path==NULL)
-      {
-         path=SDL_getenv("SDL_OPENGL_LIBRARY");
-         if (path==NULL)
-         {
-            path=SDL_getenv("SDL_OPENGLES_LIBRARY");
-         }
-      }
+    /* Check if OpenGL ES library is specified for GF driver */
+    if (path == NULL) {
+        path = SDL_getenv("SDL_OPENGL_LIBRARY");
+        if (path == NULL) {
+            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
+        }
+    }
 
-      /* Check if default library loading requested */
-      if (path==NULL)
-      {
-         /* Already linked with GF library which provides egl* subset of  */
-         /* functions, use Common profile of OpenGL ES library by default */
-         path="/usr/lib/libGLES_CM.so.1";
-      }
+    /* Check if default library loading requested */
+    if (path == NULL) {
+        /* Already linked with GF library which provides egl* subset of  */
+        /* functions, use Common profile of OpenGL ES library by default */
+        path = "/usr/lib/libGLES_CM.so.1";
+    }
 
-      /* Load dynamic library */
-      _this->gl_config.dll_handle=SDL_LoadObject(path);
-      if (!_this->gl_config.dll_handle)
-      {
-         /* Failed to load new GL ES library */
-         SDL_SetError("Photon: Failed to locate OpenGL ES library");
-         return -1;
-      }
+    /* Load dynamic library */
+    _this->gl_config.dll_handle = SDL_LoadObject(path);
+    if (!_this->gl_config.dll_handle) {
+        /* Failed to load new GL ES library */
+        SDL_SetError("Photon: Failed to locate OpenGL ES library");
+        return -1;
+    }
 
-      /* Store OpenGL ES library path and name */
-      SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
+    /* Store OpenGL ES library path and name */
+    SDL_strlcpy(_this->gl_config.driver_path, path,
+                SDL_arraysize(_this->gl_config.driver_path));
 
-      /* New OpenGL ES library is loaded */
-      return 0;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return -1;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    /* New OpenGL ES library is loaded */
+    return 0;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return -1;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-void* photon_gl_getprocaddres(_THIS, const char* proc)
+void *
+photon_gl_getprocaddres(_THIS, const char *proc)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
-      void* function_address;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    void *function_address;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return NULL;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return NULL;
+    }
 
-      /* Try to get function address through the egl interface */
-      function_address=eglGetProcAddress(proc);
-      if (function_address!=NULL)
-      {
-         return function_address;
-      }
+    /* Try to get function address through the egl interface */
+    function_address = eglGetProcAddress(proc);
+    if (function_address != NULL) {
+        return function_address;
+    }
 
-      /* Then try to get function in the OpenGL ES library */
-      if (_this->gl_config.dll_handle)
-      {
-         function_address=SDL_LoadFunction(_this->gl_config.dll_handle, proc);
-         if (function_address!=NULL)
-         {
+    /* Then try to get function in the OpenGL ES library */
+    if (_this->gl_config.dll_handle) {
+        function_address =
+            SDL_LoadFunction(_this->gl_config.dll_handle, proc);
+        if (function_address != NULL) {
             return function_address;
-         }
-      }
+        }
+    }
 
-      /* Add emulated OpenGL ES 1.1 functions */
-      if (SDL_strcmp(proc, "glTexParameteri")==0)
-      {
-         return glTexParameteri;
-      }
-      if (SDL_strcmp(proc, "glTexParameteriv")==0)
-      {
-         return glTexParameteriv;
-      }
-      if (SDL_strcmp(proc, "glColor4ub")==0)
-      {
-         return glColor4ub;
-      }
+    /* Add emulated OpenGL ES 1.1 functions */
+    if (SDL_strcmp(proc, "glTexParameteri") == 0) {
+        return glTexParameteri;
+    }
+    if (SDL_strcmp(proc, "glTexParameteriv") == 0) {
+        return glTexParameteriv;
+    }
+    if (SDL_strcmp(proc, "glColor4ub") == 0) {
+        return glColor4ub;
+    }
 
-      /* Failed to get GL ES function address pointer */
-      SDL_SetError("Photon: Cannot locate OpenGL ES function name");
-      return NULL;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return NULL;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    /* Failed to get GL ES function address pointer */
+    SDL_SetError("Photon: Cannot locate OpenGL ES function name");
+    return NULL;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return NULL;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-void photon_gl_unloadlibrary(_THIS)
+void
+photon_gl_unloadlibrary(_THIS)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 
-      if (phdata->gfinitialized==SDL_TRUE)
-      {
-         /* Unload OpenGL ES library */
-         if (_this->gl_config.dll_handle)
-         {
+    if (phdata->gfinitialized == SDL_TRUE) {
+        /* Unload OpenGL ES library */
+        if (_this->gl_config.dll_handle) {
             SDL_UnloadObject(_this->gl_config.dll_handle);
-            _this->gl_config.dll_handle=NULL;
-         }
-      }
-      else
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-      }
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+            _this->gl_config.dll_handle = NULL;
+        }
+    } else {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+    }
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window)
+SDL_GLContext
+photon_gl_createcontext(_THIS, SDL_Window * window)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
-      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
-      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-      EGLBoolean       status;
-      int32_t          gfstatus;
-      EGLint           configs;
-      uint32_t         attr_pos;
-      EGLint           attr_value;
-      EGLint           cit;
-
-      /* Check if GF was initialized */
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return NULL;
-      }
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    EGLBoolean status;
+    int32_t gfstatus;
+    EGLint configs;
+    uint32_t attr_pos;
+    EGLint attr_value;
+    EGLint cit;
 
-      /* Prepare attributes list to pass them to OpenGL ES */
-      attr_pos=0;
-      wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
-      wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
-      wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
-      wdata->gles_attributes[attr_pos++]=_this->gl_config.red_size;
-      wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
-      wdata->gles_attributes[attr_pos++]=_this->gl_config.green_size;
-      wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
-      wdata->gles_attributes[attr_pos++]=_this->gl_config.blue_size;
-      wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
+    /* Check if GF was initialized */
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return NULL;
+    }
 
-      /* Setup alpha size in bits */
-      if (_this->gl_config.alpha_size)
-      {
-         wdata->gles_attributes[attr_pos++]=_this->gl_config.alpha_size;
-      }
-      else
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-      }
+    /* Prepare attributes list to pass them to OpenGL ES */
+    attr_pos = 0;
+    wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
+    wdata->gles_attributes[attr_pos++] =
+        qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
+    wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
+    wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
+    wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
+    wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
 
-      /* Setup color buffer size */
-      if (_this->gl_config.buffer_size)
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
-         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
-      }
-      else
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
-         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-      }
+    /* Setup alpha size in bits */
+    if (_this->gl_config.alpha_size) {
+        wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
+    } else {
+        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+    }
 
-      /* Setup depth buffer bits */
-      wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
-      wdata->gles_attributes[attr_pos++]=_this->gl_config.depth_size;
+    /* Setup color buffer size */
+    if (_this->gl_config.buffer_size) {
+        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
+    } else {
+        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+    }
+
+    /* Setup depth buffer bits */
+    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
 
-      /* Setup stencil bits */
-      if (_this->gl_config.stencil_size)
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
-         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
-      }
-      else
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
-         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-      }
+    /* Setup stencil bits */
+    if (_this->gl_config.stencil_size) {
+        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
+    } else {
+        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+    }
 
-      /* Set number of samples in multisampling */
-      if (_this->gl_config.multisamplesamples)
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
-         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples;
-      }
+    /* Set number of samples in multisampling */
+    if (_this->gl_config.multisamplesamples) {
+        wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
+        wdata->gles_attributes[attr_pos++] =
+            _this->gl_config.multisamplesamples;
+    }
 
-      /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
-      if (_this->gl_config.multisamplebuffers)
-      {
-         wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
-         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplebuffers;
-      }
+    /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
+    if (_this->gl_config.multisamplebuffers) {
+        wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
+        wdata->gles_attributes[attr_pos++] =
+            _this->gl_config.multisamplebuffers;
+    }
 
-      /* Finish attributes list */
-      wdata->gles_attributes[attr_pos]=EGL_NONE;
+    /* Finish attributes list */
+    wdata->gles_attributes[attr_pos] = EGL_NONE;
 
-      /* Request first suitable framebuffer configuration */
-      status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
-                             wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
-      if (status!=EGL_TRUE)
-      {
-         SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
-         return NULL;
-      }
+    /* Request first suitable framebuffer configuration */
+    status = eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
+                             wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS,
+                             &configs);
+    if (status != EGL_TRUE) {
+        SDL_SetError
+            ("Photon: Can't find closest configuration for OpenGL ES");
+        return NULL;
+    }
 
-      /* Check if nothing has been found, try "don't care" settings */
-      if (configs==0)
-      {
-         int32_t it;
-         int32_t jt;
-         GLint   depthbits[4]={32, 24, 16, EGL_DONT_CARE};
+    /* Check if nothing has been found, try "don't care" settings */
+    if (configs == 0) {
+        int32_t it;
+        int32_t jt;
+        GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
 
-         for (it=0; it<4; it++)
-         {
-            for (jt=16; jt>=0; jt--)
-            {
-               /* Don't care about color buffer bits, use what exist */
-               /* Replace previous set data with EGL_DONT_CARE       */
-               attr_pos=0;
-               wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
-               wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
-               wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
+        for (it = 0; it < 4; it++) {
+            for (jt = 16; jt >= 0; jt--) {
+                /* Don't care about color buffer bits, use what exist */
+                /* Replace previous set data with EGL_DONT_CARE       */
+                attr_pos = 0;
+                wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
+                wdata->gles_attributes[attr_pos++] =
+                    qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
+                wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 
-               /* Try to find requested or smallest depth */
-               if (_this->gl_config.depth_size)
-               {
-                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
-                  wdata->gles_attributes[attr_pos++]=depthbits[it];
-               }
-               else
-               {
-                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
-                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               }
+                /* Try to find requested or smallest depth */
+                if (_this->gl_config.depth_size) {
+                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+                    wdata->gles_attributes[attr_pos++] = depthbits[it];
+                } else {
+                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                }
 
-               if (_this->gl_config.stencil_size)
-               {
-                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
-                  wdata->gles_attributes[attr_pos++]=jt;
-               }
-               else
-               {
-                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
-                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               }
+                if (_this->gl_config.stencil_size) {
+                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+                    wdata->gles_attributes[attr_pos++] = jt;
+                } else {
+                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                }
 
-               wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
-               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
-               wdata->gles_attributes[attr_pos]=EGL_NONE;
+                wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos] = EGL_NONE;
 
-               /* Request first suitable framebuffer configuration */
-               status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
-                                      wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
-               if (status!=EGL_TRUE)
-               {
-                  SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
-                  return NULL;
-               }
-               if (configs!=0)
-               {
-                  break;
-               }
+                /* Request first suitable framebuffer configuration */
+                status =
+                    eglChooseConfig(phdata->egldisplay,
+                                    wdata->gles_attributes,
+                                    wdata->gles_configs,
+                                    SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
+                if (status != EGL_TRUE) {
+                    SDL_SetError
+                        ("Photon: Can't find closest configuration for OpenGL ES");
+                    return NULL;
+                }
+                if (configs != 0) {
+                    break;
+                }
             }
-            if (configs!=0)
-            {
-               break;
+            if (configs != 0) {
+                break;
             }
-         }
+        }
 
-         /* No available configs */
-         if (configs==0)
-         {
-            SDL_SetError("Photon: Can't find any configuration for OpenGL ES");
+        /* No available configs */
+        if (configs == 0) {
+            SDL_SetError
+                ("Photon: Can't find any configuration for OpenGL ES");
             return NULL;
-         }
-      }
-
-      /* Initialize config index */
-      wdata->gles_config=0;
+        }
+    }
 
-      /* Now check each configuration to find out the best */
-      for (cit=0; cit<configs; cit++)
-      {
-         uint32_t stencil_found;
-         uint32_t depth_found;
+    /* Initialize config index */
+    wdata->gles_config = 0;
 
-         stencil_found=0;
-         depth_found=0;
+    /* Now check each configuration to find out the best */
+    for (cit = 0; cit < configs; cit++) {
+        uint32_t stencil_found;
+        uint32_t depth_found;
+
+        stencil_found = 0;
+        depth_found = 0;
 
-         if (_this->gl_config.stencil_size)
-         {
-            status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value);
-            if (status==EGL_TRUE)
-            {
-               if (attr_value!=0)
-               {
-                  stencil_found=1;
-               }
+        if (_this->gl_config.stencil_size) {
+            status =
+                eglGetConfigAttrib(phdata->egldisplay,
+                                   wdata->gles_configs[cit], EGL_STENCIL_SIZE,
+                                   &attr_value);
+            if (status == EGL_TRUE) {
+                if (attr_value != 0) {
+                    stencil_found = 1;
+                }
             }
-         }
-         else
-         {
-            stencil_found=1;
-         }
+        } else {
+            stencil_found = 1;
+        }
 
-         if (_this->gl_config.depth_size)
-         {
-            status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value);
-            if (status==EGL_TRUE)
-            {
-               if (attr_value!=0)
-               {
-                  depth_found=1;
-               }
+        if (_this->gl_config.depth_size) {
+            status =
+                eglGetConfigAttrib(phdata->egldisplay,
+                                   wdata->gles_configs[cit], EGL_DEPTH_SIZE,
+                                   &attr_value);
+            if (status == EGL_TRUE) {
+                if (attr_value != 0) {
+                    depth_found = 1;
+                }
             }
-         }
-         else
-         {
-            depth_found=1;
-         }
+        } else {
+            depth_found = 1;
+        }
 
-         /* Exit from loop if found appropriate configuration */
-         if ((depth_found!=0) && (stencil_found!=0))
-         {
+        /* Exit from loop if found appropriate configuration */
+        if ((depth_found != 0) && (stencil_found != 0)) {
             break;
-         }
-      }
+        }
+    }
 
-      /* If best could not be found, use first */
-      if (cit==configs)
-      {
-         cit=0;
-      }
-      wdata->gles_config=cit;
+    /* If best could not be found, use first */
+    if (cit == configs) {
+        cit = 0;
+    }
+    wdata->gles_config = cit;
 
-      /* Create OpenGL ES context */
-      wdata->gles_context=eglCreateContext(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL);
-      if (wdata->gles_context==EGL_NO_CONTEXT)
-      {
-         SDL_SetError("Photon: OpenGL ES context creation has been failed");
-         return NULL;
-      }
+    /* Create OpenGL ES context */
+    wdata->gles_context =
+        eglCreateContext(phdata->egldisplay,
+                         wdata->gles_configs[wdata->gles_config],
+                         EGL_NO_CONTEXT, NULL);
+    if (wdata->gles_context == EGL_NO_CONTEXT) {
+        SDL_SetError("Photon: OpenGL ES context creation has been failed");
+        return NULL;
+    }
 
-      /* Check if surface is exist */
-      if (wdata->gfsurface!=NULL)
-      {
-         gf_surface_free(wdata->gfsurface);
-         wdata->gfsurface=NULL;
-      }
+    /* Check if surface is exist */
+    if (wdata->gfsurface != NULL) {
+        gf_surface_free(wdata->gfsurface);
+        wdata->gfsurface = NULL;
+    }
 
-      /* Create GF surface */
-      gfstatus=gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w, window->h,
-               qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL,
-               GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
-               GF_SURFACE_CREATE_SHAREABLE);
-      if (gfstatus!=GF_ERR_OK)
-      {
-         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
-         wdata->gles_context=EGL_NO_CONTEXT;
-         SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus);
-         return NULL;
-      }
+    /* Create GF surface */
+    gfstatus =
+        gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w,
+                          window->h,
+                          qnxgf_sdl_to_gf_pixelformat(didata->current_mode.
+                                                      format), NULL,
+                          GF_SURFACE_CREATE_2D_ACCESSIBLE |
+                          GF_SURFACE_CREATE_3D_ACCESSIBLE |
+                          GF_SURFACE_CREATE_SHAREABLE);
+    if (gfstatus != GF_ERR_OK) {
+        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
+        wdata->gles_context = EGL_NO_CONTEXT;
+        SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus);
+        return NULL;
+    }
 
-      /* Create pixmap 3D target surface */
-      wdata->gles_surface=eglCreatePixmapSurface(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->gfsurface, NULL);
-      if (wdata->gles_surface==EGL_NO_SURFACE)
-      {
-         gf_surface_free(wdata->gfsurface);
-         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
-         wdata->gles_context=EGL_NO_CONTEXT;
-         SDL_SetError("Photon: Can't create EGL pixmap surface");
-         return NULL;
-      }
+    /* Create pixmap 3D target surface */
+    wdata->gles_surface =
+        eglCreatePixmapSurface(phdata->egldisplay,
+                               wdata->gles_configs[wdata->gles_config],
+                               wdata->gfsurface, NULL);
+    if (wdata->gles_surface == EGL_NO_SURFACE) {
+        gf_surface_free(wdata->gfsurface);
+        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
+        wdata->gles_context = EGL_NO_CONTEXT;
+        SDL_SetError("Photon: Can't create EGL pixmap surface");
+        return NULL;
+    }
 
-      /* Make just created context current */
-      status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
-      if (status!=EGL_TRUE)
-      {
-         /* Destroy OpenGL ES surface */
-         eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
-         gf_surface_free(wdata->gfsurface);
-         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
-         wdata->gles_context=EGL_NO_CONTEXT;
-         SDL_SetError("Photon: Can't set OpenGL ES context on creation");
-         return NULL;
-      }
+    /* Make just created context current */
+    status =
+        eglMakeCurrent(phdata->egldisplay, wdata->gles_surface,
+                       wdata->gles_surface, wdata->gles_context);
+    if (status != EGL_TRUE) {
+        /* Destroy OpenGL ES surface */
+        eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
+        gf_surface_free(wdata->gfsurface);
+        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
+        wdata->gles_context = EGL_NO_CONTEXT;
+        SDL_SetError("Photon: Can't set OpenGL ES context on creation");
+        return NULL;
+    }
 
-      /* Setup into SDL internals state of OpenGL ES:  */
-      /* it is accelerated or not                      */
-      if ((didata->caps & SDL_PHOTON_ACCELERATED_3D)==SDL_PHOTON_ACCELERATED_3D)
-      {
-         _this->gl_config.accelerated=1;
-      }
-      else
-      {
-         _this->gl_config.accelerated=0;
-      }
+    /* Setup into SDL internals state of OpenGL ES:  */
+    /* it is accelerated or not                      */
+    if ((didata->caps & SDL_PHOTON_ACCELERATED_3D) ==
+        SDL_PHOTON_ACCELERATED_3D) {
+        _this->gl_config.accelerated = 1;
+    } else {
+        _this->gl_config.accelerated = 0;
+    }
 
-      /* Always clear stereo enable, since OpenGL ES do not supports stereo */
-      _this->gl_config.stereo=0;
+    /* Always clear stereo enable, since OpenGL ES do not supports stereo */
+    _this->gl_config.stereo = 0;
 
-      /* Get back samples and samplebuffers configurations. Rest framebuffer */
-      /* parameters could be obtained through the OpenGL ES API              */
-      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value);
-      if (status==EGL_TRUE)
-      {
-         _this->gl_config.multisamplesamples=attr_value;
-      }
-      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value);
-      if (status==EGL_TRUE)
-      {
-         _this->gl_config.multisamplebuffers=attr_value;
-      }
+    /* Get back samples and samplebuffers configurations. Rest framebuffer */
+    /* parameters could be obtained through the OpenGL ES API              */
+    status =
+        eglGetConfigAttrib(phdata->egldisplay,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_SAMPLES, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.multisamplesamples = attr_value;
+    }
+    status =
+        eglGetConfigAttrib(phdata->egldisplay,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_SAMPLE_BUFFERS, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.multisamplebuffers = attr_value;
+    }
 
-      /* Get back stencil and depth buffer sizes */
-      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value);
-      if (status==EGL_TRUE)
-      {
-         _this->gl_config.depth_size=attr_value;
-      }
-      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value);
-      if (status==EGL_TRUE)
-      {
-         _this->gl_config.stencil_size=attr_value;
-      }
+    /* Get back stencil and depth buffer sizes */
+    status =
+        eglGetConfigAttrib(phdata->egldisplay,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_DEPTH_SIZE, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.depth_size = attr_value;
+    }
+    status =
+        eglGetConfigAttrib(phdata->egldisplay,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_STENCIL_SIZE, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.stencil_size = attr_value;
+    }
 
-      /* Under Photon OpenGL ES output can't be double buffered */
-      _this->gl_config.double_buffer=0;
+    /* Under Photon OpenGL ES output can't be double buffered */
+    _this->gl_config.double_buffer = 0;
 
-      /* Check if current device is not the same as target */
-      if (phdata->current_device_id!=didata->device_id)
-      {
-         /* Set target device as default for Pd and Pg functions */
-         status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
-         if (status!=0)
-         {
+    /* Check if current device is not the same as target */
+    if (phdata->current_device_id != didata->device_id) {
+        /* Set target device as default for Pd and Pg functions */
+        status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
+        if (status != 0) {
             /* Destroy OpenGL ES surface */
             eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
             gf_surface_free(wdata->gfsurface);
             eglDestroyContext(phdata->egldisplay, wdata->gles_context);
-            wdata->gles_context=EGL_NO_CONTEXT;
+            wdata->gles_context = EGL_NO_CONTEXT;
             SDL_SetError("Photon: Can't set default target device\n");
             return NULL;
-         }
-         phdata->current_device_id=didata->device_id;
-      }
+        }
+        phdata->current_device_id = didata->device_id;
+    }
 
-      wdata->phsurface=PdCreateOffscreenContextGF(wdata->gfsurface);
-      if (wdata->phsurface==NULL)
-      {
-         /* Destroy OpenGL ES surface */
-         eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
-         gf_surface_free(wdata->gfsurface);
-         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
-         wdata->gles_context=EGL_NO_CONTEXT;
-         SDL_SetError("Photon: Can't bind GF surface to Photon\n");
-         return NULL;
-      }
+    wdata->phsurface = PdCreateOffscreenContextGF(wdata->gfsurface);
+    if (wdata->phsurface == NULL) {
+        /* Destroy OpenGL ES surface */
+        eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
+        gf_surface_free(wdata->gfsurface);
+        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
+        wdata->gles_context = EGL_NO_CONTEXT;
+        SDL_SetError("Photon: Can't bind GF surface to Photon\n");
+        return NULL;
+    }
 
-      /* GL ES context was successfully created */
-      return wdata->gles_context;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return NULL;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    /* GL ES context was successfully created */
+    return wdata->gles_context;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return NULL;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context)
+int
+photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData*  phdata=(SDL_VideoData*)_this->driverdata;
-      SDL_WindowData* wdata;
-      EGLBoolean status;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_WindowData *wdata;
+    EGLBoolean status;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return -1;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return -1;
+    }
 
-      if ((window==NULL) && (context==NULL))
-      {
-         status=eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-         if (status!=EGL_TRUE)
-         {
+    if ((window == NULL) && (context == NULL)) {
+        status =
+            eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
+                           EGL_NO_CONTEXT);
+        if (status != EGL_TRUE) {
             /* Failed to set current GL ES context */
             SDL_SetError("Photon: Can't set OpenGL ES context");
             return -1;
-         }
-      }
-      else
-      {
-         wdata=(SDL_WindowData*)window->driverdata;
-         if (wdata->gles_surface==EGL_NO_SURFACE)
-         {
-            SDL_SetError("Photon: OpenGL ES surface is not initialized for this window");
+        }
+    } else {
+        wdata = (SDL_WindowData *) window->driverdata;
+        if (wdata->gles_surface == EGL_NO_SURFACE) {
+            SDL_SetError
+                ("Photon: OpenGL ES surface is not initialized for this window");
             return -1;
-         }
-         if (wdata->gles_context==EGL_NO_CONTEXT)
-         {
-            SDL_SetError("Photon: OpenGL ES context is not initialized for this window");
+        }
+        if (wdata->gles_context == EGL_NO_CONTEXT) {
+            SDL_SetError
+                ("Photon: OpenGL ES context is not initialized for this window");
             return -1;
-         }
-         if (wdata->gles_context!=context)
-         {
-            SDL_SetError("Photon: OpenGL ES context is not belong to this window");
+        }
+        if (wdata->gles_context != context) {
+            SDL_SetError
+                ("Photon: OpenGL ES context is not belong to this window");
             return -1;
-         }
-         status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
-         if (status!=EGL_TRUE)
-         {
+        }
+        status =
+            eglMakeCurrent(phdata->egldisplay, wdata->gles_surface,
+                           wdata->gles_surface, wdata->gles_context);
+        if (status != EGL_TRUE) {
             /* Failed to set current GL ES context */
             SDL_SetError("Photon: Can't set OpenGL ES context");
             return -1;
-         }
-      }
+        }
+    }
 
-      return 0;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return -1;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    return 0;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return -1;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-int photon_gl_setswapinterval(_THIS, int interval)
+int
+photon_gl_setswapinterval(_THIS, int interval)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
-      EGLBoolean     status;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    EGLBoolean status;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return -1;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return -1;
+    }
 
-      /* Check if OpenGL ES connection has been initialized */
-      if (phdata->egldisplay!=EGL_NO_DISPLAY)
-      {
-         /* Set swap OpenGL ES interval */
-         status=eglSwapInterval(phdata->egldisplay, interval);
-         if (status==EGL_TRUE)
-         {
+    /* Check if OpenGL ES connection has been initialized */
+    if (phdata->egldisplay != EGL_NO_DISPLAY) {
+        /* Set swap OpenGL ES interval */
+        status = eglSwapInterval(phdata->egldisplay, interval);
+        if (status == EGL_TRUE) {
             /* Return success to upper level */
-            phdata->swapinterval=interval;
+            phdata->swapinterval = interval;
             return 0;
-         }
-      }
+        }
+    }
 
-      /* Failed to set swap interval */
-      SDL_SetError("Photon: Cannot set swap interval");
-      return -1;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return -1;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    /* Failed to set swap interval */
+    SDL_SetError("Photon: Cannot set swap interval");
+    return -1;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return -1;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-int photon_gl_getswapinterval(_THIS)
+int
+photon_gl_getswapinterval(_THIS)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return -1;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return -1;
+    }
 
-      /* Return default swap interval value */
-      return phdata->swapinterval;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return -1;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    /* Return default swap interval value */
+    return phdata->swapinterval;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return -1;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-void photon_gl_swapwindow(_THIS, SDL_Window* window)
+void
+photon_gl_swapwindow(_THIS, SDL_Window * window)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
-      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
-      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
-      PhRect_t         dst_rect;
-      PhRect_t         src_rect;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    PhRect_t dst_rect;
+    PhRect_t src_rect;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return;
+    }
 
-      /* Many applications do not uses glFinish(), so we call it for them */
-      glFinish();
+    /* Many applications do not uses glFinish(), so we call it for them */
+    glFinish();
 
-      /* Wait until OpenGL ES rendering is completed */
-      eglWaitGL();
+    /* Wait until OpenGL ES rendering is completed */
+    eglWaitGL();
 
-      /* Wait for VSYNC manually, if it was enabled */
-      if (phdata->swapinterval!=0)
-      {
-         /* Wait for VSYNC, we use GF function, since Photon requires */
-         /* to enter to the Direct mode to call PgWaitVSync()         */
-         gf_display_wait_vsync(didata->display);
-      }
+    /* Wait for VSYNC manually, if it was enabled */
+    if (phdata->swapinterval != 0) {
+        /* Wait for VSYNC, we use GF function, since Photon requires */
+        /* to enter to the Direct mode to call PgWaitVSync()         */
+        gf_display_wait_vsync(didata->display);
+    }
+
+    /* Set blit area */
+    dst_rect = *PtGetCanvas(wdata->window);
+    src_rect.ul.x = 0;
+    src_rect.ul.y = 0;
+    src_rect.lr.x = window->w - 1;
+    src_rect.lr.y = window->h - 1;
 
-      /* Set blit area */
-      dst_rect=*PtGetCanvas(wdata->window);
-      src_rect.ul.x=0;
-      src_rect.ul.y=0;
-      src_rect.lr.x=window->w-1;
-      src_rect.lr.y=window->h-1;
+    /* Blit OpenGL ES pixmap surface directly to window region */
+    PgFFlush(Ph_START_DRAW);
+    PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
+    PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
+    PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
+    PgFFlush(Ph_DONE_DRAW);
+    PgWaitHWIdle();
 
-      /* Blit OpenGL ES pixmap surface directly to window region */
-      PgFFlush(Ph_START_DRAW);
-      PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
-      PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
-      PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
-      PgFFlush(Ph_DONE_DRAW);
-      PgWaitHWIdle();
-
-      eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
-void photon_gl_deletecontext(_THIS, SDL_GLContext context)
+void
+photon_gl_deletecontext(_THIS, SDL_GLContext context)
 {
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
-      EGLBoolean     status;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    EGLBoolean status;
 
-      if (phdata->gfinitialized!=SDL_TRUE)
-      {
-         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
-         return;
-      }
+    if (phdata->gfinitialized != SDL_TRUE) {
+        SDL_SetError
+            ("Photon: GF initialization failed, no OpenGL ES support");
+        return;
+    }
 
-      /* Check if OpenGL ES connection has been initialized */
-      if (phdata->egldisplay!=EGL_NO_DISPLAY)
-      {
-         if (context!=EGL_NO_CONTEXT)
-         {
-            status=eglDestroyContext(phdata->egldisplay, context);
-            if (status!=EGL_TRUE)
-            {
-               /* Error during OpenGL ES context destroying */
-               SDL_SetError("Photon: OpenGL ES context destroy error");
-               return;
+    /* Check if OpenGL ES connection has been initialized */
+    if (phdata->egldisplay != EGL_NO_DISPLAY) {
+        if (context != EGL_NO_CONTEXT) {
+            status = eglDestroyContext(phdata->egldisplay, context);
+            if (status != EGL_TRUE) {
+                /* Error during OpenGL ES context destroying */
+                SDL_SetError("Photon: OpenGL ES context destroy error");
+                return;
             }
-         }
-      }
+        }
+    }
 
-      return;
-   #else
-      SDL_SetError("Photon: OpenGL ES support is not compiled in");
-      return;
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    return;
+#else
+    SDL_SetError("Photon: OpenGL ES support is not compiled in");
+    return;
+#endif /* SDL_VIDEO_OPENGL_ES */
 }
 
 /*****************************************************************************/
 /* SDL Event handling function                                               */
 /*****************************************************************************/
-void photon_pumpevents(_THIS)
+void
+photon_pumpevents(_THIS)
 {
-   uint8_t    eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE];
-   PhEvent_t* event=(PhEvent_t*)eventbuffer;
-   int32_t    status;
-   uint32_t   finish=0;
-   uint32_t   it;
-   SDL_Window* window;
-   SDL_WindowData* wdata;
+    uint8_t eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE];
+    PhEvent_t *event = (PhEvent_t *) eventbuffer;
+    int32_t status;
+    uint32_t finish = 0;
+    uint32_t it;
+    SDL_Window *window;
+    SDL_WindowData *wdata;
 
-   do {
-      status=PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE);
-      switch (status)
-      {
-         case Ph_RESIZE_MSG:
-              {
-                 SDL_SetError("Photon: Event size too much for buffer");
-                 return;
-              }
-              break;
-         case Ph_EVENT_MSG:
-              {
-                 /* Find a window, to which this handle destinated */
-                 status=0;
-                 for (it=0; it<SDL_CurrentDisplay.num_windows; it++)
-                 {
-                    wdata=(SDL_WindowData*)SDL_CurrentDisplay.windows[it].driverdata;
+    do {
+        status = PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE);
+        switch (status) {
+        case Ph_RESIZE_MSG:
+            {
+                SDL_SetError("Photon: Event size too much for buffer");
+                return;
+            }
+            break;
+        case Ph_EVENT_MSG:
+            {
+                /* Find a window, to which this handle destinated */
+                status = 0;
+                for (it = 0; it < SDL_CurrentDisplay.num_windows; it++) {
+                    wdata =
+                        (SDL_WindowData *) SDL_CurrentDisplay.windows[it].
+                        driverdata;
 
                     /* Find the proper window */
-                    if (wdata->window!=NULL)
-                    {
-                       if (PtWidgetRid(wdata->window)==event->collector.rid)
-                       {
-                          window=(SDL_Window*)&SDL_CurrentDisplay.windows[it];
-                          status=1;
-                          break;
-                       }
-                    }
-                    else
-                    {
-                       continue;
+                    if (wdata->window != NULL) {
+                        if (PtWidgetRid(wdata->window) ==
+                            event->collector.rid) {
+                            window =
+                                (SDL_Window *) & SDL_CurrentDisplay.
+                                windows[it];
+                            status = 1;
+                            break;
+                        }
+                    } else {
+                        continue;
                     }
-                 }
-                 if (status==0)
-                 {
-                    window=NULL;
-                    wdata=NULL;
-                 }
+                }
+                if (status == 0) {
+                    window = NULL;
+                    wdata = NULL;
+                }
 
-                 /* Event is ready */
-                 switch(event->type)
-                 {
-                    case Ph_EV_BOUNDARY:
-                         {
-                            switch(event->subtype)
+                /* Event is ready */
+                switch (event->type) {
+                case Ph_EV_BOUNDARY:
+                    {
+                        switch (event->subtype) {
+                        case Ph_EV_PTR_ENTER:
                             {
-                               case Ph_EV_PTR_ENTER:
-                                    {
-                                       /* Mouse cursor over handled window */
-                                       if (window!=NULL)
-                                       {
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_ENTER, 0, 0);
-                                          SDL_SetMouseFocus(0, window->id);
-                                       }
-                                    }
-                                    break;
-                               case Ph_EV_PTR_LEAVE:
-                                    {
-                                       /* Mouse cursor out of handled window */
-                                       if (window!=NULL)
-                                       {
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
-                                       }
-                                    }
-                                    break;
+                                /* Mouse cursor over handled window */
+                                if (window != NULL) {
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_ENTER,
+                                                        0, 0);
+                                    SDL_SetMouseFocus(0, window->id);
+                                }
+                            }
+                            break;
+                        case Ph_EV_PTR_LEAVE:
+                            {
+                                /* Mouse cursor out of handled window */
+                                if (window != NULL) {
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_LEAVE,
+                                                        0, 0);
+                                }
                             }
-                         }
-                         break;
-                    case Ph_EV_PTR_MOTION_BUTTON:
-                    case Ph_EV_PTR_MOTION_NOBUTTON:
-                         {
-                            PhPointerEvent_t* pevent=NULL;
-                            PhRect_t* prects=NULL;
+                            break;
+                        }
+                    }
+                    break;
+                case Ph_EV_PTR_MOTION_BUTTON:
+                case Ph_EV_PTR_MOTION_NOBUTTON:
+                    {
+                        PhPointerEvent_t *pevent = NULL;
+                        PhRect_t *prects = NULL;
+
+                        /* Get event data */
+                        pevent = PhGetData(event);
+                        /* Get associated event rectangles */
+                        prects = PhGetRects(event);
+                        if ((pevent != NULL) && (prects != NULL)) {
+                            SDL_SendMouseMotion(0, 0, prects->ul.x,
+                                                prects->ul.y, 0);
+                        }
+                    }
+                    break;
+                case Ph_EV_BUT_PRESS:
+                    {
+                        /* Button press event */
+                        PhPointerEvent_t *pevent = NULL;
+                        uint32_t sdlbutton = 0x00000000;
 
-                            /* Get event data */
-                            pevent=PhGetData(event);
-                            /* Get associated event rectangles */
-                            prects=PhGetRects(event);
-                            if ((pevent!=NULL) && (prects!=NULL))
-                            {
-                               SDL_SendMouseMotion(0, 0, prects->ul.x, prects->ul.y, 0);
+                        /* Get event data */
+                        pevent = PhGetData(event);
+                        if (pevent != NULL) {
+                            for (it = 0; it < sizeof(pevent->buttons) * 8;
+                                 it++) {
+                                if ((pevent->buttons & (0x0001 << it)) ==
+                                    (0x0001 << it)) {
+                                    switch (it) {
+                                    case 0:
+                                        {
+                                            sdlbutton = SDL_BUTTON_RIGHT;
+                                        }
+                                        break;
+                                    case 1:
+                                        {
+                                            sdlbutton = SDL_BUTTON_MIDDLE;
+                                        }
+                                        break;
+                                    case 2:
+                                        {
+                                            sdlbutton = SDL_BUTTON_LEFT;
+                                        }
+                                        break;
+                                    default:
+                                        {
+                                            sdlbutton = it + 1;
+                                        }
+                                        break;
+                                    }
+                                    SDL_SendMouseButton(0, SDL_PRESSED,
+                                                        sdlbutton);
+                                }
                             }
-                         }
-                         break;
-                    case Ph_EV_BUT_PRESS:
-                         {
-                            /* Button press event */
-                            PhPointerEvent_t* pevent=NULL;
-                            uint32_t sdlbutton=0x00000000;
+                        }
+                    }
+                    break;
+                case Ph_EV_BUT_RELEASE:
+                    {
+                        /* Button press event */
+                        PhPointerEvent_t *pevent = NULL;
+                        uint32_t sdlbutton = 0x00000000;
 
-                            /* Get event data */
-                            pevent=PhGetData(event);
-                            if (pevent!=NULL)
+                        /* Get event data */
+                        pevent = PhGetData(event);
+                        if (pevent != NULL) {
+                            for (it = 0; it < sizeof(pevent->buttons) * 8;
+                                 it++) {
+                                if ((pevent->buttons & (0x0001 << it)) ==
+                                    (0x0001 << it)) {
+                                    switch (it) {
+                                    case 0:
+                                        {
+                                            sdlbutton = SDL_BUTTON_RIGHT;
+                                        }
+                                        break;
+                                    case 1:
+                                        {
+                                            sdlbutton = SDL_BUTTON_MIDDLE;
+                                        }
+                                        break;
+                                    case 2:
+                                        {
+                                            sdlbutton = SDL_BUTTON_LEFT;
+                                        }
+                                        break;
+                                    default:
+                                        {
+                                            sdlbutton = it + 1;
+                                        }
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+
+                        switch (event->subtype) {
+                        case Ph_EV_RELEASE_REAL:
                             {
-                               for (it=0; it<sizeof(pevent->buttons)*8; it++)
-                               {
-                                  if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
-                                  {
-                                     switch (it)
-                                     {
-                                        case 0:
-                                             {
-                                                sdlbutton=SDL_BUTTON_RIGHT;
-                                             }
-                                             break;
-                                        case 1:
-                                             {
-                                                sdlbutton=SDL_BUTTON_MIDDLE;
-                                             }
-                                             break;
-                                        case 2:
-                                             {
-                                                sdlbutton=SDL_BUTTON_LEFT;
-                                             }
-                                             break;
-                                        default:
-                                             {
-                                                sdlbutton=it+1;
-                                             }
-                                             break;
-                                     }
-                                     SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
-                                  }
-                               }
+                                /* Real release button event */
+                                SDL_SendMouseButton(0, SDL_RELEASED,
+                                                    sdlbutton);
                             }
-                         }
-                         break;
-                    case Ph_EV_BUT_RELEASE:
-                         {
-                            /* Button press event */
-                            PhPointerEvent_t* pevent=NULL;
-                            uint32_t sdlbutton=0x00000000;
-
-                            /* Get event data */
-                            pevent=PhGetData(event);
-                            if (pevent!=NULL)
+                            break;
+                        case Ph_EV_RELEASE_PHANTOM:
                             {
-                               for (it=0; it<sizeof(pevent->buttons)*8; it++)
-                               {
-                                  if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
-                                  {
-                                     switch (it)
-                                     {
-                                        case 0:
-                                             {
-                                                sdlbutton=SDL_BUTTON_RIGHT;
-                                             }
-                                             break;
-                                        case 1:
-                                             {
-                                                sdlbutton=SDL_BUTTON_MIDDLE;
-                                             }
-                                             break;
-                                        case 2:
-                                             {
-                                                sdlbutton=SDL_BUTTON_LEFT;
-                                             }
-                                             break;
-                                        default:
-                                             {
-                                                sdlbutton=it+1;
-                                             }
-                                             break;
-                                     }
-                                  }
-                               }
+                                /* We will get phantom button release */
+                                /* event in case if it was unpressed  */
+                                /* outside of window                  */
+                                if (window != NULL) {
+                                    if ((window->
+                                         flags & SDL_WINDOW_MOUSE_FOCUS) !=
+                                        SDL_WINDOW_MOUSE_FOCUS) {
+                                        /* Send phantom button release */
+                                        SDL_SendMouseButton(0, SDL_RELEASED,
+                                                            sdlbutton);
+                                    }
+                                }
                             }
-
-                            switch(event->subtype)
+                            break;
+                        }
+                    }
+                    break;
+                case Ph_EV_EXPOSE:
+                    {
+                        switch (event->subtype) {
+                        case Ph_NORMAL_EXPOSE:
                             {
-                               case Ph_EV_RELEASE_REAL:
-                                    {
-                                       /* Real release button event */
-                                       SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
-                                    }
+                                PhRect_t *rects = NULL;
+
+                                /* Get array of rectangles to be updated */
+                                rects = PhGetRects(event);
+                                if (rects == NULL) {
                                     break;
-                               case Ph_EV_RELEASE_PHANTOM:
-                                    {
-                                       /* We will get phantom button release */
-                                       /* event in case if it was unpressed  */
-                                       /* outside of window                  */
-                                       if (window!=NULL)
-                                       {
-                                          if ((window->flags & SDL_WINDOW_MOUSE_FOCUS)!=SDL_WINDOW_MOUSE_FOCUS)
-                                          {
-                                             /* Send phantom button release */
-                                             SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
-                                          }
-                                       }
+                                }
+
+                                /* Check if expose come to one of the our windows */
+                                if ((wdata != NULL) && (window != NULL)) {
+                                    /* Check if window uses OpenGL ES */
+                                    if (wdata->uses_gles == SDL_TRUE) {
+                                        PhRect_t dst_rect;
+                                        PhRect_t src_rect;
+
+                                        /* Cycle through each rectangle */
+                                        for (it = 0; it < event->num_rects;
+                                             it++) {
+                                            /* Blit OpenGL ES pixmap surface directly to window region */
+                                            PgFFlush(Ph_START_DRAW);
+                                            PgSetRegionCx(PhDCGetCurrent(),
+                                                          PtWidgetRid(wdata->
+                                                                      window));
+                                            PgClearTranslationCx(PgGetGCCx
+                                                                 (PhDCGetCurrent
+                                                                  ()));
+                                            PgContextBlit(wdata->phsurface,
+                                                          &rects[it], NULL,
+                                                          &rects[it]);
+                                            PgFFlush(Ph_DONE_DRAW);
+                                            PgWaitHWIdle();
+                                        }
+                                    } else {
+                                        /* Normal window */
+                                        /* TODO: update the damaged rectangles */
                                     }
-                                    break;
+                                }
+
+                                /* Flush all blittings */
+                                PgFlush();
                             }
-                         }
-                         break;
-                    case Ph_EV_EXPOSE:
-                         {
-                            switch(event->subtype)
+                            break;
+                        case Ph_CAPTURE_EXPOSE:
                             {
-                               case Ph_NORMAL_EXPOSE:
-                                    {
-                                       PhRect_t* rects=NULL;
+                                /* Check if expose come to one of the our windows */
+                                if ((wdata != NULL) && (window != NULL)) {
+                                    /* Check if window uses OpenGL ES */
+                                    if (wdata->uses_gles == SDL_TRUE) {
+                                        PhRect_t dst_rect;
+                                        PhRect_t src_rect;
 
-                                       /* Get array of rectangles to be updated */
-                                       rects=PhGetRects(event);
-                                       if (rects==NULL)
-                                       {
-                                          break;
-                                       }
+                                        /* Set blit area */
+                                        dst_rect =
+                                            *PtGetCanvas(wdata->window);
+                                        src_rect.ul.x = 0;
+                                        src_rect.ul.y = 0;
+                                        src_rect.lr.x = window->w - 1;
+                                        src_rect.lr.y = window->h - 1;
 
-                                       /* Check if expose come to one of the our windows */
-                                       if ((wdata!=NULL) && (window!=NULL))
-                                       {
-                                          /* Check if window uses OpenGL ES */
-                                          if (wdata->uses_gles==SDL_TRUE)
-                                          {
-                                             PhRect_t dst_rect;
-                                             PhRect_t src_rect;
+                                        /* We need to redraw entire window */
+                                        PgFFlush(Ph_START_DRAW);
+                                        PgSetRegionCx(PhDCGetCurrent(),
+                                                      PtWidgetRid(wdata->
+                                                                  window));
+                                        PgClearTranslationCx(PgGetGCCx
+                                                             (PhDCGetCurrent
+                                                              ()));
+                                        PgContextBlit(wdata->phsurface,
+                                                      &src_rect, NULL,
+                                                      &dst_rect);
+                                        PgFFlush(Ph_DONE_DRAW);
+                                        PgWaitHWIdle();
+                                    } else {
+                                        /* Normal window */
+                                        /* TODO: update the damaged rectangles */
 
-                                             /* Cycle through each rectangle */
-                                             for (it=0; it<event->num_rects; it++)
-                                             {
-                                                /* Blit OpenGL ES pixmap surface directly to window region */
-                                                PgFFlush(Ph_START_DRAW);
-                                                PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
-                                                PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
-                                                PgContextBlit(wdata->phsurface, &rects[it], NULL, &rects[it]);
-                                                PgFFlush(Ph_DONE_DRAW);
-                                                PgWaitHWIdle();
-                                             }
-                                          }
-                                          else
-                                          {
-                                             /* Normal window */
-                                             /* TODO: update the damaged rectangles */
-                                          }
-                                       }
+                                        /* We need to redraw entire window */
+                                    }
+                                }
+                            }
+                            break;
+                        case Ph_GRAPHIC_EXPOSE:
+                            {
+                                /* TODO: What this event means ? */
+                            }
+                            break;
+                        }
+                    }
+                    break;
+                case Ph_EV_INFO:
+                    {
+                    }
+                    break;
+                case Ph_EV_KEY:
+                    {
+                        PhKeyEvent_t *keyevent = NULL;
+                        SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
+                        SDL_bool pressed = SDL_FALSE;
 
-                                       /* Flush all blittings */
-                                       PgFlush();
-                                    }
+                        keyevent = PhGetData(event);
+                        if (keyevent == NULL) {
+                            break;
+                        }
+
+                        /* Check if key is repeated */
+                        if ((keyevent->key_flags & Pk_KF_Key_Repeat) ==
+                            Pk_KF_Key_Repeat) {
+                            /* Ignore such events */
+                            break;
+                        }
+
+                        /* Check if key has its own scancode */
+                        if ((keyevent->key_flags & Pk_KF_Scan_Valid) ==
+                            Pk_KF_Scan_Valid) {
+                            if ((keyevent->key_flags & Pk_KF_Key_Down) ==
+                                Pk_KF_Key_Down) {
+                                pressed = SDL_TRUE;
+                            } else {
+                                pressed = SDL_FALSE;
+                            }
+                            scancode =
+                                photon_to_sdl_keymap(keyevent->key_scan);
+
+                            /* Add details for the pressed key */
+                            if ((keyevent->key_flags & Pk_KF_Cap_Valid) ==
+                                Pk_KF_Cap_Valid) {
+                                switch (keyevent->key_cap) {
+                                case Pk_Hyper_R:       /* Right windows flag key */
+                                    scancode = SDL_SCANCODE_RGUI;
                                     break;
-                               case Ph_CAPTURE_EXPOSE:
-                                    {
-                                       /* Check if expose come to one of the our windows */
-                                       if ((wdata!=NULL) && (window!=NULL))
-                                       {
-                                          /* Check if window uses OpenGL ES */
-                                          if (wdata->uses_gles==SDL_TRUE)
-                                          {
-                                             PhRect_t dst_rect;
-                                             PhRect_t src_rect;
-
-                                             /* Set blit area */
-                                             dst_rect=*PtGetCanvas(wdata->window);
-                                             src_rect.ul.x=0;
-                                             src_rect.ul.y=0;
-                                             src_rect.lr.x=window->w-1;
-                                             src_rect.lr.y=window->h-1;
-
-                                             /* We need to redraw entire window */
-                                             PgFFlush(Ph_START_DRAW);
-                                             PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
-                                             PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
-                                             PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
-                                             PgFFlush(Ph_DONE_DRAW);
-                                             PgWaitHWIdle();
-                                          }
-                                          else
-                                          {
-                                             /* Normal window */
-                                             /* TODO: update the damaged rectangles */
-
-                                             /* We need to redraw entire window */
-                                          }
-                                       }
-                                    }
+                                case Pk_Control_R:     /* Right Ctrl key */
+                                    scancode = SDL_SCANCODE_RCTRL;
+                                    break;
+                                case Pk_Alt_R: /* Right Alt key */
+                                    scancode = SDL_SCANCODE_RALT;
                                     break;
-                               case Ph_GRAPHIC_EXPOSE:
-                                    {
-                                       /* TODO: What this event means ? */
+                                case Pk_Up:    /* Up key but with invalid scan */
+                                    if (scancode != SDL_SCANCODE_UP) {
+                                        /* This is a mouse wheel event */
+                                        SDL_SendMouseWheel(0, 0, 1);
+                                        return;
                                     }
                                     break;
-                            }
-                         }
-                         break;
-                    case Ph_EV_INFO:
-                         {
-                         }
-                         break;
-                    case Ph_EV_KEY:
-                         {
-                            PhKeyEvent_t* keyevent=NULL;
-                            SDL_scancode scancode=SDL_SCANCODE_UNKNOWN;
-                            SDL_bool pressed=SDL_FALSE;
-
-                            keyevent=PhGetData(event);
-                            if (keyevent==NULL)
-                            {
-                               break;
+                                case Pk_KP_8:  /* Up arrow or 8 on keypad */
+                                    scancode = SDL_SCANCODE_KP_8;
+                                    break;
+                                case Pk_Down:  /* Down key but with invalid scan */
+                                    if (scancode != SDL_SCANCODE_DOWN) {
+                                        /* This is a mouse wheel event */
+                                        SDL_SendMouseWheel(0, 0, -1);
+                                        return;
+                                    }
+                                    break;
+                                case Pk_KP_2:  /* Down arrow or 2 on keypad */
+                                    scancode = SDL_SCANCODE_KP_2;
+                                    break;
+                                case Pk_Left:  /* Left arrow key */
+                                    scancode = SDL_SCANCODE_LEFT;
+                                    break;
+                                case Pk_KP_4:  /* Left arrow or 4 on keypad */
+                                    scancode = SDL_SCANCODE_KP_4;
+                                    break;
+                                case Pk_Right: /* Right arrow key */
+                                    scancode = SDL_SCANCODE_RIGHT;
+                                    break;
+                                case Pk_KP_6:  /* Right arrow or 6 on keypad */
+                                    scancode = SDL_SCANCODE_KP_6;
+                                    break;
+                                case Pk_Insert:        /* Insert key */
+                                    scancode = SDL_SCANCODE_INSERT;
+                                    break;
+                                case Pk_KP_0:  /* Insert or 0 on keypad */
+                                    scancode = SDL_SCANCODE_KP_0;
+                                    break;
+                                case Pk_Home:  /* Home key */
+                                    scancode = SDL_SCANCODE_HOME;
+                                    break;
+                                case Pk_KP_7:  /* Home or 7 on keypad */
+                                    scancode = SDL_SCANCODE_KP_7;
+                                    break;
+                                case Pk_Pg_Up: /* PageUp key */
+                                    scancode = SDL_SCANCODE_PAGEUP;
+                                    break;
+                                case Pk_KP_9:  /* PgUp or 9 on keypad */
+                                    scancode = SDL_SCANCODE_KP_9;
+                                    break;
+                                case Pk_Delete:        /* Delete key */
+                                    scancode = SDL_SCANCODE_DELETE;
+                                    break;
+                                case Pk_KP_Decimal:    /* Del or . on keypad */
+                                    scancode = SDL_SCANCODE_KP_PERIOD;
+                                    break;
+                                case Pk_End:   /* End key */
+                                    scancode = SDL_SCANCODE_END;
+                                    break;
+                                case Pk_KP_1:  /* End or 1 on keypad */
+                                    scancode = SDL_SCANCODE_KP_1;
+                                    break;
+                                case Pk_Pg_Down:       /* PageDown key */
+                                    scancode = SDL_SCANCODE_PAGEDOWN;
+                                    break;
+                                case Pk_KP_3:  /* PgDn or 3 on keypad */
+                                    scancode = SDL_SCANCODE_KP_3;
+                                    break;
+                                case Pk_KP_5:  /* 5 on keypad */
+                                    scancode = SDL_SCANCODE_KP_5;
+                                    break;
+                                case Pk_KP_Enter:
+                                    scancode = SDL_SCANCODE_KP_ENTER;
+                                    break;
+                                case Pk_KP_Add:
+                                    scancode = SDL_SCANCODE_KP_PLUS;
+                                    break;
+                                case Pk_KP_Subtract:
+                                    scancode = SDL_SCANCODE_KP_MINUS;
+                                    break;
+                                case Pk_KP_Multiply:
+                                    scancode = SDL_SCANCODE_KP_MULTIPLY;
+                                    break;
+                                case Pk_KP_Divide:
+                                    scancode = SDL_SCANCODE_KP_DIVIDE;
+                                    break;
+                                case Pk_Pause:
+                                    scancode = SDL_SCANCODE_PAUSE;
+                                    break;
+                                }
                             }
 
-                            /* Check if key is repeated */
-                            if ((keyevent->key_flags & Pk_KF_Key_Repeat)==Pk_KF_Key_Repeat)
-                            {
-                               /* Ignore such events */
-                               break;
+                            /* Finally check if scancode has been decoded */
+                            if (scancode == SDL_SCANCODE_UNKNOWN) {
+                                /* Something was pressed, which is not supported */
+                                break;
+                            }
+
+                            /* Report pressed/released key to SDL */
+                            if (pressed == SDL_TRUE) {
+                                SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
+                            } else {
+                                SDL_SendKeyboardKey(0, SDL_RELEASED,
+                                                    scancode);
                             }
 
-                            /* Check if key has its own scancode */
-                            if ((keyevent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)
-                            {
-                               if ((keyevent->key_flags & Pk_KF_Key_Down)==Pk_KF_Key_Down)
-                               {
-                                  pressed=SDL_TRUE;
-                               }
-                               else
-                               {
-                                  pressed=SDL_FALSE;
-                               }
-                               scancode=photon_to_sdl_keymap(keyevent->key_scan);
+                            /* Photon doesn't send a release event for PrnScr key */
+                            if ((scancode == SDL_SCANCODE_PRINTSCREEN)
+                                && (pressed)) {
+                                SDL_SendKeyboardKey(0, SDL_RELEASED,
+                                                    scancode);
+                            }
+                        }
+                    }
+                    break;
+                case Ph_EV_SERVICE:
+                    {
+                    }
+                    break;
+                case Ph_EV_SYSTEM:
+                    {
+                    }
+                    break;
+                case Ph_EV_WM:
+                    {
+                        PhWindowEvent_t *wmevent = NULL;
+
+                        /* Get associated event data */
+                        wmevent = PhGetData(event);
+                        if (wmevent == NULL) {
+                            break;
+                        }
 
-                               /* Add details for the pressed key */
-                               if ((keyevent->key_flags & Pk_KF_Cap_Valid)==Pk_KF_Cap_Valid)
-                               {
-                                  switch(keyevent->key_cap)
-                                  {
-                                     case Pk_Hyper_R: /* Right windows flag key */
-                                          scancode=SDL_SCANCODE_RGUI;
-                                          break;
-                                     case Pk_Control_R: /* Right Ctrl key */
-                                          scancode=SDL_SCANCODE_RCTRL;
-                                          break;
-                                     case Pk_Alt_R: /* Right Alt key */
-                                          scancode=SDL_SCANCODE_RALT;
-                                          break;
-                                     case Pk_Up: /* Up key but with invalid scan */
-                                          if (scancode!=SDL_SCANCODE_UP)
-                                          {
-                                             /* This is a mouse wheel event */
-                                             SDL_SendMouseWheel(0, 0, 1);
-                                             return;
-                                          }
-                                          break;
-                                     case Pk_KP_8: /* Up arrow or 8 on keypad */
-                                          scancode=SDL_SCANCODE_KP_8;
-                                          break;
-                                     case Pk_Down: /* Down key but with invalid scan */
-                                          if (scancode!=SDL_SCANCODE_DOWN)
-                                          {
-                                             /* This is a mouse wheel event */
-                                             SDL_SendMouseWheel(0, 0, -1);
-                                             return;
-                                          }
-                                          break;
-                                     case Pk_KP_2: /* Down arrow or 2 on keypad */
-                                          scancode=SDL_SCANCODE_KP_2;
-                                          break;
-                                     case Pk_Left: /* Left arrow key */
-                                          scancode=SDL_SCANCODE_LEFT;
-                                          break;
-                                     case Pk_KP_4: /* Left arrow or 4 on keypad */
-                                          scancode=SDL_SCANCODE_KP_4;
-                                          break;
-                                     case Pk_Right: /* Right arrow key */
-                                          scancode=SDL_SCANCODE_RIGHT;
-                                          break;
-                                     case Pk_KP_6: /* Right arrow or 6 on keypad */
-                                          scancode=SDL_SCANCODE_KP_6;
-                                          break;
-                                     case Pk_Insert: /* Insert key */
-                                          scancode=SDL_SCANCODE_INSERT;
-                                          break;
-                                     case Pk_KP_0: /* Insert or 0 on keypad */
-                                          scancode=SDL_SCANCODE_KP_0;
-                                          break;
-                                     case Pk_Home: /* Home key */
-                                          scancode=SDL_SCANCODE_HOME;
-                                          break;
-                                     case Pk_KP_7: /* Home or 7 on keypad */
-                                          scancode=SDL_SCANCODE_KP_7;
-                                          break;
-                                     case Pk_Pg_Up: /* PageUp key */
-                                          scancode=SDL_SCANCODE_PAGEUP;
-                                          break;
-                                     case Pk_KP_9: /* PgUp or 9 on keypad */
-                                          scancode=SDL_SCANCODE_KP_9;
-                                          break;
-                                     case Pk_Delete: /* Delete key */
-                                          scancode=SDL_SCANCODE_DELETE;
-                                          break;
-                                     case Pk_KP_Decimal: /* Del or . on keypad */
-                                          scancode=SDL_SCANCODE_KP_PERIOD;
-                                          break;
-                                     case Pk_End: /* End key */
-                                          scancode=SDL_SCANCODE_END;
-                                          break;
-                                     case Pk_KP_1: /* End or 1 on keypad */
-                                          scancode=SDL_SCANCODE_KP_1;
-                                          break;
-                                     case Pk_Pg_Down: /* PageDown key */
-                                          scancode=SDL_SCANCODE_PAGEDOWN;
-                                          break;
-                                     case Pk_KP_3: /* PgDn or 3 on keypad */
-                                          scancode=SDL_SCANCODE_KP_3;
-                                          break;
-                                     case Pk_KP_5: /* 5 on keypad */
-                                          scancode=SDL_SCANCODE_KP_5;
-                                          break;
-                                     case Pk_KP_Enter:
-                                          scancode=SDL_SCANCODE_KP_ENTER;
-                                          break;
-                                     case Pk_KP_Add:
-                                          scancode=SDL_SCANCODE_KP_PLUS;
-                                          break;
-                                     case Pk_KP_Subtract:
-                                          scancode=SDL_SCANCODE_KP_MINUS;
-                                          break;
-                                     case Pk_KP_Multiply:
-                                          scancode=SDL_SCANCODE_KP_MULTIPLY;
-                                          break;
-                                     case Pk_KP_Divide:
-                                          scancode=SDL_SCANCODE_KP_DIVIDE;
-                                          break;
-                                     case Pk_Pause:
-                                          scancode=SDL_SCANCODE_PAUSE;
-                                          break;
-                                  }
-                               }
+                        switch (wmevent->event_f) {
+                        case Ph_WM_CLOSE:
+                            {
+                                if (window != NULL) {
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_CLOSE,
+                                                        0, 0);
+                                }
+                            }
+                            break;
+                        case Ph_WM_FOCUS:
+                            {
+                                if (wmevent->event_state ==
+                                    Ph_WM_EVSTATE_FOCUS) {
+                                    if (window != NULL) {
+                                        PhRegion_t wregion;
+
+                                        SDL_SendWindowEvent(window->id,
+                                                            SDL_WINDOWEVENT_FOCUS_GAINED,
+                                                            0, 0);
+                                        SDL_SetKeyboardFocus(0, window->id);
 
-                               /* Finally check if scancode has been decoded */
-                               if (scancode==SDL_SCANCODE_UNKNOWN)
-                               {
-                                  /* Something was pressed, which is not supported */
-                                  break;
-                               }
+                                        /* Set window region sensible to mouse motion events */
+                                        PhRegionQuery(PtWidgetRid
+                                                      (wdata->window),
+                                                      &wregion, NULL, NULL,
+                                                      0);
+                                        wregion.events_sense |=
+                                            Ph_EV_PTR_MOTION_BUTTON |
+                                            Ph_EV_PTR_MOTION_NOBUTTON;
+                                        PhRegionChange(Ph_REGION_EV_SENSE, 0,
+                                                       &wregion, NULL, NULL);
 
-                               /* Report pressed/released key to SDL */
-                               if (pressed==SDL_TRUE)
-                               {
-                                  SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
-                               }
-                               else
-                               {
-                                  SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
-                               }
+                                        /* If window got a focus, the it is visible */
+                                        SDL_SendWindowEvent(window->id,
+                                                            SDL_WINDOWEVENT_SHOWN,
+                                                            0, 0);
+                                    }
+                                }
+                                if (wmevent->event_state ==
+                                    Ph_WM_EVSTATE_FOCUSLOST) {
+                                    if (window != NULL) {
+                                        PhRegion_t wregion;
+
+                                        SDL_SendWindowEvent(window->id,
+                                                            SDL_WINDOWEVENT_FOCUS_LOST,
+                                                            0, 0);
 
-                               /* Photon doesn't send a release event for PrnScr key */
-                               if ((scancode==SDL_SCANCODE_PRINTSCREEN) && (pressed))
-                               {
-                                  SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
-                               }
-                            }
-                         }
-                         break;
-                    case Ph_EV_SERVICE:
-                         {
-                         }
-                         break;
-                    case Ph_EV_SYSTEM:
-                         {
-                         }
-                         break;
-                    case Ph_EV_WM:
-                         {
-                            PhWindowEvent_t* wmevent=NULL;
-
-                            /* Get associated event data */
-                            wmevent=PhGetData(event);
-                            if (wmevent==NULL)
-                            {
-                               break;
-                            }
-
-                            switch(wmevent->event_f)
-                            {
-                               case Ph_WM_CLOSE:
-                                    {
-                                       if (window!=NULL)
-                                       {
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
-                                       }
-                                    }
-                                    break;
-                               case Ph_WM_FOCUS:
-                                    {
-                                       if (wmevent->event_state==Ph_WM_EVSTATE_FOCUS)
-                                       {
-                                          if (window!=NULL)
-                                          {
-                                             PhRegion_t wregion;
-
-                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
-                                             SDL_SetKeyboardFocus(0, window->id);
-
-                                             /* Set window region sensible to mouse motion events */
-                                             PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
-                                             wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
-                                             PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
-
-                                             /* If window got a focus, the it is visible */
-                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
-                                          }
-                                       }
-                                       if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST)
-                                       {
-                                          if (window!=NULL)
-                                          {
-                                             PhRegion_t wregion;
-
-                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
-
-                                             /* Set window region ignore mouse motion events */
-                                             PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
-                                             wregion.events_sense&=~(Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON);
-                                             PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
-                                          }
-                                       }
+                                        /* Set window region ignore mouse motion events */
+                                        PhRegionQuery(PtWidgetRid
+                                                      (wdata->window),
+                                                      &wregion, NULL, NULL,
+                                                      0);
+                                        wregion.events_sense &=
+                                            ~(Ph_EV_PTR_MOTION_BUTTON |
+                                              Ph_EV_PTR_MOTION_NOBUTTON);
+                                        PhRegionChange(Ph_REGION_EV_SENSE, 0,
+                                                       &wregion, NULL, NULL);
                                     }
-                                    break;
-                               case Ph_WM_MOVE:
-                                    {
-                                       if (window!=NULL)
-                                       {
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
-                                       }
-                                    }
-                                    break;
-                               case Ph_WM_RESIZE:
-                                    {
-                                       if (window!=NULL)
-                                       {
-                                          /* Set new window position after resize */
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
-                                          /* Set new window size after resize */
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESIZED, wmevent->size.w, wmevent->size.h);
-                                       }
-                                    }
-                                    break;
-                               case Ph_WM_HIDE:
-                                    {
-                                       if (window!=NULL)
-                                       {
-                                          /* Send new window state: minimized */
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
-                                          /* In case window is minimized, then it is hidden */
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
-                                       }
-                                    }
-                                    break;
-                               case Ph_WM_MAX:
-                                    {
-                                       if (window!=NULL)
-                                       {
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
-                                       }
-                                    }
-                                    break;
-                               case Ph_WM_RESTORE:
-                                    {
-                                       if (window!=NULL)
-                                       {
-                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
-                                       }
-                                    }
-                                    break;
+                                }
+                            }
+                            break;
+                        case Ph_WM_MOVE:
+                            {
+                                if (window != NULL) {
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_MOVED,
+                                                        wmevent->pos.x,
+                                                        wmevent->pos.y);
+                                }
+                            }
+                            break;
+                        case Ph_WM_RESIZE:
+                            {
+                                if (window != NULL) {
+                                    /* Set new window position after resize */
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_MOVED,
+                                                        wmevent->pos.x,
+                                                        wmevent->pos.y);
+                                    /* Set new window size after resize */
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_RESIZED,
+                                                        wmevent->size.w,
+                                                        wmevent->size.h);
+                                }
+                            }
+                            break;
+                        case Ph_WM_HIDE:
+                            {
+                                if (window != NULL) {
+                                    /* Send new window state: minimized */
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_MINIMIZED,
+                                                        0, 0);
+                                    /* In case window is minimized, then it is hidden */
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_HIDDEN,
+                                                        0, 0);
+                                }
                             }
-                         }
-                         break;
-                 }
-                 PtEventHandler(event);
-              }
-              break;
-         case 0:
-              {
-                 /* All events are read */
-                 finish=1;
-                 break;
-              }
-         case -1:
-              {
-                 /* Error occured in event reading */
-                 SDL_SetError("Photon: Can't read event");
-                 return;
-              }
-              break;
-      }
-      if (finish!=0)
-      {
-         break;
-      }
-   } while(1);
+                            break;
+                        case Ph_WM_MAX:
+                            {
+                                if (window != NULL) {
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_MAXIMIZED,
+                                                        0, 0);
+                                }
+                            }
+                            break;
+                        case Ph_WM_RESTORE:
+                            {
+                                if (window != NULL) {
+                                    SDL_SendWindowEvent(window->id,
+                                                        SDL_WINDOWEVENT_RESTORED,
+                                                        0, 0);
+                                }
+                            }
+                            break;
+                        }
+                    }
+                    break;
+                }
+                PtEventHandler(event);
+            }
+            break;
+        case 0:
+            {
+                /* All events are read */
+                finish = 1;
+                break;
+            }
+        case -1:
+            {
+                /* Error occured in event reading */
+                SDL_SetError("Photon: Can't read event");
+                return;
+            }
+            break;
+        }
+        if (finish != 0) {
+            break;
+        }
+    } while (1);
 }
 
 /*****************************************************************************/
 /* SDL screen saver related functions                                        */
 /*****************************************************************************/
-void photon_suspendscreensaver(_THIS)
+void
+photon_suspendscreensaver(_THIS)
 {
-   /* There is no screensaver in pure console, it may exist when running */
-   /* GF under Photon, but I do not know, how to disable screensaver     */
+    /* There is no screensaver in pure console, it may exist when running */
+    /* GF under Photon, but I do not know, how to disable screensaver     */
 }
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/photon/SDL_photon.h	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon.h	Sat May 23 22:41:08 2009 +0000
@@ -29,8 +29,8 @@
 
 /* GF headers must be included first for the Photon GF functions */
 #if defined(SDL_VIDEO_OPENGL_ES)
-   #include <gf/gf.h>
-   #include <GLES/egl.h>
+#include <gf/gf.h>
+#include <GLES/egl.h>
 #endif /* SDL_VIDEO_OPENGL_ES */
 
 #include "SDL_config.h"
@@ -45,17 +45,17 @@
 
 typedef struct SDL_VideoData
 {
-   PhRid_t  rid[SDL_VIDEO_PHOTON_MAX_RIDS];
-   uint32_t avail_rids;
-   uint32_t current_device_id;
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      gf_dev_t      gfdev;           /* GF device handle                     */
-      gf_dev_info_t gfdev_info;      /* GF device information                */
-      SDL_bool      gfinitialized;   /* GF device initialization status      */
-      EGLDisplay    egldisplay;      /* OpenGL ES display connection         */
-      uint32_t      egl_refcount;    /* OpenGL ES reference count            */
-      uint32_t      swapinterval;    /* OpenGL ES default swap interval      */
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    PhRid_t rid[SDL_VIDEO_PHOTON_MAX_RIDS];
+    uint32_t avail_rids;
+    uint32_t current_device_id;
+#if defined(SDL_VIDEO_OPENGL_ES)
+    gf_dev_t gfdev;             /* GF device handle                     */
+    gf_dev_info_t gfdev_info;   /* GF device information                */
+    SDL_bool gfinitialized;     /* GF device initialization status      */
+    EGLDisplay egldisplay;      /* OpenGL ES display connection         */
+    uint32_t egl_refcount;      /* OpenGL ES reference count            */
+    uint32_t swapinterval;      /* OpenGL ES default swap interval      */
+#endif                          /* SDL_VIDEO_OPENGL_ES */
 } SDL_VideoData;
 
 /* This is hardcoded value in photon/Pg.h */
@@ -67,19 +67,19 @@
 
 typedef struct SDL_DisplayData
 {
-   uint32_t          device_id;
-   uint32_t          custom_refresh;   /* Custom refresh rate for all modes  */
-   SDL_DisplayMode   current_mode;     /* Current video mode                 */
-   uint8_t           description[SDL_VIDEO_PHOTON_DEVICENAME_MAX];
-                                       /* Device description                 */
-   uint32_t          caps;             /* Device capabilities                */
-   PhCursorDef_t*    cursor;           /* Global cursor settings             */
-   SDL_bool          cursor_visible;   /* SDL_TRUE if cursor visible         */
-   uint32_t          cursor_size;      /* Cursor size in memory w/ structure */
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      gf_display_t      display;       /* GF display handle                  */
-      gf_display_info_t display_info;  /* GF display information             */
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    uint32_t device_id;
+    uint32_t custom_refresh;    /* Custom refresh rate for all modes  */
+    SDL_DisplayMode current_mode;       /* Current video mode                 */
+    uint8_t description[SDL_VIDEO_PHOTON_DEVICENAME_MAX];
+    /* Device description                 */
+    uint32_t caps;              /* Device capabilities                */
+    PhCursorDef_t *cursor;      /* Global cursor settings             */
+    SDL_bool cursor_visible;    /* SDL_TRUE if cursor visible         */
+    uint32_t cursor_size;       /* Cursor size in memory w/ structure */
+#if defined(SDL_VIDEO_OPENGL_ES)
+    gf_display_t display;       /* GF display handle                  */
+    gf_display_info_t display_info;     /* GF display information             */
+#endif                          /* SDL_VIDEO_OPENGL_ES */
 } SDL_DisplayData;
 
 /* Maximum amount of OpenGL ES framebuffer configurations */
@@ -87,18 +87,18 @@
 
 typedef struct SDL_WindowData
 {
-   SDL_bool       uses_gles;           /* if true window must support OpenGL ES*/
-   PtWidget_t*    window;              /* window handle                        */
-   #if defined(SDL_VIDEO_OPENGL_ES)
-      EGLConfig    gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
-                                         /* OpenGL ES framebuffer confs        */
-      EGLint       gles_config;          /* OpenGL ES configuration index      */
-      EGLContext   gles_context;         /* OpenGL ES context                  */
-      EGLint       gles_attributes[256]; /* OpenGL ES attributes for context   */
-      EGLSurface   gles_surface;         /* OpenGL ES target rendering surface */
-      gf_surface_t gfsurface;            /* OpenGL ES GF's surface             */
-      PdOffscreenContext_t* phsurface;   /* OpenGL ES Photon's surface         */
-   #endif /* SDL_VIDEO_OPENGL_ES */
+    SDL_bool uses_gles;         /* if true window must support OpenGL ES */
+    PtWidget_t *window;         /* window handle                        */
+#if defined(SDL_VIDEO_OPENGL_ES)
+    EGLConfig gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
+    /* OpenGL ES framebuffer confs        */
+    EGLint gles_config;         /* OpenGL ES configuration index      */
+    EGLContext gles_context;    /* OpenGL ES context                  */
+    EGLint gles_attributes[256];        /* OpenGL ES attributes for context   */
+    EGLSurface gles_surface;    /* OpenGL ES target rendering surface */
+    gf_surface_t gfsurface;     /* OpenGL ES GF's surface             */
+    PdOffscreenContext_t *phsurface;    /* OpenGL ES Photon's surface         */
+#endif                          /* SDL_VIDEO_OPENGL_ES */
 } SDL_WindowData;
 
 /****************************************************************************/
@@ -106,8 +106,8 @@
 /****************************************************************************/
 typedef struct Photon_DeviceCaps
 {
-   uint8_t* name;
-   uint32_t caps;
+    uint8_t *name;
+    uint32_t caps;
 } Photon_DeviceCaps;
 
 #define SDL_PHOTON_UNACCELERATED         0x00000000
@@ -120,41 +120,42 @@
 /****************************************************************************/
 
 /* Display and window functions */
-int  photon_videoinit(_THIS);
+int photon_videoinit(_THIS);
 void photon_videoquit(_THIS);
 void photon_getdisplaymodes(_THIS);
-int  photon_setdisplaymode(_THIS, SDL_DisplayMode* mode);
-int  photon_setdisplaypalette(_THIS, SDL_Palette* palette);
-int  photon_getdisplaypalette(_THIS, SDL_Palette* palette);
-int  photon_setdisplaygammaramp(_THIS, Uint16* ramp);
-int  photon_getdisplaygammaramp(_THIS, Uint16* ramp);
-int  photon_createwindow(_THIS, SDL_Window* window);
-int  photon_createwindowfrom(_THIS, SDL_Window* window, const void* data);
-void photon_setwindowtitle(_THIS, SDL_Window* window);
-void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon);
-void photon_setwindowposition(_THIS, SDL_Window* window);
-void photon_setwindowsize(_THIS, SDL_Window* window);
-void photon_showwindow(_THIS, SDL_Window* window);
-void photon_hidewindow(_THIS, SDL_Window* window);
-void photon_raisewindow(_THIS, SDL_Window* window);
-void photon_maximizewindow(_THIS, SDL_Window* window);
-void photon_minimizewindow(_THIS, SDL_Window* window);
-void photon_restorewindow(_THIS, SDL_Window* window);
-void photon_setwindowgrab(_THIS, SDL_Window* window);
-void photon_destroywindow(_THIS, SDL_Window* window);
+int photon_setdisplaymode(_THIS, SDL_DisplayMode * mode);
+int photon_setdisplaypalette(_THIS, SDL_Palette * palette);
+int photon_getdisplaypalette(_THIS, SDL_Palette * palette);
+int photon_setdisplaygammaramp(_THIS, Uint16 * ramp);
+int photon_getdisplaygammaramp(_THIS, Uint16 * ramp);
+int photon_createwindow(_THIS, SDL_Window * window);
+int photon_createwindowfrom(_THIS, SDL_Window * window, const void *data);
+void photon_setwindowtitle(_THIS, SDL_Window * window);
+void photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void photon_setwindowposition(_THIS, SDL_Window * window);
+void photon_setwindowsize(_THIS, SDL_Window * window);
+void photon_showwindow(_THIS, SDL_Window * window);
+void photon_hidewindow(_THIS, SDL_Window * window);
+void photon_raisewindow(_THIS, SDL_Window * window);
+void photon_maximizewindow(_THIS, SDL_Window * window);
+void photon_minimizewindow(_THIS, SDL_Window * window);
+void photon_restorewindow(_THIS, SDL_Window * window);
+void photon_setwindowgrab(_THIS, SDL_Window * window);
+void photon_destroywindow(_THIS, SDL_Window * window);
 
 /* Window manager function */
-SDL_bool photon_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info);
+SDL_bool photon_getwindowwminfo(_THIS, SDL_Window * window,
+                                struct SDL_SysWMinfo *info);
 
 /* OpenGL/OpenGL ES functions */
-int photon_gl_loadlibrary(_THIS, const char* path);
-void* photon_gl_getprocaddres(_THIS, const char* proc);
+int photon_gl_loadlibrary(_THIS, const char *path);
+void *photon_gl_getprocaddres(_THIS, const char *proc);
 void photon_gl_unloadlibrary(_THIS);
-SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window);
-int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context);
+SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window * window);
+int photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
 int photon_gl_setswapinterval(_THIS, int interval);
 int photon_gl_getswapinterval(_THIS);
-void photon_gl_swapwindow(_THIS, SDL_Window* window);
+void photon_gl_swapwindow(_THIS, SDL_Window * window);
 void photon_gl_deletecontext(_THIS, SDL_GLContext context);
 
 /* Event handling function */
--- a/src/video/photon/SDL_photon_input.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon_input.c	Sat May 23 22:41:08 2009 +0000
@@ -34,727 +34,699 @@
 #include "SDL_photon_keycodes.h"
 
 /* Mouse related functions */
-SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y);
-int  photon_showcursor(SDL_Cursor* cursor);
-void photon_movecursor(SDL_Cursor* cursor);
-void photon_freecursor(SDL_Cursor* cursor);
-void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y);
-void photon_freemouse(SDL_Mouse* mouse);
+SDL_Cursor *photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y);
+int photon_showcursor(SDL_Cursor * cursor);
+void photon_movecursor(SDL_Cursor * cursor);
+void photon_freecursor(SDL_Cursor * cursor);
+void photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y);
+void photon_freemouse(SDL_Mouse * mouse);
 
-int32_t photon_addinputdevices(_THIS)
+int32_t
+photon_addinputdevices(_THIS)
 {
-   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData*  didata=NULL;
-   struct SDL_Mouse  photon_mouse;
-   SDL_MouseData*    mdata=NULL;
-   SDL_Keyboard      photon_keyboard;
-   SDLKey   keymap[SDL_NUM_SCANCODES];
-   uint32_t it;
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata = NULL;
+    struct SDL_Mouse photon_mouse;
+    SDL_MouseData *mdata = NULL;
+    SDL_Keyboard photon_keyboard;
+    SDLKey keymap[SDL_NUM_SCANCODES];
+    uint32_t it;
 
-   for (it=0; it<_this->num_displays; it++)
-   {
-      /* Clear SDL mouse structure */
-      SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse));
+    for (it = 0; it < _this->num_displays; it++) {
+        /* Clear SDL mouse structure */
+        SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse));
 
-      /* Allocate SDL_MouseData structure */
-      mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData));
-      if (mdata==NULL)
-      {
-         SDL_OutOfMemory();
-         return -1;
-      }
+        /* Allocate SDL_MouseData structure */
+        mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData));
+        if (mdata == NULL) {
+            SDL_OutOfMemory();
+            return -1;
+        }
 
-      /* Mark this mouse with ID 0 */
-      photon_mouse.id=it;
-      photon_mouse.driverdata=(void*)mdata;
-      photon_mouse.CreateCursor=photon_createcursor;
-      photon_mouse.ShowCursor=photon_showcursor;
-      photon_mouse.MoveCursor=photon_movecursor;
-      photon_mouse.FreeCursor=photon_freecursor;
-      photon_mouse.WarpMouse=photon_warpmouse;
-      photon_mouse.FreeMouse=photon_freemouse;
+        /* Mark this mouse with ID 0 */
+        photon_mouse.id = it;
+        photon_mouse.driverdata = (void *) mdata;
+        photon_mouse.CreateCursor = photon_createcursor;
+        photon_mouse.ShowCursor = photon_showcursor;
+        photon_mouse.MoveCursor = photon_movecursor;
+        photon_mouse.FreeCursor = photon_freecursor;
+        photon_mouse.WarpMouse = photon_warpmouse;
+        photon_mouse.FreeMouse = photon_freemouse;
 
-      /* Get display data */
-      didata=(SDL_DisplayData*)_this->displays[it].driverdata;
+        /* Get display data */
+        didata = (SDL_DisplayData *) _this->displays[it].driverdata;
 
-      /* Store SDL_DisplayData pointer in the mouse driver internals */
-      mdata->didata=didata;
+        /* Store SDL_DisplayData pointer in the mouse driver internals */
+        mdata->didata = didata;
 
-      /* Register mouse cursor in SDL */
-      SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1);
-   }
+        /* Register mouse cursor in SDL */
+        SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1);
+    }
 
-   /* Photon maps all keyboards to one */
-   SDL_zero(photon_keyboard);
-   SDL_AddKeyboard(&photon_keyboard, -1);
+    /* Photon maps all keyboards to one */
+    SDL_zero(photon_keyboard);
+    SDL_AddKeyboard(&photon_keyboard, -1);
 
-   /* Add default scancode to key mapping */
-   SDL_GetDefaultKeymap(keymap);
-   SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
+    /* Add default scancode to key mapping */
+    SDL_GetDefaultKeymap(keymap);
+    SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
 
-   return 0;
+    return 0;
 }
 
-int32_t photon_delinputdevices(_THIS)
+int32_t
+photon_delinputdevices(_THIS)
 {
-   /* Destroy all of the mice */
-   SDL_MouseQuit();
+    /* Destroy all of the mice */
+    SDL_MouseQuit();
 }
 
 /*****************************************************************************/
 /* Photon mouse related functions                                            */
 /*****************************************************************************/
-SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
+SDL_Cursor *
+photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y)
 {
-   PhCursorDef_t* internal_cursor;
-   SDL_Cursor*    sdl_cursor;
-   uint8_t*       image0=NULL;
-   uint8_t*       image1=NULL;
-   uint32_t       it;
-   uint32_t       jt;
-   uint32_t       shape_color;
+    PhCursorDef_t *internal_cursor;
+    SDL_Cursor *sdl_cursor;
+    uint8_t *image0 = NULL;
+    uint8_t *image1 = NULL;
+    uint32_t it;
+    uint32_t jt;
+    uint32_t shape_color;
 
-   /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
-   /* and we must convert it back to monochrome, this routine handles */
-   /* 24/32bpp surfaces only                                          */
-   if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24))
-   {
-      SDL_SetError("Photon: Cursor shape is not 24/32bpp.");
-      return NULL;
-   }
+    /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
+    /* and we must convert it back to monochrome, this routine handles */
+    /* 24/32bpp surfaces only                                          */
+    if ((surface->format->BitsPerPixel != 32)
+        && (surface->format->BitsPerPixel != 24)) {
+        SDL_SetError("Photon: Cursor shape is not 24/32bpp.");
+        return NULL;
+    }
 
-   /* Checking data parameters */
-   if ((surface->w==0) || (surface->h==0))
-   {
-      SDL_SetError("Photon: Cursor shape dimensions are zero");
-      return NULL;
-   }
+    /* Checking data parameters */
+    if ((surface->w == 0) || (surface->h == 0)) {
+        SDL_SetError("Photon: Cursor shape dimensions are zero");
+        return NULL;
+    }
 
-   /* Allocate memory for the internal cursor format */
-   internal_cursor=(PhCursorDef_t*)SDL_calloc(1, sizeof(PhCursorDef_t)+
-      ((((surface->w+7)>>3)*surface->h)*2)-1);
-   if (internal_cursor==NULL)
-   {
-      SDL_OutOfMemory();
-      return NULL;
-   }
+    /* Allocate memory for the internal cursor format */
+    internal_cursor = (PhCursorDef_t *) SDL_calloc(1, sizeof(PhCursorDef_t) +
+                                                   ((((surface->w +
+                                                       7) >> 3) *
+                                                     surface->h) * 2) - 1);
+    if (internal_cursor == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
-   /* Allocate memory for the SDL cursor */
-   sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor));
-   if (sdl_cursor==NULL)
-   {
-      SDL_free(internal_cursor);
-      SDL_OutOfMemory();
-      return NULL;
-   }
+    /* Allocate memory for the SDL cursor */
+    sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor));
+    if (sdl_cursor == NULL) {
+        SDL_free(internal_cursor);
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
-   /* Set driverdata as photon cursor format */
-   image0=(uint8_t*)internal_cursor;
-   image0+=sizeof(PhCursorDef_t)-1;
-   image1=image0;
-   image1+=((surface->w+7)>>3)*surface->h;
-   sdl_cursor->driverdata=(void*)internal_cursor;
-   internal_cursor->hdr.len=(sizeof(PhCursorDef_t)-sizeof(PhRegionDataHdr_t))+
-                            ((((surface->w+7)>>3)*surface->h)*2)-1;
-   internal_cursor->hdr.type=Ph_RDATA_CURSOR;
-   internal_cursor->size1.x=surface->w;
-   internal_cursor->size1.y=surface->h;
-   internal_cursor->size2.x=surface->w;
-   internal_cursor->size2.y=surface->h;
-   internal_cursor->offset1.x=hot_x;
-   internal_cursor->offset1.y=hot_y;
-   internal_cursor->offset2.x=hot_x;
-   internal_cursor->offset2.y=hot_y;
-   internal_cursor->bytesperline1=((surface->w+7)>>3);
-   internal_cursor->bytesperline2=((surface->w+7)>>3);
-   internal_cursor->color1=(SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF;
-   internal_cursor->color2=(SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF;
+    /* Set driverdata as photon cursor format */
+    image0 = (uint8_t *) internal_cursor;
+    image0 += sizeof(PhCursorDef_t) - 1;
+    image1 = image0;
+    image1 += ((surface->w + 7) >> 3) * surface->h;
+    sdl_cursor->driverdata = (void *) internal_cursor;
+    internal_cursor->hdr.len =
+        (sizeof(PhCursorDef_t) - sizeof(PhRegionDataHdr_t)) +
+        ((((surface->w + 7) >> 3) * surface->h) * 2) - 1;
+    internal_cursor->hdr.type = Ph_RDATA_CURSOR;
+    internal_cursor->size1.x = surface->w;
+    internal_cursor->size1.y = surface->h;
+    internal_cursor->size2.x = surface->w;
+    internal_cursor->size2.y = surface->h;
+    internal_cursor->offset1.x = hot_x;
+    internal_cursor->offset1.y = hot_y;
+    internal_cursor->offset2.x = hot_x;
+    internal_cursor->offset2.y = hot_y;
+    internal_cursor->bytesperline1 = ((surface->w + 7) >> 3);
+    internal_cursor->bytesperline2 = ((surface->w + 7) >> 3);
+    internal_cursor->color1 = (SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF;
+    internal_cursor->color2 = (SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF;
 
-   /* Convert cursor from 32 bpp */
-   for (jt=0; jt<surface->h; jt++)
-   {
-      for (it=0; it<surface->w; it++)
-      {
-         shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel));
-         switch(shape_color)
-         {
+    /* Convert cursor from 32 bpp */
+    for (jt = 0; jt < surface->h; jt++) {
+        for (it = 0; it < surface->w; it++) {
+            shape_color =
+                *((uint32_t *) ((uint8_t *) surface->pixels +
+                                jt * surface->pitch +
+                                it * surface->format->BytesPerPixel));
+            switch (shape_color) {
             case SDL_PHOTON_MOUSE_COLOR_BLACK:
-                 {
-                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))|=0x80>>(it%8);
-                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
-                 }
-                 break;
+                {
+                    *(image0 + jt * (internal_cursor->bytesperline1) +
+                      (it >> 3)) |= 0x80 >> (it % 8);
+                    *(image1 + jt * (internal_cursor->bytesperline2) +
+                      (it >> 3)) &= ~(0x80 >> (it % 8));
+                }
+                break;
             case SDL_PHOTON_MOUSE_COLOR_WHITE:
-                 {
-                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
-                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))|=0x80>>(it%8);
-                 }
-                 break;
+                {
+                    *(image0 + jt * (internal_cursor->bytesperline1) +
+                      (it >> 3)) &= ~(0x80 >> (it % 8));
+                    *(image1 + jt * (internal_cursor->bytesperline2) +
+                      (it >> 3)) |= 0x80 >> (it % 8);
+                }
+                break;
             case SDL_PHOTON_MOUSE_COLOR_TRANS:
-                 {
-                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
-                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
-                 }
-                 break;
+                {
+                    *(image0 + jt * (internal_cursor->bytesperline1) +
+                      (it >> 3)) &= ~(0x80 >> (it % 8));
+                    *(image1 + jt * (internal_cursor->bytesperline2) +
+                      (it >> 3)) &= ~(0x80 >> (it % 8));
+                }
+                break;
             default:
-                 {
+                {
                     /* The same as transparent color, must not happen */
-                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
-                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
-                 }
-                 break;
-         }
-      }
-   }
+                    *(image0 + jt * (internal_cursor->bytesperline1) +
+                      (it >> 3)) &= ~(0x80 >> (it % 8));
+                    *(image1 + jt * (internal_cursor->bytesperline2) +
+                      (it >> 3)) &= ~(0x80 >> (it % 8));
+                }
+                break;
+            }
+        }
+    }
 
-   return sdl_cursor;
+    return sdl_cursor;
 }
 
-int photon_showcursor(SDL_Cursor* cursor)
+int
+photon_showcursor(SDL_Cursor * cursor)
 {
-   SDL_VideoDisplay* display;
-   SDL_DisplayData*  didata;
-   SDL_Window*       window;
-   SDL_WindowData*   wdata;
-   SDL_WindowID      window_id;
-   PhCursorDef_t*    internal_cursor;
-   int32_t status;
+    SDL_VideoDisplay *display;
+    SDL_DisplayData *didata;
+    SDL_Window *window;
+    SDL_WindowData *wdata;
+    SDL_WindowID window_id;
+    PhCursorDef_t *internal_cursor;
+    int32_t status;
+
+    /* Get current window id */
+    window_id = SDL_GetFocusWindow();
+    if (window_id <= 0) {
+        SDL_MouseData *mdata = NULL;
 
-   /* Get current window id */
-   window_id=SDL_GetFocusWindow();
-   if (window_id<=0)
-   {
-      SDL_MouseData* mdata=NULL;
+        /* If there is no current window, then someone calls this function */
+        /* to set global mouse settings during SDL initialization          */
+        if (cursor != NULL) {
+            /* Store cursor for future usage */
+            mdata = (SDL_MouseData *) cursor->mouse->driverdata;
+            didata = (SDL_DisplayData *) mdata->didata;
+            internal_cursor = (PhCursorDef_t *) cursor->driverdata;
+
+            if (didata->cursor_size >=
+                (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) {
+                SDL_memcpy(didata->cursor, internal_cursor,
+                           internal_cursor->hdr.len +
+                           sizeof(PhRegionDataHdr_t));
+            } else {
+                /* Partitial cursor image */
+                SDL_memcpy(didata->cursor, internal_cursor,
+                           didata->cursor_size);
+            }
 
-      /* If there is no current window, then someone calls this function */
-      /* to set global mouse settings during SDL initialization          */
-      if (cursor!=NULL)
-      {
-         /* Store cursor for future usage */
-         mdata=(SDL_MouseData*)cursor->mouse->driverdata;
-         didata=(SDL_DisplayData*)mdata->didata;
-         internal_cursor=(PhCursorDef_t*)cursor->driverdata;
+            didata->cursor_visible = SDL_TRUE;
+            return 0;
+        } else {
+            /* We can't get SDL_DisplayData at this point, return fake success */
+            return 0;
+        }
+    } else {
+        /* Sanity checks */
+        window = SDL_GetWindowFromID(window_id);
+        if (window != NULL) {
+            display = SDL_GetDisplayFromWindow(window);
+            if (display != NULL) {
+                didata = (SDL_DisplayData *) display->driverdata;
+                if (didata != NULL) {
+                    wdata = (SDL_WindowData *) window->driverdata;
+                    if (wdata == NULL) {
+                        return -1;
+                    }
+                } else {
+                    return -1;
+                }
+            } else {
+                return -1;
+            }
+        } else {
+            return -1;
+        }
+    }
+
+    /* return if window widget has been destroyed already */
+    if (wdata->window == NULL) {
+        return;
+    }
 
-         if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)))
-         {
-            SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
-         }
-         else
-         {
+    /* Check if we need to set new shape or disable cursor shape */
+    if (cursor != NULL) {
+        /* Retrieve photon cursor shape */
+        internal_cursor = (PhCursorDef_t *) cursor->driverdata;
+        if (internal_cursor == NULL) {
+            SDL_SetError("Photon: Internal cursor data is absent");
+            return -1;
+        }
+
+        /* Setup cursor type */
+        status =
+            PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP,
+                          0);
+        if (status != 0) {
+            SDL_SetError("Photon: Failed to set cursor type to bitmap");
+            return -1;
+        }
+
+        /* Setup cursor color to default */
+        status =
+            PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
+                          Ph_CURSOR_DEFAULT_COLOR, 0);
+        if (status != 0) {
+            SDL_SetError("Photon: Failed to set cursor color");
+            return -1;
+        }
+
+        /* Setup cursor shape */
+        status =
+            PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR,
+                          internal_cursor,
+                          internal_cursor->hdr.len +
+                          sizeof(PhRegionDataHdr_t));
+        if (status != 0) {
+            SDL_SetError("Photon: Failed to set cursor color");
+            return -1;
+        }
+
+        /* Store current cursor for future usage */
+        if (didata->cursor_size >=
+            (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) {
+            SDL_memcpy(didata->cursor, internal_cursor,
+                       internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t));
+        } else {
             /* Partitial cursor image */
             SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
-         }
-
-         didata->cursor_visible=SDL_TRUE;
-         return 0;
-      }
-      else
-      {
-         /* We can't get SDL_DisplayData at this point, return fake success */
-         return 0;
-      }
-   }
-   else
-   {
-      /* Sanity checks */
-      window=SDL_GetWindowFromID(window_id);
-      if (window!=NULL)
-      {
-         display=SDL_GetDisplayFromWindow(window);
-         if (display!=NULL)
-         {
-            didata=(SDL_DisplayData*)display->driverdata;
-            if (didata!=NULL)
-            {
-               wdata=(SDL_WindowData*)window->driverdata;
-               if (wdata==NULL)
-               {
-                  return -1;
-               }
-            }
-            else
-            {
-               return -1;
-            }
-         }
-         else
-         {
-            return -1;
-         }
-      }
-      else
-      {
-         return -1;
-      }
-   }
-
-   /* return if window widget has been destroyed already */
-   if (wdata->window==NULL)
-   {
-      return;
-   }
+        }
 
-   /* Check if we need to set new shape or disable cursor shape */
-   if (cursor!=NULL)
-   {
-      /* Retrieve photon cursor shape */
-      internal_cursor=(PhCursorDef_t*)cursor->driverdata;
-      if (internal_cursor==NULL)
-      {
-         SDL_SetError("Photon: Internal cursor data is absent");
-         return -1;
-      }
-
-      /* Setup cursor type */
-      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Failed to set cursor type to bitmap");
-         return -1;
-      }
-
-      /* Setup cursor color to default */
-      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Failed to set cursor color");
-         return -1;
-      }
+        /* Set cursor visible */
+        didata->cursor_visible = SDL_TRUE;
+    } else {
+        /* SDL requests to disable cursor */
+        status =
+            PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE,
+                          0);
+        if (status != 0) {
+            SDL_SetError("Photon: Can't disable cursor");
+            return -1;
+        }
 
-      /* Setup cursor shape */
-      status=PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, internal_cursor,
-                           internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Failed to set cursor color");
-         return -1;
-      }
-
-      /* Store current cursor for future usage */
-      if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)))
-      {
-         SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
-      }
-      else
-      {
-         /* Partitial cursor image */
-         SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
-      }
+        /* Set cursor invisible */
+        didata->cursor_visible = SDL_FALSE;
+    }
 
-      /* Set cursor visible */
-      didata->cursor_visible=SDL_TRUE;
-   }
-   else
-   {
-      /* SDL requests to disable cursor */
-      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
-      if (status!=0)
-      {
-         SDL_SetError("Photon: Can't disable cursor");
-         return -1;
-      }
+    /* Flush all pending widget data */
+    PtFlush();
 
-      /* Set cursor invisible */
-      didata->cursor_visible=SDL_FALSE;
-   }
-
-   /* Flush all pending widget data */
-   PtFlush();
-
-   /* New cursor shape is set */
-   return 0;
+    /* New cursor shape is set */
+    return 0;
 }
 
-void photon_movecursor(SDL_Cursor* cursor)
+void
+photon_movecursor(SDL_Cursor * cursor)
 {
-   SDL_VideoDisplay* display;
-   SDL_DisplayData*  didata;
-   SDL_Window*       window;
-   SDL_WindowData*   wdata;
-   SDL_WindowID window_id;
-   int32_t status;
+    SDL_VideoDisplay *display;
+    SDL_DisplayData *didata;
+    SDL_Window *window;
+    SDL_WindowData *wdata;
+    SDL_WindowID window_id;
+    int32_t status;
 
-   /* Get current window id */
-   window_id=SDL_GetFocusWindow();
-   if (window_id<=0)
-   {
-      didata=(SDL_DisplayData*)cursor->mouse->driverdata;
-   }
-   else
-   {
-      /* Sanity checks */
-      window=SDL_GetWindowFromID(window_id);
-      if (window!=NULL)
-      {
-         display=SDL_GetDisplayFromWindow(window);
-         if (display!=NULL)
-         {
-            didata=(SDL_DisplayData*)display->driverdata;
-            if (didata!=NULL)
-            {
-               wdata=(SDL_WindowData*)window->driverdata;
-               if (wdata==NULL)
-               {
-                  return;
-               }
+    /* Get current window id */
+    window_id = SDL_GetFocusWindow();
+    if (window_id <= 0) {
+        didata = (SDL_DisplayData *) cursor->mouse->driverdata;
+    } else {
+        /* Sanity checks */
+        window = SDL_GetWindowFromID(window_id);
+        if (window != NULL) {
+            display = SDL_GetDisplayFromWindow(window);
+            if (display != NULL) {
+                didata = (SDL_DisplayData *) display->driverdata;
+                if (didata != NULL) {
+                    wdata = (SDL_WindowData *) window->driverdata;
+                    if (wdata == NULL) {
+                        return;
+                    }
+                } else {
+                    return;
+                }
+            } else {
+                return;
             }
-            else
-            {
-               return;
-            }
-         }
-         else
-         {
+        } else {
             return;
-         }
-      }
-      else
-      {
-         return;
-      }
-   }
+        }
+    }
+
+    /* No need to move mouse cursor manually in the photon */
+
+    return;
+}
 
-   /* No need to move mouse cursor manually in the photon */
+void
+photon_freecursor(SDL_Cursor * cursor)
+{
+    PhCursorDef_t *internal_cursor = NULL;
 
-   return;
+    if (cursor != NULL) {
+        internal_cursor = (PhCursorDef_t *) cursor->driverdata;
+        if (internal_cursor != NULL) {
+            SDL_free(internal_cursor);
+            cursor->driverdata = NULL;
+        }
+    }
 }
 
-void photon_freecursor(SDL_Cursor* cursor)
+void
+photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
 {
-   PhCursorDef_t* internal_cursor=NULL;
+    SDL_VideoDisplay *display;
+    SDL_DisplayData *didata;
+    SDL_Window *window;
+    SDL_WindowData *wdata;
+    int16_t wx;
+    int16_t wy;
 
-   if (cursor!=NULL)
-   {
-      internal_cursor=(PhCursorDef_t*)cursor->driverdata;
-      if (internal_cursor!=NULL)
-      {
-         SDL_free(internal_cursor);
-         cursor->driverdata=NULL;
-      }
-   }
+    /* Sanity checks */
+    window = SDL_GetWindowFromID(windowID);
+    if (window != NULL) {
+        display = SDL_GetDisplayFromWindow(window);
+        if (display != NULL) {
+            didata = (SDL_DisplayData *) display->driverdata;
+            if (didata != NULL) {
+                wdata = (SDL_WindowData *) window->driverdata;
+                if (wdata == NULL) {
+                    return;
+                }
+            } else {
+                return;
+            }
+        } else {
+            return;
+        }
+    } else {
+        return;
+    }
+
+    PtGetAbsPosition(wdata->window, &wx, &wy);
+    PhMoveCursorAbs(PhInputGroup(NULL), wx + x, wy + y);
+
+    return;
 }
 
-void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y)
+void
+photon_freemouse(SDL_Mouse * mouse)
 {
-   SDL_VideoDisplay* display;
-   SDL_DisplayData*  didata;
-   SDL_Window*       window;
-   SDL_WindowData*   wdata;
-   int16_t           wx;
-   int16_t           wy;
+    if (mouse->driverdata == NULL) {
+        return;
+    }
 
-   /* Sanity checks */
-   window=SDL_GetWindowFromID(windowID);
-   if (window!=NULL)
-   {
-      display=SDL_GetDisplayFromWindow(window);
-      if (display!=NULL)
-      {
-         didata=(SDL_DisplayData*)display->driverdata;
-         if (didata!=NULL)
-         {
-            wdata=(SDL_WindowData*)window->driverdata;
-            if (wdata==NULL)
-            {
-               return;
-            }
-         }
-         else
-         {
-            return;
-         }
-      }
-      else
-      {
-         return;
-      }
-   }
-   else
-   {
-      return;
-   }
+    /* Mouse framework doesn't deletes automatically our driverdata */
+    SDL_free(mouse->driverdata);
+    mouse->driverdata = NULL;
 
-   PtGetAbsPosition(wdata->window, &wx, &wy);
-   PhMoveCursorAbs(PhInputGroup(NULL), wx+x, wy+y);
-
-   return;
-}
-
-void photon_freemouse(SDL_Mouse* mouse)
-{
-   if (mouse->driverdata==NULL)
-   {
-      return;
-   }
-
-   /* Mouse framework doesn't deletes automatically our driverdata */
-   SDL_free(mouse->driverdata);
-   mouse->driverdata=NULL;
-
-   return;
+    return;
 }
 
-SDL_scancode photon_to_sdl_keymap(uint32_t key)
+SDL_scancode
+photon_to_sdl_keymap(uint32_t key)
 {
-   SDL_scancode scancode=SDL_SCANCODE_UNKNOWN;
+    SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
 
-   switch(key & 0x0000007F)
-   {
-      case PHOTON_SCANCODE_ESCAPE:
-           scancode=SDL_SCANCODE_ESCAPE;
-           break;
-      case PHOTON_SCANCODE_F1:
-           scancode=SDL_SCANCODE_F1;
-           break;
-      case PHOTON_SCANCODE_F2:
-           scancode=SDL_SCANCODE_F2;
-           break;
-      case PHOTON_SCANCODE_F3:
-           scancode=SDL_SCANCODE_F3;
-           break;
-      case PHOTON_SCANCODE_F4:
-           scancode=SDL_SCANCODE_F4;
-           break;
-      case PHOTON_SCANCODE_F5:
-           scancode=SDL_SCANCODE_F5;
-           break;
-      case PHOTON_SCANCODE_F6:
-           scancode=SDL_SCANCODE_F6;
-           break;
-      case PHOTON_SCANCODE_F7:
-           scancode=SDL_SCANCODE_F7;
-           break;
-      case PHOTON_SCANCODE_F8:
-           scancode=SDL_SCANCODE_F8;
-           break;
-      case PHOTON_SCANCODE_F9:
-           scancode=SDL_SCANCODE_F9;
-           break;
-      case PHOTON_SCANCODE_F10:
-           scancode=SDL_SCANCODE_F10;
-           break;
-      case PHOTON_SCANCODE_F11:
-           scancode=SDL_SCANCODE_F11;
-           break;
-      case PHOTON_SCANCODE_F12:
-           scancode=SDL_SCANCODE_F12;
-           break;
-      case PHOTON_SCANCODE_BACKQOUTE:
-           scancode=SDL_SCANCODE_GRAVE;
-           break;
-      case PHOTON_SCANCODE_1:
-           scancode=SDL_SCANCODE_1;
-           break;
-      case PHOTON_SCANCODE_2:
-           scancode=SDL_SCANCODE_2;
-           break;
-      case PHOTON_SCANCODE_3:
-           scancode=SDL_SCANCODE_3;
-           break;
-      case PHOTON_SCANCODE_4:
-           scancode=SDL_SCANCODE_4;
-           break;
-      case PHOTON_SCANCODE_5:
-           scancode=SDL_SCANCODE_5;
-           break;
-      case PHOTON_SCANCODE_6:
-           scancode=SDL_SCANCODE_6;
-           break;
-      case PHOTON_SCANCODE_7:
-           scancode=SDL_SCANCODE_7;
-           break;
-      case PHOTON_SCANCODE_8:
-           scancode=SDL_SCANCODE_8;
-           break;
-      case PHOTON_SCANCODE_9:
-           scancode=SDL_SCANCODE_9;
-           break;
-      case PHOTON_SCANCODE_0:
-           scancode=SDL_SCANCODE_0;
-           break;
-      case PHOTON_SCANCODE_MINUS:
-           scancode=SDL_SCANCODE_MINUS;
-           break;
-      case PHOTON_SCANCODE_EQUAL:
-           scancode=SDL_SCANCODE_EQUALS;
-           break;
-      case PHOTON_SCANCODE_BACKSPACE:
-           scancode=SDL_SCANCODE_BACKSPACE;
-           break;
-      case PHOTON_SCANCODE_TAB:
-           scancode=SDL_SCANCODE_TAB;
-           break;
-      case PHOTON_SCANCODE_Q:
-           scancode=SDL_SCANCODE_Q;
-           break;
-      case PHOTON_SCANCODE_W:
-           scancode=SDL_SCANCODE_W;
-           break;
-      case PHOTON_SCANCODE_E:
-           scancode=SDL_SCANCODE_E;
-           break;
-      case PHOTON_SCANCODE_R:
-           scancode=SDL_SCANCODE_R;
-           break;
-      case PHOTON_SCANCODE_T:
-           scancode=SDL_SCANCODE_T;
-           break;
-      case PHOTON_SCANCODE_Y:
-           scancode=SDL_SCANCODE_Y;
-           break;
-      case PHOTON_SCANCODE_U:
-           scancode=SDL_SCANCODE_U;
-           break;
-      case PHOTON_SCANCODE_I:
-           scancode=SDL_SCANCODE_I;
-           break;
-      case PHOTON_SCANCODE_O:
-           scancode=SDL_SCANCODE_O;
-           break;
-      case PHOTON_SCANCODE_P:
-           scancode=SDL_SCANCODE_P;
-           break;
-      case PHOTON_SCANCODE_LEFT_SQ_BR:
-           scancode=SDL_SCANCODE_LEFTBRACKET;
-           break;
-      case PHOTON_SCANCODE_RIGHT_SQ_BR:
-           scancode=SDL_SCANCODE_RIGHTBRACKET;
-           break;
-      case PHOTON_SCANCODE_ENTER:
-           scancode=SDL_SCANCODE_RETURN;
-           break;
-      case PHOTON_SCANCODE_CAPSLOCK:
-           scancode=SDL_SCANCODE_CAPSLOCK;
-           break;
-      case PHOTON_SCANCODE_A:
-           scancode=SDL_SCANCODE_A;
-           break;
-      case PHOTON_SCANCODE_S:
-           scancode=SDL_SCANCODE_S;
-           break;
-      case PHOTON_SCANCODE_D:
-           scancode=SDL_SCANCODE_D;
-           break;
-      case PHOTON_SCANCODE_F:
-           scancode=SDL_SCANCODE_F;
-           break;
-      case PHOTON_SCANCODE_G:
-           scancode=SDL_SCANCODE_G;
-           break;
-      case PHOTON_SCANCODE_H:
-           scancode=SDL_SCANCODE_H;
-           break;
-      case PHOTON_SCANCODE_J:
-           scancode=SDL_SCANCODE_J;
-           break;
-      case PHOTON_SCANCODE_K:
-           scancode=SDL_SCANCODE_K;
-           break;
-      case PHOTON_SCANCODE_L:
-           scancode=SDL_SCANCODE_L;
-           break;
-      case PHOTON_SCANCODE_SEMICOLON:
-           scancode=SDL_SCANCODE_SEMICOLON;
-           break;
-      case PHOTON_SCANCODE_QUOTE:
-           scancode=SDL_SCANCODE_APOSTROPHE;
-           break;
-      case PHOTON_SCANCODE_BACKSLASH:
-           scancode=SDL_SCANCODE_BACKSLASH;
-           break;
-      case PHOTON_SCANCODE_LEFT_SHIFT:
-           scancode=SDL_SCANCODE_LSHIFT;
-           break;
-      case PHOTON_SCANCODE_Z:
-           scancode=SDL_SCANCODE_Z;
-           break;
-      case PHOTON_SCANCODE_X:
-           scancode=SDL_SCANCODE_X;
-           break;
-      case PHOTON_SCANCODE_C:
-           scancode=SDL_SCANCODE_C;
-           break;
-      case PHOTON_SCANCODE_V:
-           scancode=SDL_SCANCODE_V;
-           break;
-      case PHOTON_SCANCODE_B:
-           scancode=SDL_SCANCODE_B;
-           break;
-      case PHOTON_SCANCODE_N:
-           scancode=SDL_SCANCODE_N;
-           break;
-      case PHOTON_SCANCODE_M:
-           scancode=SDL_SCANCODE_M;
-           break;
-      case PHOTON_SCANCODE_COMMA:
-           scancode=SDL_SCANCODE_COMMA;
-           break;
-      case PHOTON_SCANCODE_POINT:
-           scancode=SDL_SCANCODE_PERIOD;
-           break;
-      case PHOTON_SCANCODE_SLASH:
-           scancode=SDL_SCANCODE_SLASH;
-           break;
-      case PHOTON_SCANCODE_RIGHT_SHIFT:
-           scancode=SDL_SCANCODE_RSHIFT;
-           break;
-      case PHOTON_SCANCODE_CTRL:
-           scancode=SDL_SCANCODE_LCTRL;
-           break;
-      case PHOTON_SCANCODE_WFLAG:
-           scancode=SDL_SCANCODE_LGUI;
-           break;
-      case PHOTON_SCANCODE_ALT:
-           scancode=SDL_SCANCODE_LALT;
-           break;
-      case PHOTON_SCANCODE_SPACE:
-           scancode=SDL_SCANCODE_SPACE;
-           break;
-      case PHOTON_SCANCODE_MENU:
-           scancode=SDL_SCANCODE_MENU;
-           break;
-      case PHOTON_SCANCODE_PRNSCR:
-           scancode=SDL_SCANCODE_PRINTSCREEN;
-           break;
-      case PHOTON_SCANCODE_SCROLLLOCK:
-           scancode=SDL_SCANCODE_SCROLLLOCK;
-           break;
-      case PHOTON_SCANCODE_INSERT:
-           scancode=SDL_SCANCODE_INSERT;
-           break;
-      case PHOTON_SCANCODE_HOME:
-           scancode=SDL_SCANCODE_HOME;
-           break;
-      case PHOTON_SCANCODE_PAGEUP:
-           scancode=SDL_SCANCODE_PAGEUP;
-           break;
-      case PHOTON_SCANCODE_DELETE:
-           scancode=SDL_SCANCODE_DELETE;
-           break;
-      case PHOTON_SCANCODE_END:
-           scancode=SDL_SCANCODE_END;
-           break;
-      case PHOTON_SCANCODE_PAGEDOWN:
-           scancode=SDL_SCANCODE_PAGEDOWN;
-           break;
-      case PHOTON_SCANCODE_UP:
-           scancode=SDL_SCANCODE_UP;
-           break;
-      case PHOTON_SCANCODE_DOWN:
-           scancode=SDL_SCANCODE_DOWN;
-           break;
-      case PHOTON_SCANCODE_LEFT:
-           scancode=SDL_SCANCODE_LEFT;
-           break;
-      case PHOTON_SCANCODE_RIGHT:
-           scancode=SDL_SCANCODE_RIGHT;
-           break;
-      case PHOTON_SCANCODE_NUMLOCK:
-           scancode=SDL_SCANCODE_NUMLOCKCLEAR;
-           break;
-      default:
-           break;
-   }
+    switch (key & 0x0000007F) {
+    case PHOTON_SCANCODE_ESCAPE:
+        scancode = SDL_SCANCODE_ESCAPE;
+        break;
+    case PHOTON_SCANCODE_F1:
+        scancode = SDL_SCANCODE_F1;
+        break;
+    case PHOTON_SCANCODE_F2:
+        scancode = SDL_SCANCODE_F2;
+        break;
+    case PHOTON_SCANCODE_F3:
+        scancode = SDL_SCANCODE_F3;
+        break;
+    case PHOTON_SCANCODE_F4:
+        scancode = SDL_SCANCODE_F4;
+        break;
+    case PHOTON_SCANCODE_F5:
+        scancode = SDL_SCANCODE_F5;
+        break;
+    case PHOTON_SCANCODE_F6:
+        scancode = SDL_SCANCODE_F6;
+        break;
+    case PHOTON_SCANCODE_F7:
+        scancode = SDL_SCANCODE_F7;
+        break;
+    case PHOTON_SCANCODE_F8:
+        scancode = SDL_SCANCODE_F8;
+        break;
+    case PHOTON_SCANCODE_F9:
+        scancode = SDL_SCANCODE_F9;
+        break;
+    case PHOTON_SCANCODE_F10:
+        scancode = SDL_SCANCODE_F10;
+        break;
+    case PHOTON_SCANCODE_F11:
+        scancode = SDL_SCANCODE_F11;
+        break;
+    case PHOTON_SCANCODE_F12:
+        scancode = SDL_SCANCODE_F12;
+        break;
+    case PHOTON_SCANCODE_BACKQOUTE:
+        scancode = SDL_SCANCODE_GRAVE;
+        break;
+    case PHOTON_SCANCODE_1:
+        scancode = SDL_SCANCODE_1;
+        break;
+    case PHOTON_SCANCODE_2:
+        scancode = SDL_SCANCODE_2;
+        break;
+    case PHOTON_SCANCODE_3:
+        scancode = SDL_SCANCODE_3;
+        break;
+    case PHOTON_SCANCODE_4:
+        scancode = SDL_SCANCODE_4;
+        break;
+    case PHOTON_SCANCODE_5:
+        scancode = SDL_SCANCODE_5;
+        break;
+    case PHOTON_SCANCODE_6:
+        scancode = SDL_SCANCODE_6;
+        break;
+    case PHOTON_SCANCODE_7:
+        scancode = SDL_SCANCODE_7;
+        break;
+    case PHOTON_SCANCODE_8:
+        scancode = SDL_SCANCODE_8;
+        break;
+    case PHOTON_SCANCODE_9:
+        scancode = SDL_SCANCODE_9;
+        break;
+    case PHOTON_SCANCODE_0:
+        scancode = SDL_SCANCODE_0;
+        break;
+    case PHOTON_SCANCODE_MINUS:
+        scancode = SDL_SCANCODE_MINUS;
+        break;
+    case PHOTON_SCANCODE_EQUAL:
+        scancode = SDL_SCANCODE_EQUALS;
+        break;
+    case PHOTON_SCANCODE_BACKSPACE:
+        scancode = SDL_SCANCODE_BACKSPACE;
+        break;
+    case PHOTON_SCANCODE_TAB:
+        scancode = SDL_SCANCODE_TAB;
+        break;
+    case PHOTON_SCANCODE_Q:
+        scancode = SDL_SCANCODE_Q;
+        break;
+    case PHOTON_SCANCODE_W:
+        scancode = SDL_SCANCODE_W;
+        break;
+    case PHOTON_SCANCODE_E:
+        scancode = SDL_SCANCODE_E;
+        break;
+    case PHOTON_SCANCODE_R:
+        scancode = SDL_SCANCODE_R;
+        break;
+    case PHOTON_SCANCODE_T:
+        scancode = SDL_SCANCODE_T;
+        break;
+    case PHOTON_SCANCODE_Y:
+        scancode = SDL_SCANCODE_Y;
+        break;
+    case PHOTON_SCANCODE_U:
+        scancode = SDL_SCANCODE_U;
+        break;
+    case PHOTON_SCANCODE_I:
+        scancode = SDL_SCANCODE_I;
+        break;
+    case PHOTON_SCANCODE_O:
+        scancode = SDL_SCANCODE_O;
+        break;
+    case PHOTON_SCANCODE_P:
+        scancode = SDL_SCANCODE_P;
+        break;
+    case PHOTON_SCANCODE_LEFT_SQ_BR:
+        scancode = SDL_SCANCODE_LEFTBRACKET;
+        break;
+    case PHOTON_SCANCODE_RIGHT_SQ_BR:
+        scancode = SDL_SCANCODE_RIGHTBRACKET;
+        break;
+    case PHOTON_SCANCODE_ENTER:
+        scancode = SDL_SCANCODE_RETURN;
+        break;
+    case PHOTON_SCANCODE_CAPSLOCK:
+        scancode = SDL_SCANCODE_CAPSLOCK;
+        break;
+    case PHOTON_SCANCODE_A:
+        scancode = SDL_SCANCODE_A;
+        break;
+    case PHOTON_SCANCODE_S:
+        scancode = SDL_SCANCODE_S;
+        break;
+    case PHOTON_SCANCODE_D:
+        scancode = SDL_SCANCODE_D;
+        break;
+    case PHOTON_SCANCODE_F:
+        scancode = SDL_SCANCODE_F;
+        break;
+    case PHOTON_SCANCODE_G:
+        scancode = SDL_SCANCODE_G;
+        break;
+    case PHOTON_SCANCODE_H:
+        scancode = SDL_SCANCODE_H;
+        break;
+    case PHOTON_SCANCODE_J:
+        scancode = SDL_SCANCODE_J;
+        break;
+    case PHOTON_SCANCODE_K:
+        scancode = SDL_SCANCODE_K;
+        break;
+    case PHOTON_SCANCODE_L:
+        scancode = SDL_SCANCODE_L;
+        break;
+    case PHOTON_SCANCODE_SEMICOLON:
+        scancode = SDL_SCANCODE_SEMICOLON;
+        break;
+    case PHOTON_SCANCODE_QUOTE:
+        scancode = SDL_SCANCODE_APOSTROPHE;
+        break;
+    case PHOTON_SCANCODE_BACKSLASH:
+        scancode = SDL_SCANCODE_BACKSLASH;
+        break;
+    case PHOTON_SCANCODE_LEFT_SHIFT:
+        scancode = SDL_SCANCODE_LSHIFT;
+        break;
+    case PHOTON_SCANCODE_Z:
+        scancode = SDL_SCANCODE_Z;
+        break;
+    case PHOTON_SCANCODE_X:
+        scancode = SDL_SCANCODE_X;
+        break;
+    case PHOTON_SCANCODE_C:
+        scancode = SDL_SCANCODE_C;
+        break;
+    case PHOTON_SCANCODE_V:
+        scancode = SDL_SCANCODE_V;
+        break;
+    case PHOTON_SCANCODE_B:
+        scancode = SDL_SCANCODE_B;
+        break;
+    case PHOTON_SCANCODE_N:
+        scancode = SDL_SCANCODE_N;
+        break;
+    case PHOTON_SCANCODE_M:
+        scancode = SDL_SCANCODE_M;
+        break;
+    case PHOTON_SCANCODE_COMMA:
+        scancode = SDL_SCANCODE_COMMA;
+        break;
+    case PHOTON_SCANCODE_POINT:
+        scancode = SDL_SCANCODE_PERIOD;
+        break;
+    case PHOTON_SCANCODE_SLASH:
+        scancode = SDL_SCANCODE_SLASH;
+        break;
+    case PHOTON_SCANCODE_RIGHT_SHIFT:
+        scancode = SDL_SCANCODE_RSHIFT;
+        break;
+    case PHOTON_SCANCODE_CTRL:
+        scancode = SDL_SCANCODE_LCTRL;
+        break;
+    case PHOTON_SCANCODE_WFLAG:
+        scancode = SDL_SCANCODE_LGUI;
+        break;
+    case PHOTON_SCANCODE_ALT:
+        scancode = SDL_SCANCODE_LALT;
+        break;
+    case PHOTON_SCANCODE_SPACE:
+        scancode = SDL_SCANCODE_SPACE;
+        break;
+    case PHOTON_SCANCODE_MENU:
+        scancode = SDL_SCANCODE_MENU;
+        break;
+    case PHOTON_SCANCODE_PRNSCR:
+        scancode = SDL_SCANCODE_PRINTSCREEN;
+        break;
+    case PHOTON_SCANCODE_SCROLLLOCK:
+        scancode = SDL_SCANCODE_SCROLLLOCK;
+        break;
+    case PHOTON_SCANCODE_INSERT:
+        scancode = SDL_SCANCODE_INSERT;
+        break;
+    case PHOTON_SCANCODE_HOME:
+        scancode = SDL_SCANCODE_HOME;
+        break;
+    case PHOTON_SCANCODE_PAGEUP:
+        scancode = SDL_SCANCODE_PAGEUP;
+        break;
+    case PHOTON_SCANCODE_DELETE:
+        scancode = SDL_SCANCODE_DELETE;
+        break;
+    case PHOTON_SCANCODE_END:
+        scancode = SDL_SCANCODE_END;
+        break;
+    case PHOTON_SCANCODE_PAGEDOWN:
+        scancode = SDL_SCANCODE_PAGEDOWN;
+        break;
+    case PHOTON_SCANCODE_UP:
+        scancode = SDL_SCANCODE_UP;
+        break;
+    case PHOTON_SCANCODE_DOWN:
+        scancode = SDL_SCANCODE_DOWN;
+        break;
+    case PHOTON_SCANCODE_LEFT:
+        scancode = SDL_SCANCODE_LEFT;
+        break;
+    case PHOTON_SCANCODE_RIGHT:
+        scancode = SDL_SCANCODE_RIGHT;
+        break;
+    case PHOTON_SCANCODE_NUMLOCK:
+        scancode = SDL_SCANCODE_NUMLOCKCLEAR;
+        break;
+    default:
+        break;
+    }
 
-   return scancode;
+    return scancode;
 }
--- a/src/video/photon/SDL_photon_input.h	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon_input.h	Sat May 23 22:41:08 2009 +0000
@@ -35,7 +35,7 @@
 
 typedef struct SDL_MouseData
 {
-   SDL_DisplayData* didata;
+    SDL_DisplayData *didata;
 } SDL_MouseData;
 
 int32_t photon_addinputdevices(_THIS);
--- a/src/video/photon/SDL_photon_keycodes.h	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon_keycodes.h	Sat May 23 22:41:08 2009 +0000
@@ -104,9 +104,11 @@
 #define PHOTON_SCANCODE_SPACE       0x39
 #define PHOTON_SCANCODE_MENU        0x5D
 
-#define PHOTON_SCANCODE_PRNSCR      0x54   /* only key pressed event, no release */
+#define PHOTON_SCANCODE_PRNSCR      0x54        /* only key pressed event, no release */
 #define PHOTON_SCANCODE_SCROLLLOCK  0x46
-/* #define PHOTON_SCANCODE_PAUSE 0x?? */   /* pause doesn't generates a scancode */
+#if 0                           /* pause doesn't generates a scancode */
+#define PHOTON_SCANCODE_PAUSE       0x??
+#endif
 #define PHOTON_SCANCODE_INSERT      0x52
 #define PHOTON_SCANCODE_HOME        0x47
 #define PHOTON_SCANCODE_PAGEUP      0x49
--- a/src/video/photon/SDL_photon_pixelfmt.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon_pixelfmt.c	Sat May 23 22:41:08 2009 +0000
@@ -26,173 +26,173 @@
 
 #include "SDL_photon_pixelfmt.h"
 
-uint32_t photon_bits_to_sdl_pixelformat(uint32_t pixelfmt)
+uint32_t
+photon_bits_to_sdl_pixelformat(uint32_t pixelfmt)
 {
-   switch(pixelfmt)
-   {
-      case 8:
-           {
-              return SDL_PIXELFORMAT_INDEX8;
-           }
-           break;
-      case 15:
-           {
-              return SDL_PIXELFORMAT_ARGB1555;
-           }
-           break;
-      case 16:
-           {
-              return SDL_PIXELFORMAT_RGB565;
-           }
-           break;
-      case 24:
-           {
-              return SDL_PIXELFORMAT_RGB888;
-           }
-           break;
-      case 32:
-           {
-              return SDL_PIXELFORMAT_ARGB8888;
-           }
-           break;
-   }
+    switch (pixelfmt) {
+    case 8:
+        {
+            return SDL_PIXELFORMAT_INDEX8;
+        }
+        break;
+    case 15:
+        {
+            return SDL_PIXELFORMAT_ARGB1555;
+        }
+        break;
+    case 16:
+        {
+            return SDL_PIXELFORMAT_RGB565;
+        }
+        break;
+    case 24:
+        {
+            return SDL_PIXELFORMAT_RGB888;
+        }
+        break;
+    case 32:
+        {
+            return SDL_PIXELFORMAT_ARGB8888;
+        }
+        break;
+    }
 }
 
-uint32_t photon_sdl_to_bits_pixelformat(uint32_t pixelfmt)
+uint32_t
+photon_sdl_to_bits_pixelformat(uint32_t pixelfmt)
 {
-   switch(pixelfmt)
-   {
-      case SDL_PIXELFORMAT_INDEX8:
-           {
-              return 8;
-           }
-           break;
-      case SDL_PIXELFORMAT_ARGB1555:
-           {
-              return 15;
-           }
-           break;
-      case SDL_PIXELFORMAT_ABGR1555:
-           {
-              return 15;
-           }
-           break;
-      case SDL_PIXELFORMAT_RGB565:
-           {
-              return 16;
-           }
-           break;
-      case SDL_PIXELFORMAT_RGB888:
-           {
-              return 24;
-           }
-           break;
-      case SDL_PIXELFORMAT_BGRA8888:
-           {
-              return 32;
-           }
-           break;
-      case SDL_PIXELFORMAT_ARGB8888:
-           {
-              return 32;
-           }
-           break;
-      case SDL_PIXELFORMAT_YV12:
-           {
-              return 8;
-           }
-           break;
-      case SDL_PIXELFORMAT_YUY2:
-           {
-              return 16;
-           }
-           break;
-      case SDL_PIXELFORMAT_UYVY:
-           {
-              return 16;
-           }
-           break;
-      case SDL_PIXELFORMAT_YVYU:
-           {
-              return 16;
-           }
-           break;
-   }
+    switch (pixelfmt) {
+    case SDL_PIXELFORMAT_INDEX8:
+        {
+            return 8;
+        }
+        break;
+    case SDL_PIXELFORMAT_ARGB1555:
+        {
+            return 15;
+        }
+        break;
+    case SDL_PIXELFORMAT_ABGR1555:
+        {
+            return 15;
+        }
+        break;
+    case SDL_PIXELFORMAT_RGB565:
+        {
+            return 16;
+        }
+        break;
+    case SDL_PIXELFORMAT_RGB888:
+        {
+            return 24;
+        }
+        break;
+    case SDL_PIXELFORMAT_BGRA8888:
+        {
+            return 32;
+        }
+        break;
+    case SDL_PIXELFORMAT_ARGB8888:
+        {
+            return 32;
+        }
+        break;
+    case SDL_PIXELFORMAT_YV12:
+        {
+            return 8;
+        }
+        break;
+    case SDL_PIXELFORMAT_YUY2:
+        {
+            return 16;
+        }
+        break;
+    case SDL_PIXELFORMAT_UYVY:
+        {
+            return 16;
+        }
+        break;
+    case SDL_PIXELFORMAT_YVYU:
+        {
+            return 16;
+        }
+        break;
+    }
 
-   return 0;
+    return 0;
 }
 
-uint32_t photon_image_to_sdl_pixelformat(uint32_t pixelfmt)
+uint32_t
+photon_image_to_sdl_pixelformat(uint32_t pixelfmt)
 {
-   switch(pixelfmt)
-   {
-      case Pg_IMAGE_PALETTE_BYTE:
-           {
-              return SDL_PIXELFORMAT_INDEX8;
-           }
-           break;
-      case Pg_IMAGE_DIRECT_8888:
-           {
-              return SDL_PIXELFORMAT_BGRA8888;
-           }
-           break;
-      case Pg_IMAGE_DIRECT_888:
-           {
-              return SDL_PIXELFORMAT_RGB888;
-           }
-           break;
-      case Pg_IMAGE_DIRECT_565:
-           {
-              return SDL_PIXELFORMAT_RGB565;
-           }
-           break;
-      case Pg_IMAGE_DIRECT_555:
-           {
-              return SDL_PIXELFORMAT_RGB555;
-           }
-           break;
-      case Pg_IMAGE_DIRECT_1555:
-           {
-              return SDL_PIXELFORMAT_ARGB1555;
-           }
-           break;
-   }
+    switch (pixelfmt) {
+    case Pg_IMAGE_PALETTE_BYTE:
+        {
+            return SDL_PIXELFORMAT_INDEX8;
+        }
+        break;
+    case Pg_IMAGE_DIRECT_8888:
+        {
+            return SDL_PIXELFORMAT_BGRA8888;
+        }
+        break;
+    case Pg_IMAGE_DIRECT_888:
+        {
+            return SDL_PIXELFORMAT_RGB888;
+        }
+        break;
+    case Pg_IMAGE_DIRECT_565:
+        {
+            return SDL_PIXELFORMAT_RGB565;
+        }
+        break;
+    case Pg_IMAGE_DIRECT_555:
+        {
+            return SDL_PIXELFORMAT_RGB555;
+        }
+        break;
+    case Pg_IMAGE_DIRECT_1555:
+        {
+            return SDL_PIXELFORMAT_ARGB1555;
+        }
+        break;
+    }
 
-   return 0;
+    return 0;
 }
 
-uint32_t photon_sdl_to_image_pixelformat(uint32_t pixelfmt)
+uint32_t
+photon_sdl_to_image_pixelformat(uint32_t pixelfmt)
 {
-   switch(pixelfmt)
-   {
-      case SDL_PIXELFORMAT_INDEX8:
-           {
-              return Pg_IMAGE_PALETTE_BYTE;
-           }
-           break;
-      case SDL_PIXELFORMAT_BGRA8888:
-           {
-              return Pg_IMAGE_DIRECT_8888;
-           }
-           break;
-      case SDL_PIXELFORMAT_RGB888:
-           {
-              return Pg_IMAGE_DIRECT_888;
-           }
-           break;
-      case SDL_PIXELFORMAT_RGB565:
-           {
-              return Pg_IMAGE_DIRECT_565;
-           }
-           break;
-      case SDL_PIXELFORMAT_ARGB1555:
-           {
-              return Pg_IMAGE_DIRECT_1555;
-           }
-           break;
-   }
+    switch (pixelfmt) {
+    case SDL_PIXELFORMAT_INDEX8:
+        {
+            return Pg_IMAGE_PALETTE_BYTE;
+        }
+        break;
+    case SDL_PIXELFORMAT_BGRA8888:
+        {
+            return Pg_IMAGE_DIRECT_8888;
+        }
+        break;
+    case SDL_PIXELFORMAT_RGB888:
+        {
+            return Pg_IMAGE_DIRECT_888;
+        }
+        break;
+    case SDL_PIXELFORMAT_RGB565:
+        {
+            return Pg_IMAGE_DIRECT_565;
+        }
+        break;
+    case SDL_PIXELFORMAT_ARGB1555:
+        {
+            return Pg_IMAGE_DIRECT_1555;
+        }
+        break;
+    }
 
-   return 0;
+    return 0;
 }
 
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/photon/SDL_photon_render.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon_render.c	Sat May 23 22:41:08 2009 +0000
@@ -34,308 +34,343 @@
 #include "SDL_photon_render.h"
 #include "SDL_photon.h"
 
-static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags);
-static int  photon_displaymodechanged(SDL_Renderer* renderer);
-static int  photon_activaterenderer(SDL_Renderer* renderer);
-static int  photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture);
-static int  photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch);
-static int  photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors);
-static int  photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors);
-static int  photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture);
-static int  photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture);
-static int  photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture);
-static int  photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture);
-static int  photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch);
-static int  photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch);
-static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture);
-static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects);
-static int  photon_renderpoint(SDL_Renderer* renderer, int x, int y);
-static int  photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2);
-static int  photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect);
-static int  photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
-static void photon_renderpresent(SDL_Renderer* renderer);
-static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture);
-static void photon_destroyrenderer(SDL_Renderer* renderer);
+static SDL_Renderer *photon_createrenderer(SDL_Window * window, Uint32 flags);
+static int photon_displaymodechanged(SDL_Renderer * renderer);
+static int photon_activaterenderer(SDL_Renderer * renderer);
+static int photon_createtexture(SDL_Renderer * renderer,
+                                SDL_Texture * texture);
+static int photon_querytexturepixels(SDL_Renderer * renderer,
+                                     SDL_Texture * texture, void **pixels,
+                                     int *pitch);
+static int photon_settexturepalette(SDL_Renderer * renderer,
+                                    SDL_Texture * texture,
+                                    const SDL_Color * colors, int firstcolor,
+                                    int ncolors);
+static int photon_gettexturepalette(SDL_Renderer * renderer,
+                                    SDL_Texture * texture, SDL_Color * colors,
+                                    int firstcolor, int ncolors);
+static int photon_settexturecolormod(SDL_Renderer * renderer,
+                                     SDL_Texture * texture);
+static int photon_settexturealphamod(SDL_Renderer * renderer,
+                                     SDL_Texture * texture);
+static int photon_settextureblendmode(SDL_Renderer * renderer,
+                                      SDL_Texture * texture);
+static int photon_settexturescalemode(SDL_Renderer * renderer,
+                                      SDL_Texture * texture);
+static int photon_updatetexture(SDL_Renderer * renderer,
+                                SDL_Texture * texture, const SDL_Rect * rect,
+                                const void *pixels, int pitch);
+static int photon_locktexture(SDL_Renderer * renderer, SDL_Texture * texture,
+                              const SDL_Rect * rect, int markDirty,
+                              void **pixels, int *pitch);
+static void photon_unlocktexture(SDL_Renderer * renderer,
+                                 SDL_Texture * texture);
+static void photon_dirtytexture(SDL_Renderer * renderer,
+                                SDL_Texture * texture, int numrects,
+                                const SDL_Rect * rects);
+static int photon_renderpoint(SDL_Renderer * renderer, int x, int y);
+static int photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2,
+                             int y2);
+static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect);
+static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
+                             const SDL_Rect * srcrect,
+                             const SDL_Rect * dstrect);
+static void photon_renderpresent(SDL_Renderer * renderer);
+static void photon_destroytexture(SDL_Renderer * renderer,
+                                  SDL_Texture * texture);
+static void photon_destroyrenderer(SDL_Renderer * renderer);
 
-SDL_RenderDriver photon_renderdriver=
-{
+SDL_RenderDriver photon_renderdriver = {
     photon_createrenderer,
     {
-       "photon",
-       (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
-        SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
-        SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD |
-        SDL_RENDERER_ACCELERATED),
-       (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
-        SDL_TEXTUREMODULATE_ALPHA),
-       (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
-        SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
-       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW),
-       13,
-       {
-          SDL_PIXELFORMAT_INDEX8,
-          SDL_PIXELFORMAT_RGB555,
-          SDL_PIXELFORMAT_RGB565,
-          SDL_PIXELFORMAT_RGB888,
-          SDL_PIXELFORMAT_BGR888,
-          SDL_PIXELFORMAT_ARGB8888,
-          SDL_PIXELFORMAT_RGBA8888,
-          SDL_PIXELFORMAT_ABGR8888,
-          SDL_PIXELFORMAT_BGRA8888,
-          SDL_PIXELFORMAT_YV12,
-          SDL_PIXELFORMAT_YUY2,
-          SDL_PIXELFORMAT_UYVY,
-          SDL_PIXELFORMAT_YVYU
-       },
-       0,
-       0
-    }
+     "photon",
+     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
+      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
+      SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_PRESENTDISCARD |
+      SDL_RENDERER_ACCELERATED),
+     (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
+      SDL_TEXTUREMODULATE_ALPHA),
+     (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
+      SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
+     (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_SLOW),
+     13,
+     {
+      SDL_PIXELFORMAT_INDEX8,
+      SDL_PIXELFORMAT_RGB555,
+      SDL_PIXELFORMAT_RGB565,
+      SDL_PIXELFORMAT_RGB888,
+      SDL_PIXELFORMAT_BGR888,
+      SDL_PIXELFORMAT_ARGB8888,
+      SDL_PIXELFORMAT_RGBA8888,
+      SDL_PIXELFORMAT_ABGR8888,
+      SDL_PIXELFORMAT_BGRA8888,
+      SDL_PIXELFORMAT_YV12,
+      SDL_PIXELFORMAT_YUY2,
+      SDL_PIXELFORMAT_UYVY,
+      SDL_PIXELFORMAT_YVYU},
+     0,
+     0}
 };
 
-static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags)
+static SDL_Renderer *
+photon_createrenderer(SDL_Window * window, Uint32 flags)
 {
-   SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(window);
-   SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata;
-   SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata;
-   SDL_Renderer* renderer = NULL;
-   SDL_RenderData* rdata = NULL;
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    SDL_Renderer *renderer = NULL;
+    SDL_RenderData *rdata = NULL;
 
-   /* Allocate new renderer structure */
-   renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer));
-   if (renderer==NULL)
-   {
-      SDL_OutOfMemory();
-      return NULL;
-   }
+    /* Allocate new renderer structure */
+    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(SDL_Renderer));
+    if (renderer == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
-   /* Allocate renderer data */
-   rdata=(SDL_RenderData*)SDL_calloc(1, sizeof(SDL_RenderData));
-   if (rdata==NULL)
-   {
-      SDL_free(renderer);
-      SDL_OutOfMemory();
-      return NULL;
-   }
+    /* Allocate renderer data */
+    rdata = (SDL_RenderData *) SDL_calloc(1, sizeof(SDL_RenderData));
+    if (rdata == NULL) {
+        SDL_free(renderer);
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
-   renderer->DisplayModeChanged=photon_displaymodechanged;
-   renderer->ActivateRenderer=photon_activaterenderer;
-   renderer->CreateTexture=photon_createtexture;
-   renderer->QueryTexturePixels=photon_querytexturepixels;
-   renderer->SetTexturePalette=photon_settexturepalette;
-   renderer->GetTexturePalette=photon_gettexturepalette;
-   renderer->SetTextureAlphaMod=photon_settexturealphamod;
-   renderer->SetTextureColorMod=photon_settexturecolormod;
-   renderer->SetTextureBlendMode=photon_settextureblendmode;
-   renderer->SetTextureScaleMode=photon_settexturescalemode;
-   renderer->UpdateTexture=photon_updatetexture;
-   renderer->LockTexture=photon_locktexture;
-   renderer->UnlockTexture=photon_unlocktexture;
-   renderer->DirtyTexture=photon_dirtytexture;
-   renderer->RenderPoint=photon_renderpoint;
-   renderer->RenderLine=photon_renderline;
-   renderer->RenderFill=photon_renderfill;
-   renderer->RenderCopy=photon_rendercopy;
-   renderer->RenderPresent = photon_renderpresent;
-   renderer->DestroyTexture = photon_destroytexture;
-   renderer->DestroyRenderer = photon_destroyrenderer;
-   renderer->info = photon_renderdriver.info;
-   renderer->window = window->id;
-   renderer->driverdata = rdata;
+    renderer->DisplayModeChanged = photon_displaymodechanged;
+    renderer->ActivateRenderer = photon_activaterenderer;
+    renderer->CreateTexture = photon_createtexture;
+    renderer->QueryTexturePixels = photon_querytexturepixels;
+    renderer->SetTexturePalette = photon_settexturepalette;
+    renderer->GetTexturePalette = photon_gettexturepalette;
+    renderer->SetTextureAlphaMod = photon_settexturealphamod;
+    renderer->SetTextureColorMod = photon_settexturecolormod;
+    renderer->SetTextureBlendMode = photon_settextureblendmode;
+    renderer->SetTextureScaleMode = photon_settexturescalemode;
+    renderer->UpdateTexture = photon_updatetexture;
+    renderer->LockTexture = photon_locktexture;
+    renderer->UnlockTexture = photon_unlocktexture;
+    renderer->DirtyTexture = photon_dirtytexture;
+    renderer->RenderPoint = photon_renderpoint;
+    renderer->RenderLine = photon_renderline;
+    renderer->RenderFill = photon_renderfill;
+    renderer->RenderCopy = photon_rendercopy;
+    renderer->RenderPresent = photon_renderpresent;
+    renderer->DestroyTexture = photon_destroytexture;
+    renderer->DestroyRenderer = photon_destroyrenderer;
+    renderer->info = photon_renderdriver.info;
+    renderer->window = window->id;
+    renderer->driverdata = rdata;
 
-   /* Set render acceleration flag in case it is accelerated */
-   if ((didata->caps & SDL_PHOTON_ACCELERATED)==SDL_PHOTON_ACCELERATED)
-   {
-      renderer->info.flags=SDL_RENDERER_ACCELERATED;
-   }
-   else
-   {
-      renderer->info.flags&=~(SDL_RENDERER_ACCELERATED);
-   }
+    /* Set render acceleration flag in case it is accelerated */
+    if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) {
+        renderer->info.flags = SDL_RENDERER_ACCELERATED;
+    } else {
+        renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED);
+    }
 
-   rdata->window=window;
+    rdata->window = window;
 
-   /* Check if upper level requested synchronization on vsync signal */
-   if ((flags & SDL_RENDERER_PRESENTVSYNC)==SDL_RENDERER_PRESENTVSYNC)
-   {
-       rdata->enable_vsync=SDL_TRUE;
-   }
-   else
-   {
-      rdata->enable_vsync=SDL_FALSE;
-   }
+    /* Check if upper level requested synchronization on vsync signal */
+    if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) {
+        rdata->enable_vsync = SDL_TRUE;
+    } else {
+        rdata->enable_vsync = SDL_FALSE;
+    }
 
-   /* Check what buffer copy/flip scheme is requested */
-   rdata->surfaces_count=0;
-   if ((flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER)
-   {
-      if ((flags & SDL_RENDERER_PRESENTDISCARD)==SDL_RENDERER_PRESENTDISCARD)
-      {
-         renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD;
-      }
-      else
-      {
-         renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
-      }
-      rdata->surfaces_count=1;
-      rdata->surface_visible_idx=0;
-      rdata->surface_render_idx=0;
-   }
-   else
-   {
-      if ((flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2)
-      {
-         renderer->info.flags|=SDL_RENDERER_PRESENTFLIP2;
-         rdata->surfaces_count=2;
-         rdata->surface_visible_idx=0;
-         rdata->surface_render_idx=1;
-      }
-      else
-      {
-         if ((flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3)
-         {
-            renderer->info.flags|=SDL_RENDERER_PRESENTFLIP3;
-            rdata->surfaces_count=3;
-            rdata->surface_visible_idx=0;
-            rdata->surface_render_idx=1;
-         }
-         else
-         {
-            renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
-            rdata->surfaces_count=1;
-            rdata->surface_visible_idx=0;
-            rdata->surface_render_idx=0;
-         }
-      }
-   }
+    /* Check what buffer copy/flip scheme is requested */
+    rdata->surfaces_count = 0;
+    if ((flags & SDL_RENDERER_SINGLEBUFFER) == SDL_RENDERER_SINGLEBUFFER) {
+        if ((flags & SDL_RENDERER_PRESENTDISCARD) ==
+            SDL_RENDERER_PRESENTDISCARD) {
+            renderer->info.flags |=
+                SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD;
+        } else {
+            renderer->info.flags |=
+                SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
+        }
+        rdata->surfaces_count = 1;
+        rdata->surface_visible_idx = 0;
+        rdata->surface_render_idx = 0;
+    } else {
+        if ((flags & SDL_RENDERER_PRESENTFLIP2) == SDL_RENDERER_PRESENTFLIP2) {
+            renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
+            rdata->surfaces_count = 2;
+            rdata->surface_visible_idx = 0;
+            rdata->surface_render_idx = 1;
+        } else {
+            if ((flags & SDL_RENDERER_PRESENTFLIP3) ==
+                SDL_RENDERER_PRESENTFLIP3) {
+                renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
+                rdata->surfaces_count = 3;
+                rdata->surface_visible_idx = 0;
+                rdata->surface_render_idx = 1;
+            } else {
+                renderer->info.flags |=
+                    SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
+                rdata->surfaces_count = 1;
+                rdata->surface_visible_idx = 0;
+                rdata->surface_render_idx = 0;
+            }
+        }
+    }
 
-   return renderer;
+    return renderer;
 }
 
-void photon_addrenderdriver(_THIS)
+void
+photon_addrenderdriver(_THIS)
 {
-   uint32_t it;
+    uint32_t it;
 
-   for (it=0; it<_this->num_displays; it++)
-   {
-      SDL_AddRenderDriver(it, &photon_renderdriver);
-   }
+    for (it = 0; it < _this->num_displays; it++) {
+        SDL_AddRenderDriver(it, &photon_renderdriver);
+    }
 }
 
 /****************************************************************************/
 /* SDL render interface                                                     */
 /****************************************************************************/
-static int photon_displaymodechanged(SDL_Renderer* renderer)
+static int
+photon_displaymodechanged(SDL_Renderer * renderer)
 {
-   SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata;
+    SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
 
-   /* Remove all allocated surfaces, they are no more valid */
+    /* Remove all allocated surfaces, they are no more valid */
 
-   /* TODO: Add video mode change detection and new parameters detection */
+    /* TODO: Add video mode change detection and new parameters detection */
 
-   return 0;
+    return 0;
 }
 
-static int photon_activaterenderer(SDL_Renderer* renderer)
+static int
+photon_activaterenderer(SDL_Renderer * renderer)
 {
-   SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata;
-   SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(rdata->window);
-   SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata;
+    SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(rdata->window);
+    SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
 
-   return 0;
+    return 0;
 }
 
-static int photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture)
+static int
+photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
-   SDL_RenderData* renderdata=(SDL_RenderData*)renderer->driverdata;
-   SDL_Window* window=SDL_GetWindowFromID(renderer->window);
-   SDL_VideoDisplay* display=SDL_GetDisplayFromWindow(window);
-   SDL_TextureData* tdata=NULL;
+    SDL_RenderData *renderdata = (SDL_RenderData *) renderer->driverdata;
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
+    SDL_TextureData *tdata = NULL;
 
-   /* Allocate texture driver data */
-   tdata=(SDL_TextureData*)SDL_calloc(1, sizeof(SDL_TextureData));
-   if (tdata==NULL)
-   {
-      SDL_OutOfMemory();
-      return -1;
-   }
+    /* Allocate texture driver data */
+    tdata = (SDL_TextureData *) SDL_calloc(1, sizeof(SDL_TextureData));
+    if (tdata == NULL) {
+        SDL_OutOfMemory();
+        return -1;
+    }
 
-   /* Set texture driver data */
-   texture->driverdata=tdata;
+    /* Set texture driver data */
+    texture->driverdata = tdata;
 
 }
 
-static int photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch)
+static int
+photon_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture,
+                          void **pixels, int *pitch)
+{
+}
+
+static int
+photon_settexturepalette(SDL_Renderer * renderer, SDL_Texture * texture,
+                         const SDL_Color * colors, int firstcolor,
+                         int ncolors)
 {
 }
 
-static int photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors)
+static int
+photon_gettexturepalette(SDL_Renderer * renderer, SDL_Texture * texture,
+                         SDL_Color * colors, int firstcolor, int ncolors)
 {
 }
 
-static int photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors)
+static int
+photon_settexturecolormod(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 }
 
-static int photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture)
+static int
+photon_settexturealphamod(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 }
 
-static int photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture)
+static int
+photon_settextureblendmode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 }
 
-static int photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture)
+static int
+photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 }
 
-static int photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture)
+static int
+photon_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture,
+                     const SDL_Rect * rect, const void *pixels, int pitch)
 {
 }
 
-static int photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch)
+static int
+photon_locktexture(SDL_Renderer * renderer, SDL_Texture * texture,
+                   const SDL_Rect * rect, int markDirty, void **pixels,
+                   int *pitch)
 {
 }
 
-static int photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch)
+static void
+photon_unlocktexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 }
 
-static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture)
-{
-}
-
-static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects)
+static void
+photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture,
+                    int numrects, const SDL_Rect * rects)
 {
 }
 
-static int photon_renderpoint(SDL_Renderer* renderer, int x, int y)
+static int
+photon_renderpoint(SDL_Renderer * renderer, int x, int y)
 {
 }
 
-static int photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2)
+static int
+photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
 {
 }
 
-static int photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect)
+static int
+photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect)
 {
 }
 
-static int photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect)
+static int
+photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
+                  const SDL_Rect * srcrect, const SDL_Rect * dstrect)
 {
 }
 
-static void photon_renderpresent(SDL_Renderer* renderer)
+static void
+photon_renderpresent(SDL_Renderer * renderer)
 {
 }
 
-static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture)
+static void
+photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
 }
 
-static void photon_destroyrenderer(SDL_Renderer* renderer)
+static void
+photon_destroyrenderer(SDL_Renderer * renderer)
 {
-   SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata;
-   uint32_t it;
+    SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
+    uint32_t it;
 
 }
 
--- a/src/video/photon/SDL_photon_render.h	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/photon/SDL_photon_render.h	Sat May 23 22:41:08 2009 +0000
@@ -35,11 +35,11 @@
 
 typedef struct SDL_RenderData
 {
-   SDL_Window*        window;        /* SDL window type                    */
-   SDL_bool           enable_vsync;  /* VSYNC flip synchronization enable  */
-   uint32_t           surface_visible_idx; /* Index of visible surface     */
-   uint32_t           surface_render_idx;  /* Index of render surface      */
-   uint32_t           surfaces_count;      /* Amount of allocated surfaces */
+    SDL_Window *window;         /* SDL window type                    */
+    SDL_bool enable_vsync;      /* VSYNC flip synchronization enable  */
+    uint32_t surface_visible_idx;       /* Index of visible surface     */
+    uint32_t surface_render_idx;        /* Index of render surface      */
+    uint32_t surfaces_count;    /* Amount of allocated surfaces */
 } SDL_RenderData;
 
 typedef struct SDL_TextureData
--- a/src/video/qnxgf/SDL_gf_input.c	Fri May 15 15:47:37 2009 +0000
+++ b/src/video/qnxgf/SDL_gf_input.c	Sat May 23 22:41:08 2009 +0000
@@ -37,539 +37,491 @@
 #include "SDL_hiddi_joystick.h"
 
 /* Mouse related functions */
-SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y);
-int  gf_showcursor(SDL_Cursor* cursor);
-void gf_movecursor(SDL_Cursor* cursor);
-void gf_freecursor(SDL_Cursor* cursor);
-void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y);
-void gf_freemouse(SDL_Mouse* mouse);
+SDL_Cursor *gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y);
+int gf_showcursor(SDL_Cursor * cursor);
+void gf_movecursor(SDL_Cursor * cursor);
+void gf_freecursor(SDL_Cursor * cursor);
+void gf_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y);
+void gf_freemouse(SDL_Mouse * mouse);
 
 /* HIDDI interacting functions */
 static int32_t hiddi_connect_devices();
 static int32_t hiddi_disconnect_devices();
 
-int32_t gf_addinputdevices(_THIS)
+int32_t
+gf_addinputdevices(_THIS)
 {
-   SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
-   SDL_DisplayData* didata;
-   struct SDL_Mouse gf_mouse;
-   SDL_Keyboard gf_keyboard;
-   SDLKey keymap[SDL_NUM_SCANCODES];
-   SDL_MouseData* mdata;
-   uint32_t it;
+    SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
+    SDL_DisplayData *didata;
+    struct SDL_Mouse gf_mouse;
+    SDL_Keyboard gf_keyboard;
+    SDLKey keymap[SDL_NUM_SCANCODES];
+    SDL_MouseData *mdata;
+    uint32_t it;
 
-   for (it=0; it<_this->num_displays; it++)
-   {
-      /* Clear SDL mouse structure */
-      SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse));
+    for (it = 0; it < _this->num_displays; it++) {
+        /* Clear SDL mouse structure */
+        SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse));
 
-      /* Allocate SDL_MouseData structure */
-      mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData));
-      if (mdata==NULL)
-      {
-         SDL_OutOfMemory();
-         return -1;
-      }
+        /* Allocate SDL_MouseData structure */
+        mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData));
+        if (mdata == NULL) {
+            SDL_OutOfMemory();
+            return -1;
+        }
 
-      /* Mark this mouse with ID 0 */
-      gf_mouse.id=it;
-      gf_mouse.driverdata=(void*)mdata;
-      gf_mouse.CreateCursor=gf_createcursor;
-      gf_mouse.ShowCursor=gf_showcursor;
-      gf_mouse.MoveCursor=gf_movecursor;
-      gf_mouse.FreeCursor=gf_freecursor;
-      gf_mouse.WarpMouse=gf_warpmouse;
-      gf_mouse.FreeMouse=gf_freemouse;
+        /* Mark this mouse with ID 0 */
+        gf_mouse.id = it;
+        gf_mouse.driverdata = (void *) mdata;
+        gf_mouse.CreateCursor = gf_createcursor;
+        gf_mouse.ShowCursor = gf_showcursor;
+        gf_mouse.MoveCursor = gf_movecursor;
+        gf_mouse.FreeCursor = gf_freecursor;
+        gf_mouse.WarpMouse = gf_warpmouse;
+        gf_mouse.FreeMouse = gf_freemouse;
 
-      /* Get display data */
-      didata=(SDL_DisplayData*)_this->displays[it].driverdata;
+        /* Get display data */
+        didata = (SDL_DisplayData *) _this->displays[it].driverdata;
 
-      /* Store SDL_DisplayData pointer in the mouse driver internals */
-      mdata->didata=didata;
+        /* Store SDL_DisplayData pointer in the mouse driver internals */
+        mdata->didata = didata;
 
-      /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */
-      gf_cursor_set_pos(didata->display, 0, 0, 0);
+        /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */
+        gf_cursor_set_pos(didata->display, 0, 0, 0);
 
-      /* Register mouse cursor in SDL */
-      SDL_AddMouse(&gf_mouse, "GF mouse cursor", 0, 0, 1);
-   }
+        /* Register mouse cursor in SDL */
+        SDL_AddMouse(&gf_mouse, "GF mouse cursor", 0, 0, 1);
+    }
 
-   /* Keyboard could be one only */
-   SDL_zero(gf_keyboard);
-   SDL_AddKeyboard(&gf_keyboard, -1);
+    /* Keyboard could be one only */
+    SDL_zero(gf_keyboard);
+    SDL_AddKeyboard(&gf_keyboard, -1);
 
-   /* Add scancode to key mapping, HIDDI uses USB HID codes, so */
-   /* map will be exact one-to-one */
-   SDL_GetDefaultKeymap(keymap);
-   SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
+    /* Add scancode to key mapping, HIDDI uses USB HID codes, so */
+    /* map will be exact one-to-one */
+    SDL_GetDefaultKeymap(keymap);
+    SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
 
-   /* Connect to HID server and enumerate all input devices */
-   hiddi_connect_devices();
+    /* Connect to HID server and enumerate all input devices */
+    hiddi_connect_devices();
 
-   return 0;
+    return 0;
 }
 
-int32_t gf_delinputdevices(_THIS)
+int32_t
+gf_delinputdevices(_THIS)
 {
-   /* Disconnect from HID server and release input devices */
-   hiddi_disconnect_devices();
+    /* Disconnect from HID server and release input devices */
+    hiddi_disconnect_devices();
 
-   /* Delete keyboard */
-   SDL_KeyboardQuit();
+    /* Delete keyboard */
+    SDL_KeyboardQuit();
 
-   /* Destroy all of the mice */
-   SDL_MouseQuit();
+    /* Destroy all of the mice */
+    SDL_MouseQuit();
 }
 
 /*****************************************************************************/
 /* GF Mouse related functions                                                */
 /*****************************************************************************/
-SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
+SDL_Cursor *
+gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y)
 {
-   gf_cursor_t* internal_cursor;
-   SDL_Cursor*  sdl_cursor;
-   uint8_t*     image0=NULL;
-   uint8_t*     image1=NULL;
-   uint32_t     it;
-   uint32_t     jt;
-   uint32_t     shape_color;
+    gf_cursor_t *internal_cursor;
+    SDL_Cursor *sdl_cursor;
+    uint8_t *image0 = NULL;
+    uint8_t *image1 = NULL;
+    uint32_t it;
+    uint32_t jt;
+    uint32_t shape_color;
 
-   /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
-   /* and we must convert it back to monochrome, this routine handles */
-   /* 24/32bpp surfaces only                                          */
-   if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24))
-   {
-      SDL_SetError("GF: Cursor shape is not 24/32bpp.");
-      return NULL;
-   }
+    /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
+    /* and we must convert it back to monochrome, this routine handles */
+    /* 24/32bpp surfaces only                                          */
+    if ((surface->format->BitsPerPixel != 32)
+        && (surface->format->BitsPerPixel != 24)) {
+        SDL_SetError("GF: Cursor shape is not 24/32bpp.");
+        return NULL;
+    }
+
+    /* Since GF is not checking data, we must check */
+    if ((surface->w == 0) || (surface->h == 0)) {
+        SDL_SetError("GF: Cursor shape dimensions are zero");
+        return NULL;
+    }
 
-   /* Since GF is not checking data, we must check */
-   if ((surface->w==0) || (surface->h==0))
-   {
-      SDL_SetError("GF: Cursor shape dimensions are zero");
-      return NULL;
-   }
+    /* Allocate memory for the internal cursor format */
+    internal_cursor = (gf_cursor_t *) SDL_calloc(1, sizeof(gf_cursor_t));
+    if (internal_cursor == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    /* Allocate memory for the SDL cursor */
+    sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor));
+    if (sdl_cursor == NULL) {
+        SDL_free(internal_cursor);
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
-   /* Allocate memory for the internal cursor format */
-   internal_cursor=(gf_cursor_t*)SDL_calloc(1, sizeof(gf_cursor_t));
-   if (internal_cursor==NULL)
-   {
-      SDL_OutOfMemory();
-      return NULL;
-   }
-
-   /* Allocate memory for the SDL cursor */
-   sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor));
-   if (sdl_cursor==NULL)
-   {
-      SDL_free(internal_cursor);
-      SDL_OutOfMemory();
-      return NULL;
-   }
+    /* Allocate two monochrome images */
+    image0 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) / 8) * surface->h);
+    if (image0 == NULL) {
+        SDL_free(sdl_cursor);
+        SDL_free(internal_cursor);
+        SDL_OutOfMemory();
+        return NULL;
+    }
+    image1 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) >> 3) * surface->h);
+    if (image1 == NULL) {
+        SDL_free(image0);
+        SDL_free(sdl_cursor);
+        SDL_free(internal_cursor);
+        SDL_OutOfMemory();
+        return NULL;
+    }
 
-   /* Allocate two monochrome images */
-   image0=(uint8_t*)SDL_calloc(1, ((surface->w+7)/8)*surface->h);
-   if (image0==NULL)
-   {
-      SDL_free(sdl_cursor);
-      SDL_free(internal_cursor);
-      SDL_OutOfMemory();
-      return NULL;
-   }
-   image1=(uint8_t*)SDL_calloc(1, ((surface->w+7)>>3)*surface->h);
-   if (image1==NULL)
-   {
-      SDL_free(image0);
-      SDL_free(sdl_cursor);
-      SDL_free(internal_cursor);
-      SDL_OutOfMemory();
-      return NULL;
-   }
+    /* Set driverdata as GF cursor format */
+    sdl_cursor->driverdata = (void *) internal_cursor;
+    internal_cursor->type = GF_CURSOR_BITMAP;
+    internal_cursor->hotspot.x = hot_x;
+    internal_cursor->