2 "$Id: keys.c 10997 2008-12-17 03:36:53Z kbulgrien $";
46 #include <gdk/gdkwin32.h>
51 #include <gdk/gdkkeysyms.h>
92 #define KEYF_NORMAL 0x01
93 #define KEYF_FIRE 0x02
95 #define KEYF_MODIFIERS 0x07
97 #define KEYF_EDIT 0x08
98 #define KEYF_STANDARD 0x10
124 if (keys[slot]==NULL) {
127 keys[slot]->
next=NULL;
131 while (newkey->
next!=NULL)
132 newkey = newkey->
next;
134 newkey = newkey->
next;
164 if (buf[0]==
'#' || buf[0]==
'\n')
return;
165 if ((cpnext = strchr(buf,
' '))==NULL) {
166 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line,buf);
172 while (*cpnext ==
' ') ++cpnext;
173 cp = strchr(cpnext,
' ');
175 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line,buf);
179 cp1 = strchr(cp,
' ');
181 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line,buf);
185 keysym = gdk_keyval_from_name(cp);
188 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Could not convert %s into keysym", cp);
191 if (!strcmp(cpnext,
"commandkey")) {
195 if (!strcmp(cpnext,
"firekey0")) {
199 if (!strcmp(cpnext,
"firekey1")) {
203 if (!strcmp(cpnext,
"runkey0")) {
207 if (!strcmp(cpnext,
"runkey1")) {
211 if (!strcmp(cpnext,
"completekey")) {
215 if (!strcmp(cpnext,
"nextkey")) {
219 if (!strcmp(cpnext,
"prevkey")) {
228 keysym = gdk_keyval_from_name(buf);
230 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Unable to convert line %d (%s) into keysym", line, cp);
234 if ((cpnext = strchr(cp,
' '))==NULL) {
235 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line, cp);
241 if ((cpnext = strchr(cp,
' '))==NULL) {
242 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Line %d (%s) corrupted in keybinding file.", line, cp);
268 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Unknown flag (%c) line %d in key binding file",
275 cpnext[strlen(cpnext)-1]=
'\0';
276 if (strlen(cpnext)>(
sizeof(
bind_buf)-1)){
278 LOG(
LOG_WARNING,
"gtk::parse_keybind_line",
"Had to truncate a too long command");
290 for(i=0;i<
sizeof(
def_keys)/
sizeof(
char *);i++) {
307 static int was_init = 0;
327 if ( was_init && keys[i] )
363 sprintf( buf,
"%s/.crossfire/%s.keys", getenv(
"HOME" ),
cpl.
name );
364 if ( access( buf, 0 ) == -1 )
367 sprintf(buf,
"%s/.crossfire/keys", getenv(
"HOME"));
371 sprintf(buf,
"%s/.crossfire/keys", getenv(
"HOME"));
373 sprintf(buf,
"%s/.crossfire/keys", getenv(
"HOME"));
375 if ((fp=fopen(buf,
"r"))==NULL) {
376 LOG(
LOG_INFO,
"gtk::init_keys",
"Could not open ~/.crossfire/keys, trying to load global bindings");
382 if ((fp=fopen(buf,
"r"))==NULL) {
387 while (fgets(buf,
BIG_BUF, fp)) {
423 gtk_label_set (GTK_LABEL(
run_label),
" ");
446 gtk_widget_grab_focus (GTK_WIDGET(
entrytext));
448 gtk_widget_grab_focus (GTK_WIDGET(
entrytext));
451 gtk_entry_set_visibility(GTK_ENTRY(
entrytext), 1);
463 gtk_label_set (GTK_LABEL(
run_label),
"Run");
469 if (present_flags ==0) present_flags =
KEYF_NORMAL;
471 keyentry = keys[keysym %
KEYHASH];
472 while (keyentry!=NULL) {
473 if ((keyentry->
keysym!=0 && keyentry->
keysym!=keysym) ||
474 (!(keyentry->
flags & present_flags))) {
475 keyentry=keyentry->
next;
478 first_match = keyentry;
482 keyentry=keyentry->
next;
487 if (first_match!=NULL) {
492 gtk_widget_grab_focus (GTK_WIDGET(
entrytext));
501 sprintf(buf,
"fire %s", first_match->
command);
508 sprintf(buf,
"run %s", first_match->
command);
521 if (key>=
'0' && key<=
'9') {
527 sprintf(buf,
"Key unused (%s%s%s)",
530 keysym==NoSymbol?
"unknown": gdk_keyval_name(keysym));
532 if ( ( 65513 != keysym ) && ( 65511 != keysym ) )
571 if(key->
keysym == NoSymbol) {
572 sprintf(buf,
"(null) %i %s %s",
576 sprintf(buf,
"%s %i %s %s",
577 gdk_keyval_name(key->
keysym), 0,
582 if(key->
keysym == NoSymbol) {
583 sprintf(buf,
"key (null) %s %s",
587 sprintf(buf,
"key %s %s %s",
588 gdk_keyval_name(key->
keysym),
605 sprintf(buf,
"Commandkey %s",
609 sprintf(buf,
"Firekeys 1: %s, 2: %s",
614 sprintf(buf,
"Runkeys 1: %s, 2: %s",
619 sprintf(buf,
"Command Completion Key %s",
623 sprintf(buf,
"Next Command in History Key %s",
627 sprintf(buf,
"Previous Command in History Key %s",
636 for (key=keys[i]; key!=NULL; key =key->
next) {
654 draw_info(
"Usage: bind [-nfre] {<commandline>/commandkey/firekey{1/2}/runkey{1/2}/",
NDI_BLACK);
660 while (*params==
' ') params++;
662 if (!strcmp(params,
"commandkey")) {
669 if (!strcmp(params,
"firekey1")) {
675 if (!strcmp(params,
"firekey2")) {
681 if (!strcmp(params,
"runkey1")) {
688 if (!strcmp(params,
"runkey2")) {
695 if (!strcmp(params,
"completekey")) {
702 if (!strcmp(params,
"prevkey")) {
709 if (!strcmp(params,
"nextkey")) {
717 if (params[0] !=
'-')
722 for (params++; *params !=
' '; params++)
740 sprintf(buf,
"Unknown flag to bind: '%c'", *params);
761 if (strlen(params) >=
sizeof(
bind_buf)) {
766 sprintf(buf,
"Push key to bind '%s'.",
bind_buf);
783 if (key==NULL)
return;
797 sprintf( buf,
"%s/.crossfire/%s.keys", getenv(
"HOME"),
cpl.
name );
799 sprintf( buf,
"%s/.crossfire/keys", getenv(
"HOME") );
801 sprintf(buf,
"%s/.crossfire/keys", getenv(
"HOME"));
808 if ((fp=fopen(buf,
"w"))==NULL) {
809 sprintf(buf2,
"Could not open %s, key bindings not saved\n", buf);
814 fprintf(fp,
"! commandkey %s %d\n",
818 fprintf(fp,
"! firekey0 %s %d\n",
822 fprintf(fp,
"! firekey1 %s %d\n",
826 fprintf(fp,
"! runkey0 %s %d\n",
830 fprintf(fp,
"! runkey1 %s %d\n",
834 fprintf(fp,
"! completekey %s %d\n",
839 fprintf(fp,
"! nextkey %s %d\n",
843 fprintf(fp,
"! prevkey %s %d\n",
895 sprintf(buf,
"Binded to key '%s' (%i)",
896 keysym==NoSymbol?
"unknown":gdk_keyval_name(keysym), keysym);
920 int count=0, keyentry, onkey,global=0;
927 if (params==NULL || params[0]==
'\0') {
933 while (*params==
' ') params++;
935 if (!strcmp(params,
"-a")) {
939 if (!strncmp(params,
"-g",2)) {
941 if (!(params=strchr(params,
' '))) {
946 if ((keyentry=atoi(params))==0) {
951 for (onkey=0; onkey<
KEYHASH; onkey++) {
952 for (key=keys[onkey]; key; key =key->
next) {
955 if (keyentry==count) {
958 if (key == keys[onkey]) {
959 keys[onkey] = key->
next;
965 for (tmp=keys[onkey]; tmp->
next!=NULL; tmp=tmp->
next) {
966 if (tmp->
next == key) {
971 LOG(
LOG_ERROR,
"gtk::unbind_key",
"found number entry, but could not find actual key");
986 sprintf(buf,
"Removed binding: %3d %s", count,
get_key_info(key,0));
998 if (event->keyval>0) {
1002 gtk_signal_emit_stop_by_name (GTK_OBJECT(window),
"key_release_event") ;
1020 text=gdk_keyval_name(event->keyval);
1023 gtk_signal_emit_stop_by_name(GTK_OBJECT(window),
"key_press_event");
1028 gtk_widget_event(GTK_WIDGET(
entrytext), (GdkEvent*)event);
1029 gtk_signal_emit_stop_by_name(
1030 GTK_OBJECT(window),
"key_press_event");
1032 gtk_widget_grab_focus(GTK_WIDGET(
entrytext));
1038 if (event->keyval<=0)
return;
1040 if (GTK_WIDGET_HAS_FOCUS (
entrytext) ) {
1049 gtk_widget_event(GTK_WIDGET(
entrytext), (GdkEvent*)event);
1050 gtk_signal_emit_stop_by_name(GTK_OBJECT(window),
"key_press_event");
1065 if (!(event->state & GDK_CONTROL_MASK)) {
1067 gtk_label_set (GTK_LABEL(
run_label),
" ");
1073 if (!(event->state & GDK_SHIFT_MASK)) {
1081 if( (event->state & GDK_CONTROL_MASK) && (event->state & GDK_SHIFT_MASK) &&
1082 (event->keyval == GDK_i || event->keyval == GDK_I) ) {
1087 parse_key(event->string[0], event->keyval);
1088 gtk_signal_emit_stop_by_name (GTK_OBJECT(window),
"key_press_event") ;
1093 gtk_signal_emit_stop_by_name (GTK_OBJECT(window),
"key_press_event") ;
1101 gtk_widget_grab_focus (GTK_WIDGET(
entrytext));
1107 gtk_widget_event(GTK_WIDGET(
entrytext), (GdkEvent*)event);
1113 gtk_signal_emit_stop_by_name (GTK_OBJECT(window),
"key_press_event") ;
1117 gtk_widget_grab_focus (GTK_WIDGET(
entrytext));
1139 gtk_clist_clear (GTK_CLIST(keylist));
1141 for (key=keys[i]; key!=NULL; key =key->
next) {
1163 if(key->
keysym != NoSymbol) {
1164 sprintf(buffer[0],
"%i",count);
1165 sprintf(buffer[1],
"%s", gdk_keyval_name(key->
keysym));
1166 sprintf(buffer[2],
"%i",i);
1167 sprintf(buffer[3],
"%s",buff);
1168 sprintf(buffer[4],
"%s", key->
command);
1169 buffers[0] = buffer[0];
1170 buffers[1] = buffer[1];
1171 buffers[2] = buffer[2];
1172 buffers[3] = buffer[3];
1173 buffers[4] = buffer[4];
1174 tmprow = gtk_clist_append (GTK_CLIST (keylist), buffers);
1183 const gchar *entry_text;
1184 const gchar *cpnext;
1185 const gchar *mod=
"";
1193 if (!strcmp(mod,
"F")) {
1196 else if (!strcmp(mod,
"R")) {
1199 else if (!strcmp(mod,
"A")) {
1203 cpnext = gtk_entry_get_text (GTK_ENTRY(
ckentrytext));
1206 keysym = gdk_keyval_from_name(entry_text);
1210 sprintf(buf,
"Binded to key '%s' (%i)", gdk_keyval_name(keysym), 0);
1217 node = GTK_CLIST(
cclist)->selection;
1227 gtk_clist_get_text (GTK_CLIST(
cclist), (gint)node->data, 0, &buf);
1234 gtk_entry_set_text (GTK_ENTRY(
ckeyentrytext), gdk_keyval_name(event->keyval));
1236 switch (event->state) {
1237 case GDK_CONTROL_MASK:
1240 case GDK_SHIFT_MASK:
1247 gtk_signal_emit_stop_by_name (GTK_OBJECT(window),
"key_press_event");
1253 gtk_entry_set_text (GTK_ENTRY(
ckeyentrytext),
"Press key to bind here");
static void insert_key(uint32 keysym, int flags, const char *command)
static uint32 firekeysym[2]
void bind_callback(GtkWidget *gtklist, GdkEventButton *event)
void unbind_key(const char *params)
void gtk_command_history(int direction)
snd_pcm_hw_params_t * params
static void parse_key_release(uint32 ks)
int make_path_to_file(char *filename)
static GtkWidget * fire_label
const char *const rcsid_gtk_keys_c
GtkWidget * ckeyentrytext
static void configure_keys(uint32 keysym)
void ckeyunbind(GtkWidget *gtklist, GdkEventButton *event)
const char *const directions[9]
void draw_keybindings(GtkWidget *keylist)
void LOG(LogLevel level, const char *origin, const char *format,...)
void gtk_complete_command(void)
static char * get_key_info(Key_Entry *key, int save_mode)
void draw_message_window(int redraw)
static uint32 * bind_keysym
sint16 use_config[CONFIG_NUMS]
static void save_keys(void)
const char *const def_keys[]
static void save_individual_key(FILE *fp, Key_Entry *key, KeyCode kc)
GtkWidget * cnumentrytext
void extended_command(const char *ocommand)
static void unbind_usage(void)
static uint32 cancelkeysym
void send_reply(const char *text)
static void show_keys(int allbindings)
static GtkWidget * run_label
static uint32 commandkeysym
static Key_Entry * keys[KEYHASH]
char * strdup_local(const char *str)
void keyrelfunc(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
static uint32 completekeysym
static void parse_keybind_line(char *buf, int line, int standard)
void bind_key(const char *params)
static void parse_key(char key, uint32 keysym)
void ckeyentry_callback(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
static char bind_buf[MAX_BUF]
void disconnect(GtkWidget *)
void draw_info(const char *str, int color)
static void init_default_keybindings(void)
static uint32 runkeysym[2]
GtkWidget * cmodentrytext
void keyfunc(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)