Annotation of hatari/src/shortcut.c, revision 1.1.1.12

1.1       root        1: /*
1.1.1.5   root        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.
1.1       root        6: 
                      7:   Shortcut keys
                      8: */
1.1.1.12! root        9: const char ShortCut_fileid[] = "Hatari shortcut.c : " __DATE__ " " __TIME__;
1.1       root       10: 
1.1.1.2   root       11: #include <SDL.h>
                     12: 
1.1       root       13: #include "main.h"
                     14: #include "dialog.h"
                     15: #include "audio.h"
1.1.1.10  root       16: #include "file.h"
                     17: #include "floppy.h"
1.1       root       18: #include "joy.h"
1.1.1.5   root       19: #include "m68000.h"
1.1       root       20: #include "memorySnapShot.h"
                     21: #include "reset.h"
                     22: #include "screen.h"
                     23: #include "screenSnapShot.h"
1.1.1.8   root       24: #include "configuration.h"
1.1       root       25: #include "shortcut.h"
1.1.1.10  root       26: #include "debugui.h"
1.1       root       27: #include "sound.h"
1.1.1.10  root       28: #include "sdlgui.h"
1.1.1.2   root       29: 
1.1.1.8   root       30: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE;  /* current shortcut key */
1.1       root       31: 
1.1.1.4   root       32: 
1.1.1.2   root       33: /*-----------------------------------------------------------------------*/
1.1.1.9   root       34: /**
                     35:  * Shortcut to toggle full-screen
                     36:  */
1.1.1.5   root       37: static void ShortCut_FullScreen(void)
1.1       root       38: {
1.1.1.9   root       39:        if (!bInFullScreen)
                     40:        {
                     41:                Screen_EnterFullScreen();
                     42:        }
                     43:        else
                     44:        {
                     45:                Screen_ReturnFromFullScreen();
                     46:        }
1.1       root       47: }
                     48: 
1.1.1.4   root       49: 
                     50: /*-----------------------------------------------------------------------*/
1.1.1.9   root       51: /**
                     52:  * Shortcut to toggle mouse mode
                     53:  */
1.1.1.5   root       54: static void ShortCut_MouseMode(void)
1.1       root       55: {
1.1.1.9   root       56:        bGrabMouse = !bGrabMouse;        /* Toggle flag */
1.1       root       57: 
1.1.1.9   root       58:        /* If we are in windowed mode, toggle the mouse cursor mode now: */
                     59:        if (!bInFullScreen)
                     60:        {
                     61:                if (bGrabMouse)
                     62:                {
                     63:                        SDL_WM_GrabInput(SDL_GRAB_ON);
                     64:                }
                     65:                else
                     66:                {
                     67:                        SDL_WM_GrabInput(SDL_GRAB_OFF);
                     68:                }
                     69:        }
1.1       root       70: }
                     71: 
1.1.1.4   root       72: 
1.1.1.5   root       73: /*-----------------------------------------------------------------------*/
1.1.1.9   root       74: /**
                     75:  * Shortcut to toggle YM/WAV sound recording
                     76:  */
1.1.1.5   root       77: static void ShortCut_RecordSound(void)
1.1       root       78: {
1.1.1.9   root       79:        /* Is working? */
                     80:        if (bSoundWorking)
                     81:        {
                     82:                /* Are we currently recording? If so stop */
                     83:                if (Sound_AreWeRecording())
                     84:                {
                     85:                        /* Stop, and save */
                     86:                        Sound_EndRecording();
                     87:                }
                     88:                else
                     89:                {
                     90:                        /* Begin recording */
                     91:                        Sound_BeginRecording(ConfigureParams.Sound.szYMCaptureFileName);
                     92:                }
                     93:        }
1.1       root       94: }
                     95: 
1.1.1.5   root       96: 
                     97: /*-----------------------------------------------------------------------*/
1.1.1.9   root       98: /**
                     99:  * Shortcut to toggle screen animation recording
                    100:  */
1.1.1.5   root      101: static void ShortCut_RecordAnimation(void)
1.1       root      102: {
1.1.1.9   root      103:        /* Are we currently recording? If so stop */
                    104:        if (ScreenSnapShot_AreWeRecording())
                    105:        {
                    106:                /* Stop */
                    107:                ScreenSnapShot_EndRecording();
                    108:        }
                    109:        else
                    110:        {
                    111:                /* Start animation */
1.1.1.10  root      112:                ScreenSnapShot_BeginRecording(ConfigureParams.Screen.bCaptureChange);
1.1.1.9   root      113:        }
1.1       root      114: }
                    115: 
1.1.1.4   root      116: 
                    117: /*-----------------------------------------------------------------------*/
1.1.1.9   root      118: /**
                    119:  * Shortcut to sound on/off
                    120:  */
1.1.1.5   root      121: static void ShortCut_SoundOnOff(void)
1.1       root      122: {
1.1.1.9   root      123:        /* Toggle sound on/off */
1.1.1.12! root      124:        ConfigureParams.Sound.bEnableSound ^= true;
1.1.1.9   root      125: 
                    126:        /* And start/stop if need to */
                    127:        if (!ConfigureParams.Sound.bEnableSound)
                    128:        {
                    129:                if (Sound_AreWeRecording())
                    130:                        Sound_EndRecording();
                    131:                Audio_UnInit();
                    132:        }
                    133:        else
                    134:        {
                    135:                Audio_Init();
                    136:        }
1.1       root      137: }
                    138: 
1.1.1.5   root      139: 
                    140: /*-----------------------------------------------------------------------*/
1.1.1.9   root      141: /**
1.1.1.10  root      142:  * Shortcut to fast forward
1.1.1.9   root      143:  */
1.1.1.10  root      144: static void ShortCut_FastForward(void)
1.1       root      145: {
1.1.1.9   root      146:        /* If already on max speed, switch back to normal */
1.1.1.12! root      147:        if (ConfigureParams.System.bFastForward == true)
1.1.1.9   root      148:        {
                    149:                /* Restore */
1.1.1.12! root      150:                ConfigureParams.System.bFastForward = false;
1.1.1.9   root      151: 
                    152:                /* Reset the sound emulation variables: */
                    153:                Sound_ResetBufferIndex();
                    154:        }
                    155:        else
                    156:        {
                    157:                /* Set maximum speed */
1.1.1.12! root      158:                ConfigureParams.System.bFastForward = true;
1.1.1.9   root      159:        }
1.1       root      160: }
                    161: 
1.1.1.5   root      162: 
                    163: /*-----------------------------------------------------------------------*/
1.1.1.9   root      164: /**
                    165:  * Shortcut to 'Boss' key, ie minmize Window and switch to another application
                    166:  */
1.1.1.5   root      167: static void ShortCut_BossKey(void)
1.1       root      168: {
1.1.1.9   root      169:        /* If we are in full-screen, then return to a window */
                    170:        Screen_ReturnFromFullScreen();
1.1.1.5   root      171: 
1.1.1.9   root      172:        if (bGrabMouse)
                    173:        {
                    174:                SDL_WM_GrabInput(SDL_GRAB_OFF);
1.1.1.12! root      175:                bGrabMouse = false;
1.1.1.9   root      176:        }
1.1.1.12! root      177:        Main_PauseEmulation(true);
1.1.1.5   root      178: 
1.1.1.9   root      179:        /* Minimize Window and give up processing to next one! */
                    180:        SDL_WM_IconifyWindow();
1.1       root      181: }
                    182: 
1.1.1.4   root      183: 
                    184: /*-----------------------------------------------------------------------*/
1.1.1.9   root      185: /**
1.1.1.12! root      186:  * Shorcut to debug interface
1.1.1.10  root      187:  */
1.1.1.12! root      188: static void ShortCut_Debug(void)
1.1.1.10  root      189: {
1.1.1.12! root      190:        int running;
1.1.1.10  root      191: 
1.1.1.12! root      192:        /* Call the debugger */
        !           193:        running = Main_PauseEmulation(true);
        !           194:        DebugUI();
        !           195:        if (running)
        !           196:                Main_UnPauseEmulation();
1.1.1.10  root      197: }
                    198: 
                    199: 
1.1.1.12! root      200: /*-----------------------------------------------------------------------*/
        !           201: /**
        !           202:  * Shorcut to pausing
        !           203:  */
        !           204: static void ShortCut_Pause(void)
        !           205: {
        !           206:        if (!Main_UnPauseEmulation())
        !           207:                Main_PauseEmulation(true);
        !           208: }
        !           209: 
1.1.1.10  root      210: /**
                    211:  * Shorcut to load a disk image
                    212:  */
                    213: static void ShortCut_InsertDisk(int drive)
                    214: {
                    215:        char *selname, *zip_path = NULL;
                    216:        const char *tmpname;
                    217: 
                    218:        if (SDLGui_SetScreen(sdlscrn))
                    219:                return;
                    220: 
                    221:        if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
                    222:                tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
                    223:        else
                    224:                tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
                    225: 
1.1.1.12! root      226:        Main_PauseEmulation(true);
        !           227:        selname = SDLGui_FileSelect(tmpname, &zip_path, false);
1.1.1.10  root      228:        if (selname)
                    229:        {
                    230:                if (File_Exists(selname))
1.1.1.11  root      231:                        Floppy_SetDiskFileName(drive, selname, zip_path);
1.1.1.10  root      232:                else
                    233:                        Floppy_SetDiskFileNameNone(drive);
1.1.1.11  root      234: 
                    235:                if (zip_path)
                    236:                        free(zip_path);
1.1.1.10  root      237:                free(selname);
1.1.1.11  root      238:                
                    239:                Floppy_InsertDiskIntoDrive(0);
1.1.1.10  root      240:        }
                    241:        Main_UnPauseEmulation();
                    242: }
                    243: 
                    244: 
                    245: /*-----------------------------------------------------------------------*/
                    246: /**
1.1.1.9   root      247:  * Check to see if pressed any shortcut keys, and call handling function
                    248:  */
1.1.1.8   root      249: void ShortCut_ActKey(void)
1.1.1.5   root      250: {
1.1.1.9   root      251:        if (ShortCutKey == SHORTCUT_NONE)
                    252:                return;
1.1.1.8   root      253: 
1.1.1.9   root      254:        switch (ShortCutKey)
                    255:        {
                    256:         case SHORTCUT_OPTIONS:
                    257:                Dialog_DoProperty();           /* Show options dialog */
                    258:                break;
                    259:         case SHORTCUT_FULLSCREEN:
                    260:                ShortCut_FullScreen();         /* Switch between fullscreen/windowed mode */
                    261:                break;
                    262:         case SHORTCUT_MOUSEMODE:
                    263:                ShortCut_MouseMode();          /* Toggle mouse mode */
                    264:                break;
                    265:         case SHORTCUT_COLDRESET:
1.1.1.10  root      266:                Main_UnPauseEmulation();
1.1.1.9   root      267:                Reset_Cold();                  /* Reset emulator with 'cold' (clear all) */
                    268:                break;
                    269:         case SHORTCUT_WARMRESET:
1.1.1.10  root      270:                Main_UnPauseEmulation();
1.1.1.9   root      271:                Reset_Warm();                  /* Emulator 'warm' reset */
                    272:                break;
                    273:         case SHORTCUT_SCREENSHOT:
                    274:                ScreenSnapShot_SaveScreen();   /* Grab screenshot */
                    275:                break;
                    276:         case SHORTCUT_BOSSKEY:
                    277:                ShortCut_BossKey();            /* Boss key */
                    278:                break;
                    279:         case SHORTCUT_CURSOREMU:          /* Toggle joystick emu on/off */
                    280:                Joy_ToggleCursorEmulation();
                    281:                break;
1.1.1.10  root      282:         case SHORTCUT_FASTFORWARD:
                    283:                ShortCut_FastForward();       /* Toggle Min/Max speed */
1.1.1.9   root      284:                break;
                    285:         case SHORTCUT_RECANIM:
                    286:                ShortCut_RecordAnimation();    /* Record animation */
                    287:                break;
                    288:         case SHORTCUT_RECSOUND:
                    289:                ShortCut_RecordSound();        /* Toggle sound recording */
                    290:                break;
                    291:         case SHORTCUT_SOUND:
                    292:                ShortCut_SoundOnOff();         /* Enable/disable sound */
                    293:                break;
1.1.1.12! root      294:         case SHORTCUT_DEBUG:
        !           295:                ShortCut_Debug();              /* Invoke the Debug UI */
        !           296:                break;
1.1.1.10  root      297:         case SHORTCUT_PAUSE:
1.1.1.12! root      298:                ShortCut_Pause();              /* Invoke Pause */
1.1.1.10  root      299:                break;
1.1.1.9   root      300:         case SHORTCUT_QUIT:
                    301:                Main_RequestQuit();
                    302:                break;
                    303:         case SHORTCUT_LOADMEM:
1.1.1.12! root      304:                MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, true);
1.1.1.9   root      305:                break;
                    306:         case SHORTCUT_SAVEMEM:
1.1.1.12! root      307:                MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, true);
1.1.1.9   root      308:                break;
1.1.1.10  root      309:         case SHORTCUT_INSERTDISKA:
                    310:                ShortCut_InsertDisk(0);
                    311:                break;
1.1.1.9   root      312:         case SHORTCUT_KEYS:
                    313:         case SHORTCUT_NONE:
                    314:                /* ERROR: cannot happen, just make compiler happy */
                    315:                break;
                    316:        }
                    317:        ShortCutKey = SHORTCUT_NONE;
                    318: }
                    319: 
                    320: 
                    321: /*-----------------------------------------------------------------------*/
                    322: /**
1.1.1.10  root      323:  * Invoke shortcut identified by name. This supports only keys for
                    324:  * functionality that cannot be invoked with command line options
1.1.1.12! root      325:  * or otherwise for remote GUIs etc.
1.1.1.10  root      326:  */
                    327: bool Shortcut_Invoke(const char *shortcut)
                    328: {
                    329:        struct {
                    330:                SHORTCUTKEYIDX id;
                    331:                const char *name;
                    332:        } shortcuts[] = {
                    333:                { SHORTCUT_MOUSEMODE, "mousemode" },
                    334:                { SHORTCUT_COLDRESET, "coldreset" },
                    335:                { SHORTCUT_WARMRESET, "warmreset" },
                    336:                { SHORTCUT_SCREENSHOT, "screenshot" },
                    337:                { SHORTCUT_BOSSKEY, "bosskey" },
                    338:                { SHORTCUT_RECANIM, "recanim" },
                    339:                { SHORTCUT_RECSOUND, "recsound" },
                    340:                { SHORTCUT_SAVEMEM, "savemem" },
                    341:                { SHORTCUT_QUIT, "quit" },
                    342:                { SHORTCUT_NONE, NULL }
                    343:        };
                    344:        int i;
                    345: 
                    346:        if (ShortCutKey != SHORTCUT_NONE)
                    347:        {
                    348:                fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
1.1.1.12! root      349:                return false;
1.1.1.10  root      350:        }
                    351:        for (i = 0; shortcuts[i].name; i++)
                    352:        {
                    353:                if (strcmp(shortcut, shortcuts[i].name) == 0)
                    354:                {
                    355:                        ShortCutKey = shortcuts[i].id;
                    356:                        ShortCut_ActKey();
                    357:                        ShortCutKey = SHORTCUT_NONE;
1.1.1.12! root      358:                        return true;
1.1.1.10  root      359:                }
                    360:        }
                    361:        fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
                    362:        fprintf(stderr, "Hatari shortcuts are:\n");
                    363:        for (i = 0; shortcuts[i].name; i++)
                    364:        {
                    365:                fprintf(stderr, "- %s\n", shortcuts[i].name);
                    366:        }
1.1.1.12! root      367:        return false;
1.1.1.10  root      368: }
                    369: 
                    370: 
                    371: /*-----------------------------------------------------------------------*/
                    372: /**
1.1.1.9   root      373:  * Check whether given key was any of the ones in given shortcut array.
                    374:  * Return corresponding array index or SHORTCUT_NONE for no match
                    375:  */
1.1.1.8   root      376: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
                    377: {
1.1.1.9   root      378:        SHORTCUTKEYIDX key;
1.1.1.12! root      379:        for (key = SHORTCUT_OPTIONS; key < SHORTCUT_KEYS; key++)
1.1.1.9   root      380:        {
                    381:                if (symkey == keys[key])
                    382:                        return key;
                    383:        }
                    384:        return SHORTCUT_NONE;
1.1.1.8   root      385: }
                    386: 
                    387: /*-----------------------------------------------------------------------*/
1.1.1.9   root      388: /**
                    389:  * Check which Shortcut key is pressed/released.
                    390:  * If press is set, store the key array index.
                    391:  * Return zero if key didn't match to a shortcut
                    392:  */
1.1.1.10  root      393: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
1.1.1.8   root      394: {
1.1.1.9   root      395:        SHORTCUTKEYIDX key;
1.1.1.8   root      396: 
1.1.1.9   root      397:        if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
                    398:                key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
                    399:        else
                    400:                key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
                    401: 
                    402:        if (key == SHORTCUT_NONE)
                    403:                return 0;
                    404:        if (press)
                    405:                ShortCutKey = key;
                    406:        return 1;
1.1.1.5   root      407: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.