1
1
char *rcsid_gtk2_keys_c =
2
"$Id: keys.c,v 1.7 2006/03/04 15:56:33 akirschbaum Exp $";
2
"$Id: keys.c 5010 2006-10-07 18:29:47Z qal21 $";
4
4
Crossfire client, a client program for the crossfire program.
68
68
static GtkListStore *keybinding_store;
69
69
static GtkTreeSelection *keybinding_selection;
71
/* Changed to KLIST_* to avoid conflicts in Win2000 and up */
72
LIST_ENTRY, LIST_KEY, LIST_MODS, LIST_EDIT, LIST_COMMAND, LIST_KEY_ENTRY
73
KLIST_ENTRY, KLIST_KEY, KLIST_MODS, KLIST_EDIT, KLIST_COMMAND, KLIST_KEY_ENTRY
75
76
GtkWidget *spinbutton_count;
321
322
/* Rest of the line is the actual command. Lets kill the newline */
322
323
cpnext[strlen(cpnext)-1]='\0';
323
if (strlen(cpnext)>(sizeof(bind_buf)-1)){
324
cpnext[sizeof(bind_buf)-1]='\0';
325
LOG(LOG_WARNING,"gtk::parse_keybind_line","Had to truncate a too long command");
324
if (strlen(cpnext)>(sizeof(bind_buf)-1)){
325
cpnext[sizeof(bind_buf)-1]='\0';
326
LOG(LOG_WARNING,"gtk::parse_keybind_line","Had to truncate a too long command");
327
329
insert_key(keysym, flags | standard, cpnext);
328
330
} /* else if not special binding line */
437
439
renderer = gtk_cell_renderer_text_new ();
438
440
column = gtk_tree_view_column_new_with_attributes ("Key", renderer,
441
gtk_tree_view_column_set_sort_column_id(column, LIST_KEY);
443
gtk_tree_view_column_set_sort_column_id(column, KLIST_KEY);
442
444
gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
444
446
renderer = gtk_cell_renderer_text_new ();
445
447
column = gtk_tree_view_column_new_with_attributes ("Modifiers", renderer,
448
gtk_tree_view_column_set_sort_column_id(column, LIST_MODS);
450
gtk_tree_view_column_set_sort_column_id(column, KLIST_MODS);
449
451
gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
451
453
renderer = gtk_cell_renderer_text_new ();
452
454
column = gtk_tree_view_column_new_with_attributes ("Edit Mode", renderer,
455
gtk_tree_view_column_set_sort_column_id(column, LIST_EDIT);
457
gtk_tree_view_column_set_sort_column_id(column, KLIST_EDIT);
456
458
gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
458
460
renderer = gtk_cell_renderer_text_new ();
459
461
column = gtk_tree_view_column_new_with_attributes ("Command", renderer,
460
"text", LIST_COMMAND,
462
"text", KLIST_COMMAND,
462
gtk_tree_view_column_set_sort_column_id(column, LIST_COMMAND);
464
gtk_tree_view_column_set_sort_column_id(column, KLIST_COMMAND);
463
465
gtk_tree_view_append_column (GTK_TREE_VIEW (keybinding_treeview), column);
547
549
Key_Entry *keyentry, *first_match=NULL;
548
550
int present_flags=0;
551
char buf[MAX_BUF], tmpbuf[MAX_BUF];
551
553
if (keysym==commandkeysym) {
552
554
gtk_widget_grab_focus (GTK_WIDGET(entry_commands));
635
637
gtk_spin_button_set_value (GTK_SPIN_BUTTON(spinbutton_count), (float) cpl.count );
638
sprintf(buf, "Key unused (%s%s%s)",
639
(cpl.fire_on? "Fire&": ""),
640
(cpl.run_on ? "Run&" : ""),
641
keysym==NoSymbol? "unknown": gdk_keyval_name(keysym));
641
if (cpl.fire_on) strcat(tmpbuf,"fire+");
642
if (cpl.run_on) strcat(tmpbuf,"run+");
643
if (cpl.alt_on) strcat(tmpbuf,"alt+");
644
if (cpl.meta_on) strcat(tmpbuf,"meta+");
646
sprintf(buf, "Key %s%s is not bound to any command. Use bind to associate this keypress with a command",
647
tmpbuf, keysym==NoSymbol? "unknown": gdk_keyval_name(keysym));
643
649
if ( ( 65513 != keysym ) && ( 65511 != keysym ) )
908
914
if (strlen(params) >= sizeof(bind_buf)) {
909
915
params[sizeof(bind_buf) - 1] = '\0';
910
draw_info("Keybinding too long! Truncated:",NDI_RED);
911
draw_info(params,NDI_RED);
916
draw_info("Keybinding too long! Truncated:",NDI_RED);
917
draw_info(params,NDI_RED);
913
919
sprintf(buf, "Push key to bind '%s'.", params);
914
920
draw_info(buf,NDI_BLACK);
1019
1025
static void configure_keys(uint32 keysym)
1021
1027
char buf[MAX_BUF];
1028
Key_Entry *keyentry, *first_match=NULL;
1023
1030
/* I think that basically if we are not rebinding the special
1024
1031
* control keys (in which case bind_kesym would be set to something)
1064
1071
bind_keysym=NULL;
1074
keyentry = keys[keysym % KEYHASH];
1075
while (keyentry!=NULL) {
1076
if ((keyentry->keysym!=0 && keyentry->keysym!=keysym) ||
1077
(!(keyentry->flags & bind_flags))) {
1078
keyentry=keyentry->next;
1081
first_match = keyentry;
1083
/* Try to find a prefect match */
1084
if ((keyentry->flags & KEYF_MODIFIERS)!= bind_flags) {
1085
keyentry=keyentry->next;
1091
sprintf(buf, "Warning: Keybind %s may conflict with new binding.", first_match->command);
1092
draw_info(buf,NDI_RED);
1067
1095
insert_key(keysym, bind_flags, bind_buf);
1158
1186
sprintf(buf,"Removed binding: %3d %s", count, get_key_info(key,0));
1160
1188
draw_info(buf,NDI_BLACK);
1161
if (key->command) free(key->command);
1439
1467
* it doesn't make much difference what widget this is set
1440
1468
* to, as long as it is something that can get focus.
1442
gtk_widget_grab_focus (GTK_WIDGET(textview_info1));
1470
gtk_widget_grab_focus (GTK_WIDGET(treeview_look));
1444
1472
if( cpl.input_state == Metaserver_Select)
1481
1509
if (key->flags & KEYF_STANDARD) strcat(modifier_buf,"(Standard) ");
1482
1510
gtk_list_store_append(keybinding_store, &iter);
1483
1511
gtk_list_store_set(keybinding_store, &iter,
1485
LIST_KEY, gdk_keyval_name(key->keysym),
1486
LIST_MODS, modifier_buf,
1487
LIST_EDIT, (key->flags & KEYF_EDIT) ? "Yes":"No",
1488
LIST_COMMAND, key->command,
1489
LIST_KEY_ENTRY, key,
1513
KLIST_KEY, gdk_keyval_name(key->keysym),
1514
KLIST_MODS, modifier_buf,
1515
KLIST_EDIT, (key->flags & KEYF_EDIT) ? "Yes":"No",
1516
KLIST_COMMAND, key->command,
1517
KLIST_KEY_ENTRY, key,
1562
1590
LOG(LOG_ERROR,"keys.c:on_keybinding_button_remove_clicked", "Function called with nothing selected\n");
1565
gtk_tree_model_get(model, &iter, LIST_KEY_ENTRY, &entry, -1);
1593
gtk_tree_model_get(model, &iter, KLIST_KEY_ENTRY, &entry, -1);
1566
1594
for (onkey=0; onkey<KEYHASH; onkey++) {
1567
1595
for (key=keys[onkey]; key; key =key->next) {
1568
1596
if (key == entry) {
1681
1709
const char *buf;
1683
1711
if (gtk_tree_selection_get_selected (keybinding_selection, &model, &iter)) {
1684
gtk_tree_model_get(model, &iter, LIST_KEY_ENTRY, &entry, -1);
1712
gtk_tree_model_get(model, &iter, KLIST_KEY_ENTRY, &entry, -1);
1687
1715
LOG(LOG_ERROR,"keys.c:on_keybinding_button_update_clicked", "Unable to get key_entry structure\n");
1690
if (entry->command) free(entry->command);
1718
free(entry->command);
1691
1719
keybinding_get_data(&entry->keysym, &entry->flags, &buf);
1692
1720
entry->command = strdup_local(buf);
1693
1721
update_keybinding_list();
1728
1756
if (gtk_tree_model_get_iter(model, &iter, path)) {
1730
gtk_tree_model_get(model, &iter, LIST_KEY_ENTRY, &entry, -1);
1758
gtk_tree_model_get(model, &iter, KLIST_KEY_ENTRY, &entry, -1);
1733
1761
LOG(LOG_ERROR,"keys.c:keybinding_selection_func", "Unable to get key_entry structure\n");