Search
lxdream.org :: lxdream/src/hotkeys.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/hotkeys.c
changeset 1072:d82e04e6d497
prev1038:f220d18c0615
next1298:d0eb2307b847
author nkeynes
date Tue Feb 28 17:25:26 2012 +1000 (10 years ago)
permissions -rw-r--r--
last change Implement display output for the GLES2 case (no fixed function
rendering)
file annotate diff log raw
1.1 --- a/src/hotkeys.c Thu Jun 25 01:15:25 2009 +0000
1.2 +++ b/src/hotkeys.c Tue Feb 28 17:25:26 2012 +1000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: $
1.6 + * $Id$
1.7 *
1.8 * Handles hotkeys for pause/continue, save states, quit, etc
1.9 *
1.10 @@ -27,34 +27,37 @@
1.11 #include "gui.h"
1.12 #include "config.h"
1.13
1.14 -static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.15 -static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.16 -static void hotkey_reset_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.17 -static void hotkey_exit_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.18 -static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.19 -static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.20 -static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.21 +static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.22 +static gboolean hotkey_config_changed( void *data, lxdream_config_group_t group, unsigned key,
1.23 + const gchar *oldval, const gchar *newval );
1.24
1.25 +#define TAG_RESUME 0
1.26 +#define TAG_STOP 1
1.27 +#define TAG_RESET 2
1.28 +#define TAG_EXIT 3
1.29 +#define TAG_SAVE 4
1.30 +#define TAG_LOAD 5
1.31 +#define TAG_SELECT(i) (6+(i))
1.32
1.33 -struct lxdream_config_entry hotkeys_config[] = {
1.34 - {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY},
1.35 - {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY},
1.36 - {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY},
1.37 - {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY},
1.38 - {"save", N_("Save current quick save"), CONFIG_TYPE_KEY},
1.39 - {"load", N_("Load current quick save"), CONFIG_TYPE_KEY},
1.40 - {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY},
1.41 - {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY},
1.42 - {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY},
1.43 - {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY},
1.44 - {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY},
1.45 - {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY},
1.46 - {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY},
1.47 - {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY},
1.48 - {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY},
1.49 - {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY},
1.50 - {NULL, CONFIG_TYPE_NONE}
1.51 -};
1.52 +struct lxdream_config_group hotkeys_group = {
1.53 + "hotkeys", input_keygroup_changed, hotkey_key_callback, NULL, {
1.54 + {"resume", N_("Resume emulation"), CONFIG_TYPE_KEY, NULL, TAG_RESUME },
1.55 + {"stop", N_("Stop emulation"), CONFIG_TYPE_KEY, NULL, TAG_STOP },
1.56 + {"reset", N_("Reset emulator"), CONFIG_TYPE_KEY, NULL, TAG_RESET },
1.57 + {"exit", N_("Exit emulator"), CONFIG_TYPE_KEY, NULL, TAG_EXIT },
1.58 + {"save", N_("Save current quick save"), CONFIG_TYPE_KEY, NULL, TAG_SAVE },
1.59 + {"load", N_("Load current quick save"), CONFIG_TYPE_KEY, NULL, TAG_LOAD },
1.60 + {"state0", N_("Select quick save state 0"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(0) },
1.61 + {"state1", N_("Select quick save state 1"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(1) },
1.62 + {"state2", N_("Select quick save state 2"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(2) },
1.63 + {"state3", N_("Select quick save state 3"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(3) },
1.64 + {"state4", N_("Select quick save state 4"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(4) },
1.65 + {"state5", N_("Select quick save state 5"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(5) },
1.66 + {"state6", N_("Select quick save state 6"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(6) },
1.67 + {"state7", N_("Select quick save state 7"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(7) },
1.68 + {"state8", N_("Select quick save state 8"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(8) },
1.69 + {"state9", N_("Select quick save state 9"), CONFIG_TYPE_KEY, NULL, TAG_SELECT(9) },
1.70 + {NULL, CONFIG_TYPE_NONE}} };
1.71
1.72 void hotkeys_init()
1.73 {
1.74 @@ -63,86 +66,47 @@
1.75
1.76 void hotkeys_register_keys()
1.77 {
1.78 - input_register_key(hotkeys_config[0].value, &hotkey_resume_callback, NULL, 0);
1.79 - input_register_key(hotkeys_config[1].value, &hotkey_stop_callback, NULL, 0);
1.80 - input_register_key(hotkeys_config[2].value, &hotkey_reset_callback, NULL, 0);
1.81 - input_register_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
1.82 - input_register_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
1.83 - input_register_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
1.84 - for (int i = 0; i < 10; i++)
1.85 - {
1.86 - input_register_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
1.87 - }
1.88 + input_register_keygroup( &hotkeys_group );
1.89 }
1.90
1.91 void hotkeys_unregister_keys()
1.92 {
1.93 - input_unregister_key(hotkeys_config[0].value, &hotkey_resume_callback, NULL, 0);
1.94 - input_unregister_key(hotkeys_config[1].value, &hotkey_stop_callback, NULL, 0);
1.95 - input_unregister_key(hotkeys_config[2].value, &hotkey_reset_callback, NULL, 0);
1.96 - input_unregister_key(hotkeys_config[3].value, &hotkey_exit_callback, NULL, 0);
1.97 - input_unregister_key(hotkeys_config[4].value, &hotkey_state_save_callback, NULL, 0);
1.98 - input_unregister_key(hotkeys_config[5].value, &hotkey_state_load_callback, NULL, 0);
1.99 - for (int i = 0; i < 10; i++)
1.100 - {
1.101 - input_unregister_key(hotkeys_config[6 + i].value, &hotkey_state_select_callback, NULL, i);
1.102 + input_unregister_keygroup( &hotkeys_group );
1.103 +}
1.104 +
1.105 +lxdream_config_group_t hotkeys_get_config()
1.106 +{
1.107 + return &hotkeys_group;
1.108 +}
1.109 +
1.110 +static void hotkey_key_callback( void *data, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.111 +{
1.112 + if( isKeyDown ) {
1.113 + switch(value) {
1.114 + case TAG_RESUME:
1.115 + if( !dreamcast_is_running() )
1.116 + gui_do_later(dreamcast_run);
1.117 + break;
1.118 + case TAG_STOP:
1.119 + if( dreamcast_is_running() )
1.120 + gui_do_later(dreamcast_stop);
1.121 + break;
1.122 + case TAG_RESET:
1.123 + dreamcast_reset();
1.124 + break;
1.125 + case TAG_EXIT:
1.126 + dreamcast_shutdown();
1.127 + exit(0);
1.128 + break;
1.129 + case TAG_SAVE:
1.130 + dreamcast_quick_save();
1.131 + break;
1.132 + case TAG_LOAD:
1.133 + dreamcast_quick_load();
1.134 + break;
1.135 + default:
1.136 + dreamcast_set_quick_state(value- TAG_SELECT(0) );
1.137 + break;
1.138 + }
1.139 }
1.140 }
1.141 -
1.142 -lxdream_config_entry_t hotkeys_get_config()
1.143 -{
1.144 - return hotkeys_config;
1.145 -}
1.146 -
1.147 -
1.148 -static void hotkey_resume_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.149 -{
1.150 - if (isKeyDown && !dreamcast_is_running() ) {
1.151 - gui_do_later(dreamcast_run);
1.152 - }
1.153 -}
1.154 -
1.155 -static void hotkey_stop_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.156 -{
1.157 - if (isKeyDown && dreamcast_is_running() ) {
1.158 - gui_do_later(dreamcast_stop);
1.159 - }
1.160 -}
1.161 -
1.162 -static void hotkey_reset_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.163 -{
1.164 - if (isKeyDown) {
1.165 - dreamcast_reset();
1.166 - }
1.167 -}
1.168 -
1.169 -static void hotkey_exit_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.170 -{
1.171 - if (isKeyDown) {
1.172 - dreamcast_shutdown();
1.173 - }
1.174 - exit(0);
1.175 -}
1.176 -
1.177 -static void hotkey_state_select_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.178 -{
1.179 - if (isKeyDown) {
1.180 - dreamcast_set_quick_state(value);
1.181 - }
1.182 -}
1.183 -
1.184 -static void hotkey_state_save_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.185 -{
1.186 - if (isKeyDown) {
1.187 - dreamcast_quick_save();
1.188 - }
1.189 -}
1.190 -
1.191 -static void hotkey_state_load_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown )
1.192 -{
1.193 - if (isKeyDown) {
1.194 - dreamcast_quick_load();
1.195 - }
1.196 -}
1.197 -
1.198 -
.