src/video/photon/SDL_ph_events.c
changeset 663 8bedd6d61642
parent 571 8e3ce997621c
child 753 b14fdadd8311
     1.1 --- a/src/video/photon/SDL_ph_events.c	Mon Jul 28 01:47:55 2003 +0000
     1.2 +++ b/src/video/photon/SDL_ph_events.c	Mon Aug 04 00:52:42 2003 +0000
     1.3 @@ -29,11 +29,12 @@
     1.4  
     1.5  #define DISABLE_X11
     1.6  
     1.7 -#include <Ph.h>
     1.8  #include <stdio.h>
     1.9  #include <setjmp.h>
    1.10 +#include <sys/time.h>
    1.11 +
    1.12 +#include <Ph.h>
    1.13  #include <photon/PkKeyDef.h>
    1.14 -#include <sys/time.h>
    1.15  
    1.16  #include "SDL.h"
    1.17  #include "SDL_syswm.h"
    1.18 @@ -44,6 +45,8 @@
    1.19  #include "SDL_ph_modes_c.h"
    1.20  #include "SDL_ph_image_c.h"
    1.21  #include "SDL_ph_events_c.h"
    1.22 +#include "SDL_phyuv_c.h"
    1.23 +
    1.24  
    1.25  
    1.26  /* The translation tables from a photon keysym to a SDL keysym */
    1.27 @@ -90,8 +93,8 @@
    1.28  
    1.29      if( window )
    1.30      {
    1.31 -        rid = PtWidgetRid( window );
    1.32 -        if( rid != 0 && PhRegionQuery( rid, &region, NULL, NULL, 0 ) == 0 )
    1.33 +        rid = PtWidgetRid(window);
    1.34 +        if( rid != 0 && PhRegionQuery(rid, &region, NULL, NULL, 0) == 0 )
    1.35          {
    1.36              region.events_sense=(region.events_sense & ~fields)|(flags & fields);
    1.37              PhRegionChange(Ph_REGION_EV_SENSE, 0, &region, NULL, NULL);
    1.38 @@ -114,6 +117,8 @@
    1.39      return (mouse_button);
    1.40  }
    1.41  
    1.42 +//                   void* PtAppCreateContext();
    1.43 +
    1.44  static int ph_DispatchEvent(_THIS)
    1.45  {
    1.46      int posted;
    1.47 @@ -217,15 +222,56 @@
    1.48              {
    1.49                  posted = SDL_PrivateQuit();
    1.50              }
    1.51 +            /* request to hide/unhide */
    1.52 +            else if (winEvent->event_f==Ph_WM_HIDE)
    1.53 +            {
    1.54 +                if (currently_hided)
    1.55 +                {
    1.56 +                   /* got unhide window event                                */
    1.57 +                   /* TODO: restore application's palette if in palette mode */
    1.58 +                   currently_hided=0;
    1.59 +                }
    1.60 +                else
    1.61 +                {
    1.62 +                   /* got hide window event                                  */
    1.63 +                   /* TODO: restore original palette if in palette mode      */
    1.64 +                   currently_hided=1;
    1.65 +                }
    1.66 +            }
    1.67              /* request to resize */
    1.68              else if (winEvent->event_f==Ph_WM_RESIZE)
    1.69              {
    1.70                  SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
    1.71              }
    1.72 +            /* request to move */
    1.73 +            else if (winEvent->event_f==Ph_WM_MOVE)
    1.74 +            {
    1.75 +                if (current_overlay!=NULL)
    1.76 +                {
    1.77 +                   int lockedstate=current_overlay->hwdata->locked;
    1.78 +                   int chromastate=current_overlay->hwdata->ischromakey;
    1.79 +                   SDL_Rect target;
    1.80 +
    1.81 +                   current_overlay->hwdata->locked=1;
    1.82 +                   target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
    1.83 +                   target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
    1.84 +                   target.w=current_overlay->hwdata->CurrentViewPort.size.w;
    1.85 +                   target.h=current_overlay->hwdata->CurrentViewPort.size.h;
    1.86 +                   current_overlay->hwdata->ischromakey=0;
    1.87 +                   ph_DisplayYUVOverlay(this, current_overlay, &target);
    1.88 +                   current_overlay->hwdata->ischromakey=chromastate;
    1.89 +                   current_overlay->hwdata->locked=lockedstate;
    1.90 +                }
    1.91 +            }
    1.92              /* request to maximize */
    1.93              else if (winEvent->event_f==Ph_WM_MAX)
    1.94              {
    1.95 -                /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */
    1.96 +                /* window already moved and resized here */
    1.97 +                SDL_PrivateResize(winEvent->size.w-winEvent->pos.x, winEvent->size.h-winEvent->pos.y);
    1.98 +            }
    1.99 +            /* request to restore */
   1.100 +            else if (winEvent->event_f==Ph_WM_RESTORE)
   1.101 +            {
   1.102              }
   1.103          }
   1.104          break;
   1.105 @@ -233,19 +279,38 @@
   1.106          /* window has been resized, moved or removed */
   1.107          case Ph_EV_EXPOSE:
   1.108          {
   1.109 -            if (SDL_VideoSurface)
   1.110 +            if (event->num_rects!=0)
   1.111              {
   1.112 -                rect = PhGetRects(event);
   1.113 +                if (SDL_VideoSurface)
   1.114 +                {
   1.115 +                    rect = PhGetRects(event);
   1.116  
   1.117 -                for(i=0;i<event->num_rects;i++)
   1.118 -                {
   1.119 -                    sdlrects[i].x = rect[i].ul.x;
   1.120 -                    sdlrects[i].y = rect[i].ul.y;
   1.121 -                    sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   1.122 -                    sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   1.123 +                    for(i=0;i<event->num_rects;i++)
   1.124 +                    {
   1.125 +                        sdlrects[i].x = rect[i].ul.x;
   1.126 +                        sdlrects[i].y = rect[i].ul.y;
   1.127 +                        sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   1.128 +                        sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   1.129 +                    }
   1.130 +
   1.131 +                    this->UpdateRects(this, event->num_rects, sdlrects);
   1.132 +
   1.133 +                    if (current_overlay!=NULL)
   1.134 +                    {
   1.135 +                        int lockedstate=current_overlay->hwdata->locked;
   1.136 +                        SDL_Rect target;
   1.137 +
   1.138 +                        current_overlay->hwdata->locked=1;
   1.139 +                        target.x=current_overlay->hwdata->CurrentViewPort.pos.x;
   1.140 +                        target.y=current_overlay->hwdata->CurrentViewPort.pos.y;
   1.141 +                        target.w=current_overlay->hwdata->CurrentViewPort.size.w;
   1.142 +                        target.h=current_overlay->hwdata->CurrentViewPort.size.h;
   1.143 +                        current_overlay->hwdata->forcedredraw=1;
   1.144 +                        ph_DisplayYUVOverlay(this, current_overlay, &target);
   1.145 +                        current_overlay->hwdata->forcedredraw=0;
   1.146 +                        current_overlay->hwdata->locked=lockedstate;
   1.147 +                    }
   1.148                  }
   1.149 -
   1.150 -                this->UpdateRects(this, event->num_rects, sdlrects);
   1.151              }
   1.152          }
   1.153  	break;
   1.154 @@ -260,13 +325,32 @@
   1.155  
   1.156              if (Pk_KF_Key_Down & keyEvent->key_flags)
   1.157              {
   1.158 +                /* split the wheel events from real key events */
   1.159 +                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   1.160 +                {
   1.161 +                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
   1.162 +                   break;
   1.163 +                }
   1.164 +                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   1.165 +                {
   1.166 +                   posted = SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
   1.167 +                   break;
   1.168 +                }
   1.169                  posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
   1.170              }
   1.171              else /* must be key release */
   1.172              {
   1.173 -                 /* Ignore repeated key release events */
   1.174 -                 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */
   1.175 -
   1.176 +                /* split the wheel events from real key events */
   1.177 +                if ((keyEvent->key_cap==Pk_Up) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   1.178 +                {
   1.179 +                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
   1.180 +                   break;
   1.181 +                }
   1.182 +                if ((keyEvent->key_cap==Pk_Down) && (keyEvent->key_scan==0) && ((keyEvent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid))
   1.183 +                {
   1.184 +                   posted = SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
   1.185 +                   break;
   1.186 +                }
   1.187                  posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
   1.188              }
   1.189          }
   1.190 @@ -282,9 +366,9 @@
   1.191      /* Flush the display connection and look to see if events are queued */
   1.192      PgFlush();
   1.193  
   1.194 -    while( 1 )
   1.195 -    {   /* note this is a non-blocking call */
   1.196 -        switch( PhEventPeek( event, EVENT_SIZE ) )
   1.197 +    while (1)
   1.198 +    {
   1.199 +        switch(PhEventPeek(event, EVENT_SIZE))
   1.200          {
   1.201              case Ph_EVENT_MSG:
   1.202                   return 1;
   1.203 @@ -308,6 +392,7 @@
   1.204  
   1.205      while (ph_Pending(this))
   1.206      {
   1.207 +        PtEventHandler(event);
   1.208          ph_DispatchEvent(this);
   1.209      }
   1.210  }
   1.211 @@ -318,11 +403,15 @@
   1.212  
   1.213      /* Odd keys used in international keyboards */
   1.214      for (i=0; i<SDL_TABLESIZE(ODD_keymap); ++i)
   1.215 +    {
   1.216          ODD_keymap[i] = SDLK_UNKNOWN;
   1.217 +    }
   1.218  
   1.219      /* Map the miscellaneous keys */
   1.220      for (i=0; i<SDL_TABLESIZE(MISC_keymap); ++i)
   1.221 +    {
   1.222          MISC_keymap[i] = SDLK_UNKNOWN;
   1.223 +    }
   1.224  
   1.225      MISC_keymap[Pk_BackSpace&0xFF] = SDLK_BACKSPACE;
   1.226      MISC_keymap[Pk_Tab&0xFF] = SDLK_TAB;
   1.227 @@ -388,15 +477,19 @@
   1.228      MISC_keymap[Pk_Alt_L&0xFF] = SDLK_LALT;
   1.229      MISC_keymap[Pk_Meta_R&0xFF] = SDLK_RMETA;
   1.230      MISC_keymap[Pk_Meta_L&0xFF] = SDLK_LMETA;
   1.231 -    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;   /* Left "Windows"  */
   1.232 -    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   1.233 +    MISC_keymap[Pk_Super_L&0xFF] = SDLK_LSUPER;
   1.234 +    MISC_keymap[Pk_Super_R&0xFF] = SDLK_RSUPER;
   1.235      MISC_keymap[Pk_Mode_switch&0xFF] = SDLK_MODE; /* "Alt Gr" key    */
   1.236  
   1.237      MISC_keymap[Pk_Help&0xFF] = SDLK_HELP;
   1.238      MISC_keymap[Pk_Print&0xFF] = SDLK_PRINT;
   1.239      MISC_keymap[Pk_Break&0xFF] = SDLK_BREAK;
   1.240 -    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;
   1.241 -    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_MENU;   /* Windows "Menu" key */
   1.242 +    MISC_keymap[Pk_Menu&0xFF] = SDLK_MENU;        /* Windows "Menu" key */
   1.243 +
   1.244 +    MISC_keymap[Pk_Hyper_R&0xFF] = SDLK_RSUPER;   /* Right "Windows" */
   1.245 +
   1.246 +    /* Left "Windows" key, but it can't be catched by application */
   1.247 +    MISC_keymap[Pk_Hyper_L&0xFF] = SDLK_LSUPER;
   1.248  }
   1.249  
   1.250  static unsigned long cap;
   1.251 @@ -447,13 +540,23 @@
   1.252          int utf8len;
   1.253          wchar_t unicode;
   1.254  
   1.255 -        utf8len = PhKeyToMb(utf8, key);
   1.256 -        if (utf8len > 0)
   1.257 +        switch (keysym->scancode)
   1.258          {
   1.259 -            utf8len = mbtowc(&unicode, utf8, utf8len);
   1.260 -            if (utf8len > 0)
   1.261 -                keysym->unicode = unicode;
   1.262 +           case 0x01: keysym->unicode = 27;
   1.263 +                      break;
   1.264 +           default:
   1.265 +                      utf8len = PhKeyToMb(utf8, key);
   1.266 +                      if (utf8len > 0)
   1.267 +                      {
   1.268 +                          utf8len = mbtowc(&unicode, utf8, utf8len);
   1.269 +                         if (utf8len > 0)
   1.270 +                         {
   1.271 +                             keysym->unicode = unicode;
   1.272 +                         }
   1.273 +                      }
   1.274 +                      break;
   1.275          }
   1.276 +
   1.277      }
   1.278  
   1.279      return (keysym);