Index: src_plugins/hid_gtk/ghid-main-menu.c =================================================================== --- src_plugins/hid_gtk/ghid-main-menu.c (revision 1487) +++ src_plugins/hid_gtk/ghid-main-menu.c (revision 1488) @@ -43,7 +43,7 @@ gint n_route_styles; GCallback action_cb; - void (*special_key_cb) (const char *accel, GtkAction * action, const lht_node_t * node); + void (*special_key_cb) (hid_cfg_mod_t mods, const char *accel, GtkAction * action, const lht_node_t * node); }; struct _GHidMainMenuClass { @@ -65,6 +65,7 @@ * gtk source distribution) to figure out the names that go with the * codes. */ +#if 0 static gchar *translate_accelerator(const char *text) { GString *ret_val = g_string_new(""); @@ -128,30 +129,22 @@ } return g_string_free(ret_val, FALSE); } +#endif -/*! \brief Check that translated accelerators are unique; warn otherwise. */ -static const char *check_unique_accel(const char *accelerator) +void ghid_main_menu_real_add_resource(GHidMainMenu * menu, GtkMenuShell * shell, const lht_node_t * res, const char *path); + +#warning remove this function? +static void note_accelerator(const char *acc, const lht_node_t *node) { - static GHashTable *accel_table; - - if (!accelerator || *accelerator) - return accelerator; - - if (!accel_table) - accel_table = g_hash_table_new(g_str_hash, g_str_equal); - - if (g_hash_table_lookup(accel_table, accelerator)) { - Message(_("Duplicate accelerator found: \"%s\"\n" "The second occurance will be dropped\n"), accelerator); - return NULL; - } - - g_hash_table_insert(accel_table, (gpointer) accelerator, (gpointer) accelerator); - - return accelerator; + lht_node_t *anode; + assert(node != NULL); + anode = hid_cfg_menu_field(node, MF_ACTION, NULL); + if (anode != NULL) + hid_cfg_keys_add_by_desc(&ghid_keymap, acc, anode, NULL, 0); + else + hid_cfg_error(node, "No action specified for key accel\n"); } -void ghid_main_menu_real_add_resource(GHidMainMenu * menu, GtkMenuShell * shell, const lht_node_t * res, const char *path); - static GtkAction *ghid_add_menu(GHidMainMenu * menu, GtkMenuShell * shell, const lht_node_t * sub_res, const char *path) { const char *tmp_val; @@ -165,8 +158,8 @@ /* Resolve accelerator */ tmp_val = hid_cfg_menu_field_str(sub_res, MF_ACCELERATOR); - if (tmp_val) - accel = check_unique_accel(translate_accelerator(tmp_val)); + if (tmp_val != NULL) + note_accelerator(tmp_val, sub_res); /* Resolve the mnemonic */ tmp_val = hid_cfg_menu_field_str(sub_res, MF_MNEMONIC); @@ -244,7 +237,7 @@ if (action) { GtkWidget *item; gtk_action_set_accel_group(action, menu->accel_group); - gtk_action_group_add_action_with_accel(menu->action_group, action, accel); +// gtk_action_group_add_action_with_accel(menu->action_group, action, accel); gtk_action_connect_accelerator(action); g_signal_connect(G_OBJECT(action), "activate", menu->action_cb, (gpointer) n_action); g_object_set_data(G_OBJECT(action), "resource", (gpointer) sub_res); @@ -251,7 +244,7 @@ item = gtk_action_create_menu_item(action); gtk_menu_shell_append(shell, item); menu->actions = g_list_append(menu->actions, action); - menu->special_key_cb(accel, action, n_action); +// menu->special_key_cb(mods, accel, action, n_action); } /* keep npath for the hash so do not free(npath); */ @@ -358,8 +351,7 @@ * * \return a freshly-allocated GHidMainMenu */ -GtkWidget *ghid_main_menu_new(GCallback action_cb, - void (*special_key_cb) (const char *accel, GtkAction * action, const lht_node_t * node)) +GtkWidget *ghid_main_menu_new(GCallback action_cb, void (*special_key_cb) (hid_cfg_mod_t mods, const char *accel, GtkAction * action, const lht_node_t * node)) { GHidMainMenu *mm = g_object_new(GHID_MAIN_MENU_TYPE, NULL); Index: src_plugins/hid_gtk/ghid-main-menu.h =================================================================== --- src_plugins/hid_gtk/ghid-main-menu.h (revision 1487) +++ src_plugins/hid_gtk/ghid-main-menu.h (revision 1488) @@ -8,6 +8,7 @@ #include "ghid-layer-selector.h" #include "ghid-route-style-selector.h" #include "hid_cfg.h" +#include "hid_cfg_input.h" G_BEGIN_DECLS /* keep c++ happy */ #define GHID_MAIN_MENU_TYPE (ghid_main_menu_get_type ()) @@ -20,7 +21,7 @@ GType ghid_main_menu_get_type(void); GtkWidget *ghid_main_menu_new(GCallback action_cb, - void (*special_key_cb) (const char *accel, GtkAction * action, const lht_node_t * node)); + void (*special_key_cb) (hid_cfg_mod_t mods, const char *accel, GtkAction * action, const lht_node_t * node)); void ghid_main_menu_add_resource(GHidMainMenu * menu, const lht_node_t * res); GtkAccelGroup *ghid_main_menu_get_accel_group(GHidMainMenu * menu); void ghid_main_menu_update_toggle_state(GHidMainMenu * menu, Index: src_plugins/hid_gtk/gui-output-events.c =================================================================== --- src_plugins/hid_gtk/gui-output-events.c (revision 1487) +++ src_plugins/hid_gtk/gui-output-events.c (revision 1488) @@ -165,107 +165,35 @@ * menu code to ever see it. We capture those here (like Tab and the * arrow keys) and feed it back to the normal menu callback. */ - gboolean ghid_port_key_press_cb(GtkWidget * drawing_area, GdkEventKey * kev, gpointer data) { - ModifierKeysState mk; - gint ksym = kev->keyval; - gboolean handled; - extern void ghid_hotkey_cb(int); - GdkModifierType state; + if (kev->keyval <= 0xffff) { + GdkModifierType state = (GdkModifierType) (kev->state); + int slen, mods = 0; + static hid_cfg_keyseq_t *seq[32]; + static int seq_len = 0; + extern void ghid_hotkey_cb(int); + unsigned short int kv = kev->keyval; - if (ghid_is_modifier_key_sym(ksym)) ghid_note_event_location(NULL); - state = (GdkModifierType) (kev->state); - mk = ghid_modifier_keys_state(&state); - - handled = TRUE; /* Start off assuming we handle it */ - switch (ksym) { - case GDK_Alt_L: - case GDK_Alt_R: - case GDK_Control_L: - case GDK_Control_R: - case GDK_Shift_L: - case GDK_Shift_R: - case GDK_Shift_Lock: - case GDK_ISO_Level3_Shift: - break; - - case GDK_Up: - ghid_hotkey_cb(GHID_KEY_UP); - break; - - case GDK_Down: - ghid_hotkey_cb(GHID_KEY_DOWN); - break; - case GDK_Left: - ghid_hotkey_cb(GHID_KEY_LEFT); - break; - case GDK_Right: - ghid_hotkey_cb(GHID_KEY_RIGHT); - break; - - case GDK_ISO_Left_Tab: - case GDK_3270_BackTab: - switch (mk) { - case NONE_PRESSED: - ghid_hotkey_cb(GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case CONTROL_PRESSED: - ghid_hotkey_cb(GHID_KEY_CONTROL | GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case MOD1_PRESSED: - ghid_hotkey_cb(GHID_KEY_ALT | GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case SHIFT_PRESSED: - ghid_hotkey_cb(GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case SHIFT_CONTROL_PRESSED: - ghid_hotkey_cb(GHID_KEY_CONTROL | GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case SHIFT_MOD1_PRESSED: - ghid_hotkey_cb(GHID_KEY_ALT | GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - - default: - handled = FALSE; - break; + if (state & GDK_MOD1_MASK) mods |= M_Alt; + if (state & GDK_CONTROL_MASK) mods |= M_Ctrl; + if (state & GDK_SHIFT_MASK) { + mods |= M_Shift; + if ((kv >= 'A') && (kv <= 'Z')) + kv = tolower(kv); } - break; - case GDK_Tab: - switch (mk) { - case NONE_PRESSED: - ghid_hotkey_cb(GHID_KEY_TAB); - break; - case CONTROL_PRESSED: - ghid_hotkey_cb(GHID_KEY_CONTROL | GHID_KEY_TAB); - break; - case MOD1_PRESSED: - ghid_hotkey_cb(GHID_KEY_ALT | GHID_KEY_TAB); - break; - case SHIFT_PRESSED: - ghid_hotkey_cb(GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case SHIFT_CONTROL_PRESSED: - ghid_hotkey_cb(GHID_KEY_CONTROL | GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - case SHIFT_MOD1_PRESSED: - ghid_hotkey_cb(GHID_KEY_ALT | GHID_KEY_SHIFT | GHID_KEY_TAB); - break; - - default: - handled = FALSE; - break; + slen = hid_cfg_keys_input(&ghid_keymap, mods, kv, seq, &seq_len); + if (slen > 0) { + ghid_port.has_entered = 1; + hid_cfg_keys_action(seq, slen); + return TRUE; } - break; - - default: - handled = FALSE; } - return handled; + return FALSE; } static hid_cfg_mod_t ghid_mouse_button(int ev_button) Index: src_plugins/hid_gtk/gui-top-window.c =================================================================== --- src_plugins/hid_gtk/gui-top-window.c (revision 1487) +++ src_plugins/hid_gtk/gui-top-window.c (revision 1488) @@ -117,6 +117,7 @@ hid_cfg_t *ghid_cfg = NULL; hid_cfg_mouse_t ghid_mouse; +hid_cfg_keys_t ghid_keymap; static gchar *bg_image_file; @@ -1508,9 +1509,26 @@ ghidgui->creating = TRUE; } +static short int ghid_translate_key(char *desc, int len) +{ + guint key = gdk_keyval_from_name(desc); + if (key > 0xffff) { + Message("Ignoring invalid/exotic key sym: '%s'\n", desc); + return 0; + } + return key; +} + + void ghid_do_export(HID_Attr_Val * options) { gtkhid_begin(); + + hid_cfg_keys_init(&ghid_keymap); + ghid_keymap.translate_key = ghid_translate_key; + ghid_keymap.auto_chr = 1; + ghid_keymap.auto_tr = hid_cfg_key_default_trans; + ghid_create_pcb_widgets(); /* These are needed to make sure the @layerpick and @layerview menus @@ -1529,6 +1547,7 @@ gtk_main(); ghid_config_files_write(); + hid_cfg_keys_uninit(&ghid_keymap); gtkhid_end(); } @@ -1685,11 +1704,9 @@ * into the menu callbacks. This function is called as new * accelerators are added when the menus are being built */ - static void - ghid_check_special_key(const char *accel, GtkAction * action, const lht_node_t * node) +static void ghid_check_special_key(hid_cfg_mod_t mods, const char *accel, GtkAction * action, const lht_node_t * node) { size_t len; - unsigned int mods; unsigned int ind; if (action == NULL || accel == NULL || *accel == '\0') @@ -1699,18 +1716,6 @@ printf("%s(\"%s\", \"%s\")\n", __FUNCTION__, accel, name); #endif - mods = 0; - if (strstr(accel, "")) { - mods |= GHID_KEY_ALT; - } - if (strstr(accel, "")) { - mods |= GHID_KEY_CONTROL; - } - if (strstr(accel, "")) { - mods |= GHID_KEY_SHIFT; - } - - len = strlen(accel); #define CHECK_KEY(a) ((len >= strlen (a)) && (strcmp (accel + len - strlen (a), (a)) == 0)) Index: src_plugins/hid_gtk/gui.h =================================================================== --- src_plugins/hid_gtk/gui.h (revision 1487) +++ src_plugins/hid_gtk/gui.h (revision 1488) @@ -81,16 +81,12 @@ /* The modifier keys */ -#define GHID_KEY_ALT 0x80 -#define GHID_KEY_CONTROL 0x40 -#define GHID_KEY_SHIFT 0x20 - /* The actual keys */ -#define GHID_KEY_TAB 0x01 -#define GHID_KEY_UP 0x02 -#define GHID_KEY_DOWN 0x03 -#define GHID_KEY_LEFT 0x04 -#define GHID_KEY_RIGHT 0x05 +#define GHID_KEY_TAB 0x81 +#define GHID_KEY_UP 0x82 +#define GHID_KEY_DOWN 0x83 +#define GHID_KEY_LEFT 0x84 +#define GHID_KEY_RIGHT 0x85 typedef struct { GtkActionGroup *main_actions, *change_selected_actions, *displayed_name_actions; @@ -515,5 +511,6 @@ extern const char *ghid_cookie; extern hid_cfg_mouse_t ghid_mouse; +extern hid_cfg_keys_t ghid_keymap; #endif /* PCB_HID_GTK_GHID_GUI_H */