src/video/nanox/SDL_nxevents.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Dec 2008 22:37:40 +0000
changeset 2853 6258fa7cd300
parent 1895 c121d94672cb
child 2859 99210400e8b9
permissions -rw-r--r--
Fixed picking blit function when RLE fails
     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 #include "SDL_config.h"
    28 
    29 #include "SDL_keysym.h"
    30 #include "../../events/SDL_events_c.h"
    31 
    32 #include "SDL_nxevents_c.h"
    33 #include "SDL_nximage_c.h"
    34 
    35 // The translation tables from a nanox keysym to a SDL keysym
    36 static SDLKey NX_NONASCII_keymap[MWKEY_LAST + 1];
    37 
    38 void
    39 NX_InitOSKeymap(_THIS)
    40 {
    41     int i;
    42 
    43     Dprintf("enter NX_InitOSKeymap\n");
    44 
    45     // Map the nanox scancodes to SDL keysyms
    46     for (i = 0; i < SDL_arraysize(NX_NONASCII_keymap); ++i)
    47         NX_NONASCII_keymap[i] = SDLK_UNKNOWN;
    48 
    49     NX_NONASCII_keymap[MWKEY_LEFT & 0xFF] = SDLK_LEFT;
    50     NX_NONASCII_keymap[MWKEY_RIGHT & 0xFF] = SDLK_RIGHT;
    51     NX_NONASCII_keymap[MWKEY_UP & 0xFF] = SDLK_UP;
    52     NX_NONASCII_keymap[MWKEY_DOWN & 0xFF] = SDLK_DOWN;
    53     NX_NONASCII_keymap[MWKEY_INSERT & 0xFF] = SDLK_INSERT;
    54     NX_NONASCII_keymap[MWKEY_DELETE & 0xFF] = SDLK_DELETE;
    55     NX_NONASCII_keymap[MWKEY_HOME & 0xFF] = SDLK_HOME;
    56     NX_NONASCII_keymap[MWKEY_END & 0xFF] = SDLK_END;
    57     NX_NONASCII_keymap[MWKEY_PAGEUP & 0xFF] = SDLK_PAGEUP;
    58     NX_NONASCII_keymap[MWKEY_PAGEDOWN & 0xFF] = SDLK_PAGEDOWN;
    59 
    60     NX_NONASCII_keymap[MWKEY_KP0 & 0xFF] = SDLK_KP0;
    61     NX_NONASCII_keymap[MWKEY_KP1 & 0xFF] = SDLK_KP1;
    62     NX_NONASCII_keymap[MWKEY_KP2 & 0xFF] = SDLK_KP2;
    63     NX_NONASCII_keymap[MWKEY_KP3 & 0xFF] = SDLK_KP3;
    64     NX_NONASCII_keymap[MWKEY_KP4 & 0xFF] = SDLK_KP4;
    65     NX_NONASCII_keymap[MWKEY_KP5 & 0xFF] = SDLK_KP5;
    66     NX_NONASCII_keymap[MWKEY_KP6 & 0xFF] = SDLK_KP6;
    67     NX_NONASCII_keymap[MWKEY_KP7 & 0xFF] = SDLK_KP7;
    68     NX_NONASCII_keymap[MWKEY_KP8 & 0xFF] = SDLK_KP8;
    69     NX_NONASCII_keymap[MWKEY_KP9 & 0xFF] = SDLK_KP9;
    70     NX_NONASCII_keymap[MWKEY_KP_PERIOD & 0xFF] = SDLK_KP_PERIOD;
    71     NX_NONASCII_keymap[MWKEY_KP_DIVIDE & 0xFF] = SDLK_KP_DIVIDE;
    72     NX_NONASCII_keymap[MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY;
    73     NX_NONASCII_keymap[MWKEY_KP_MINUS & 0xFF] = SDLK_KP_MINUS;
    74     NX_NONASCII_keymap[MWKEY_KP_PLUS & 0xFF] = SDLK_KP_PLUS;
    75     NX_NONASCII_keymap[MWKEY_KP_ENTER & 0xFF] = SDLK_KP_ENTER;
    76     NX_NONASCII_keymap[MWKEY_KP_EQUALS & 0xFF] = SDLK_KP_EQUALS;
    77 
    78     NX_NONASCII_keymap[MWKEY_F1 & 0xFF] = SDLK_F1;
    79     NX_NONASCII_keymap[MWKEY_F2 & 0xFF] = SDLK_F2;
    80     NX_NONASCII_keymap[MWKEY_F3 & 0xFF] = SDLK_F3;
    81     NX_NONASCII_keymap[MWKEY_F4 & 0xFF] = SDLK_F4;
    82     NX_NONASCII_keymap[MWKEY_F5 & 0xFF] = SDLK_F5;
    83     NX_NONASCII_keymap[MWKEY_F6 & 0xFF] = SDLK_F6;
    84     NX_NONASCII_keymap[MWKEY_F7 & 0xFF] = SDLK_F7;
    85     NX_NONASCII_keymap[MWKEY_F8 & 0xFF] = SDLK_F8;
    86     NX_NONASCII_keymap[MWKEY_F9 & 0xFF] = SDLK_F9;
    87     NX_NONASCII_keymap[MWKEY_F10 & 0xFF] = SDLK_F10;
    88     NX_NONASCII_keymap[MWKEY_F11 & 0xFF] = SDLK_F11;
    89     NX_NONASCII_keymap[MWKEY_F12 & 0xFF] = SDLK_F12;
    90 
    91     NX_NONASCII_keymap[MWKEY_NUMLOCK & 0xFF] = SDLK_NUMLOCK;
    92     NX_NONASCII_keymap[MWKEY_CAPSLOCK & 0xFF] = SDLK_CAPSLOCK;
    93     NX_NONASCII_keymap[MWKEY_SCROLLOCK & 0xFF] = SDLK_SCROLLOCK;
    94     NX_NONASCII_keymap[MWKEY_LSHIFT & 0xFF] = SDLK_LSHIFT;
    95     NX_NONASCII_keymap[MWKEY_RSHIFT & 0xFF] = SDLK_RSHIFT;
    96     NX_NONASCII_keymap[MWKEY_LCTRL & 0xFF] = SDLK_LCTRL;
    97     NX_NONASCII_keymap[MWKEY_RCTRL & 0xFF] = SDLK_RCTRL;
    98     NX_NONASCII_keymap[MWKEY_LALT & 0xFF] = SDLK_LALT;
    99     NX_NONASCII_keymap[MWKEY_RALT & 0xFF] = SDLK_RALT;
   100     NX_NONASCII_keymap[MWKEY_LMETA & 0xFF] = SDLK_LMETA;
   101     NX_NONASCII_keymap[MWKEY_RMETA & 0xFF] = SDLK_RMETA;
   102     NX_NONASCII_keymap[MWKEY_ALTGR & 0xFF] = SDLK_MODE;
   103 
   104     NX_NONASCII_keymap[MWKEY_PRINT & 0xFF] = SDLK_PRINT;
   105     NX_NONASCII_keymap[MWKEY_SYSREQ & 0xFF] = SDLK_SYSREQ;
   106     NX_NONASCII_keymap[MWKEY_PAUSE & 0xFF] = SDLK_PAUSE;
   107     NX_NONASCII_keymap[MWKEY_BREAK & 0xFF] = SDLK_BREAK;
   108     NX_NONASCII_keymap[MWKEY_MENU & 0xFF] = SDLK_MENU;
   109 
   110     Dprintf("leave NX_InitOSKeymap\n");
   111 }
   112 
   113 SDL_keysym *
   114 NX_TranslateKey(GR_EVENT_KEYSTROKE * keystroke, SDL_keysym * keysym)
   115 {
   116     GR_KEY ch = keystroke->ch;
   117 
   118     Dprintf("enter NX_TranslateKey\n");
   119 
   120     keysym->scancode = keystroke->scancode;
   121     keysym->sym = SDLK_UNKNOWN;
   122 
   123     if (ch & MWKEY_NONASCII_MASK) {
   124         keysym->sym = NX_NONASCII_keymap[ch & 0xFF];
   125     } else {
   126         keysym->sym = ch & 0x7F;
   127     }
   128 
   129     keysym->mod = KMOD_NONE;
   130 
   131 #if 1                           //   Retrieve more mode information
   132     {
   133         GR_KEYMOD mod = keystroke->modifiers;
   134 
   135         if (mod & MWKMOD_LSHIFT)
   136             keysym->mod |= KMOD_LSHIFT;
   137         if (mod & MWKMOD_RSHIFT)
   138             keysym->mod |= KMOD_RSHIFT;
   139         if (mod & MWKMOD_LCTRL)
   140             keysym->mod |= KMOD_LCTRL;
   141         if (mod & MWKMOD_RCTRL)
   142             keysym->mod |= KMOD_RCTRL;
   143         if (mod & MWKMOD_LALT)
   144             keysym->mod |= KMOD_LALT;
   145         if (mod & MWKMOD_RALT)
   146             keysym->mod |= KMOD_RALT;
   147         if (mod & MWKMOD_LMETA)
   148             keysym->mod |= KMOD_LMETA;
   149         if (mod & MWKMOD_RMETA)
   150             keysym->mod |= KMOD_RMETA;
   151         if (mod & MWKMOD_NUM)
   152             keysym->mod |= KMOD_NUM;
   153         if (mod & MWKMOD_CAPS)
   154             keysym->mod |= KMOD_CAPS;
   155         if (mod & MWKMOD_ALTGR)
   156             keysym->mod |= KMOD_MODE;
   157     }
   158 #endif
   159 
   160     keysym->unicode = ch;
   161 
   162     Dprintf("leave NX_TranslateKey\n");
   163     return keysym;
   164 }
   165 
   166 static int
   167 check_boundary(_THIS, int x, int y)
   168 {
   169     if (x < OffsetX || y < OffsetY || x > OffsetX + this->screen->w ||
   170         y > OffsetY + this->screen->h)
   171         return 0;
   172 
   173     return 1;
   174 }
   175 
   176 void
   177 NX_PumpEvents(_THIS)
   178 {
   179     GR_EVENT event;
   180     static GR_BUTTON last_button_down = 0;
   181 
   182     GrCheckNextEvent(&event);
   183     while (event.type != GR_EVENT_TYPE_NONE) {
   184 
   185         // dispatch event
   186         switch (event.type) {
   187         case GR_EVENT_TYPE_MOUSE_ENTER:
   188             {
   189                 Dprintf("mouse enter\n");
   190                 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   191                 break;
   192             }
   193 
   194         case GR_EVENT_TYPE_MOUSE_EXIT:
   195             {
   196                 Dprintf("mouse exit\n");
   197                 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   198                 break;
   199             }
   200 
   201         case GR_EVENT_TYPE_FOCUS_IN:
   202             {
   203                 Dprintf("focus in\n");
   204                 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   205                 break;
   206             }
   207 
   208         case GR_EVENT_TYPE_FOCUS_OUT:
   209             {
   210                 Dprintf("focus out\n");
   211                 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
   212                 break;
   213             }
   214 
   215         case GR_EVENT_TYPE_MOUSE_MOTION:
   216             {
   217                 Dprintf("mouse motion\n");
   218 
   219                 if (SDL_VideoSurface) {
   220                     if (currently_fullscreen) {
   221                         if (check_boundary
   222                             (this, event.button.x, event.button.y)) {
   223                             SDL_PrivateMouseMotion(0, 0,
   224                                                    event.button.x -
   225                                                    OffsetX,
   226                                                    event.button.y - OffsetY);
   227                         }
   228                     } else {
   229                         SDL_PrivateMouseMotion(0, 0, event.button.x,
   230                                                event.button.y);
   231                     }
   232                 }
   233                 break;
   234             }
   235 
   236         case GR_EVENT_TYPE_BUTTON_DOWN:
   237             {
   238                 int button = event.button.buttons;
   239 
   240                 Dprintf("button down\n");
   241 
   242                 switch (button) {
   243                 case MWBUTTON_L:
   244                     button = 1;
   245                     break;
   246                 case MWBUTTON_M:
   247                     button = 2;
   248                     break;
   249                 case MWBUTTON_R:
   250                     button = 3;
   251                     break;
   252                 default:
   253                     button = 0;
   254                 }
   255                 last_button_down = button;
   256 
   257                 if (currently_fullscreen) {
   258                     if (check_boundary(this, event.button.x, event.button.y)) {
   259                         SDL_PrivateMouseButton(SDL_PRESSED, button,
   260                                                event.button.x -
   261                                                OffsetX,
   262                                                event.button.y - OffsetY);
   263                     }
   264                 } else {
   265                     SDL_PrivateMouseButton(SDL_PRESSED, button,
   266                                            event.button.x, event.button.y);
   267                 }
   268                 break;
   269             }
   270 
   271             // do not konw which button is released
   272         case GR_EVENT_TYPE_BUTTON_UP:
   273             {
   274                 Dprintf("button up\n");
   275 
   276                 if (currently_fullscreen) {
   277                     if (check_boundary(this, event.button.x, event.button.y)) {
   278                         SDL_PrivateMouseButton(SDL_RELEASED,
   279                                                last_button_down,
   280                                                event.button.x -
   281                                                OffsetX,
   282                                                event.button.y - OffsetY);
   283                     }
   284                 } else {
   285                     SDL_PrivateMouseButton(SDL_RELEASED,
   286                                            last_button_down,
   287                                            event.button.x, event.button.y);
   288                 }
   289                 last_button_down = 0;
   290                 break;
   291             }
   292 
   293         case GR_EVENT_TYPE_KEY_DOWN:
   294             {
   295                 SDL_keysym keysym;
   296 
   297                 Dprintf("key down\n");
   298                 SDL_PrivateKeyboard(SDL_PRESSED,
   299                                     NX_TranslateKey(&event.keystroke,
   300                                                     &keysym));
   301                 break;
   302             }
   303 
   304         case GR_EVENT_TYPE_KEY_UP:
   305             {
   306                 SDL_keysym keysym;
   307 
   308                 Dprintf("key up\n");
   309                 SDL_PrivateKeyboard(SDL_RELEASED,
   310                                     NX_TranslateKey(&event.keystroke,
   311                                                     &keysym));
   312                 break;
   313             }
   314 
   315         case GR_EVENT_TYPE_CLOSE_REQ:
   316             {
   317                 Dprintf("close require\n");
   318                 SDL_PrivateQuit();
   319                 break;
   320             }
   321 
   322         case GR_EVENT_TYPE_EXPOSURE:
   323             {
   324                 Dprintf("event_type_exposure\n");
   325                 if (SDL_VideoSurface) {
   326                     NX_RefreshDisplay(this);    //, & event.exposure) ;
   327                 }
   328                 break;
   329             }
   330 
   331         case GR_EVENT_TYPE_UPDATE:
   332             {
   333                 switch (event.update.utype) {
   334                 case GR_UPDATE_MAP:
   335                     {
   336                         Dprintf("GR_UPDATE_MAP\n");
   337                         // If we're not active, make ourselves active
   338                         if (!(SDL_GetAppState() & SDL_APPACTIVE)) {
   339                             // Send an internal activate event
   340                             SDL_PrivateAppActive(1, SDL_APPACTIVE);
   341                         }
   342                         if (SDL_VideoSurface) {
   343                             NX_RefreshDisplay(this);
   344                         }
   345                         break;
   346                     }
   347 
   348                 case GR_UPDATE_UNMAP:
   349                 case GR_UPDATE_UNMAPTEMP:
   350                     {
   351                         Dprintf("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n");
   352                         // If we're active, make ourselves inactive
   353                         if (SDL_GetAppState() & SDL_APPACTIVE) {
   354                             // Send an internal deactivate event
   355                             SDL_PrivateAppActive(0,
   356                                                  SDL_APPACTIVE |
   357                                                  SDL_APPINPUTFOCUS);
   358                         }
   359                         break;
   360                     }
   361 
   362                 case GR_UPDATE_SIZE:
   363                     {
   364                         Dprintf("GR_UPDATE_SIZE\n");
   365                         SDL_PrivateResize(event.update.width,
   366                                           event.update.height);
   367                         break;
   368                     }
   369 
   370                 case GR_UPDATE_MOVE:
   371                 case GR_UPDATE_REPARENT:
   372                     {
   373                         Dprintf("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n");
   374 #ifdef ENABLE_NANOX_DIRECT_FB
   375                         if (Clientfb) {
   376                             /* Get current window position and fb pointer */
   377                             if (currently_fullscreen)
   378                                 GrGetWindowFBInfo(FSwindow, &fbinfo);
   379                             else
   380                                 GrGetWindowFBInfo(SDL_Window, &fbinfo);
   381                         }
   382 #endif
   383                         break;
   384                     }
   385 
   386                 default:
   387                     Dprintf("unknown GR_EVENT_TYPE_UPDATE\n");
   388                     break;
   389                 }
   390                 break;
   391             }
   392 
   393         default:
   394             {
   395                 Dprintf("pump event default\n");
   396             }
   397         }
   398 
   399         GrCheckNextEvent(&event);
   400     }
   401 }
   402 
   403 /* vi: set ts=4 sw=4 expandtab: */