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

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

unix.superglobalmegacorp.com

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