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