|
|
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: modkeytable = k->modtable;
79: keyboard = uaekey_make_default_kbr (k->keymap);
80: }
81:
82: return keyboard;
83: }
84:
85: struct uae_hotkeyseq *get_default_raw_hotkeys (void)
86: {
87: const struct sdl_raw_keymap *k = &keymaps[0];
88:
89: while (k->sdl_gfx_driver != get_sdlgfx_type())
90: k++;
91:
92: return k->hotkeys;
93: }
94:
95:
96: /*
97: * Map SDL modifier key to raw key code
98: *
99: * This is required on platforms where the modifiers keys aren't
100: * reported with a raw key code - but SDL_GetModState() works, e.g.,
101: * on OS X.
102: */
103: int modifier_hack (int *scancode, int *pressed)
104: {
105: int result = 1;
106:
107: static int old_modifiers = 0;
108: int modifiers = SDL_GetModState ();
109:
110: if (modkeytable && modifiers != old_modifiers) {
111: if ((modifiers & KMOD_LSHIFT) != (old_modifiers & KMOD_LSHIFT)) {
112: *scancode = modkeytable[UAEMODKEY_LSHIFT];
113: *pressed = modifiers & KMOD_LSHIFT;
114: } else if ((modifiers & KMOD_RSHIFT) != (old_modifiers & KMOD_RSHIFT)) {
115: *scancode = modkeytable[UAEMODKEY_RSHIFT];
116: *pressed = modifiers & KMOD_RSHIFT;
117: } else if ((modifiers & KMOD_LCTRL) != (old_modifiers & KMOD_LCTRL)) {
118: *scancode = modkeytable[UAEMODKEY_LCTRL];
119: *pressed = modifiers & KMOD_LCTRL;
120: } else if ((modifiers & KMOD_RCTRL) != (old_modifiers & KMOD_RCTRL)) {
121: *scancode = modkeytable[UAEMODKEY_RCTRL];
122: *pressed = modifiers & KMOD_RCTRL;
123: } else if ((modifiers & KMOD_LALT) != (old_modifiers & KMOD_LALT)) {
124: *scancode = modkeytable[UAEMODKEY_LALT];
125: *pressed = modifiers & KMOD_LALT;
126: } else if ((modifiers & KMOD_RALT) != (old_modifiers & KMOD_RALT)) {
127: *scancode = modkeytable[UAEMODKEY_RALT];
128: *pressed = modifiers & KMOD_RALT;
129: } else if ((modifiers & KMOD_LMETA) != (old_modifiers & KMOD_LMETA)) {
130: *scancode = modkeytable[UAEMODKEY_LSUPER];
131: *pressed = modifiers & KMOD_LMETA;
132: } else if ((modifiers & KMOD_RMETA) != (old_modifiers & KMOD_RMETA)) {
133: *scancode = modkeytable[UAEMODKEY_RSUPER];
134: *pressed = modifiers & KMOD_RMETA;
135: } else if ((modifiers & KMOD_CAPS) != (old_modifiers & KMOD_CAPS)) {
136: *scancode = modkeytable[UAEMODKEY_CAPSLOCK];
137: *pressed = modifiers & KMOD_CAPS;
138: } else
139: result = 0;
140: old_modifiers = modifiers;
141: } else
142: result = 0;
143:
144: return result;
145: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.