Search
lxdream.org :: lxdream/src/hotkeys.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/hotkeys.c
changeset 1072:d82e04e6d497
prev1038:f220d18c0615
next1298:d0eb2307b847
author nkeynes
date Fri Mar 02 23:49:10 2012 +1000 (8 years ago)
permissions -rw-r--r--
last change Android WIP:
* Rename gui_jni.c to gui_android.c - now quite android specific.
* Implement generic EGL driver with very minimal Java wrapper
* Run emulation in separate thread, and implement simple queue for
inter-thread communication.
* Add menu/action-bar items for start + reset
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 );
    31 static gboolean hotkey_config_changed( void *data, lxdream_config_group_t group, unsigned key,
    32                                        const gchar *oldval, const gchar *newval );
    34 #define TAG_RESUME 0
    35 #define TAG_STOP 1
    36 #define TAG_RESET 2
    37 #define TAG_EXIT 3
    38 #define TAG_SAVE 4
    39 #define TAG_LOAD 5
    40 #define TAG_SELECT(i) (6+(i))
    42 struct lxdream_config_group hotkeys_group = {
    43     "hotkeys", input_keygroup_changed, hotkey_key_callback, NULL, {
    44         {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY, NULL, TAG_RESUME },
    45         {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY, NULL, TAG_STOP },
    46         {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY, NULL, TAG_RESET },
    47         {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY, NULL, TAG_EXIT },
    48         {"save", N_("Save current quick save"), CONFIG_TYPE_KEY, NULL, TAG_SAVE },
    49         {"load", N_("Load current quick save"), CONFIG_TYPE_KEY, NULL, TAG_LOAD },
    50         {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(0) },
    51         {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(1) },
    52         {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(2) },
    53         {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(3) },
    54         {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(4) },
    55         {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(5) },
    56         {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(6) },
    57         {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(7) },
    58         {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(8) },
    59         {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(9) },
    60         {NULL, CONFIG_TYPE_NONE}} };
    62 void hotkeys_init() 
    63 {
    64     hotkeys_register_keys();
    65 }
    67 void hotkeys_register_keys()
    68 {
    69     input_register_keygroup( &hotkeys_group );
    70 }
    72 void hotkeys_unregister_keys()
    73 {
    74     input_unregister_keygroup( &hotkeys_group );
    75 }
    77 lxdream_config_group_t hotkeys_get_config()
    78 {
    79     return &hotkeys_group;
    80 }
    82 static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown )
    83 {
    84     if( isKeyDown ) {
    85         switch(value) {
    86         case TAG_RESUME:
    87             if( !dreamcast_is_running() )
    88                 gui_do_later(dreamcast_run);
    89             break;
    90         case TAG_STOP:
    91             if( dreamcast_is_running() )
    92                 gui_do_later(dreamcast_stop);
    93             break;
    94         case TAG_RESET:
    95             dreamcast_reset();
    96             break;
    97         case TAG_EXIT:
    98             dreamcast_shutdown();
    99             exit(0);
   100             break;
   101         case TAG_SAVE:
   102             dreamcast_quick_save();
   103             break;
   104         case TAG_LOAD:
   105             dreamcast_quick_load();
   106             break;
   107         default:
   108             dreamcast_set_quick_state(value- TAG_SELECT(0) );
   109             break;
   110         }
   111     }
   112 }
.