|
|
1.1 root 1: /*
2: Hatari - dlgKeyboard.c
3:
1.1.1.8 root 4: This file is distributed under the GNU General Public License, version 2
5: or at your option any later version. Read the file gpl.txt for details.
1.1 root 6: */
1.1.1.7 root 7: const char DlgKeyboard_fileid[] = "Hatari dlgKeyboard.c : " __DATE__ " " __TIME__;
1.1 root 8:
9: #include <unistd.h>
10:
11: #include "main.h"
12: #include "configuration.h"
13: #include "dialog.h"
14: #include "sdlgui.h"
15: #include "file.h"
16: #include "screen.h"
1.1.1.10 root 17: #include "str.h"
18: #include "keymap.h"
1.1 root 19:
1.1.1.10 root 20: #define DLGKEY_SYMBOLIC 4
21: #define DLGKEY_SCANCODE 5
22: #define DLGKEY_FROMFILE 6
23: #define DLGKEY_MAPNAME 8
24: #define DLGKEY_MAPBROWSE 9
25: #define DLGKEY_SCPREV 13
26: #define DLGKEY_SCNAME 14
27: #define DLGKEY_SCNEXT 15
28: #define DLGKEY_SCMODVAL 17
29: #define DLGKEY_SCMODDEF 18
30: #define DLGKEY_SCNOMODVAL 20
31: #define DLGKEY_SCNOMODDEF 21
32: #define DLGKEY_DISREPEAT 22
33: #define DLGKEY_EXIT 23
1.1 root 34:
1.1.1.10 root 35: static char sc_modval[16];
36: static char sc_nomodval[16];
1.1 root 37:
38: /* The keyboard dialog: */
39: static SGOBJ keyboarddlg[] =
40: {
1.1.1.10 root 41: { SGBOX, 0, 0, 0,0, 46,24, NULL },
1.1.1.5 root 42: { SGTEXT, 0, 0, 16,1, 14,1, "Keyboard setup" },
1.1.1.10 root 43:
44: { SGBOX, 0, 0, 1,3, 44,7, NULL },
1.1.1.4 root 45: { SGTEXT, 0, 0, 2,3, 17,1, "Keyboard mapping:" },
1.1.1.9 root 46: { SGRADIOBUT, 0, 0, 4,5, 10,1, "_Symbolic" },
47: { SGRADIOBUT, 0, 0, 17,5, 10,1, "S_cancode" },
48: { SGRADIOBUT, 0, 0, 30,5, 11,1, "_From file" },
1.1.1.4 root 49: { SGTEXT, 0, 0, 2,7, 13,1, "Mapping file:" },
1.1.1.5 root 50: { SGTEXT, 0, 0, 2,8, 42,1, NULL },
1.1.1.9 root 51: { SGBUTTON, 0, 0, 36, 7, 8,1, "_Browse" },
1.1.1.10 root 52:
53: { SGBOX, 0, 0, 1,11, 44,8, NULL },
54: { SGTEXT, 0, 0, 2,11, 12,1, "Shortcuts:" },
55: { SGBOX, 0, 0, 2,13, 42,1, NULL },
56: { SGBUTTON, 0, 0, 2,13, 1,1, "\x04", SG_SHORTCUT_LEFT },
57: { SGTEXT, 0, 0, 4,13, 20,1, NULL },
58: { SGBUTTON, 0, 0, 43,13, 1,1, "\x03", SG_SHORTCUT_RIGHT },
59: { SGTEXT, 0, 0, 2,15, 17,1, "With modifier:" },
60: { SGTEXT, 0, 0, 20,15, 12,1, sc_modval },
61: { SGBUTTON, 0, 0, 36,15, 8,1, "_Define" },
62: { SGTEXT, 0, 0, 2,17, 17,1, "Without modifier:" },
63: { SGTEXT, 0, 0, 20,17, 12,1, sc_nomodval },
64: { SGBUTTON, 0, 0, 36,17, 8,1, "D_efine" },
65:
66: { SGCHECKBOX, 0, 0, 2,20, 41,1, "Disable key _repeat in fast forward mode" },
67: { SGBUTTON, SG_DEFAULT, 0, 13,22, 20,1, "Back to main menu" },
68: { SGSTOP, 0, 0, 0,0, 0,0, NULL }
69: };
70:
71:
72: static char *sc_names[SHORTCUT_KEYS] = {
73: "Edit settings",
74: "Toggle fullscreen",
1.1.1.11! root 75: "Toggle borders",
1.1.1.10 root 76: "Grab mouse",
77: "Cold reset",
78: "Warm reset",
79: "Take screenshot",
80: "Boss key",
81: "Joystick cursor emulation",
82: "Fast forward",
83: "Record animation",
84: "Record sound",
85: "Toggle sound",
86: "Enter debugger",
87: "Pause emulation",
88: "Quit emulator",
89: "Load memory snapshot",
90: "Save memory snapshot",
91: "Insert disk A:",
92: "Toggle joystick 0",
93: "Toggle joystick 1",
94: "Toggle joypad A",
95: "Toggle joypad B"
96: };
97:
98: static char sScKeyType[28];
99: static char sScKeyName[28];
100:
101: static SGOBJ sckeysdlg[] =
102: {
103: { SGBOX, 0, 0, 0,0, 30,6, NULL },
104: { SGTEXT, 0, 0, 2,1, 28,1, "Press key for:" },
105: { SGTEXT, 0, 0, 2,2, 28,1, sScKeyType },
106: { SGTEXT, 0, 0, 2,4, 28,1, sScKeyName },
107: { SGSTOP, 0, 0, 0,0, 0,0, NULL }
1.1 root 108: };
109:
110:
1.1.1.10 root 111: /**
112: * Show dialogs for defining shortcut keys and wait for a key press.
113: */
114: static void DlgKbd_DefineShortcutKey(int sc, bool withMod)
115: {
116: SDL_Event sdlEvent;
117: int *pscs;
118: int i;
119:
120: if (bQuitProgram)
121: return;
122:
123: SDLGui_CenterDlg(sckeysdlg);
124:
125: if (withMod)
126: pscs = ConfigureParams.Shortcut.withModifier;
127: else
128: pscs = ConfigureParams.Shortcut.withoutModifier;
129:
130: snprintf(sScKeyType, sizeof(sScKeyType), "'%s'", sc_names[sc]);
131: snprintf(sScKeyName, sizeof(sScKeyName), "(was: '%s')", Keymap_GetKeyName(pscs[sc]));
132:
133: SDLGui_DrawDialog(sckeysdlg);
134:
135: /* drain buffered key events */
136: SDL_Delay(200);
137: while (SDL_PollEvent(&sdlEvent))
138: {
139: if (sdlEvent.type == SDL_KEYUP || sdlEvent.type == SDL_KEYDOWN)
140: break;
141: }
142:
143: /* get the real key */
144: do
145: {
146: SDL_WaitEvent(&sdlEvent);
147: switch (sdlEvent.type)
148: {
149: case SDL_KEYDOWN:
150: pscs[sc] = sdlEvent.key.keysym.sym;
151: snprintf(sScKeyName, sizeof(sScKeyName), "(now: '%s')",
152: Keymap_GetKeyName(sdlEvent.key.keysym.sym));
153: SDLGui_DrawDialog(sckeysdlg);
154: break;
155: case SDL_MOUSEBUTTONDOWN:
156: if (sdlEvent.button.button == SDL_BUTTON_RIGHT)
157: {
158: pscs[sc] = 0;
159: return;
160: }
161: else if (sdlEvent.button.button == SDL_BUTTON_LEFT)
162: {
163: return;
164: }
165: break;
166: case SDL_QUIT:
167: bQuitProgram = true;
168: return;
169: }
170: } while (sdlEvent.type != SDL_KEYUP);
171:
172: /* Make sure that no other shortcut key has the same value */
173: for (i = 0; i < SHORTCUT_KEYS; i++)
174: {
175: if (i == sc)
176: continue;
177: if (pscs[i] == pscs[sc])
178: {
179: pscs[i] = 0;
180: DlgAlert_Notice("Removing key from other shortcut!");
181: }
182: }
183: }
184:
185:
186: /**
187: * Set name for given sortcut, or show it's unset
188: */
189: static void DlgKbd_SetName(char *str, size_t maxlen, int keysym)
190: {
191: if (keysym)
192: strlcpy(str, Keymap_GetKeyName(keysym), maxlen);
193: else
194: strlcpy(str, "<not set>", maxlen);
195: }
196:
197:
198: /**
199: * Refresh the shortcut texts in the dialog
200: */
201: static void DlgKbd_RefreshShortcuts(int sc)
202: {
203: int keysym;
204:
205: /* with modifier */
206: keysym = ConfigureParams.Shortcut.withModifier[sc];
207: DlgKbd_SetName(sc_modval, sizeof(sc_modval), keysym);
208:
209: /* without modifier */
210: keysym = ConfigureParams.Shortcut.withoutModifier[sc];
211: DlgKbd_SetName(sc_nomodval, sizeof(sc_nomodval), keysym);
212:
213: keyboarddlg[DLGKEY_SCNAME].txt = sc_names[sc];
214: }
215:
1.1.1.4 root 216: /**
217: * Show and process the "Keyboard" dialog.
218: */
1.1 root 219: void Dialog_KeyboardDlg(void)
220: {
1.1.1.4 root 221: int i, but;
1.1.1.5 root 222: char dlgmapfile[44];
1.1.1.10 root 223: int cur_sc = 0;
1.1 root 224:
1.1.1.4 root 225: SDLGui_CenterDlg(keyboarddlg);
226:
227: /* Set up dialog from actual values: */
228: for (i = DLGKEY_SYMBOLIC; i <= DLGKEY_FROMFILE; i++)
229: {
230: keyboarddlg[i].state &= ~SG_SELECTED;
231: }
1.1.1.5 root 232: keyboarddlg[DLGKEY_SYMBOLIC+ConfigureParams.Keyboard.nKeymapType].state |= SG_SELECTED;
1.1.1.4 root 233:
1.1.1.5 root 234: File_ShrinkName(dlgmapfile, ConfigureParams.Keyboard.szMappingFileName,
1.1.1.4 root 235: keyboarddlg[DLGKEY_MAPNAME].w);
236: keyboarddlg[DLGKEY_MAPNAME].txt = dlgmapfile;
237:
1.1.1.10 root 238: DlgKbd_RefreshShortcuts(cur_sc);
239:
1.1.1.5 root 240: if (ConfigureParams.Keyboard.bDisableKeyRepeat)
241: keyboarddlg[DLGKEY_DISREPEAT].state |= SG_SELECTED;
242: else
243: keyboarddlg[DLGKEY_DISREPEAT].state &= ~SG_SELECTED;
244:
1.1.1.4 root 245: /* Show the dialog: */
246: do
247: {
1.1.1.9 root 248: but = SDLGui_DoDialog(keyboarddlg, NULL, false);
1.1.1.4 root 249:
1.1.1.10 root 250: switch (but)
1.1.1.4 root 251: {
1.1.1.10 root 252: case DLGKEY_MAPBROWSE:
1.1.1.9 root 253: SDLGui_FileConfSelect("Keyboard mapping file:", dlgmapfile,
1.1.1.5 root 254: ConfigureParams.Keyboard.szMappingFileName,
1.1.1.7 root 255: keyboarddlg[DLGKEY_MAPNAME].w, false);
1.1.1.10 root 256: break;
257: case DLGKEY_SCPREV:
258: if (cur_sc > 0)
259: {
260: --cur_sc;
261: DlgKbd_RefreshShortcuts(cur_sc);
262: }
263: break;
264: case DLGKEY_SCNEXT:
265: if (cur_sc < SHORTCUT_KEYS-1)
266: {
267: ++cur_sc;
268: DlgKbd_RefreshShortcuts(cur_sc);
269: }
270: break;
271: case DLGKEY_SCMODDEF:
272: DlgKbd_DefineShortcutKey(cur_sc, true);
273: DlgKbd_RefreshShortcuts(cur_sc);
274: break;
275: case DLGKEY_SCNOMODDEF:
276: DlgKbd_DefineShortcutKey(cur_sc, false);
277: DlgKbd_RefreshShortcuts(cur_sc);
278: break;
1.1.1.4 root 279: }
280: }
281: while (but != DLGKEY_EXIT && but != SDLGUI_QUIT
282: && but != SDLGUI_ERROR && !bQuitProgram);
283:
284: /* Read values from dialog: */
285: if (keyboarddlg[DLGKEY_SYMBOLIC].state & SG_SELECTED)
1.1.1.5 root 286: ConfigureParams.Keyboard.nKeymapType = KEYMAP_SYMBOLIC;
1.1.1.4 root 287: else if (keyboarddlg[DLGKEY_SCANCODE].state & SG_SELECTED)
1.1.1.5 root 288: ConfigureParams.Keyboard.nKeymapType = KEYMAP_SCANCODE;
1.1.1.4 root 289: else
1.1.1.5 root 290: ConfigureParams.Keyboard.nKeymapType = KEYMAP_LOADED;
291:
292: ConfigureParams.Keyboard.bDisableKeyRepeat = (keyboarddlg[DLGKEY_DISREPEAT].state & SG_SELECTED);
1.1 root 293: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.