|
|
1.1 root 1: /*
2: Hatari - shortcut.c
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6:
7: Shortcut keys
8: */
9: const char ShortCut_fileid[] = "Hatari shortcut.c : " __DATE__ " " __TIME__;
10:
11: #include <SDL.h>
12:
13: #include "main.h"
14: #include "dialog.h"
15: #include "file.h"
16: #include "m68000.h"
1.1.1.3 ! root 17: #include "dimension.h"
1.1 root 18: #include "memorySnapShot.h"
19: #include "reset.h"
20: #include "screen.h"
21: #include "screenSnapShot.h"
22: #include "configuration.h"
23: #include "shortcut.h"
24: #include "debugui.h"
25: #include "sdlgui.h"
26: #include "video.h"
1.1.1.3 ! root 27: #include "snd.h"
! 28: #include "statusbar.h"
1.1.1.2 root 29: #include "clocks_timings.h"
1.1 root 30:
31: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE; /* current shortcut key */
32:
33:
34: /*-----------------------------------------------------------------------*/
35: /**
36: * Shortcut to toggle full-screen
37: */
38: static void ShortCut_FullScreen(void)
39: {
40: if (!bInFullScreen)
41: {
42: Screen_EnterFullScreen();
43: }
44: else
45: {
46: Screen_ReturnFromFullScreen();
47: }
48: }
49:
50:
51: /*-----------------------------------------------------------------------*/
52: /**
53: * Shortcut to toggle mouse grabbing mode
54: */
55: static void ShortCut_MouseGrab(void)
56: {
57: bGrabMouse = !bGrabMouse; /* Toggle flag */
58:
59: /* If we are in windowed mode, toggle the mouse cursor mode now: */
60: if (!bInFullScreen)
61: {
62: if (bGrabMouse)
63: {
1.1.1.3 ! root 64: SDL_SetRelativeMouseMode(SDL_TRUE);
! 65: SDL_SetWindowGrab(sdlWindow, SDL_TRUE);
! 66: Main_SetTitle(MOUSE_LOCK_MSG);
1.1 root 67: }
68: else
69: {
1.1.1.3 ! root 70: SDL_SetRelativeMouseMode(SDL_FALSE);
! 71: SDL_SetWindowGrab(sdlWindow, SDL_FALSE);
! 72: Main_SetTitle(NULL);
1.1 root 73: }
74: }
75: }
76:
77:
78: /*-----------------------------------------------------------------------*/
79: /**
80: * Shortcut to toggle YM/WAV sound recording
81: */
82: static void ShortCut_RecordSound(void)
83: {
84: }
85:
86:
87: /*-----------------------------------------------------------------------*/
88: /**
89: * Shortcut to toggle screen animation recording
90: */
91: static void ShortCut_RecordAnimation(void)
92: {
93: }
94:
95:
96: /*-----------------------------------------------------------------------*/
97: /**
98: * Shortcut to sound on/off
99: */
100: static void ShortCut_SoundOnOff(void)
101: {
1.1.1.3 ! root 102: ConfigureParams.Sound.bEnableSound = !ConfigureParams.Sound.bEnableSound;
! 103:
! 104: Sound_Reset();
1.1 root 105: }
106:
107:
108: /*-----------------------------------------------------------------------*/
109: /**
110: * Shortcut to fast forward
111: */
112: static void ShortCut_FastForward(void)
113: {
114: /* Set maximum speed */
115: ConfigureParams.System.bFastForward = true;
116: }
117:
118:
119: /*-----------------------------------------------------------------------*/
120: /**
121: * Shortcut to 'Boss' key, ie minmize Window and switch to another application
122: */
123: static void ShortCut_BossKey(void)
124: {
125: /* If we are in full-screen, then return to a window */
126: Screen_ReturnFromFullScreen();
127:
128: if (bGrabMouse)
129: {
1.1.1.3 ! root 130: SDL_SetRelativeMouseMode(SDL_FALSE);
! 131: SDL_SetWindowGrab(sdlWindow, SDL_FALSE);
1.1 root 132: bGrabMouse = false;
133: }
134: Main_PauseEmulation(true);
135:
136: /* Minimize Window and give up processing to next one! */
1.1.1.3 ! root 137: fprintf(stderr,"FIXME: minimize window!\n");
1.1 root 138: }
139:
140:
141: /*-----------------------------------------------------------------------*/
142: /**
143: * Shorcut to debug interface
144: */
145: static void ShortCut_Debug(void)
146: {
147: int running;
148:
149: /* Call the debugger */
150: running = Main_PauseEmulation(true);
151: DebugUI();
152: if (running)
153: Main_UnPauseEmulation();
154: }
155:
156:
157: /*-----------------------------------------------------------------------*/
158: /**
159: * Shorcut to pausing
160: */
161: static void ShortCut_Pause(void)
162: {
163: if (!Main_UnPauseEmulation())
164: Main_PauseEmulation(true);
165: }
166:
167: /**
168: * Shorcut to load a disk image
169: */
1.1.1.3 ! root 170: static void ShortCut_Dimension(void)
1.1 root 171: {
1.1.1.3 ! root 172: #if ENABLE_DIMENSION
! 173: if(ConfigureParams.Screen.nMonitorType != MONITOR_TYPE_DUAL) {
! 174: if (ConfigureParams.Screen.nMonitorType==MONITOR_TYPE_DIMENSION) {
! 175: ConfigureParams.Screen.nMonitorType=MONITOR_TYPE_CPU;
! 176: } else {
! 177: ConfigureParams.Screen.nMonitorType=MONITOR_TYPE_DIMENSION;
! 178: }
! 179: }
! 180: Statusbar_UpdateInfo();
! 181: Screen_SetFullUpdate();
! 182: #endif
1.1 root 183: }
184:
185:
186: /*-----------------------------------------------------------------------*/
187: /**
188: * Check to see if pressed any shortcut keys, and call handling function
189: */
190: void ShortCut_ActKey(void)
191: {
192: if (ShortCutKey == SHORTCUT_NONE)
193: return;
194:
195: switch (ShortCutKey)
196: {
197: case SHORTCUT_OPTIONS:
198: Dialog_DoProperty(); /* Show options dialog */
199: break;
200: case SHORTCUT_FULLSCREEN:
201: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */
202: break;
203: case SHORTCUT_MOUSEGRAB:
204: ShortCut_MouseGrab(); /* Toggle mouse grab */
205: break;
206: case SHORTCUT_COLDRESET:
207: Main_UnPauseEmulation();
208: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */
209: break;
1.1.1.3 ! root 210: #if 0
1.1 root 211: case SHORTCUT_WARMRESET:
212: Main_UnPauseEmulation();
213: Reset_Warm(); /* Emulator 'warm' reset */
214: break;
215: case SHORTCUT_SCREENSHOT:
216: ScreenSnapShot_SaveScreen(); /* Grab screenshot */
217: break;
218: case SHORTCUT_BOSSKEY:
219: ShortCut_BossKey(); /* Boss key */
220: break;
221: case SHORTCUT_CURSOREMU: /* Toggle joystick emu on/off */
1.1.1.3 ! root 222: Joy_ToggleCursorEmulation();
1.1 root 223: break;
224: case SHORTCUT_FASTFORWARD:
225: ShortCut_FastForward(); /* Toggle Min/Max speed */
226: break;
227: case SHORTCUT_RECANIM:
228: ShortCut_RecordAnimation(); /* Record animation */
229: break;
230: case SHORTCUT_RECSOUND:
1.1.1.3 ! root 231: ShortCut_RecordSound(); /* Toggle sound recording */
1.1 root 232: break;
1.1.1.3 ! root 233: #endif
1.1 root 234: case SHORTCUT_SOUND:
235: ShortCut_SoundOnOff(); /* Enable/disable sound */
236: break;
1.1.1.3 ! root 237: #if 0
1.1 root 238: case SHORTCUT_DEBUG:
239: ShortCut_Debug(); /* Invoke the Debug UI */
240: break;
1.1.1.3 ! root 241: #endif
! 242: #if ENABLE_DIMENSION
! 243: case SHORTCUT_DEBUG:
! 244: nd_start_debugger(); /* Invoke the Debug UI */
! 245: break;
! 246: #endif
1.1 root 247: case SHORTCUT_PAUSE:
248: ShortCut_Pause(); /* Invoke Pause */
249: break;
250: case SHORTCUT_QUIT:
251: Main_RequestQuit();
252: break;
1.1.1.3 ! root 253: #if 0
1.1 root 254: case SHORTCUT_LOADMEM:
255: MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, true);
256: break;
257: case SHORTCUT_SAVEMEM:
258: MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, true);
259: break;
1.1.1.3 ! root 260: #endif
! 261: case SHORTCUT_DIMENSION:
! 262: ShortCut_Dimension();
1.1 root 263: break;
264: case SHORTCUT_KEYS:
265: case SHORTCUT_NONE:
266: /* ERROR: cannot happen, just make compiler happy */
1.1.1.3 ! root 267: default:
1.1 root 268: break;
269: }
270: ShortCutKey = SHORTCUT_NONE;
271: }
272:
273:
274: /*-----------------------------------------------------------------------*/
275: /**
276: * Invoke shortcut identified by name. This supports only keys for
277: * functionality that cannot be invoked with command line options
278: * or otherwise for remote GUIs etc.
279: */
280: bool Shortcut_Invoke(const char *shortcut)
281: {
282: struct {
283: SHORTCUTKEYIDX id;
284: const char *name;
285: } shortcuts[] = {
286: { SHORTCUT_MOUSEGRAB, "mousegrab" },
287: { SHORTCUT_COLDRESET, "coldreset" },
288: { SHORTCUT_WARMRESET, "warmreset" },
289: { SHORTCUT_SCREENSHOT, "screenshot" },
290: { SHORTCUT_BOSSKEY, "bosskey" },
291: { SHORTCUT_RECANIM, "recanim" },
292: { SHORTCUT_RECSOUND, "recsound" },
293: { SHORTCUT_SAVEMEM, "savemem" },
294: { SHORTCUT_QUIT, "quit" },
295: { SHORTCUT_NONE, NULL }
296: };
297: int i;
298:
299: if (ShortCutKey != SHORTCUT_NONE)
300: {
301: fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
302: return false;
303: }
304: for (i = 0; shortcuts[i].name; i++)
305: {
306: if (strcmp(shortcut, shortcuts[i].name) == 0)
307: {
308: ShortCutKey = shortcuts[i].id;
309: ShortCut_ActKey();
310: ShortCutKey = SHORTCUT_NONE;
311: return true;
312: }
313: }
314: fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
315: fprintf(stderr, "Hatari shortcuts are:\n");
316: for (i = 0; shortcuts[i].name; i++)
317: {
318: fprintf(stderr, "- %s\n", shortcuts[i].name);
319: }
320: return false;
321: }
322:
323:
324: /*-----------------------------------------------------------------------*/
325: /**
326: * Check whether given key was any of the ones in given shortcut array.
327: * Return corresponding array index or SHORTCUT_NONE for no match
328: */
329: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
330: {
331: SHORTCUTKEYIDX key;
332: for (key = SHORTCUT_OPTIONS; key < SHORTCUT_KEYS; key++)
333: {
334: if (symkey == keys[key])
335: return key;
336: }
337: return SHORTCUT_NONE;
338: }
339:
340: /*-----------------------------------------------------------------------*/
341: /**
342: * Check which Shortcut key is pressed/released.
343: * If press is set, store the key array index.
344: * Return zero if key didn't match to a shortcut
345: */
346: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
347: {
348: SHORTCUTKEYIDX key;
349:
1.1.1.3 ! root 350: #if defined(__APPLE__)
! 351: if ((modkey&(KMOD_RCTRL|KMOD_LCTRL)) && (modkey&(KMOD_RALT|KMOD_LALT)))
! 352: #else
! 353: if (modkey & (KMOD_RALT|KMOD_LGUI|KMOD_RGUI|KMOD_MODE))
! 354: #endif
1.1 root 355: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
356: else
357: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
358:
359: if (key == SHORTCUT_NONE)
360: return 0;
361: if (press) {
362: ShortCutKey = key;
363: fprintf(stderr,"Short :%x\n",ShortCutKey);
364: }
365: return 1;
366: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.