Annotation of uae/src/rawkeys.c, revision 1.1

1.1     ! root        1:  /*
        !             2:   * UAE - The Un*x Amiga Emulator
        !             3:   *
        !             4:   * Support for mapping SDL raw keycodes
        !             5:   *
        !             6:   * Copyright 2004 Richard Drummond
        !             7:   */
        !             8: 
        !             9: #include "sysconfig.h"
        !            10: #include "sysdeps.h"
        !            11: 
        !            12: #include "options.h"
        !            13: #include "inputdevice.h"
        !            14: #include "keyboard.h"
        !            15: 
        !            16: #include "hotkeys.h"
        !            17: #include "keymap/keymap.h"
        !            18: #include "keymap/keymap_all.h"
        !            19: #include "sdlgfx.h"
        !            20: 
        !            21: #include <SDL.h>
        !            22: 
        !            23: /*
        !            24:  * This stuff is hacked together for now to get
        !            25:  * raw keyboard support working and tested.
        !            26:  *
        !            27:  * A cleaner implementation will be coming . . .
        !            28:  */
        !            29: struct sdl_raw_keymap
        !            30: {
        !            31:     int                          sdl_gfx_driver;
        !            32:     const char                  *name;
        !            33:     const struct uaekey_hostmap *keymap;
        !            34:          struct uae_hotkeyseq  *hotkeys;
        !            35:     const int                   *modtable;
        !            36: };
        !            37: 
        !            38: static struct uae_input_device_kbr_default *keyboard = 0;
        !            39: static const int *modkeytable;
        !            40: 
        !            41: /*
        !            42:  * Table used to pick keymapping based on SDL gfx driver
        !            43:  */
        !            44: static const struct sdl_raw_keymap keymaps[] = {
        !            45: #if (defined __i386__ || defined __x86_64__ || defined __powerpc__ || defined __ppc__) && defined __linux__
        !            46:     { SDLGFX_DRIVER_X11,     "x11pc",  x11pc_keymap,  x11pc_hotkeys,  0},
        !            47:     { SDLGFX_DRIVER_DGA,     "x11pc",  x11pc_keymap,  x11pc_hotkeys,  0},
        !            48: #endif
        !            49: #if (defined __powerpc__ || defined __ppc__) && defined __APPLE__
        !            50:     { SDLGFX_DRIVER_QUARTZ,  "quartz", quartz_keymap, quartz_hotkeys, quartz_modkeytable},
        !            51: #endif
        !            52: #ifdef __BEOS__
        !            53:     { SDLGFX_DRIVER_BWINDOW, "beos",   beos_keymap,   beos_hotkeys,   0},
        !            54: #endif
        !            55: #ifdef TARGET_AMIGAOS
        !            56: # ifdef __amigaos4__
        !            57:     { SDLGFX_DRIVER_AMIGAOS4, "amiga", amiga_keymap,  amiga_hotkeys,  0},
        !            58: # else
        !            59:     { SDLGFX_DRIVER_CYBERGFX, "amiga", amiga_keymap,  amiga_hotkeys,  0},
        !            60: # endif
        !            61: #endif
        !            62:     { 0, 0, 0, 0, 0 }
        !            63: };
        !            64: 
        !            65: struct uae_input_device_kbr_default *get_default_raw_keymap (int type)
        !            66: {
        !            67:     const struct sdl_raw_keymap *k = &keymaps[0];
        !            68: 
        !            69:     if (!keyboard) {
        !            70:        free (keyboard);
        !            71:        keyboard = 0;
        !            72:     }
        !            73: 
        !            74:     while (k->sdl_gfx_driver != type && k->sdl_gfx_driver != 0)
        !            75:        k++;
        !            76: 
        !            77:     if (k->keymap) {
        !            78:        write_log ("Found %s raw keyboard mapping\n", k->name);
        !            79:        modkeytable = k->modtable;
        !            80:        keyboard = uaekey_make_default_kbr (k->keymap);
        !            81:     }
        !            82: 
        !            83:     return keyboard;
        !            84: }
        !            85: 
        !            86: struct uae_hotkeyseq *get_default_raw_hotkeys (void)
        !            87: {
        !            88:     const struct sdl_raw_keymap *k = &keymaps[0];
        !            89: 
        !            90:     while (k->sdl_gfx_driver != get_sdlgfx_type())
        !            91:        k++;
        !            92: 
        !            93:     return k->hotkeys;
        !            94: }
        !            95: 
        !            96: 
        !            97: /*
        !            98:  * Map SDL modifier key to raw key code
        !            99:  *
        !           100:  * This is required on platforms where the modifiers keys aren't
        !           101:  * reported with a raw key code - but SDL_GetModState() works, e.g.,
        !           102:  * on OS X.
        !           103:  */
        !           104: int modifier_hack (int *scancode, int *pressed)
        !           105: {
        !           106:     int result = 1;
        !           107: 
        !           108:     static int old_modifiers = 0;
        !           109:     int modifiers = SDL_GetModState ();
        !           110: 
        !           111:     if (modkeytable && modifiers != old_modifiers) {
        !           112:        if ((modifiers & KMOD_LSHIFT) != (old_modifiers & KMOD_LSHIFT)) {
        !           113:             *scancode = modkeytable[UAEMODKEY_LSHIFT];
        !           114:             *pressed  = modifiers & KMOD_LSHIFT;
        !           115:        } else if ((modifiers & KMOD_RSHIFT) != (old_modifiers & KMOD_RSHIFT)) {
        !           116:             *scancode = modkeytable[UAEMODKEY_RSHIFT];
        !           117:             *pressed  = modifiers & KMOD_RSHIFT;
        !           118:        } else if ((modifiers & KMOD_LCTRL) != (old_modifiers & KMOD_LCTRL)) {
        !           119:             *scancode = modkeytable[UAEMODKEY_LCTRL];
        !           120:             *pressed  = modifiers & KMOD_LCTRL;
        !           121:        } else if ((modifiers & KMOD_RCTRL) != (old_modifiers & KMOD_RCTRL)) {
        !           122:             *scancode = modkeytable[UAEMODKEY_RCTRL];
        !           123:             *pressed  = modifiers & KMOD_RCTRL;
        !           124:        } else if ((modifiers & KMOD_LALT) != (old_modifiers & KMOD_LALT)) {
        !           125:             *scancode = modkeytable[UAEMODKEY_LALT];
        !           126:             *pressed  = modifiers & KMOD_LALT;
        !           127:        } else if ((modifiers & KMOD_RALT) != (old_modifiers & KMOD_RALT)) {
        !           128:             *scancode = modkeytable[UAEMODKEY_RALT];
        !           129:             *pressed  = modifiers & KMOD_RALT;
        !           130:        } else if ((modifiers & KMOD_LMETA) != (old_modifiers & KMOD_LMETA)) {
        !           131:             *scancode = modkeytable[UAEMODKEY_LSUPER];
        !           132:             *pressed  = modifiers & KMOD_LMETA;
        !           133:        } else if ((modifiers & KMOD_RMETA) != (old_modifiers & KMOD_RMETA)) {
        !           134:             *scancode = modkeytable[UAEMODKEY_RSUPER];
        !           135:             *pressed  = modifiers & KMOD_RMETA;
        !           136:        } else if ((modifiers & KMOD_CAPS) != (old_modifiers & KMOD_CAPS)) {
        !           137:             *scancode = modkeytable[UAEMODKEY_CAPSLOCK];
        !           138:             *pressed  = modifiers & KMOD_CAPS;
        !           139:        } else
        !           140:             result = 0;
        !           141:        old_modifiers = modifiers;
        !           142:     } else
        !           143:        result = 0;
        !           144: 
        !           145:     return result;
        !           146: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.