Search
lxdream.org :: lxdream/src/hotkeys.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/hotkeys.c
changeset 1298:d0eb2307b847
prev1072:d82e04e6d497
author nkeynes
date Wed Feb 04 08:38:23 2015 +1000 (5 years ago)
permissions -rw-r--r--
last change Fix assorted compile warnings reported by Clang
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Handles hotkeys for pause/continue, save states, quit, etc
     5  *
     6  * Copyright (c) 2009 wahrhaft
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License as published by
    10  * the Free Software Foundation; either version 2 of the License, or
    11  * (at your option) any later version.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  */
    18 #include <assert.h>
    19 #include <glib.h>
    20 #include <sys/stat.h>
    21 #include <stdint.h>
    22 #include <stdlib.h>
    23 #include "lxdream.h"
    24 #include "dreamcast.h"
    25 #include "display.h"
    26 #include "hotkeys.h"
    27 #include "gui.h"
    28 #include "config.h"
    30 static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );
    32 #define TAG_RESUME 0
    33 #define TAG_STOP 1
    34 #define TAG_RESET 2
    35 #define TAG_EXIT 3
    36 #define TAG_SAVE 4
    37 #define TAG_LOAD 5
    38 #define TAG_SELECT(i) (6+(i))
    40 struct lxdream_config_group hotkeys_group = {
    41     "hotkeys", input_keygroup_changed, hotkey_key_callback, NULL, {
    42         {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY, NULL, TAG_RESUME },
    43         {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY, NULL, TAG_STOP },
    44         {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY, NULL, TAG_RESET },
    45         {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY, NULL, TAG_EXIT },
    46         {"save", N_("Save current quick save"), CONFIG_TYPE_KEY, NULL, TAG_SAVE },
    47         {"load", N_("Load current quick save"), CONFIG_TYPE_KEY, NULL, TAG_LOAD },
    48         {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(0) },
    49         {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(1) },
    50         {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(2) },
    51         {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(3) },
    52         {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(4) },
    53         {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(5) },
    54         {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(6) },
    55         {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(7) },
    56         {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(8) },
    57         {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(9) },
    58         {NULL, CONFIG_TYPE_NONE}} };
    60 void hotkeys_init() 
    61 {
    62     hotkeys_register_keys();
    63 }
    65 void hotkeys_register_keys()
    66 {
    67     input_register_keygroup( &hotkeys_group );
    68 }
    70 void hotkeys_unregister_keys()
    71 {
    72     input_unregister_keygroup( &hotkeys_group );
    73 }
    75 lxdream_config_group_t hotkeys_get_config()
    76 {
    77     return &hotkeys_group;
    78 }
    80 static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown )
    81 {
    82     if( isKeyDown ) {
    83         switch(value) {
    84         case TAG_RESUME:
    85             if( !dreamcast_is_running() )
    86                 gui_do_later(dreamcast_run);
    87             break;
    88         case TAG_STOP:
    89             if( dreamcast_is_running() )
    90                 gui_do_later(dreamcast_stop);
    91             break;
    92         case TAG_RESET:
    93             dreamcast_reset();
    94             break;
    95         case TAG_EXIT:
    96             dreamcast_shutdown();
    97             exit(0);
    98             break;
    99         case TAG_SAVE:
   100             dreamcast_quick_save();
   101             break;
   102         case TAG_LOAD:
   103             dreamcast_quick_load();
   104             break;
   105         default:
   106             dreamcast_set_quick_state(value- TAG_SELECT(0) );
   107             break;
   108         }
   109     }
   110 }
.