Search
lxdream.org :: lxdream/src/gtkui/ctrl_dlg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/ctrl_dlg.c
changeset 736:a02d1475ccfd
prev669:ab344e42bca9
author nkeynes
date Sat Jul 19 02:48:50 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Add debian control files to the dist
file annotate diff log raw
1.1 --- a/src/gtkui/ctrl_dlg.c Mon May 12 10:00:13 2008 +0000
1.2 +++ b/src/gtkui/ctrl_dlg.c Sat Jul 19 02:48:50 2008 +0000
1.3 @@ -44,8 +44,8 @@
1.4 } *maple_slot_data_t;
1.5
1.6 static struct maple_config_class maple_device_config[] = {
1.7 - { "Sega Controller", controller_device_configure },
1.8 - { NULL, NULL } };
1.9 + { "Sega Controller", controller_device_configure },
1.10 + { NULL, NULL } };
1.11
1.12 static struct maple_slot_data maple_data[MAX_DEVICES];
1.13
1.14 @@ -61,9 +61,9 @@
1.15 {
1.16 gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));
1.17 if( !keypress_mode ) {
1.18 - gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );
1.19 - g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );
1.20 - input_set_keysym_hook(config_keysym_hook, widget);
1.21 + gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );
1.22 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );
1.23 + input_set_keysym_hook(config_keysym_hook, widget);
1.24 }
1.25 return FALSE;
1.26 }
1.27 @@ -72,64 +72,64 @@
1.28 {
1.29 gboolean keypress_mode = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(widget), "keypress_mode"));
1.30 if( keypress_mode ) {
1.31 - if( event->keyval == GDK_Escape ) {
1.32 - gtk_entry_set_text( GTK_ENTRY(widget), "" );
1.33 - g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.34 - return TRUE;
1.35 - }
1.36 - GdkKeymap *keymap = gdk_keymap_get_default();
1.37 - guint keyval;
1.38 -
1.39 - gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,
1.40 - NULL, NULL, NULL );
1.41 - gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) );
1.42 - g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.43 - input_set_keysym_hook(NULL, NULL);
1.44 - return TRUE;
1.45 + if( event->keyval == GDK_Escape ) {
1.46 + gtk_entry_set_text( GTK_ENTRY(widget), "" );
1.47 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.48 + return TRUE;
1.49 + }
1.50 + GdkKeymap *keymap = gdk_keymap_get_default();
1.51 + guint keyval;
1.52 +
1.53 + gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,
1.54 + NULL, NULL, NULL );
1.55 + gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) );
1.56 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.57 + input_set_keysym_hook(NULL, NULL);
1.58 + return TRUE;
1.59 } else {
1.60 - switch( event->keyval ) {
1.61 - case GDK_Return:
1.62 - case GDK_KP_Enter:
1.63 - gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );
1.64 - g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );
1.65 - input_set_keysym_hook(config_keysym_hook, widget);
1.66 - return TRUE;
1.67 - case GDK_BackSpace:
1.68 - case GDK_Delete:
1.69 - gtk_entry_set_text( GTK_ENTRY(widget), "" );
1.70 - return TRUE;
1.71 - }
1.72 - return FALSE;
1.73 + switch( event->keyval ) {
1.74 + case GDK_Return:
1.75 + case GDK_KP_Enter:
1.76 + gtk_entry_set_text( GTK_ENTRY(widget), _("<press key>") );
1.77 + g_object_set_data( G_OBJECT(widget), "keypress_mode", GINT_TO_POINTER(TRUE) );
1.78 + input_set_keysym_hook(config_keysym_hook, widget);
1.79 + return TRUE;
1.80 + case GDK_BackSpace:
1.81 + case GDK_Delete:
1.82 + gtk_entry_set_text( GTK_ENTRY(widget), "" );
1.83 + return TRUE;
1.84 + }
1.85 + return FALSE;
1.86 }
1.87 -
1.88 +
1.89 }
1.90
1.91 static void controller_config_done( GtkWidget *panel, gboolean isOK )
1.92 {
1.93 if( isOK ) {
1.94 - maple_device_t device = (maple_device_t)gtk_object_get_data( GTK_OBJECT(panel), "maple_device" );
1.95 - lxdream_config_entry_t conf = device->get_config(device);
1.96 - int i;
1.97 - for( i=0; conf[i].key != NULL; i++ ) {
1.98 - char buf[64];
1.99 - GtkWidget *entry1, *entry2;
1.100 - const gchar *key1, *key2;
1.101 - snprintf( buf, sizeof(buf), "%s.1", conf[i].key );
1.102 - entry1 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));
1.103 - key1 = gtk_entry_get_text(GTK_ENTRY(entry1));
1.104 - snprintf( buf, sizeof(buf), "%s.2", conf[i].key );
1.105 - entry2 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));
1.106 - key2 = gtk_entry_get_text(GTK_ENTRY(entry2));
1.107 - if( key1 == NULL || key1[0] == '\0') {
1.108 - lxdream_set_config_value( &conf[i], key2 );
1.109 - } else if( key2 == NULL || key2[0] == '\0') {
1.110 - lxdream_set_config_value( &conf[i], key1 );
1.111 - } else {
1.112 - char buf[64];
1.113 - snprintf( buf, sizeof(buf), "%s, %s", key1, key2 );
1.114 - lxdream_set_config_value( &conf[i], buf );
1.115 - }
1.116 - }
1.117 + maple_device_t device = (maple_device_t)gtk_object_get_data( GTK_OBJECT(panel), "maple_device" );
1.118 + lxdream_config_entry_t conf = device->get_config(device);
1.119 + int i;
1.120 + for( i=0; conf[i].key != NULL; i++ ) {
1.121 + char buf[64];
1.122 + GtkWidget *entry1, *entry2;
1.123 + const gchar *key1, *key2;
1.124 + snprintf( buf, sizeof(buf), "%s.1", conf[i].key );
1.125 + entry1 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));
1.126 + key1 = gtk_entry_get_text(GTK_ENTRY(entry1));
1.127 + snprintf( buf, sizeof(buf), "%s.2", conf[i].key );
1.128 + entry2 = GTK_WIDGET(g_object_get_qdata( G_OBJECT(panel), g_quark_from_string(buf)));
1.129 + key2 = gtk_entry_get_text(GTK_ENTRY(entry2));
1.130 + if( key1 == NULL || key1[0] == '\0') {
1.131 + lxdream_set_config_value( &conf[i], key2 );
1.132 + } else if( key2 == NULL || key2[0] == '\0') {
1.133 + lxdream_set_config_value( &conf[i], key1 );
1.134 + } else {
1.135 + char buf[64];
1.136 + snprintf( buf, sizeof(buf), "%s, %s", key1, key2 );
1.137 + lxdream_set_config_value( &conf[i], buf );
1.138 + }
1.139 + }
1.140 }
1.141 input_set_keysym_hook(NULL, NULL);
1.142 }
1.143 @@ -144,50 +144,50 @@
1.144 GList *focus_chain = NULL;
1.145 gtk_object_set_data( GTK_OBJECT(table), "maple_device", device );
1.146 for( i=0; i<count; i++ ) {
1.147 - GtkWidget *text, *text2;
1.148 - char buf[64];
1.149 - int x=0;
1.150 - int y=i;
1.151 - if( i >= (count+1)>>1 ) {
1.152 - x = 3;
1.153 - y -= (count+1)>>1;
1.154 - }
1.155 - gtk_table_attach( GTK_TABLE(table), gtk_label_new(conf[i].key), x, x+1, y, y+1,
1.156 - GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.157 - text = gtk_entry_new();
1.158 - gtk_entry_set_width_chars( GTK_ENTRY(text), 11 );
1.159 - gtk_entry_set_editable( GTK_ENTRY(text), FALSE );
1.160 - g_signal_connect( text, "key_press_event",
1.161 - G_CALLBACK(config_key_keypress), NULL );
1.162 - g_signal_connect( text, "button_press_event",
1.163 - G_CALLBACK(config_key_buttonpress), NULL );
1.164 - snprintf( buf, sizeof(buf), "%s.1", conf[i].key );
1.165 - g_object_set_data( G_OBJECT(text), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.166 - g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text );
1.167 - gtk_table_attach_defaults( GTK_TABLE(table), text, x+1, x+2, y, y+1);
1.168 - focus_chain = g_list_append( focus_chain, text );
1.169 - text2 = gtk_entry_new();
1.170 - gtk_entry_set_width_chars( GTK_ENTRY(text2), 11 );
1.171 - gtk_entry_set_editable( GTK_ENTRY(text2), FALSE );
1.172 - g_signal_connect( text2, "key_press_event",
1.173 - G_CALLBACK(config_key_keypress), NULL );
1.174 - g_signal_connect( text2, "button_press_event",
1.175 - G_CALLBACK(config_key_buttonpress), NULL );
1.176 - snprintf( buf, sizeof(buf), "%s.2", conf[i].key );
1.177 - g_object_set_data( G_OBJECT(text2), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.178 - g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text2 );
1.179 - gtk_table_attach_defaults( GTK_TABLE(table), text2, x+2, x+3, y, y+1);
1.180 - focus_chain = g_list_append( focus_chain, text2 );
1.181 - if( conf[i].value != NULL ) {
1.182 - gchar **parts = g_strsplit(conf[i].value,",",3);
1.183 - if( parts[0] != NULL ) {
1.184 - gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) );
1.185 - if( parts[1] != NULL ) {
1.186 - gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) );
1.187 - }
1.188 - }
1.189 - g_strfreev(parts);
1.190 - }
1.191 + GtkWidget *text, *text2;
1.192 + char buf[64];
1.193 + int x=0;
1.194 + int y=i;
1.195 + if( i >= (count+1)>>1 ) {
1.196 + x = 3;
1.197 + y -= (count+1)>>1;
1.198 + }
1.199 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(conf[i].key), x, x+1, y, y+1,
1.200 + GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.201 + text = gtk_entry_new();
1.202 + gtk_entry_set_width_chars( GTK_ENTRY(text), 11 );
1.203 + gtk_entry_set_editable( GTK_ENTRY(text), FALSE );
1.204 + g_signal_connect( text, "key_press_event",
1.205 + G_CALLBACK(config_key_keypress), NULL );
1.206 + g_signal_connect( text, "button_press_event",
1.207 + G_CALLBACK(config_key_buttonpress), NULL );
1.208 + snprintf( buf, sizeof(buf), "%s.1", conf[i].key );
1.209 + g_object_set_data( G_OBJECT(text), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.210 + g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text );
1.211 + gtk_table_attach_defaults( GTK_TABLE(table), text, x+1, x+2, y, y+1);
1.212 + focus_chain = g_list_append( focus_chain, text );
1.213 + text2 = gtk_entry_new();
1.214 + gtk_entry_set_width_chars( GTK_ENTRY(text2), 11 );
1.215 + gtk_entry_set_editable( GTK_ENTRY(text2), FALSE );
1.216 + g_signal_connect( text2, "key_press_event",
1.217 + G_CALLBACK(config_key_keypress), NULL );
1.218 + g_signal_connect( text2, "button_press_event",
1.219 + G_CALLBACK(config_key_buttonpress), NULL );
1.220 + snprintf( buf, sizeof(buf), "%s.2", conf[i].key );
1.221 + g_object_set_data( G_OBJECT(text2), "keypress_mode", GINT_TO_POINTER(FALSE) );
1.222 + g_object_set_qdata( G_OBJECT(table), g_quark_from_string(buf), text2 );
1.223 + gtk_table_attach_defaults( GTK_TABLE(table), text2, x+2, x+3, y, y+1);
1.224 + focus_chain = g_list_append( focus_chain, text2 );
1.225 + if( conf[i].value != NULL ) {
1.226 + gchar **parts = g_strsplit(conf[i].value,",",3);
1.227 + if( parts[0] != NULL ) {
1.228 + gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) );
1.229 + if( parts[1] != NULL ) {
1.230 + gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) );
1.231 + }
1.232 + }
1.233 + g_strfreev(parts);
1.234 + }
1.235 }
1.236 gtk_container_set_focus_chain( GTK_CONTAINER(table), focus_chain );
1.237 gtk_gui_run_property_dialog( _("Controller Configuration"), table, controller_config_done );
1.238 @@ -197,20 +197,20 @@
1.239 {
1.240 maple_slot_data_t data = (maple_slot_data_t)user_data;
1.241 if( data->new_device != NULL ) {
1.242 - int i;
1.243 - for( i=0; maple_device_config[i].name != NULL; i++ ) {
1.244 - if( strcmp(data->new_device->device_class->name, maple_device_config[i].name) == 0 ) {
1.245 - if( data->new_device == data->old_device ) {
1.246 - // Make a copy at this point if we haven't already
1.247 - data->new_device = data->old_device->clone(data->old_device);
1.248 - }
1.249 - maple_device_config[i].config_func(data->new_device);
1.250 - break;
1.251 - }
1.252 - }
1.253 - if( maple_device_config[i].name == NULL ) {
1.254 - gui_error_dialog( _("No configuration page available for device type") );
1.255 - }
1.256 + int i;
1.257 + for( i=0; maple_device_config[i].name != NULL; i++ ) {
1.258 + if( strcmp(data->new_device->device_class->name, maple_device_config[i].name) == 0 ) {
1.259 + if( data->new_device == data->old_device ) {
1.260 + // Make a copy at this point if we haven't already
1.261 + data->new_device = data->old_device->clone(data->old_device);
1.262 + }
1.263 + maple_device_config[i].config_func(data->new_device);
1.264 + break;
1.265 + }
1.266 + }
1.267 + if( maple_device_config[i].name == NULL ) {
1.268 + gui_error_dialog( _("No configuration page available for device type") );
1.269 + }
1.270 }
1.271 return TRUE;
1.272 }
1.273 @@ -221,25 +221,25 @@
1.274 int active = gtk_combo_box_get_active(combo);
1.275 gboolean has_config = FALSE;
1.276 if( active != 0 ) {
1.277 - gchar *devname = gtk_combo_box_get_active_text(combo);
1.278 - const maple_device_class_t devclz = maple_get_device_class(devname);
1.279 - assert(devclz != NULL);
1.280 - if( data->new_device != NULL ) {
1.281 - if( data->new_device->device_class != devclz ) {
1.282 - if( data->new_device != data->old_device ) {
1.283 - data->new_device->destroy(data->new_device);
1.284 - }
1.285 - data->new_device = maple_new_device(devname);
1.286 - }
1.287 - } else {
1.288 - data->new_device = maple_new_device(devname);
1.289 - }
1.290 - has_config = data->new_device != NULL && data->new_device->get_config != NULL;
1.291 + gchar *devname = gtk_combo_box_get_active_text(combo);
1.292 + const maple_device_class_t devclz = maple_get_device_class(devname);
1.293 + assert(devclz != NULL);
1.294 + if( data->new_device != NULL ) {
1.295 + if( data->new_device->device_class != devclz ) {
1.296 + if( data->new_device != data->old_device ) {
1.297 + data->new_device->destroy(data->new_device);
1.298 + }
1.299 + data->new_device = maple_new_device(devname);
1.300 + }
1.301 + } else {
1.302 + data->new_device = maple_new_device(devname);
1.303 + }
1.304 + has_config = data->new_device != NULL && data->new_device->get_config != NULL;
1.305 } else {
1.306 - if( data->new_device != NULL && data->new_device != data->old_device ) {
1.307 - data->new_device->destroy(data->new_device);
1.308 - }
1.309 - data->new_device = NULL;
1.310 + if( data->new_device != NULL && data->new_device != data->old_device ) {
1.311 + data->new_device->destroy(data->new_device);
1.312 + }
1.313 + data->new_device = NULL;
1.314 }
1.315 gtk_widget_set_sensitive(data->button, has_config);
1.316 return TRUE;
1.317 @@ -248,26 +248,26 @@
1.318 void maple_dialog_done( GtkWidget *panel, gboolean isOK )
1.319 {
1.320 if( isOK ) {
1.321 - int i;
1.322 - for( i=0; i<MAX_DEVICES; i++ ) {
1.323 - if( maple_data[i].new_device != maple_data[i].old_device ) {
1.324 - if( maple_data[i].old_device != NULL ) {
1.325 - maple_detach_device(i,0);
1.326 - }
1.327 - if( maple_data[i].new_device != NULL ) {
1.328 - maple_attach_device(maple_data[i].new_device, i, 0 );
1.329 - }
1.330 - }
1.331 - }
1.332 - lxdream_save_config();
1.333 + int i;
1.334 + for( i=0; i<MAX_DEVICES; i++ ) {
1.335 + if( maple_data[i].new_device != maple_data[i].old_device ) {
1.336 + if( maple_data[i].old_device != NULL ) {
1.337 + maple_detach_device(i,0);
1.338 + }
1.339 + if( maple_data[i].new_device != NULL ) {
1.340 + maple_attach_device(maple_data[i].new_device, i, 0 );
1.341 + }
1.342 + }
1.343 + }
1.344 + lxdream_save_config();
1.345 } else {
1.346 - int i;
1.347 - for( i=0; i<MAX_DEVICES; i++ ) {
1.348 - if( maple_data[i].new_device != NULL &&
1.349 - maple_data[i].new_device != maple_data[i].old_device ) {
1.350 - maple_data[i].new_device->destroy(maple_data[i].new_device);
1.351 - }
1.352 - }
1.353 + int i;
1.354 + for( i=0; i<MAX_DEVICES; i++ ) {
1.355 + if( maple_data[i].new_device != NULL &&
1.356 + maple_data[i].new_device != maple_data[i].old_device ) {
1.357 + maple_data[i].new_device->destroy(maple_data[i].new_device);
1.358 + }
1.359 + }
1.360 }
1.361
1.362 }
1.363 @@ -279,34 +279,34 @@
1.364 const struct maple_device_class **devices = maple_get_device_classes();
1.365
1.366 for( i=0; i< MAX_DEVICES; i++ ) {
1.367 - char buf[12];
1.368 - GtkWidget *combo, *button;
1.369 - int active = 0;
1.370 - maple_device_t device = maple_get_device(i,0);
1.371 - sprintf( buf, _("Slot %d."), i );
1.372 - gtk_table_attach_defaults( GTK_TABLE(table), gtk_label_new(buf), 0, 1, i, i+1 );
1.373 - combo = gtk_combo_box_new_text();
1.374 - gtk_combo_box_append_text( GTK_COMBO_BOX(combo), _("<empty>") );
1.375 - for( j=0; devices[j] != NULL; j++ ) {
1.376 - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), devices[j]->name);
1.377 - if( device != NULL && device->device_class == devices[j] ) {
1.378 - active = j+1;
1.379 - }
1.380 - }
1.381 - gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active);
1.382 - gtk_table_attach_defaults( GTK_TABLE(table), combo, 1, 2, i, i+1 );
1.383 - button = gtk_button_new_from_stock( GTK_STOCK_PROPERTIES );
1.384 - gtk_widget_set_sensitive(button, active != 0 && device->get_config != NULL);
1.385 - gtk_table_attach_defaults( GTK_TABLE(table), button, 2, 3, i, i+1 );
1.386 + char buf[12];
1.387 + GtkWidget *combo, *button;
1.388 + int active = 0;
1.389 + maple_device_t device = maple_get_device(i,0);
1.390 + sprintf( buf, _("Slot %d."), i );
1.391 + gtk_table_attach_defaults( GTK_TABLE(table), gtk_label_new(buf), 0, 1, i, i+1 );
1.392 + combo = gtk_combo_box_new_text();
1.393 + gtk_combo_box_append_text( GTK_COMBO_BOX(combo), _("<empty>") );
1.394 + for( j=0; devices[j] != NULL; j++ ) {
1.395 + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), devices[j]->name);
1.396 + if( device != NULL && device->device_class == devices[j] ) {
1.397 + active = j+1;
1.398 + }
1.399 + }
1.400 + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active);
1.401 + gtk_table_attach_defaults( GTK_TABLE(table), combo, 1, 2, i, i+1 );
1.402 + button = gtk_button_new_from_stock( GTK_STOCK_PROPERTIES );
1.403 + gtk_widget_set_sensitive(button, active != 0 && device->get_config != NULL);
1.404 + gtk_table_attach_defaults( GTK_TABLE(table), button, 2, 3, i, i+1 );
1.405
1.406 - maple_data[i].old_device = device;
1.407 - maple_data[i].new_device = device;
1.408 - maple_data[i].combo = combo;
1.409 - maple_data[i].button = button;
1.410 - g_signal_connect( button, "clicked",
1.411 - G_CALLBACK( maple_properties_activated ), &maple_data[i] );
1.412 - g_signal_connect( combo, "changed",
1.413 - G_CALLBACK( maple_device_changed ), &maple_data[i] );
1.414 + maple_data[i].old_device = device;
1.415 + maple_data[i].new_device = device;
1.416 + maple_data[i].combo = combo;
1.417 + maple_data[i].button = button;
1.418 + g_signal_connect( button, "clicked",
1.419 + G_CALLBACK( maple_properties_activated ), &maple_data[i] );
1.420 + g_signal_connect( combo, "changed",
1.421 + G_CALLBACK( maple_device_changed ), &maple_data[i] );
1.422
1.423 }
1.424 return table;
.