1.1 --- a/src/gui/ctrl_dlg.c Sun Oct 21 05:21:35 2007 +0000
1.2 +++ b/src/gui/ctrl_dlg.c Tue Oct 23 10:47:17 2007 +0000
1.5 - * $Id: ctrl_dlg.c,v 1.3 2007-10-21 05:21:35 nkeynes Exp $
1.6 + * $Id: ctrl_dlg.c,v 1.4 2007-10-23 10:47:17 nkeynes Exp $
1.8 * Define the main (emu) GTK window, along with its menubars,
1.13 #include <gtk/gtk.h>
1.14 +#include <gdk/gdkkeysyms.h>
1.17 #include "gui/gtkui.h"
1.20 static struct maple_slot_data maple_data[MAX_DEVICES];
1.22 +static gboolean config_key_buttonpress( GtkWidget *widget, GdkEventButton *event, gpointer user_data )
1.24 + gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));
1.25 + if( !keypress_mode ) {
1.26 + gtk_entry_set_text( GTK_ENTRY(widget), "<press key>" );
1.27 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );
1.32 static gboolean config_key_keypress( GtkWidget *widget, GdkEventKey *event, gpointer user_data )
1.34 - GdkKeymap *keymap = gdk_keymap_get_default();
1.37 - gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,
1.38 - NULL, NULL, NULL );
1.39 - gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) );
1.41 + gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));
1.42 + if( keypress_mode ) {
1.43 + if( event->keyval == GDK_Escape ) {
1.44 + gtk_entry_set_text( GTK_ENTRY(widget), "" );
1.45 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.48 + GdkKeymap *keymap = gdk_keymap_get_default();
1.51 + gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,
1.52 + NULL, NULL, NULL );
1.53 + gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) );
1.54 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.57 + switch( event->keyval ) {
1.59 + case GDK_KP_Enter:
1.60 + gtk_entry_set_text( GTK_ENTRY(widget), "<press key>" );
1.61 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );
1.63 + case GDK_BackSpace:
1.65 + gtk_entry_set_text( GTK_ENTRY(widget), "" );
1.73 static void controller_config_done( GtkWidget *panel, gboolean isOK )
1.78 + maple_device_t device = (maple_device_t)gtk_object_get_data( GTK_OBJECT(panel), "maple_device" );
1.79 + lxdream_config_entry_t conf = device->get_config(device);
1.81 + for( i=0; conf[i].key != NULL; i++ ) {
1.83 + GtkWidget *entry1, *entry2;
1.84 + const gchar *key1, *key2;
1.85 + snprintf( buf, sizeof(buf), "%s.1", conf[i].key );
1.86 + entry1 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));
1.87 + key1 = gtk_entry_get_text(GTK_ENTRY(entry1));
1.88 + snprintf( buf, sizeof(buf), "%s.2", conf[i].key );
1.89 + entry2 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));
1.90 + key2 = gtk_entry_get_text(GTK_ENTRY(entry2));
1.91 + if( key1 == NULL || key1[0] == '\0') {
1.92 + lxdream_set_config_value( &conf[i], key2 );
1.93 + } else if( key2 == NULL || key2[0] == '\0') {
1.94 + lxdream_set_config_value( &conf[i], key1 );
1.97 + snprintf( buf, sizeof(buf), "%s, %s", key1, key2 );
1.98 + lxdream_set_config_value( &conf[i], buf );
1.105 static void controller_device_configure( maple_device_t device )
1.106 @@ -70,8 +128,12 @@
1.107 for( count=0; conf[count].key != NULL; count++ );
1.109 GtkWidget *table = gtk_table_new( (count+1)>>1, 6, FALSE );
1.110 + GList *focus_chain = NULL;
1.111 + gtk_object_set_data( GTK_OBJECT(table), "maple_device", device );
1.112 for( i=0; i<count; i++ ) {
1.113 GtkWidget *text, *text2;
1.118 if( i >= (count+1)>>1 ) {
1.119 @@ -80,27 +142,42 @@
1.121 gtk_table_attach( GTK_TABLE(table), gtk_label_new(conf[i].key), x, x+1, y, y+1,
1.122 GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.123 - gchar **parts = g_strsplit(conf[i].value,",",3);
1.125 text = gtk_entry_new();
1.126 gtk_entry_set_width_chars( GTK_ENTRY(text), 8 );
1.127 + gtk_entry_set_editable( GTK_ENTRY(text), FALSE );
1.128 g_signal_connect( text, "key_press_event",
1.129 G_CALLBACK(config_key_keypress), NULL );
1.130 + g_signal_connect( text, "button_press_event",
1.131 + G_CALLBACK(config_key_buttonpress), NULL );
1.132 + snprintf( buf, sizeof(buf), "%s.1", conf[i].key );
1.133 + g_object_set_data( G_OBJECT(text), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.134 + g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text );
1.135 gtk_table_attach_defaults( GTK_TABLE(table), text, x+1, x+2, y, y+1);
1.137 + focus_chain = g_list_append( focus_chain, text );
1.138 text2 = gtk_entry_new();
1.139 gtk_entry_set_width_chars( GTK_ENTRY(text2), 8 );
1.140 + gtk_entry_set_editable( GTK_ENTRY(text2), FALSE );
1.141 g_signal_connect( text2, "key_press_event",
1.142 G_CALLBACK(config_key_keypress), NULL );
1.143 + g_signal_connect( text2, "button_press_event",
1.144 + G_CALLBACK(config_key_buttonpress), NULL );
1.145 + snprintf( buf, sizeof(buf), "%s.2", conf[i].key );
1.146 + g_object_set_data( G_OBJECT(text2), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.147 + g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text2 );
1.148 gtk_table_attach_defaults( GTK_TABLE(table), text2, x+2, x+3, y, y+1);
1.149 - if( parts[0] != NULL ) {
1.150 - gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) );
1.151 - if( parts[1] != NULL ) {
1.152 - gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) );
1.153 + focus_chain = g_list_append( focus_chain, text2 );
1.154 + if( conf[i].value != NULL ) {
1.155 + gchar **parts = g_strsplit(conf[i].value,",",3);
1.156 + if( parts[0] != NULL ) {
1.157 + gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) );
1.158 + if( parts[1] != NULL ) {
1.159 + gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) );
1.162 + g_strfreev(parts);
1.164 - g_strfreev(parts);
1.166 + gtk_container_set_focus_chain( GTK_CONTAINER(table), focus_chain );
1.167 gtk_gui_run_property_dialog( "Controller Configuration", table, controller_config_done );
1.170 @@ -112,6 +189,10 @@
1.172 for( i=0; maple_device_config[i].name != NULL; i++ ) {
1.173 if( strcmp(data->new_device->device_class->name, maple_device_config[i].name) == 0 ) {
1.174 + if( data->new_device == data->old_device ) {
1.175 + // Make a copy at this point if we haven't already
1.176 + data->new_device = data->old_device->clone(data->old_device);
1.178 maple_device_config[i].config_func(data->new_device);
1.181 @@ -149,31 +230,31 @@
1.185 -void maple_commit_changes( )
1.186 +void maple_dialog_done( GtkWidget *panel, gboolean isOK )
1.189 - for( i=0; i<MAX_DEVICES; i++ ) {
1.190 - if( maple_data[i].new_device != maple_data[i].old_device ) {
1.191 - if( maple_data[i].old_device != NULL ) {
1.192 - maple_detach_device(i,0);
1.195 + for( i=0; i<MAX_DEVICES; i++ ) {
1.196 + if( maple_data[i].new_device != maple_data[i].old_device ) {
1.197 + if( maple_data[i].old_device != NULL ) {
1.198 + maple_detach_device(i,0);
1.200 + if( maple_data[i].new_device != NULL ) {
1.201 + maple_attach_device(maple_data[i].new_device, i, 0 );
1.204 - if( maple_data[i].new_device != NULL ) {
1.205 - maple_attach_device(maple_data[i].new_device, i, 0 );
1.207 + lxdream_save_config();
1.210 + for( i=0; i<MAX_DEVICES; i++ ) {
1.211 + if( maple_data[i].new_device != NULL &&
1.212 + maple_data[i].new_device != maple_data[i].old_device ) {
1.213 + maple_data[i].new_device->destroy(maple_data[i].new_device);
1.217 - lxdream_save_config();
1.220 -void maple_cancel_changes( )
1.223 - for( i=0; i<MAX_DEVICES; i++ ) {
1.224 - if( maple_data[i].new_device != NULL &&
1.225 - maple_data[i].new_device != maple_data[i].old_device ) {
1.226 - maple_data[i].new_device->destroy(maple_data[i].new_device);
1.231 GtkWidget *maple_panel_new()
1.232 @@ -217,12 +298,7 @@
1.236 -void maple_dialog_run( GtkWindow *parent )
1.237 +void maple_dialog_run( )
1.239 - gint result = gtk_gui_run_property_dialog( "Controller Settings", maple_panel_new(), NULL );
1.240 - if( result == GTK_RESPONSE_ACCEPT ) {
1.241 - maple_commit_changes();
1.243 - maple_cancel_changes();
1.245 + gtk_gui_run_property_dialog( "Controller Settings", maple_panel_new(), maple_dialog_done );