Annotation of previous/src/shortcut.c, revision 1.1.1.2

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 "memorySnapShot.h"
                     18: #include "reset.h"
                     19: #include "screen.h"
                     20: #include "screenSnapShot.h"
                     21: #include "configuration.h"
                     22: #include "shortcut.h"
                     23: #include "debugui.h"
                     24: #include "sdlgui.h"
                     25: #include "video.h"
                     26: #include "avi_record.h"
1.1.1.2 ! root       27: #include "clocks_timings.h"
1.1       root       28: 
                     29: static SHORTCUTKEYIDX ShortCutKey = SHORTCUT_NONE;  /* current shortcut key */
                     30: 
                     31: 
                     32: /*-----------------------------------------------------------------------*/
                     33: /**
                     34:  * Shortcut to toggle full-screen
                     35:  */
                     36: static void ShortCut_FullScreen(void)
                     37: {
                     38:        if (!bInFullScreen)
                     39:        {
                     40:                Screen_EnterFullScreen();
                     41:        }
                     42:        else
                     43:        {
                     44:                Screen_ReturnFromFullScreen();
                     45:        }
                     46: }
                     47: 
                     48: 
                     49: /*-----------------------------------------------------------------------*/
                     50: /**
                     51:  * Shortcut to toggle mouse grabbing mode
                     52:  */
                     53: static void ShortCut_MouseGrab(void)
                     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_WM_GrabInput(SDL_GRAB_ON);
                     63:                }
                     64:                else
                     65:                {
                     66:                        SDL_WM_GrabInput(SDL_GRAB_OFF);
                     67:                }
                     68:        }
                     69: }
                     70: 
                     71: 
                     72: /*-----------------------------------------------------------------------*/
                     73: /**
                     74:  * Shortcut to toggle YM/WAV sound recording
                     75:  */
                     76: static void ShortCut_RecordSound(void)
                     77: {
                     78: }
                     79: 
                     80: 
                     81: /*-----------------------------------------------------------------------*/
                     82: /**
                     83:  * Shortcut to toggle screen animation recording
                     84:  */
                     85: static void ShortCut_RecordAnimation(void)
                     86: {
                     87: }
                     88: 
                     89: 
                     90: /*-----------------------------------------------------------------------*/
                     91: /**
                     92:  * Shortcut to sound on/off
                     93:  */
                     94: static void ShortCut_SoundOnOff(void)
                     95: {
                     96: }
                     97: 
                     98: 
                     99: /*-----------------------------------------------------------------------*/
                    100: /**
                    101:  * Shortcut to fast forward
                    102:  */
                    103: static void ShortCut_FastForward(void)
                    104: {
                    105:                /* Set maximum speed */
                    106:                ConfigureParams.System.bFastForward = true;
                    107: }
                    108: 
                    109: 
                    110: /*-----------------------------------------------------------------------*/
                    111: /**
                    112:  * Shortcut to 'Boss' key, ie minmize Window and switch to another application
                    113:  */
                    114: static void ShortCut_BossKey(void)
                    115: {
                    116:        /* If we are in full-screen, then return to a window */
                    117:        Screen_ReturnFromFullScreen();
                    118: 
                    119:        if (bGrabMouse)
                    120:        {
                    121:                SDL_WM_GrabInput(SDL_GRAB_OFF);
                    122:                bGrabMouse = false;
                    123:        }
                    124:        Main_PauseEmulation(true);
                    125: 
                    126:        /* Minimize Window and give up processing to next one! */
                    127:        SDL_WM_IconifyWindow();
                    128: }
                    129: 
                    130: 
                    131: /*-----------------------------------------------------------------------*/
                    132: /**
                    133:  * Shorcut to debug interface
                    134:  */
                    135: static void ShortCut_Debug(void)
                    136: {
                    137:        int running;
                    138: 
                    139:        /* Call the debugger */
                    140:        running = Main_PauseEmulation(true);
                    141:        DebugUI();
                    142:        if (running)
                    143:                Main_UnPauseEmulation();
                    144: }
                    145: 
                    146: 
                    147: /*-----------------------------------------------------------------------*/
                    148: /**
                    149:  * Shorcut to pausing
                    150:  */
                    151: static void ShortCut_Pause(void)
                    152: {
                    153:        if (!Main_UnPauseEmulation())
                    154:                Main_PauseEmulation(true);
                    155: }
                    156: 
                    157: /**
                    158:  * Shorcut to load a disk image
                    159:  */
                    160: static void ShortCut_InsertDisk(int drive)
                    161: {
                    162: }
                    163: 
                    164: 
                    165: /*-----------------------------------------------------------------------*/
                    166: /**
                    167:  * Check to see if pressed any shortcut keys, and call handling function
                    168:  */
                    169: void ShortCut_ActKey(void)
                    170: {
                    171:        if (ShortCutKey == SHORTCUT_NONE)
                    172:                return;
                    173: 
                    174:        switch (ShortCutKey)
                    175:        {
                    176:         case SHORTCUT_OPTIONS:
                    177:                Dialog_DoProperty();           /* Show options dialog */
                    178:                break;
                    179:         case SHORTCUT_FULLSCREEN:
                    180:                ShortCut_FullScreen();         /* Switch between fullscreen/windowed mode */
                    181:                break;
                    182:         case SHORTCUT_MOUSEGRAB:
                    183:                ShortCut_MouseGrab();          /* Toggle mouse grab */
                    184:                break;
                    185:         case SHORTCUT_COLDRESET:
                    186:                Main_UnPauseEmulation();
                    187:                Reset_Cold();                  /* Reset emulator with 'cold' (clear all) */
                    188:                break;
                    189:         case SHORTCUT_WARMRESET:
                    190:                Main_UnPauseEmulation();
                    191:                Reset_Warm();                  /* Emulator 'warm' reset */
                    192:                break;
                    193:         case SHORTCUT_SCREENSHOT:
                    194:                ScreenSnapShot_SaveScreen();   /* Grab screenshot */
                    195:                break;
                    196:         case SHORTCUT_BOSSKEY:
                    197:                ShortCut_BossKey();            /* Boss key */
                    198:                break;
                    199:         case SHORTCUT_CURSOREMU:          /* Toggle joystick emu on/off */
                    200: //             Joy_ToggleCursorEmulation();
                    201:                break;
                    202:         case SHORTCUT_FASTFORWARD:
                    203:                ShortCut_FastForward();       /* Toggle Min/Max speed */
                    204:                break;
                    205:         case SHORTCUT_RECANIM:
                    206:                ShortCut_RecordAnimation();    /* Record animation */
                    207:                break;
                    208:         case SHORTCUT_RECSOUND:
                    209: //             ShortCut_RecordSound();        /* Toggle sound recording */
                    210:                break;
                    211:         case SHORTCUT_SOUND:
                    212:                ShortCut_SoundOnOff();         /* Enable/disable sound */
                    213:                break;
                    214:         case SHORTCUT_DEBUG:
                    215:                ShortCut_Debug();              /* Invoke the Debug UI */
                    216:                break;
                    217:         case SHORTCUT_PAUSE:
                    218:                ShortCut_Pause();              /* Invoke Pause */
                    219:                break;
                    220:         case SHORTCUT_QUIT:
                    221:                Main_RequestQuit();
                    222:                break;
                    223:         case SHORTCUT_LOADMEM:
                    224:                MemorySnapShot_Restore(ConfigureParams.Memory.szMemoryCaptureFileName, true);
                    225:                break;
                    226:         case SHORTCUT_SAVEMEM:
                    227:                MemorySnapShot_Capture(ConfigureParams.Memory.szMemoryCaptureFileName, true);
                    228:                break;
                    229:         case SHORTCUT_INSERTDISKA:
                    230: //             ShortCut_InsertDisk(0);
                    231:                break;
                    232:         case SHORTCUT_KEYS:
                    233:         case SHORTCUT_NONE:
                    234:                /* ERROR: cannot happen, just make compiler happy */
                    235:                break;
                    236:        }
                    237:        ShortCutKey = SHORTCUT_NONE;
                    238: }
                    239: 
                    240: 
                    241: /*-----------------------------------------------------------------------*/
                    242: /**
                    243:  * Invoke shortcut identified by name. This supports only keys for
                    244:  * functionality that cannot be invoked with command line options
                    245:  * or otherwise for remote GUIs etc.
                    246:  */
                    247: bool Shortcut_Invoke(const char *shortcut)
                    248: {
                    249:        struct {
                    250:                SHORTCUTKEYIDX id;
                    251:                const char *name;
                    252:        } shortcuts[] = {
                    253:                { SHORTCUT_MOUSEGRAB, "mousegrab" },
                    254:                { SHORTCUT_COLDRESET, "coldreset" },
                    255:                { SHORTCUT_WARMRESET, "warmreset" },
                    256:                { SHORTCUT_SCREENSHOT, "screenshot" },
                    257:                { SHORTCUT_BOSSKEY, "bosskey" },
                    258:                { SHORTCUT_RECANIM, "recanim" },
                    259:                { SHORTCUT_RECSOUND, "recsound" },
                    260:                { SHORTCUT_SAVEMEM, "savemem" },
                    261:                { SHORTCUT_QUIT, "quit" },
                    262:                { SHORTCUT_NONE, NULL }
                    263:        };
                    264:        int i;
                    265: 
                    266:        if (ShortCutKey != SHORTCUT_NONE)
                    267:        {
                    268:                fprintf(stderr, "Shortcut invocation failed, shortcut already active\n");
                    269:                return false;
                    270:        }
                    271:        for (i = 0; shortcuts[i].name; i++)
                    272:        {
                    273:                if (strcmp(shortcut, shortcuts[i].name) == 0)
                    274:                {
                    275:                        ShortCutKey = shortcuts[i].id;
                    276:                        ShortCut_ActKey();
                    277:                        ShortCutKey = SHORTCUT_NONE;
                    278:                        return true;
                    279:                }
                    280:        }
                    281:        fprintf(stderr, "WARNING: unknown shortcut '%s'\n\n", shortcut);
                    282:        fprintf(stderr, "Hatari shortcuts are:\n");
                    283:        for (i = 0; shortcuts[i].name; i++)
                    284:        {
                    285:                fprintf(stderr, "- %s\n", shortcuts[i].name);
                    286:        }
                    287:        return false;
                    288: }
                    289: 
                    290: 
                    291: /*-----------------------------------------------------------------------*/
                    292: /**
                    293:  * Check whether given key was any of the ones in given shortcut array.
                    294:  * Return corresponding array index or SHORTCUT_NONE for no match
                    295:  */
                    296: static SHORTCUTKEYIDX ShortCut_CheckKey(int symkey, int *keys)
                    297: {
                    298:        SHORTCUTKEYIDX key;
                    299:        for (key = SHORTCUT_OPTIONS; key < SHORTCUT_KEYS; key++)
                    300:        {
                    301:                if (symkey == keys[key])
                    302:                        return key;
                    303:        }
                    304:        return SHORTCUT_NONE;
                    305: }
                    306: 
                    307: /*-----------------------------------------------------------------------*/
                    308: /**
                    309:  * Check which Shortcut key is pressed/released.
                    310:  * If press is set, store the key array index.
                    311:  * Return zero if key didn't match to a shortcut
                    312:  */
                    313: int ShortCut_CheckKeys(int modkey, int symkey, bool press)
                    314: {
                    315:        SHORTCUTKEYIDX key;
                    316: 
                    317:        if (modkey & (KMOD_RALT|KMOD_LMETA|KMOD_RMETA|KMOD_MODE))
                    318:                key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withModifier);
                    319:        else
                    320:                key = ShortCut_CheckKey(symkey, ConfigureParams.Shortcut.withoutModifier);
                    321: 
                    322:        if (key == SHORTCUT_NONE)
                    323:                return 0;
                    324:        if (press) {
                    325:                ShortCutKey = key;
                    326:                fprintf(stderr,"Short :%x\n",ShortCutKey);
                    327:        }
                    328:        return 1;
                    329: }

unix.superglobalmegacorp.com

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