"Fossies" - the Fresh Open Source Software Archive

Member "dosemu-1.4.0/src/plugin/sdl/keyb_SDL.c" (4 May 2007, 6622 Bytes) of package /linux/misc/old/dosemu-1.4.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "keyb_SDL.c" see the Fossies "Dox" file reference documentation.

    1 /* 
    2  * (C) Copyright 1992, ..., 2007 the "DOSEMU-Development-Team".
    3  *
    4  * for details see file COPYING.DOSEMU in the DOSEMU distribution
    5  */
    6 
    7 #include "config.h"
    8 
    9 #include <SDL.h>
   10 #include <langinfo.h>
   11 #include <string.h>
   12 
   13 #include "emu.h"
   14 #include "keyb_clients.h"
   15 #include "keyboard.h"
   16 #include "keysym_attributes.h"
   17 #include "video.h"
   18 #include "sdl.h"
   19 
   20 static int use_move_key(t_keysym key)
   21 {
   22     int result = FALSE;
   23         /* If it's some kind of function key move it
   24          * otherwise just make sure it gets pressed
   25          */
   26         if (is_keysym_function(key) ||
   27             is_keysym_dosemu_key(key) ||
   28             is_keypad_keysym(key) ||
   29             (key == KEY_TAB) ||
   30             (key == KEY_RETURN) ||
   31             (key == KEY_BKSP)) {
   32                 result = TRUE;
   33         }
   34     return result;
   35 }
   36 
   37 static t_modifiers map_SDL_modifiers(SDLMod e_state)
   38 {
   39         t_modifiers modifiers = 0;
   40         if (e_state & KMOD_SHIFT) {
   41                 modifiers |= MODIFIER_SHIFT;
   42         }
   43         if (e_state & KMOD_CTRL) {
   44                 modifiers |= MODIFIER_CTRL;
   45         }
   46         if (e_state & KMOD_LALT) {
   47                 modifiers |= MODIFIER_ALT;
   48         }
   49         if (e_state & (KMOD_RALT|KMOD_MODE)) {
   50                 modifiers |= MODIFIER_ALTGR;
   51         }
   52         if (e_state & KMOD_CAPS) {
   53                 modifiers |= MODIFIER_CAPS;
   54         }
   55         if (e_state & KMOD_NUM) {
   56                 modifiers |= MODIFIER_NUM;
   57         }
   58 #if 0
   59         if (e_state & X_mi.ScrollLockMask) {
   60                 modifiers |= MODIFIER_SCR;
   61         }
   62         if (e_state & X_mi.InsLockMask) {
   63                 modifiers |= MODIFIER_INS;
   64         }
   65 #endif
   66         return modifiers;
   67 }
   68 
   69 static void SDL_sync_shiftstate(Boolean make, SDLKey kc, SDLMod e_state)
   70 {
   71     t_modifiers shiftstate = get_shiftstate();
   72 
   73     /* Check for modifiers released outside this window */
   74     if (!!(shiftstate & MODIFIER_SHIFT) != !!(e_state & KMOD_SHIFT)) {
   75         shiftstate ^= MODIFIER_SHIFT;
   76     }
   77     if (!!(shiftstate & MODIFIER_CTRL) != !!(e_state & KMOD_CTRL)) {
   78         shiftstate ^= MODIFIER_CTRL;
   79     }
   80     if (!!(shiftstate & MODIFIER_ALT) != !!(e_state & KMOD_LALT)) {
   81         shiftstate ^= MODIFIER_ALT;
   82     }
   83     if (!!(shiftstate & MODIFIER_ALTGR) != !!(e_state & (KMOD_RALT|KMOD_MODE))) {
   84         shiftstate ^= MODIFIER_ALTGR;
   85     }
   86 
   87     if (!!(shiftstate & MODIFIER_CAPS) != !!(e_state & KMOD_CAPS)
   88         && (make || (kc != SDLK_CAPSLOCK))) {
   89         shiftstate ^= MODIFIER_CAPS;
   90     }
   91     if (!!(shiftstate & MODIFIER_NUM) != !!(e_state & KMOD_NUM)
   92         && (make || (kc != SDLK_NUMLOCK))) {
   93         shiftstate ^= MODIFIER_NUM;
   94     }
   95 #if 0
   96     if (!!(shiftstate & MODIFIER_SCR) != !!(e_state & X_mi.ScrollLockMask)) {
   97         && (make || (kc != SDLK_SCROLLOCK))) {
   98         shiftstate ^= MODIFIER_SCR;
   99     }
  100     if (!!(shiftstate & MODIFIER_INS) != !!(e_state & X_mi.InsLockMask)) {
  101         shiftstate ^= MODIFIER_INS;
  102     }
  103 #endif
  104     set_shiftstate(shiftstate);
  105 }
  106 
  107 void SDL_process_key(SDL_KeyboardEvent keyevent)
  108 {
  109     SDL_keysym keysym = keyevent.keysym;
  110     t_unicode key = keysym.unicode;
  111     t_modifiers modifiers = map_SDL_modifiers(keysym.mod);
  112 
  113     switch (keysym.sym) {
  114       case SDLK_UNKNOWN:
  115         /* workaround for X11+SDL bug with AltGR (from QEMU) */
  116         if (keysym.scancode == 113)
  117             key = KEY_R_ALT;
  118         break;
  119 
  120       case SDLK_SPACE ... SDLK_DELETE-1: /* ASCII range 32..126 */
  121         key = keysym.sym;
  122         break;
  123 
  124       case SDLK_WORLD_0 ... SDLK_WORLD_95:
  125         /* workaround for older SDLs; harmless for newer;
  126            this just fixes the iso-8859-1 subset of utf-8; other
  127            characters are almost impossible with SDL < 1.2.10
  128          */
  129         if (key < 0x100 && strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
  130             key = keysym.sym;
  131         break;
  132 
  133       case SDLK_CAPSLOCK:
  134         key = KEY_CAPS;
  135         break;
  136 
  137       case SDLK_NUMLOCK:
  138         key = KEY_NUM;
  139         break;
  140         
  141       case SDLK_SCROLLOCK:
  142         key = KEY_SCROLL;
  143         break;
  144         
  145       case SDLK_KP0 ... SDLK_KP9:
  146         key = (keysym.sym - SDLK_KP0) + KEY_PAD_0;
  147         break;
  148 
  149       case SDLK_KP_PERIOD:
  150         key = KEY_PAD_DECIMAL;
  151         break;
  152 
  153       case SDLK_KP_DIVIDE:
  154         key = KEY_PAD_SLASH;
  155         break;
  156 
  157       case SDLK_KP_MULTIPLY:
  158         key = KEY_PAD_AST;
  159         break;
  160 
  161       case SDLK_KP_MINUS:
  162         key = KEY_PAD_MINUS;
  163         break;
  164 
  165       case SDLK_KP_PLUS:
  166         key = KEY_PAD_PLUS;
  167         break;
  168 
  169       case SDLK_KP_ENTER:
  170         key = KEY_PAD_ENTER;
  171         break;
  172 
  173       case SDLK_KP_EQUALS:
  174         key = KEY_PAD_EQUAL;
  175         break;
  176 
  177       case SDLK_F1 ... SDLK_F10:
  178         key = (keysym.sym - SDLK_F1) + KEY_F1 ;
  179         break;
  180 #define DOKEY(x) case SDLK_##x: key = KEY_##x; break;
  181       DOKEY(F11)
  182       DOKEY(F12)
  183       DOKEY(F13)
  184       DOKEY(F14)
  185       DOKEY(F15)
  186       DOKEY(RETURN)
  187       DOKEY(TAB)
  188       DOKEY(PAUSE)
  189       DOKEY(BREAK)
  190       DOKEY(HOME)
  191       DOKEY(LEFT)
  192       DOKEY(UP)
  193       DOKEY(RIGHT)
  194       DOKEY(DOWN)
  195       DOKEY(END)
  196       case SDLK_PAGEUP:
  197         key = KEY_PGUP;
  198         break;
  199       case SDLK_PAGEDOWN:
  200         key = KEY_PGDN;
  201         break;
  202       case SDLK_DELETE:
  203         key = KEY_DEL;
  204         break;
  205         
  206       case SDLK_INSERT:
  207         key = KEY_INS;
  208         break;      
  209         
  210       case SDLK_BACKSPACE:
  211         key = KEY_BKSP;
  212         break;
  213         
  214       case SDLK_ESCAPE:
  215         key = KEY_ESC;
  216         break;
  217 
  218       case SDLK_SYSREQ:
  219         key = KEY_SYSRQ;
  220         break;
  221 
  222       case SDLK_CLEAR:
  223         key = KEY_DOSEMU_CLEAR;
  224         break;
  225 
  226       case SDLK_COMPOSE:
  227         key = KEY_MULTI_KEY;
  228         break;
  229 
  230       case SDLK_PRINT:
  231         key = KEY_PRTSCR;
  232         break;
  233 
  234       case SDLK_MENU:
  235         key = KEY_DOSEMU_UNDO;
  236         break;
  237 
  238       case SDLK_HELP:
  239         key = KEY_DOSEMU_HELP;
  240         break;
  241 
  242       case SDLK_EURO:
  243         key = U_EURO_SIGN;
  244         break;
  245 
  246       case SDLK_UNDO:
  247         key = KEY_DOSEMU_UNDO;
  248         break;
  249 
  250       case SDLK_RSHIFT: key = KEY_R_SHIFT ; break;      
  251       case SDLK_LSHIFT: key = KEY_L_SHIFT ; break;      
  252       case SDLK_RCTRL: key = KEY_R_CTRL ; break;        
  253       case SDLK_LCTRL: key = KEY_L_CTRL ; break;        
  254       case SDLK_RMETA: key = KEY_R_META ; break;
  255       case SDLK_MODE: key = KEY_MODE_SWITCH ; break;
  256       case SDLK_RALT: key = KEY_R_ALT ; break;      
  257       case SDLK_RSUPER: key = KEY_R_SUPER ; break;
  258       case SDLK_LMETA: key = KEY_L_META ; break;
  259       case SDLK_LALT: key = KEY_L_ALT ; break;      
  260       case SDLK_LSUPER: key = KEY_L_SUPER ; break;
  261 
  262       /* case SDLK_POWER: */
  263       default: 
  264         if (keysym.sym > 255)
  265             key = KEY_VOID;
  266         break;
  267      }
  268 
  269     SDL_sync_shiftstate(keyevent.state==SDL_PRESSED, keysym.sym, keysym.mod);
  270 
  271         if (!use_move_key(key) || (move_key(keyevent.state == SDL_PRESSED, key) < 0)) {
  272                 put_modified_symbol(keyevent.state==SDL_PRESSED, modifiers, key);
  273         }
  274 }
  275 
  276 static int probe_SDL_keyb(void)
  277 {
  278     int result = FALSE;
  279     if (Video == &Video_SDL) {
  280         result = TRUE;
  281     }
  282     return result;
  283 }
  284 
  285 struct keyboard_client Keyboard_SDL =  {
  286     "SDL",                  /* name */
  287     probe_SDL_keyb,         /* probe */
  288     NULL,                   /* init */
  289     NULL,                   /* reset */
  290     NULL,                   /* close */
  291     NULL,                   /* run */       
  292     NULL                    /* set_leds */
  293 };