Search
lxdream.org :: lxdream/src/maple/controller.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/maple/controller.c
changeset 1072:d82e04e6d497
prev1034:7044e01148f0
next1298:d0eb2307b847
author nkeynes
date Tue Jul 21 20:33:21 2009 +1000 (13 years ago)
permissions -rw-r--r--
last change Heavy configuration management refactor
- Configuration groups now take both an on_change event handler and a
default keybinding handler, making most keybinding tasks quite simple
- GUI configuration all merged into a unified model, drastically reducing
the amount of GUI config code.

Bonuses
- OSX now has a hotkey preference pane
- GTK keybinding editor is much more usable
file annotate diff log raw
1.1 --- a/src/maple/controller.c Wed Jun 24 02:41:12 2009 +0000
1.2 +++ b/src/maple/controller.c Tue Jul 21 20:33:21 2009 +1000
1.3 @@ -79,18 +79,17 @@
1.4
1.5 static void controller_attach( maple_device_t dev );
1.6 static void controller_detach( maple_device_t dev );
1.7 -static void controller_destroy( maple_device_t dev );
1.8 +static void controller_key_callback( void *mdev, uint32_t value, uint32_t pressure, gboolean isKeyDown );
1.9 static maple_device_t controller_clone( maple_device_t dev );
1.10 static maple_device_t controller_new();
1.11 -static lxdream_config_entry_t controller_get_config( maple_device_t dev );
1.12 -static void controller_set_config_value( maple_device_t dev, unsigned int key, const gchar *value );
1.13 +static lxdream_config_group_t controller_get_config( maple_device_t dev );
1.14 static int controller_get_cond( maple_device_t dev, int function, unsigned char *outbuf,
1.15 unsigned int *outlen );
1.16
1.17 typedef struct controller_device {
1.18 struct maple_device dev;
1.19 uint32_t condition[2];
1.20 - struct lxdream_config_entry config[CONTROLLER_CONFIG_ENTRIES+1];
1.21 + struct lxdream_config_group config;
1.22 } *controller_device_t;
1.23
1.24 struct maple_device_class controller_class = { "Sega Controller",
1.25 @@ -99,26 +98,30 @@
1.26 static struct controller_device base_controller = {
1.27 { MAPLE_DEVICE_TAG, &controller_class,
1.28 CONTROLLER_IDENT, CONTROLLER_VERSION,
1.29 - controller_get_config, controller_set_config_value,
1.30 - controller_attach, controller_detach, controller_destroy,
1.31 + controller_get_config,
1.32 + controller_attach, controller_detach, maple_default_destroy,
1.33 controller_clone, NULL, NULL, controller_get_cond, NULL, NULL, NULL, NULL, NULL, NULL },
1.34 - {0x0000FFFF, 0x80808080},
1.35 - {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY },
1.36 - { "dpad right", N_("Dpad right"), CONFIG_TYPE_KEY },
1.37 - { "dpad up", N_("Dpad up"), CONFIG_TYPE_KEY },
1.38 - { "dpad down", N_("Dpad down"), CONFIG_TYPE_KEY },
1.39 - { "analog left", N_("Analog left"), CONFIG_TYPE_KEY },
1.40 - { "analog right", N_("Analog right"), CONFIG_TYPE_KEY },
1.41 - { "analog up", N_("Analog up"), CONFIG_TYPE_KEY },
1.42 - { "analog down", N_("Analog down"), CONFIG_TYPE_KEY },
1.43 - { "button X", N_("Button X"), CONFIG_TYPE_KEY },
1.44 - { "button Y", N_("Button Y"), CONFIG_TYPE_KEY },
1.45 - { "button A", N_("Button A"), CONFIG_TYPE_KEY },
1.46 - { "button B", N_("Button B"), CONFIG_TYPE_KEY },
1.47 - { "trigger left", N_("Trigger left"), CONFIG_TYPE_KEY },
1.48 - { "trigger right", N_("Trigger right"), CONFIG_TYPE_KEY },
1.49 - { "start", N_("Start button"), CONFIG_TYPE_KEY },
1.50 - { NULL, CONFIG_TYPE_NONE }} };
1.51 + {0x0000FFFF, 0x80808080},
1.52 + {"Sega Controller", NULL, controller_key_callback, NULL,
1.53 + {{ "dpad left", N_("Dpad left"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_LEFT },
1.54 + { "dpad right", N_("Dpad right"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_RIGHT },
1.55 + { "dpad up", N_("Dpad up"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_UP },
1.56 + { "dpad down", N_("Dpad down"), CONFIG_TYPE_KEY, NULL, BUTTON_DPAD_DOWN },
1.57 + { "analog left", N_("Analog left"), CONFIG_TYPE_KEY, NULL, JOY_LEFT },
1.58 + { "analog right", N_("Analog right"), CONFIG_TYPE_KEY, NULL, JOY_RIGHT },
1.59 + { "analog up", N_("Analog up"), CONFIG_TYPE_KEY, NULL, JOY_UP },
1.60 + { "analog down", N_("Analog down"), CONFIG_TYPE_KEY, NULL, JOY_DOWN },
1.61 + { "button X", N_("Button X"), CONFIG_TYPE_KEY, NULL, BUTTON_X },
1.62 + { "button Y", N_("Button Y"), CONFIG_TYPE_KEY, NULL, BUTTON_Y },
1.63 + { "button A", N_("Button A"), CONFIG_TYPE_KEY, NULL, BUTTON_A },
1.64 + { "button B", N_("Button B"), CONFIG_TYPE_KEY, NULL, BUTTON_B },
1.65 + { "trigger left", N_("Trigger left"), CONFIG_TYPE_KEY, NULL, BUTTON_LEFT_TRIGGER },
1.66 + { "trigger right", N_("Trigger right"), CONFIG_TYPE_KEY, NULL, BUTTON_RIGHT_TRIGGER },
1.67 + { "start", N_("Start button"), CONFIG_TYPE_KEY, NULL, BUTTON_START },
1.68 + { NULL, CONFIG_TYPE_NONE }}} };
1.69 +
1.70 +/* Get the controller_device * from a lxdream_config_group_t */
1.71 +#define DEV_FROM_CONFIG_GROUP(grp) ((controller_device_t)(((char *)grp) - offsetof( struct controller_device, config )))
1.72
1.73 static int config_button_map[] = {
1.74 BUTTON_DPAD_LEFT, BUTTON_DPAD_RIGHT, BUTTON_DPAD_UP, BUTTON_DPAD_DOWN,
1.75 @@ -129,8 +132,9 @@
1.76
1.77 static maple_device_t controller_new( )
1.78 {
1.79 - controller_device_t dev = malloc( sizeof(struct controller_device) );
1.80 + controller_device_t dev = malloc( sizeof(base_controller) );
1.81 memcpy( dev, &base_controller, sizeof(base_controller) );
1.82 + dev->config.data = dev;
1.83 return MAPLE_DEVICE(dev);
1.84 }
1.85
1.86 @@ -138,7 +142,7 @@
1.87 {
1.88 controller_device_t src = (controller_device_t)srcdevice;
1.89 controller_device_t dev = (controller_device_t)controller_new();
1.90 - lxdream_copy_config_list( dev->config, src->config );
1.91 + lxdream_copy_config_group( &dev->config, &src->config );
1.92 memcpy( dev->condition, src->condition, sizeof(src->condition) );
1.93 return MAPLE_DEVICE(dev);
1.94 }
1.95 @@ -194,25 +198,10 @@
1.96 }
1.97 }
1.98
1.99 -static lxdream_config_entry_t controller_get_config( maple_device_t mdev )
1.100 +static lxdream_config_group_t controller_get_config( maple_device_t mdev )
1.101 {
1.102 controller_device_t dev = (controller_device_t)mdev;
1.103 - return dev->config;
1.104 -}
1.105 -
1.106 -static void controller_set_config_value( maple_device_t mdev, unsigned int key, const gchar *value )
1.107 -{
1.108 - controller_device_t dev = (controller_device_t)mdev;
1.109 - assert( key < CONTROLLER_CONFIG_ENTRIES );
1.110 -
1.111 - input_unregister_key( dev->config[key].value, controller_key_callback, dev, config_button_map[key] );
1.112 - lxdream_set_config_value( &dev->config[key], value );
1.113 - input_register_key( dev->config[key].value, controller_key_callback, dev, config_button_map[key] );
1.114 -}
1.115 -
1.116 -static void controller_destroy( maple_device_t mdev )
1.117 -{
1.118 - free( mdev );
1.119 + return &dev->config;
1.120 }
1.121
1.122 /**
1.123 @@ -222,20 +211,15 @@
1.124 static void controller_attach( maple_device_t mdev )
1.125 {
1.126 controller_device_t dev = (controller_device_t)mdev;
1.127 - int i;
1.128 - for( i=0; i<CONTROLLER_CONFIG_ENTRIES; i++ ) {
1.129 - input_register_key( dev->config[i].value, controller_key_callback, dev, config_button_map[i] );
1.130 - }
1.131 + dev->config.on_change = input_keygroup_changed;
1.132 + input_register_keygroup( &dev->config );
1.133 }
1.134
1.135 static void controller_detach( maple_device_t mdev )
1.136 {
1.137 controller_device_t dev = (controller_device_t)mdev;
1.138 - int i;
1.139 - for( i=0; i<CONTROLLER_CONFIG_ENTRIES; i++ ) {
1.140 - input_unregister_key( dev->config[i].value, controller_key_callback, dev, config_button_map[i] );
1.141 - }
1.142 -
1.143 + input_unregister_keygroup( &dev->config );
1.144 + dev->config.on_change = NULL;
1.145 }
1.146
1.147
.