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

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

unix.superglobalmegacorp.com

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