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

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.11! root        9: const char ShortCut_rcsid[] = "Hatari $Id: shortcut.c,v 1.43 2008-11-22 18:21:33 eerot Exp $";
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 */
                    124:        ConfigureParams.Sound.bEnableSound ^= TRUE;
                    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.10  root      147:        if (ConfigureParams.System.bFastForward == TRUE)
1.1.1.9   root      148:        {
                    149:                /* Restore */
1.1.1.10  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.10  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);
                    175:                bGrabMouse = FALSE;
                    176:        }
1.1.1.10  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.10  root      186:  * Shorcut to pause or debug interface
                    187:  */
                    188: static void ShortCut_Pause(void)
                    189: {
                    190:        if (bEnableDebug)
                    191:        {
                    192:                int running;
                    193:                
                    194:                if (bInFullScreen)
                    195:                        Screen_ReturnFromFullScreen();
                    196: 
                    197:                /* Call the debugger */
                    198:                running = Main_PauseEmulation(TRUE);
                    199:                DebugUI();
                    200:                if (running)
                    201:                        Main_UnPauseEmulation();
                    202:        }
                    203:        else
                    204:        {
                    205:                if (!Main_UnPauseEmulation())
                    206:                        Main_PauseEmulation(TRUE);
                    207:        }
                    208: }
                    209: 
                    210: 
                    211: /**
                    212:  * Shorcut to load a disk image
                    213:  */
                    214: static void ShortCut_InsertDisk(int drive)
                    215: {
                    216:        char *selname, *zip_path = NULL;
                    217:        const char *tmpname;
                    218: 
                    219:        if (SDLGui_SetScreen(sdlscrn))
                    220:                return;
                    221: 
                    222:        if (ConfigureParams.DiskImage.szDiskFileName[drive][0])
                    223:                tmpname = ConfigureParams.DiskImage.szDiskFileName[drive];
                    224:        else
                    225:                tmpname = ConfigureParams.DiskImage.szDiskImageDirectory;
                    226: 
                    227:        Main_PauseEmulation(TRUE);
                    228:        selname = SDLGui_FileSelect(tmpname, &zip_path, FALSE);
                    229:        if (selname)
                    230:        {
                    231:                if (File_Exists(selname))
1.1.1.11! root      232:                        Floppy_SetDiskFileName(drive, selname, zip_path);
1.1.1.10  root      233:                else
                    234:                        Floppy_SetDiskFileNameNone(drive);
1.1.1.11! root      235: 
        !           236:                if (zip_path)
        !           237:                        free(zip_path);
1.1.1.10  root      238:                free(selname);
1.1.1.11! root      239:                
        !           240:                Floppy_InsertDiskIntoDrive(0);
1.1.1.10  root      241:        }
                    242:        Main_UnPauseEmulation();
                    243: }
                    244: 
                    245: 
                    246: /*-----------------------------------------------------------------------*/
                    247: /**
1.1.1.9   root      248:  * Check to see if pressed any shortcut keys, and call handling function
                    249:  */
1.1.1.8   root      250: void ShortCut_ActKey(void)
1.1.1.5   root      251: {
1.1.1.9   root      252:        if (ShortCutKey == SHORTCUT_NONE)
                    253:                return;
1.1.1.8   root      254: 
1.1.1.9   root      255:        switch (ShortCutKey)
                    256:        {
                    257:         case SHORTCUT_OPTIONS:
                    258:                Dialog_DoProperty();           /* Show options dialog */
                    259:                break;
                    260:         case SHORTCUT_FULLSCREEN:
                    261:                ShortCut_FullScreen();         /* Switch between fullscreen/windowed mode */
                    262:                break;
                    263:         case SHORTCUT_MOUSEMODE:
                    264:                ShortCut_MouseMode();          /* Toggle mouse mode */
                    265:                break;
                    266:         case SHORTCUT_COLDRESET:
1.1.1.10  root      267:                Main_UnPauseEmulation();
1.1.1.9   root      268:                Reset_Cold();                  /* Reset emulator with 'cold' (clear all) */
                    269:                break;
                    270:         case SHORTCUT_WARMRESET:
1.1.1.10  root      271:                Main_UnPauseEmulation();
1.1.1.9   root      272:                Reset_Warm();                  /* Emulator 'warm' reset */
                    273:                break;
                    274:         case SHORTCUT_SCREENSHOT:
                    275:                ScreenSnapShot_SaveScreen();   /* Grab screenshot */
                    276:                break;
                    277:         case SHORTCUT_BOSSKEY:
                    278:                ShortCut_BossKey();            /* Boss key */
                    279:                break;
                    280:         case SHORTCUT_CURSOREMU:          /* Toggle joystick emu on/off */
                    281:                Joy_ToggleCursorEmulation();
                    282:                break;
1.1.1.10  root      283:         case SHORTCUT_FASTFORWARD:
                    284:                ShortCut_FastForward();       /* Toggle Min/Max speed */
1.1.1.9   root      285:                break;
                    286:         case SHORTCUT_RECANIM:
                    287:                ShortCut_RecordAnimation();    /* Record animation */
                    288:                break;
                    289:         case SHORTCUT_RECSOUND:
                    290:                ShortCut_RecordSound();        /* Toggle sound recording */
                    291:                break;
                    292:         case SHORTCUT_SOUND:
                    293:                ShortCut_SoundOnOff();         /* Enable/disable sound */
                    294:                break;
1.1.1.10  root      295:         case SHORTCUT_PAUSE:
                    296:                ShortCut_Pause();              /* Invoke Pause or Debug UI */
                    297:                break;
1.1.1.9   root      298:         case SHORTCUT_QUIT:
                    299:                Main_RequestQuit();
                    300:                break;
                    301:         case SHORTCUT_LOADMEM:
                    302:                MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
                    303:                break;
                    304:         case SHORTCUT_SAVEMEM:
                    305:                MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, TRUE);
                    306:                break;
1.1.1.10  root      307:         case SHORTCUT_INSERTDISKA:
                    308:                ShortCut_InsertDisk(0);
                    309:                break;
1.1.1.9   root      310:         case SHORTCUT_KEYS:
                    311:         case SHORTCUT_NONE:
                    312:                /* ERROR: cannot happen, just make compiler happy */
                    313:                break;
                    314:        }
                    315:        ShortCutKey = SHORTCUT_NONE;
                    316: }
                    317: 
                    318: 
                    319: /*-----------------------------------------------------------------------*/
                    320: /**
1.1.1.10  root      321:  * Invoke shortcut identified by name. This supports only keys for
                    322:  * functionality that cannot be invoked with command line options
                    323:  * (for remote GUIs etc).
                    324:  */
                    325: bool Shortcut_Invoke(const char *shortcut)
                    326: {
                    327:        struct {
                    328:                SHORTCUTKEYIDX id;
                    329:                const char *name;
                    330:        } shortcuts[] = {
                    331:                { SHORTCUT_MOUSEMODE, "mousemode" },
                    332:                { SHORTCUT_COLDRESET, "coldreset" },
                    333:                { SHORTCUT_WARMRESET, "warmreset" },
                    334:                { SHORTCUT_SCREENSHOT, "screenshot" },
                    335:                { SHORTCUT_BOSSKEY, "bosskey" },
                    336:                { SHORTCUT_RECANIM, "recanim" },
                    337:                { SHORTCUT_RECSOUND, "recsound" },
                    338:                { SHORTCUT_SAVEMEM, "savemem" },
                    339:                { SHORTCUT_QUIT, "quit" },
                    340:                { SHORTCUT_NONE, NULL }
                    341:        };
                    342:        int i;
                    343: 
                    344:        if (ShortCutKey != SHORTCUT_NONE)
                    345:        {
                    346:                fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
                    347:                return FALSE;
                    348:        }
                    349:        for (i = 0; shortcuts[i].name; i++)
                    350:        {
                    351:                if (strcmp(shortcut, shortcuts[i].name) == 0)
                    352:                {
                    353:                        ShortCutKey = shortcuts[i].id;
                    354:                        ShortCut_ActKey();
                    355:                        ShortCutKey = SHORTCUT_NONE;
                    356:                        return TRUE;
                    357:                }
                    358:        }
                    359:        fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
                    360:        fprintf(stderr, "Hatari shortcuts are:\n");
                    361:        for (i = 0; shortcuts[i].name; i++)
                    362:        {
                    363:                fprintf(stderr, "- %s\n", shortcuts[i].name);
                    364:        }
                    365:        return FALSE;
                    366: }
                    367: 
                    368: 
                    369: /*-----------------------------------------------------------------------*/
                    370: /**
1.1.1.9   root      371:  * Check whether given key was any of the ones in given shortcut array.
                    372:  * Return corresponding array index or SHORTCUT_NONE for no match
                    373:  */
1.1.1.8   root      374: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
                    375: {
1.1.1.9   root      376:        SHORTCUTKEYIDX key;
                    377:        for (key = 0; key < SHORTCUT_KEYS; key++)
                    378:        {
                    379:                if (symkey == keys[key])
                    380:                        return key;
                    381:        }
                    382:        return SHORTCUT_NONE;
1.1.1.8   root      383: }
                    384: 
                    385: /*-----------------------------------------------------------------------*/
1.1.1.9   root      386: /**
                    387:  * Check which Shortcut key is pressed/released.
                    388:  * If press is set, store the key array index.
                    389:  * Return zero if key didn't match to a shortcut
                    390:  */
1.1.1.10  root      391: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
1.1.1.8   root      392: {
1.1.1.9   root      393:        SHORTCUTKEYIDX key;
1.1.1.8   root      394: 
1.1.1.9   root      395:        if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
                    396:                key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
                    397:        else
                    398:                key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
                    399: 
                    400:        if (key == SHORTCUT_NONE)
                    401:                return 0;
                    402:        if (press)
                    403:                ShortCutKey = key;
                    404:        return 1;
1.1.1.5   root      405: }

unix.superglobalmegacorp.com

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