src/video/nanox/SDL_nxevents.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 769 b8d311d90021
child 1361 19418e4422cb
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2004 Sam Lantinga
     4     Copyright (C) 2001  Hsieh-Fu Tsai
     5     Copyright (C) 2002  Greg Haerr <greg@censoft.com>
     6 
     7     This library is free software; you can redistribute it and/or
     8     modify it under the terms of the GNU Library General Public
     9     License as published by the Free Software Foundation; either
    10     version 2 of the License, or (at your option) any later version.
    11 
    12     This library is distributed in the hope that it will be useful,
    13     but WITHOUT ANY WARRANTY; without even the implied warranty of
    14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    15     Library General Public License for more details.
    16 
    17     You should have received a copy of the GNU Library General Public
    18     License along with this library; if not, write to the Free
    19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    20 
    21     Sam Lantinga
    22     slouken@libsdl.org
    23     
    24     Hsieh-Fu Tsai
    25     clare@setabox.com
    26 */
    27 
    28 #include "SDL_keysym.h"
    29 #include "SDL_events_c.h"
    30 
    31 #include "SDL_nxevents_c.h"
    32 #include "SDL_nximage_c.h"
    33 
    34 // The translation tables from a nanox keysym to a SDL keysym
    35 static SDLKey NX_NONASCII_keymap [MWKEY_LAST + 1] ;
    36 
    37 void NX_InitOSKeymap (_THIS)
    38 {
    39     int i ;
    40 
    41     Dprintf ("enter NX_InitOSKeymap\n") ;
    42 
    43     // Map the nanox scancodes to SDL keysyms
    44     for (i = 0; i < SDL_TABLESIZE (NX_NONASCII_keymap); ++ i)
    45         NX_NONASCII_keymap [i] = SDLK_UNKNOWN ;
    46 
    47     NX_NONASCII_keymap [MWKEY_LEFT        & 0xFF] = SDLK_LEFT ;
    48     NX_NONASCII_keymap [MWKEY_RIGHT       & 0xFF] = SDLK_RIGHT ;
    49     NX_NONASCII_keymap [MWKEY_UP          & 0xFF] = SDLK_UP ;
    50     NX_NONASCII_keymap [MWKEY_DOWN        & 0xFF] = SDLK_DOWN ;
    51     NX_NONASCII_keymap [MWKEY_INSERT      & 0xFF] = SDLK_INSERT ;
    52     NX_NONASCII_keymap [MWKEY_DELETE      & 0xFF] = SDLK_DELETE ;
    53     NX_NONASCII_keymap [MWKEY_HOME        & 0xFF] = SDLK_HOME ;
    54     NX_NONASCII_keymap [MWKEY_END         & 0xFF] = SDLK_END ;
    55     NX_NONASCII_keymap [MWKEY_PAGEUP      & 0xFF] = SDLK_PAGEUP ;
    56     NX_NONASCII_keymap [MWKEY_PAGEDOWN    & 0xFF] = SDLK_PAGEDOWN ;
    57 
    58     NX_NONASCII_keymap [MWKEY_KP0         & 0xFF] = SDLK_KP0 ;
    59     NX_NONASCII_keymap [MWKEY_KP1         & 0xFF] = SDLK_KP1 ;
    60     NX_NONASCII_keymap [MWKEY_KP2         & 0xFF] = SDLK_KP2 ;
    61     NX_NONASCII_keymap [MWKEY_KP3         & 0xFF] = SDLK_KP3 ;
    62     NX_NONASCII_keymap [MWKEY_KP4         & 0xFF] = SDLK_KP4 ;
    63     NX_NONASCII_keymap [MWKEY_KP5         & 0xFF] = SDLK_KP5 ;
    64     NX_NONASCII_keymap [MWKEY_KP6         & 0xFF] = SDLK_KP6 ;
    65     NX_NONASCII_keymap [MWKEY_KP7         & 0xFF] = SDLK_KP7 ;
    66     NX_NONASCII_keymap [MWKEY_KP8         & 0xFF] = SDLK_KP8 ;
    67     NX_NONASCII_keymap [MWKEY_KP9         & 0xFF] = SDLK_KP9 ;
    68     NX_NONASCII_keymap [MWKEY_KP_PERIOD   & 0xFF] = SDLK_KP_PERIOD ;
    69     NX_NONASCII_keymap [MWKEY_KP_DIVIDE   & 0xFF] = SDLK_KP_DIVIDE ;
    70     NX_NONASCII_keymap [MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY ;
    71     NX_NONASCII_keymap [MWKEY_KP_MINUS    & 0xFF] = SDLK_KP_MINUS ;
    72     NX_NONASCII_keymap [MWKEY_KP_PLUS     & 0xFF] = SDLK_KP_PLUS ;
    73     NX_NONASCII_keymap [MWKEY_KP_ENTER    & 0xFF] = SDLK_KP_ENTER ;
    74     NX_NONASCII_keymap [MWKEY_KP_EQUALS   & 0xFF] = SDLK_KP_EQUALS ;
    75 
    76     NX_NONASCII_keymap [MWKEY_F1          & 0xFF] = SDLK_F1 ;
    77     NX_NONASCII_keymap [MWKEY_F2          & 0xFF] = SDLK_F2 ;
    78     NX_NONASCII_keymap [MWKEY_F3          & 0xFF] = SDLK_F3 ;
    79     NX_NONASCII_keymap [MWKEY_F4          & 0xFF] = SDLK_F4 ;
    80     NX_NONASCII_keymap [MWKEY_F5          & 0xFF] = SDLK_F5 ;
    81     NX_NONASCII_keymap [MWKEY_F6          & 0xFF] = SDLK_F6 ;
    82     NX_NONASCII_keymap [MWKEY_F7          & 0xFF] = SDLK_F7 ;
    83     NX_NONASCII_keymap [MWKEY_F8          & 0xFF] = SDLK_F8 ;
    84     NX_NONASCII_keymap [MWKEY_F9          & 0xFF] = SDLK_F9 ;
    85     NX_NONASCII_keymap [MWKEY_F10         & 0xFF] = SDLK_F10 ;
    86     NX_NONASCII_keymap [MWKEY_F11         & 0xFF] = SDLK_F11 ;
    87     NX_NONASCII_keymap [MWKEY_F12         & 0xFF] = SDLK_F12 ;
    88 
    89     NX_NONASCII_keymap [MWKEY_NUMLOCK     & 0xFF] = SDLK_NUMLOCK ;
    90     NX_NONASCII_keymap [MWKEY_CAPSLOCK    & 0xFF] = SDLK_CAPSLOCK ;
    91     NX_NONASCII_keymap [MWKEY_SCROLLOCK   & 0xFF] = SDLK_SCROLLOCK ;
    92     NX_NONASCII_keymap [MWKEY_LSHIFT      & 0xFF] = SDLK_LSHIFT ;
    93     NX_NONASCII_keymap [MWKEY_RSHIFT      & 0xFF] = SDLK_RSHIFT ;
    94     NX_NONASCII_keymap [MWKEY_LCTRL       & 0xFF] = SDLK_LCTRL ;
    95     NX_NONASCII_keymap [MWKEY_RCTRL       & 0xFF] = SDLK_RCTRL ;
    96     NX_NONASCII_keymap [MWKEY_LALT        & 0xFF] = SDLK_LALT ;
    97     NX_NONASCII_keymap [MWKEY_RALT        & 0xFF] = SDLK_RALT ;
    98     NX_NONASCII_keymap [MWKEY_LMETA       & 0xFF] = SDLK_LMETA ;
    99     NX_NONASCII_keymap [MWKEY_RMETA       & 0xFF] = SDLK_RMETA ;
   100     NX_NONASCII_keymap [MWKEY_ALTGR       & 0xFF] = SDLK_MODE ;
   101 
   102     NX_NONASCII_keymap [MWKEY_PRINT       & 0xFF] = SDLK_PRINT ;
   103     NX_NONASCII_keymap [MWKEY_SYSREQ      & 0xFF] = SDLK_SYSREQ ;
   104     NX_NONASCII_keymap [MWKEY_PAUSE       & 0xFF] = SDLK_PAUSE ;
   105     NX_NONASCII_keymap [MWKEY_BREAK       & 0xFF] = SDLK_BREAK ;
   106     NX_NONASCII_keymap [MWKEY_MENU        & 0xFF] = SDLK_MENU ;
   107 
   108     Dprintf ("leave NX_InitOSKeymap\n") ;
   109 }
   110 
   111 SDL_keysym * NX_TranslateKey (GR_EVENT_KEYSTROKE * keystroke, SDL_keysym * keysym)
   112 {
   113     GR_KEY ch = keystroke -> ch ;
   114 
   115     Dprintf ("enter NX_TranslateKey\n") ;
   116 
   117     keysym -> scancode = keystroke -> scancode ;
   118     keysym -> sym = SDLK_UNKNOWN ;
   119 
   120     if (ch & MWKEY_NONASCII_MASK) {
   121         keysym -> sym = NX_NONASCII_keymap [ch & 0xFF] ;
   122     } else {
   123         keysym -> sym = ch & 0x7F ;
   124     }
   125 
   126     keysym -> mod = KMOD_NONE ;
   127     
   128 #if 1   //   Retrieve more mode information
   129     {
   130         GR_KEYMOD   mod = keystroke -> modifiers ;
   131 
   132         if (mod & MWKMOD_LSHIFT)
   133             keysym -> mod |= KMOD_LSHIFT ;
   134         if (mod & MWKMOD_RSHIFT)
   135             keysym -> mod |= KMOD_RSHIFT ;
   136         if (mod & MWKMOD_LCTRL)
   137             keysym -> mod |= KMOD_LCTRL ;
   138         if (mod & MWKMOD_RCTRL)
   139             keysym -> mod |= KMOD_RCTRL ;
   140         if (mod & MWKMOD_LALT)
   141             keysym -> mod |= KMOD_LALT ;
   142         if (mod & MWKMOD_RALT)
   143             keysym -> mod |= KMOD_RALT ;
   144         if (mod & MWKMOD_LMETA)
   145             keysym -> mod |= KMOD_LMETA ;
   146         if (mod & MWKMOD_RMETA)
   147             keysym -> mod |= KMOD_RMETA ;
   148         if (mod & MWKMOD_NUM)
   149             keysym -> mod |= KMOD_NUM ;
   150         if (mod & MWKMOD_CAPS)
   151             keysym -> mod |= KMOD_CAPS ;
   152         if (mod & MWKMOD_ALTGR)
   153             keysym -> mod |= KMOD_MODE ;
   154     }
   155 #endif
   156 
   157     keysym -> unicode = ch ;
   158 
   159     Dprintf ("leave NX_TranslateKey\n") ;
   160     return keysym ;
   161 }
   162 
   163 static int check_boundary (_THIS, int x, int y)
   164 {
   165     if (x < OffsetX || y < OffsetY || x > OffsetX + this -> screen -> w ||
   166         y > OffsetY + this -> screen -> h)
   167         return 0 ;
   168             
   169     return 1 ;
   170 }
   171 
   172 void NX_PumpEvents (_THIS)
   173 {
   174     GR_EVENT         event ;
   175     static GR_BUTTON last_button_down = 0 ;
   176 
   177     GrCheckNextEvent (& event) ;
   178     while (event.type != GR_EVENT_TYPE_NONE) {
   179 
   180         // dispatch event
   181         switch (event.type) {
   182             case GR_EVENT_TYPE_MOUSE_ENTER :
   183             {
   184                 Dprintf ("mouse enter\n") ;
   185                 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
   186                 break ;
   187             }
   188 
   189             case GR_EVENT_TYPE_MOUSE_EXIT :
   190             {
   191                 Dprintf ("mouse exit\n") ;
   192                 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
   193                 break ;
   194             }
   195 
   196             case GR_EVENT_TYPE_FOCUS_IN :
   197             {
   198                 Dprintf ("focus in\n") ;
   199                 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS) ;
   200                 break ;
   201             }
   202 
   203             case GR_EVENT_TYPE_FOCUS_OUT :
   204             {
   205                 Dprintf ("focus out\n") ;
   206                 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS) ;
   207                 break ;
   208             }
   209 
   210             case GR_EVENT_TYPE_MOUSE_MOTION :
   211             {               
   212                 Dprintf ("mouse motion\n") ;
   213 
   214                 if (SDL_VideoSurface) {
   215                     if (currently_fullscreen) {
   216                         if (check_boundary (this, event.button.x, event.button.y)) {
   217                             SDL_PrivateMouseMotion (0, 0, event.button.x - OffsetX, 
   218                                 event.button.y - OffsetY) ;
   219                         }
   220                     } else {
   221                         SDL_PrivateMouseMotion (0, 0, event.button.x, event.button.y) ;
   222                     }
   223                 }
   224                 break ;
   225             }
   226 
   227             case GR_EVENT_TYPE_BUTTON_DOWN :
   228             {
   229                 int button = event.button.buttons ;
   230                 
   231                 Dprintf ("button down\n") ;
   232 
   233                 switch (button) {
   234                     case MWBUTTON_L :
   235                         button = 1 ;
   236                         break ;
   237                     case MWBUTTON_M :
   238                         button = 2 ;
   239                         break ;
   240                     case MWBUTTON_R :
   241                         button = 3 ;
   242                         break ;
   243                     default :
   244                         button = 0 ;
   245                 }
   246                 last_button_down = button ;
   247                 
   248                 if (currently_fullscreen) {
   249                     if (check_boundary (this, event.button.x, event.button.y)) {
   250                         SDL_PrivateMouseButton (SDL_PRESSED, button, 
   251                             event.button.x - OffsetX, event.button.y - OffsetY) ;
   252                     }
   253                 } else {
   254                     SDL_PrivateMouseButton (SDL_PRESSED, button, 
   255                         event.button.x, event.button.y) ;
   256                 }
   257                 break ;
   258             }
   259 
   260             // do not konw which button is released
   261             case GR_EVENT_TYPE_BUTTON_UP :
   262             {   
   263                 Dprintf ("button up\n") ;
   264 
   265                 if (currently_fullscreen) {
   266                     if (check_boundary (this, event.button.x, event.button.y)) {
   267                         SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, 
   268                             event.button.x - OffsetX, event.button.y - OffsetY) ;
   269                     }
   270                 } else {
   271                     SDL_PrivateMouseButton (SDL_RELEASED, last_button_down, 
   272                         event.button.x, event.button.y) ;
   273                 }
   274                 last_button_down = 0 ;
   275                 break ;
   276             }
   277 
   278             case GR_EVENT_TYPE_KEY_DOWN :
   279             {
   280                 SDL_keysym keysym ;
   281 
   282                 Dprintf ("key down\n") ;
   283                 SDL_PrivateKeyboard (SDL_PRESSED,
   284                     NX_TranslateKey (& event.keystroke, & keysym)) ;
   285                 break ;
   286             }
   287 
   288             case GR_EVENT_TYPE_KEY_UP :
   289             {
   290                 SDL_keysym keysym ;
   291 
   292                 Dprintf ("key up\n") ;
   293                 SDL_PrivateKeyboard (SDL_RELEASED,
   294                     NX_TranslateKey (& event.keystroke, & keysym)) ;
   295                 break ;
   296             }
   297 
   298             case GR_EVENT_TYPE_CLOSE_REQ :
   299             {
   300                 Dprintf ("close require\n") ;
   301                 SDL_PrivateQuit () ;
   302                 break ;
   303             }
   304 
   305             case GR_EVENT_TYPE_EXPOSURE :
   306             {
   307                 Dprintf ("event_type_exposure\n") ;
   308                 if (SDL_VideoSurface) {
   309                     NX_RefreshDisplay (this) ;//, & event.exposure) ;
   310                 }
   311                 break ;
   312             }
   313 
   314             case GR_EVENT_TYPE_UPDATE :
   315             {
   316                 switch (event.update.utype) {
   317                     case GR_UPDATE_MAP :
   318                     {
   319                         Dprintf ("GR_UPDATE_MAP\n") ;
   320                         // If we're not active, make ourselves active
   321                         if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
   322                             // Send an internal activate event
   323                             SDL_PrivateAppActive (1, SDL_APPACTIVE) ;
   324                         }
   325                         if (SDL_VideoSurface) {
   326                             NX_RefreshDisplay (this) ;
   327                         }
   328                         break ;
   329                     }
   330                     
   331                     case GR_UPDATE_UNMAP :
   332                     case GR_UPDATE_UNMAPTEMP :
   333                     {
   334                         Dprintf ("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n") ;
   335                         // If we're active, make ourselves inactive
   336                         if (SDL_GetAppState () & SDL_APPACTIVE) {
   337                             // Send an internal deactivate event
   338                             SDL_PrivateAppActive (0, SDL_APPACTIVE | SDL_APPINPUTFOCUS) ;
   339                         }
   340                         break ; 
   341                     }
   342                     
   343                     case GR_UPDATE_SIZE :
   344                     {
   345                         Dprintf ("GR_UPDATE_SIZE\n") ;
   346                         SDL_PrivateResize (event.update.width, event.update.height) ;
   347                         break ; 
   348                     }
   349 
   350                     case GR_UPDATE_MOVE :
   351 		    case GR_UPDATE_REPARENT :
   352                     {
   353                         Dprintf ("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n") ;
   354 #ifdef ENABLE_NANOX_DIRECT_FB
   355 			if (Clientfb) {
   356 			    /* Get current window position and fb pointer*/
   357 			    if (currently_fullscreen) 
   358 				GrGetWindowFBInfo(FSwindow, &fbinfo);
   359 			    else
   360 				GrGetWindowFBInfo(SDL_Window, &fbinfo);
   361 			}
   362 #endif
   363                         break ; 
   364                     }
   365                     
   366                     default :
   367                         Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ;
   368                         break ; 
   369                 }
   370                 break ; 
   371             }
   372                 
   373             default :
   374             {
   375                 Dprintf ("pump event default\n") ;
   376             }
   377         }
   378 
   379         GrCheckNextEvent (& event) ;
   380     }
   381 }