diff src/video/photon/SDL_ph_events.c @ 663:8bedd6d61642

Date: Sat, 2 Aug 2003 16:22:51 +0300 From: "Mike Gorchak" Subject: New patches for QNX6 Here my patches for the SDL/QNX: QNXSDL.diff - diff to non-QNX related sources: - updated BUGS file, I think QNX6 is now will be officially supported - configure.in - added shared library support for QNX, and removed dependency between the ALSA and QNX6. - SDL_audio.c - added QNX NTO sound bootstrap insted of ALSA's. - SDL_sysaudio.h - the same. - SDL_nto_audio.c - the same. - SDL_video.c - right now, QNX doesn't offer any method to obtain pointers to the OpenGL functions by function name, so they must be hardcoded in library, otherwise OpenGL will not be supported. - testsprite.c - fixed: do not draw vertical red line if we are in non-double-buffered mode. sdlqnxph.tar.gz - archive of the ./src/video/photon/* . Too many changes in code to make diffs :) : + Added stub for support hide/unhide window event + Added full YUV overlays support. + Added window maximize support. + Added mouse wheel events. + Added support for some specific key codes in Unicode mode (like ESC). + Added more checks to the all memory allocation code. + Added SDL_DOUBLEBUF support in all fullscreen modes. + Added fallback to window mode, if desired fullscreen mode is not supported. + Added stub support for the GL_LoadLibrary and GL_GetProcAddress functions. + Added resizable window support without caption. ! Fixed bug in the Ph_EV_EXPOSE event handler, when rectangles to update is 0 and when width or height of the rectangle is 0. ! Fixed bug in the event handler code. Events has not been passed to the window widget handler. ! Fixed codes for Win keys (Super/Hyper/Menu). ! Fixed memory leak, when deallocation palette. ! Fixed palette emulation code bugs. ! Fixed fullscreen and hwsurface handling. ! Fixed CLOSE button bug. First event was passed to the handler, but second terminated the application. Now all events passed to the application correctly. - Removed all printfs in code, now SDL_SetError used instead of them. - Disabled ToggleFullScreen function. README.QNX - updated README.QNX file. Added much more issues.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 04 Aug 2003 00:52:42 +0000
parents 8e3ce997621c
children b14fdadd8311
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_events.c	Mon Jul 28 01:47:55 2003 +0000
+++ b/src/video/photon/SDL_ph_events.c	Mon Aug 04 00:52:42 2003 +0000
@@ -29,11 +29,12 @@
 
 #define DISABLE_X11
 
-#include <Ph.h>
 #include <stdio.h>
 #include <setjmp.h>
+#include <sys/time.h>
+
+#include <Ph.h>
 #include <photon/PkKeyDef.h>
-#include <sys/time.h>
 
 #include "SDL.h"
 #include "SDL_syswm.h"
@@ -44,6 +45,8 @@
 #include "SDL_ph_modes_c.h"
 #include "SDL_ph_image_c.h"
 #include "SDL_ph_events_c.h"
+#include "SDL_phyuv_c.h"
+
 
 
 /* The translation tables from a photon keysym to a SDL keysym */
@@ -90,8 +93,8 @@
 
     if( window )
     {
-        rid = PtWidgetRid( window );
-        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
+        rid = PtWidgetRid(window);
+        if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )
         {
             region.events_sense=(region.events_sense & ~fields)|(flags & fields);
             PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
@@ -114,6 +117,8 @@
     return (mouse_button);
 }
 
+//                   void* PtAppCreateContext();
+
 static int ph_DispatchEvent(_THIS)
 {
     int posted;
@@ -217,15 +222,56 @@
             {
                 posted = SDL_PrivateQuit();
             }
+            /* request to hide/unhide */
+            else if (winEvent->event_f==Ph_WM_HIDE)
+            {
+                if (currently_hided)
+                {
+                   /* got unhide window event                                */
+                   /* TODO: restore application's palette if in palette mode */
+                   currently_hided=0;
+                }
+                else
+                {
+                   /* got hide window event                                  */
+                   /* TODO: restore original palette if in palette mode      */
+                   currently_hided=1;
+                }
+            }
             /* request to resize */
             else if (winEvent->event_f==Ph_WM_RESIZE)
             {
                 SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
             }
+            /* request to move */
+            else if (winEvent->event_f==Ph_WM_MOVE)
+            {
+                if (current_overlay!=NULL)
+                {
+                   int lockedstate=current_overlay->hwdata->locked;
+                   int chromastate=current_overlay->hwdata->ischromakey;
+                   SDL_Rect target;
+
+                   current_overlay->hwdata->locked=1;
+                   target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
+                   target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
+                   target.w=current_overlay->hwdata->CurrentViewPort.size.w;
+                   target.h=current_overlay->hwdata->CurrentViewPort.size.h;
+                   current_overlay->hwdata->ischromakey=0;
+                   ph_DisplayYUVOverlay(this, current_overlay, &target);
+                   current_overlay->hwdata->ischromakey=chromastate;
+                   current_overlay->hwdata->locked=lockedstate;
+                }
+            }
             /* request to maximize */
             else if (winEvent->event_f==Ph_WM_MAX)
             {
-                /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */
+                /* window already moved and resized here */
+                SDL_PrivateResize(winEvent->size.w-winEvent->pos.x, winEvent->size.h-winEvent->pos.y);
+            }
+            /* request to restore */
+            else if (winEvent->event_f==Ph_WM_RESTORE)
+            {
             }
         }
         break;
@@ -233,19 +279,38 @@
         /* window has been resized, moved or removed */
         case Ph_EV_EXPOSE:
         {
-            if (SDL_VideoSurface)
+            if (event->num_rects!=0)
             {
-                rect = PhGetRects(event);
-
-                for(i=0;i<event->num_rects;i++)
+                if (SDL_VideoSurface)
                 {
-                    sdlrects[i].x = rect[i].ul.x;
-                    sdlrects[i].y = rect[i].ul.y;
-                    sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
-                    sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
+                    rect = PhGetRects(event);
+
+                    for(i=0;i<event->num_rects;i++)
+                    {
+                        sdlrects[i].x = rect[i].ul.x;
+                        sdlrects[i].y = rect[i].ul.y;
+                        sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
+                        sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
+                    }
+
+                    this->UpdateRects(this, event->num_rects, sdlrects);
+
+                    if (current_overlay!=NULL)
+                    {
+                        int lockedstate=current_overlay->hwdata->locked;
+                        SDL_Rect target;
+
+                        current_overlay->hwdata->locked=1;
+                        target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
+                        target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
+                        target.w=current_overlay->hwdata->CurrentViewPort.size.w;
+                        target.h=current_overlay->hwdata->CurrentViewPort.size.h;
+                        current_overlay->hwdata->forcedredraw=1;
+                        ph_DisplayYUVOverlay(this, current_overlay, &target);
+                        current_overlay->hwdata->forcedredraw=0;
+                        current_overlay->hwdata->locked=lockedstate;
+                    }
                 }
-
-                this->UpdateRects(this, event->num_rects, sdlrects);
             }
         }
 	break;
@@ -260,13 +325,32 @@
 
             if (Pk_KF_Key_Down & keyEvent->key_flags)
             {
+                /* split the wheel events from real key events */
+                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
+                {
+                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
+                   break;
+                }
+                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
+                {
+                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
+                   break;
+                }
                 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
             }
             else /* must be key release */
             {
-                 /* Ignore repeated key release events */
-                 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */
-
+                /* split the wheel events from real key events */
+                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
+                {
+                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
+                   break;
+                }
+                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
+                {
+                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
+                   break;
+                }
                 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
             }
         }
@@ -282,9 +366,9 @@
     /* Flush the display connection and look to see if events are queued */
     PgFlush();
 
-    while( 1 )
-    {   /* note this is a non-blocking call */
-        switch( PhEventPeek( event, EVENT_SIZE ) )
+    while (1)
+    {
+        switch(PhEventPeek(event, EVENT_SIZE))
         {
             case Ph_EVENT_MSG:
                  return 1;
@@ -308,6 +392,7 @@
 
     while (ph_Pending(this))
     {
+        PtEventHandler(event);
         ph_DispatchEvent(this);
     }
 }
@@ -318,11 +403,15 @@
 
     /* Odd keys used in international keyboards */
     for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
+    {
         ODD_keymap[i] = SDLK_UNKNOWN;
+    }
 
     /* Map the miscellaneous keys */
     for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
+    {
         MISC_keymap[i] = SDLK_UNKNOWN;
+    }
 
     MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
     MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
@@ -388,15 +477,19 @@
     MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
     MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
     MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
-    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
-    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
+    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;
+    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;
     MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
 
     MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
     MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
     MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
-    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
-    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
+    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;        /* Windows "Menu" key */
+
+    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
+
+    /* Left "Windows" key, but it can't be catched by application */
+    MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER;
 }
 
 static unsigned long cap;
@@ -447,13 +540,23 @@
         int utf8len;
         wchar_t unicode;
 
-        utf8len = PhKeyToMb(utf8, key);
-        if (utf8len > 0)
+        switch (keysym->scancode)
         {
-            utf8len = mbtowc(&unicode, utf8, utf8len);
-            if (utf8len > 0)
-                keysym->unicode = unicode;
+           case 0x01: keysym->unicode = 27;
+                      break;
+           default:
+                      utf8len = PhKeyToMb(utf8, key);
+                      if (utf8len > 0)
+                      {
+                          utf8len = mbtowc(&unicode, utf8, utf8len);
+                         if (utf8len > 0)
+                         {
+                             keysym->unicode = unicode;
+                         }
+                      }
+                      break;
         }
+
     }
 
     return (keysym);