src/video/wscons/SDL_wsconsevents.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
    37 #include "SDL_wsconsevents_c.h"
    37 #include "SDL_wsconsevents_c.h"
    38 
    38 
    39 static int posted = 0;
    39 static int posted = 0;
    40 
    40 
    41 int
    41 int
    42 WSCONS_InitKeyboard (_THIS)
    42 WSCONS_InitKeyboard(_THIS)
    43 {
    43 {
    44     struct termios tty;
    44     struct termios tty;
    45 
    45 
    46     if (ioctl (private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) {
    46     if (ioctl(private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) {
    47         WSCONS_ReportError ("cannot get keyboard type: %s", strerror (errno));
    47         WSCONS_ReportError("cannot get keyboard type: %s", strerror(errno));
    48         return -1;
    48         return -1;
    49     }
    49     }
    50 
    50 
    51     if (tcgetattr (private->fd, &private->saved_tty) == -1) {
    51     if (tcgetattr(private->fd, &private->saved_tty) == -1) {
    52         WSCONS_ReportError ("cannot get terminal attributes: %s",
    52         WSCONS_ReportError("cannot get terminal attributes: %s",
    53                             strerror (errno));
    53                            strerror(errno));
    54         return -1;
    54         return -1;
    55     }
    55     }
    56     private->did_save_tty = 1;
    56     private->did_save_tty = 1;
    57     tty = private->saved_tty;
    57     tty = private->saved_tty;
    58     tty.c_iflag = IGNPAR | IGNBRK;
    58     tty.c_iflag = IGNPAR | IGNBRK;
    59     tty.c_oflag = 0;
    59     tty.c_oflag = 0;
    60     tty.c_cflag = CREAD | CS8;
    60     tty.c_cflag = CREAD | CS8;
    61     tty.c_lflag = 0;
    61     tty.c_lflag = 0;
    62     tty.c_cc[VTIME] = 0;
    62     tty.c_cc[VTIME] = 0;
    63     tty.c_cc[VMIN] = 1;
    63     tty.c_cc[VMIN] = 1;
    64     cfsetispeed (&tty, 9600);
    64     cfsetispeed(&tty, 9600);
    65     cfsetospeed (&tty, 9600);
    65     cfsetospeed(&tty, 9600);
    66     if (tcsetattr (private->fd, TCSANOW, &tty) < 0) {
    66     if (tcsetattr(private->fd, TCSANOW, &tty) < 0) {
    67         WSCONS_ReportError ("cannot set terminal attributes: %s",
    67         WSCONS_ReportError("cannot set terminal attributes: %s",
    68                             strerror (errno));
    68                            strerror(errno));
    69         return -1;
    69         return -1;
    70     }
    70     }
    71     if (ioctl (private->fd, KDSKBMODE, K_RAW) == -1) {
    71     if (ioctl(private->fd, KDSKBMODE, K_RAW) == -1) {
    72         WSCONS_ReportError ("cannot set raw keyboard mode: %s",
    72         WSCONS_ReportError("cannot set raw keyboard mode: %s",
    73                             strerror (errno));
    73                            strerror(errno));
    74         return -1;
    74         return -1;
    75     }
    75     }
    76 
    76 
    77     return 0;
    77     return 0;
    78 }
    78 }
    79 
    79 
    80 void
    80 void
    81 WSCONS_ReleaseKeyboard (_THIS)
    81 WSCONS_ReleaseKeyboard(_THIS)
    82 {
    82 {
    83     if (private->fd != -1) {
    83     if (private->fd != -1) {
    84         if (ioctl (private->fd, KDSKBMODE, K_XLATE) == -1) {
    84         if (ioctl(private->fd, KDSKBMODE, K_XLATE) == -1) {
    85             WSCONS_ReportError
    85             WSCONS_ReportError
    86                 ("cannot restore keyboard to translated mode: %s",
    86                 ("cannot restore keyboard to translated mode: %s",
    87                  strerror (errno));
    87                  strerror(errno));
    88         }
    88         }
    89         if (private->did_save_tty) {
    89         if (private->did_save_tty) {
    90             if (tcsetattr (private->fd, TCSANOW, &private->saved_tty) < 0) {
    90             if (tcsetattr(private->fd, TCSANOW, &private->saved_tty) < 0) {
    91                 WSCONS_ReportError
    91                 WSCONS_ReportError
    92                     ("cannot restore keynoard attributes: %s",
    92                     ("cannot restore keynoard attributes: %s",
    93                      strerror (errno));
    93                      strerror(errno));
    94             }
    94             }
    95         }
    95         }
    96     }
    96     }
    97 }
    97 }
    98 
    98 
    99 static void
    99 static void
   100 updateMouse ()
   100 updateMouse()
   101 {
   101 {
   102 }
   102 }
   103 
   103 
   104 static SDLKey keymap[128];
   104 static SDLKey keymap[128];
   105 
   105 
   106 static SDL_keysym *
   106 static SDL_keysym *
   107 TranslateKey (int scancode, SDL_keysym * keysym)
   107 TranslateKey(int scancode, SDL_keysym * keysym)
   108 {
   108 {
   109     keysym->scancode = scancode;
   109     keysym->scancode = scancode;
   110     keysym->sym = SDLK_UNKNOWN;
   110     keysym->sym = SDLK_UNKNOWN;
   111     keysym->mod = KMOD_NONE;
   111     keysym->mod = KMOD_NONE;
   112 
   112 
   113     if (scancode < SDL_arraysize (keymap))
   113     if (scancode < SDL_arraysize(keymap))
   114         keysym->sym = keymap[scancode];
   114         keysym->sym = keymap[scancode];
   115 
   115 
   116     if (keysym->sym == SDLK_UNKNOWN)
   116     if (keysym->sym == SDLK_UNKNOWN)
   117         printf ("Unknown mapping for scancode %d\n", scancode);
   117         printf("Unknown mapping for scancode %d\n", scancode);
   118 
   118 
   119     return keysym;
   119     return keysym;
   120 }
   120 }
   121 
   121 
   122 static void
   122 static void
   123 updateKeyboard (_THIS)
   123 updateKeyboard(_THIS)
   124 {
   124 {
   125     unsigned char buf[100];
   125     unsigned char buf[100];
   126     SDL_keysym keysym;
   126     SDL_keysym keysym;
   127     int n, i;
   127     int n, i;
   128 
   128 
   129     if ((n = read (private->fd, buf, sizeof (buf))) > 0) {
   129     if ((n = read(private->fd, buf, sizeof(buf))) > 0) {
   130         for (i = 0; i < n; i++) {
   130         for (i = 0; i < n; i++) {
   131             unsigned char c = buf[i] & 0x7f;
   131             unsigned char c = buf[i] & 0x7f;
   132             if (c == 224)       // special key prefix -- what should we do with it?
   132             if (c == 224)       // special key prefix -- what should we do with it?
   133                 continue;
   133                 continue;
   134             posted +=
   134             posted +=
   135                 SDL_PrivateKeyboard ((buf[i] & 0x80) ? SDL_RELEASED :
   135                 SDL_PrivateKeyboard((buf[i] & 0x80) ? SDL_RELEASED :
   136                                      SDL_PRESSED, TranslateKey (c, &keysym));
   136                                     SDL_PRESSED, TranslateKey(c, &keysym));
   137         }
   137         }
   138     }
   138     }
   139 }
   139 }
   140 
   140 
   141 void
   141 void
   142 WSCONS_PumpEvents (_THIS)
   142 WSCONS_PumpEvents(_THIS)
   143 {
   143 {
   144     do {
   144     do {
   145         posted = 0;
   145         posted = 0;
   146         updateMouse ();
   146         updateMouse();
   147         updateKeyboard (this);
   147         updateKeyboard(this);
   148     }
   148     }
   149     while (posted);
   149     while (posted);
   150 }
   150 }
   151 
   151 
   152 void
   152 void
   153 WSCONS_InitOSKeymap (_THIS)
   153 WSCONS_InitOSKeymap(_THIS)
   154 {
   154 {
   155     int i;
   155     int i;
   156 
   156 
   157     /* Make sure unknown keys are mapped correctly */
   157     /* Make sure unknown keys are mapped correctly */
   158     for (i = 0; i < SDL_arraysize (keymap); i++) {
   158     for (i = 0; i < SDL_arraysize(keymap); i++) {
   159         keymap[i] = SDLK_UNKNOWN;
   159         keymap[i] = SDLK_UNKNOWN;
   160     }
   160     }
   161 
   161 
   162     switch (private->kbdType) {
   162     switch (private->kbdType) {
   163 #ifdef WSKBD_TYPE_ZAURUS
   163 #ifdef WSKBD_TYPE_ZAURUS
   235         keymap[80] = SDLK_DOWN;
   235         keymap[80] = SDLK_DOWN;
   236         break;
   236         break;
   237 #endif /* WSKBD_TYPE_ZAURUS */
   237 #endif /* WSKBD_TYPE_ZAURUS */
   238 
   238 
   239     default:
   239     default:
   240         WSCONS_ReportError ("Unable to map keys for keyboard type %u",
   240         WSCONS_ReportError("Unable to map keys for keyboard type %u",
   241                             private->kbdType);
   241                            private->kbdType);
   242         break;
   242         break;
   243     }
   243     }
   244 }
   244 }
   245 
   245 
   246 /* end of SDL_wsconsevents.c ... */
   246 /* end of SDL_wsconsevents.c ... */