|
|
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 "reset.h"
19: #include "screen.h"
20: #include "configuration.h"
21: #include "shortcut.h"
22: #include "debugui.h"
23: #include "sdlgui.h"
24: #include "video.h"
1.1.1.3 root 25: #include "snd.h"
26: #include "statusbar.h"
1.1 root 27:
28: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE; /* current shortcut key */
29:
30:
31: /*-----------------------------------------------------------------------*/
32: /**
33: * Shortcut to toggle full-screen
34: */
35: static void ShortCut_FullScreen(void)
36: {
37: if (!bInFullScreen)
38: {
39: Screen_EnterFullScreen();
40: }
41: else
42: {
43: Screen_ReturnFromFullScreen();
44: }
45: }
46:
47:
48: /*-----------------------------------------------------------------------*/
49: /**
50: * Shortcut to toggle mouse grabbing mode
51: */
52: static void ShortCut_MouseGrab(void)
53: {
54: bGrabMouse = !bGrabMouse; /* Toggle flag */
55:
56: /* If we are in windowed mode, toggle the mouse cursor mode now: */
57: if (!bInFullScreen)
58: {
59: if (bGrabMouse)
60: {
1.1.1.3 root 61: SDL_SetRelativeMouseMode(SDL_TRUE);
62: SDL_SetWindowGrab(sdlWindow, SDL_TRUE);
63: Main_SetTitle(MOUSE_LOCK_MSG);
1.1 root 64: }
65: else
66: {
1.1.1.3 root 67: SDL_SetRelativeMouseMode(SDL_FALSE);
68: SDL_SetWindowGrab(sdlWindow, SDL_FALSE);
69: Main_SetTitle(NULL);
1.1 root 70: }
71: }
72: }
73:
74:
75: /*-----------------------------------------------------------------------*/
76: /**
77: * Shortcut to sound on/off
78: */
79: static void ShortCut_SoundOnOff(void)
80: {
1.1.1.3 root 81: ConfigureParams.Sound.bEnableSound = !ConfigureParams.Sound.bEnableSound;
82:
83: Sound_Reset();
1.1 root 84: }
85:
86: /*-----------------------------------------------------------------------*/
87: /**
1.1.1.4 ! root 88: * Shorcut to M68K debug interface
1.1 root 89: */
1.1.1.4 ! root 90: void ShortCut_Debug_M68K(void)
1.1 root 91: {
92: int running;
93:
94: running = Main_PauseEmulation(true);
1.1.1.4 ! root 95: /* Call the debugger */
1.1 root 96: DebugUI();
97: if (running)
98: Main_UnPauseEmulation();
99: }
100:
1.1.1.4 ! root 101: /*-----------------------------------------------------------------------*/
! 102: /**
! 103: * Shorcut to I860 debug interface
! 104: */
! 105: void ShortCut_Debug_I860(void) {
! 106: int running;
! 107:
! 108: if (bInFullScreen)
! 109: Screen_ReturnFromFullScreen();
! 110:
! 111: running = Main_PauseEmulation(true);
! 112:
! 113: /* override paused message so that user knows to look into console
! 114: * on how to continue in case he invoked the debugger by accident.
! 115: */
! 116: Statusbar_AddMessage("I860 Console Debugger", 100);
! 117: Statusbar_Update(sdlscrn);
! 118:
! 119: /* disable normal GUI alerts while on console */
! 120: int alertLevel = Log_SetAlertLevel(LOG_FATAL);
! 121:
! 122: /* Call the debugger */
! 123: nd_start_debugger();
! 124: Log_SetAlertLevel(alertLevel);
! 125:
! 126: if (running)
! 127: Main_UnPauseEmulation();
! 128: }
1.1 root 129:
130: /*-----------------------------------------------------------------------*/
131: /**
132: * Shorcut to pausing
133: */
134: static void ShortCut_Pause(void)
135: {
136: if (!Main_UnPauseEmulation())
137: Main_PauseEmulation(true);
138: }
139:
140: /**
1.1.1.4 ! root 141: * Shorcut to switch monochrome and dimension screen
1.1 root 142: */
1.1.1.3 root 143: static void ShortCut_Dimension(void)
1.1 root 144: {
1.1.1.4 ! root 145: if (ConfigureParams.System.nMachineType==NEXT_STATION || !ConfigureParams.Dimension.bEnabled) {
! 146: return;
! 147: }
! 148:
! 149: if (ConfigureParams.Screen.nMonitorType != MONITOR_TYPE_DUAL) {
1.1.1.3 root 150: if (ConfigureParams.Screen.nMonitorType==MONITOR_TYPE_DIMENSION) {
151: ConfigureParams.Screen.nMonitorType=MONITOR_TYPE_CPU;
152: } else {
153: ConfigureParams.Screen.nMonitorType=MONITOR_TYPE_DIMENSION;
154: }
155: }
156: Statusbar_UpdateInfo();
1.1 root 157: }
158:
159:
160: /*-----------------------------------------------------------------------*/
161: /**
162: * Check to see if pressed any shortcut keys, and call handling function
163: */
164: void ShortCut_ActKey(void)
165: {
166: if (ShortCutKey == SHORTCUT_NONE)
167: return;
168:
169: switch (ShortCutKey)
170: {
171: case SHORTCUT_OPTIONS:
172: Dialog_DoProperty(); /* Show options dialog */
173: break;
174: case SHORTCUT_FULLSCREEN:
175: ShortCut_FullScreen(); /* Switch between fullscreen/windowed mode */
176: break;
177: case SHORTCUT_MOUSEGRAB:
178: ShortCut_MouseGrab(); /* Toggle mouse grab */
179: break;
180: case SHORTCUT_COLDRESET:
181: Main_UnPauseEmulation();
182: Reset_Cold(); /* Reset emulator with 'cold' (clear all) */
183: break;
184: case SHORTCUT_SOUND:
185: ShortCut_SoundOnOff(); /* Enable/disable sound */
186: break;
1.1.1.4 ! root 187: case SHORTCUT_DEBUG_M68K:
! 188: ShortCut_Debug_M68K(); /* Invoke the Debug UI */
1.1 root 189: break;
1.1.1.4 ! root 190: case SHORTCUT_DEBUG_I860:
! 191: ShortCut_Debug_I860(); /* Invoke the M68K UI */
1.1.1.3 root 192: break;
1.1 root 193: case SHORTCUT_PAUSE:
194: ShortCut_Pause(); /* Invoke Pause */
195: break;
196: case SHORTCUT_QUIT:
197: Main_RequestQuit();
198: break;
1.1.1.3 root 199: case SHORTCUT_DIMENSION:
200: ShortCut_Dimension();
1.1 root 201: break;
202: case SHORTCUT_KEYS:
203: case SHORTCUT_NONE:
204: /* ERROR: cannot happen, just make compiler happy */
1.1.1.3 root 205: default:
1.1 root 206: break;
207: }
208: ShortCutKey = SHORTCUT_NONE;
209: }
210:
211:
212: /*-----------------------------------------------------------------------*/
213: /**
214: * Invoke shortcut identified by name. This supports only keys for
215: * functionality that cannot be invoked with command line options
216: * or otherwise for remote GUIs etc.
217: */
218: bool Shortcut_Invoke(const char *shortcut)
219: {
220: struct {
221: SHORTCUTKEYIDX id;
222: const char *name;
223: } shortcuts[] = {
224: { SHORTCUT_MOUSEGRAB, "mousegrab" },
225: { SHORTCUT_COLDRESET, "coldreset" },
226: { SHORTCUT_WARMRESET, "warmreset" },
227: { SHORTCUT_QUIT, "quit" },
228: { SHORTCUT_NONE, NULL }
229: };
230: int i;
231:
232: if (ShortCutKey != SHORTCUT_NONE)
233: {
234: fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
235: return false;
236: }
237: for (i = 0; shortcuts[i].name; i++)
238: {
239: if (strcmp(shortcut, shortcuts[i].name) == 0)
240: {
241: ShortCutKey = shortcuts[i].id;
242: ShortCut_ActKey();
243: ShortCutKey = SHORTCUT_NONE;
244: return true;
245: }
246: }
247: fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
248: fprintf(stderr, "Hatari shortcuts are:\n");
249: for (i = 0; shortcuts[i].name; i++)
250: {
251: fprintf(stderr, "- %s\n", shortcuts[i].name);
252: }
253: return false;
254: }
255:
256:
257: /*-----------------------------------------------------------------------*/
258: /**
259: * Check whether given key was any of the ones in given shortcut array.
260: * Return corresponding array index or SHORTCUT_NONE for no match
261: */
262: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
263: {
264: SHORTCUTKEYIDX key;
265: for (key = SHORTCUT_OPTIONS; key < SHORTCUT_KEYS; key++)
266: {
267: if (symkey == keys[key])
268: return key;
269: }
270: return SHORTCUT_NONE;
271: }
272:
273: /*-----------------------------------------------------------------------*/
274: /**
275: * Check which Shortcut key is pressed/released.
276: * If press is set, store the key array index.
277: * Return zero if key didn't match to a shortcut
278: */
279: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
280: {
281: SHORTCUTKEYIDX key;
282:
1.1.1.3 root 283: #if defined(__APPLE__)
284: if ((modkey&(KMOD_RCTRL|KMOD_LCTRL)) && (modkey&(KMOD_RALT|KMOD_LALT)))
285: #else
286: if (modkey & (KMOD_RALT|KMOD_LGUI|KMOD_RGUI|KMOD_MODE))
287: #endif
1.1 root 288: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
289: else
290: key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
291:
292: if (key == SHORTCUT_NONE)
293: return 0;
294: if (press) {
295: ShortCutKey = key;
296: fprintf(stderr,"Short :%x\n",ShortCutKey);
297: }
298: return 1;
299: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.