--- rxvt-unicode/src/keyboard.C 2005/02/06 15:18:01 1.11 +++ rxvt-unicode/src/keyboard.C 2005/02/24 13:01:01 1.13 @@ -8,6 +8,39 @@ #include "keyboard.h" #include "command.h" +/* an intro to the data structure: + * + * vector keymap[] is grouped. + * + * inside each group, elements are sorted by the criteria given by compare_priority(). + * the lookup of keysym is done in two steps: + * 1) locate the group corresponds to the keysym; + * 2) do a linear search inside the group. + * + * array hash[] effectively defines a map from a keysym to a group in keymap[]. + * + * each group has its address(the index of first group element in keymap[]), + * which is computed and stored in hash[]. + * hash[] stores the addresses in the form of: + * index: 0 I1 I2 I3 In + * value: 0...0, A1...A1, A2...A2, A3...A3, ..., An...An + * where + * A1 = 0; + * Ai+1 = N1 + N2 + ... + Ni. + * it is computed from hash_budget_size[]: + * index: 0 I1 I2 I3 In + * value: 0...0, N1, 0...0, N2, 0...0, N3, ..., Nn, 0...0 + * 0...0, 0.......0, N1.....N1, N1+N2...N1+N2, ... (the compution of hash[]) + * or we can say + * hash_budget_size[Ii] = Ni; hash_budget_size[elsewhere] = 0, + * where + * set {I1, I2, ..., In} = { hashkey of keymap[0]->keysym, ..., keymap[keymap.size-1]->keysym } + * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK + * n(the number of groups) = the number of non-zero member of hash_budget_size[]; + * Ni(the size of group i) = hash_budget_size[Ii]. + */ + +#if STOCK_KEYMAP //////////////////////////////////////////////////////////////////////////////// // default keycode translation map and keyevent handlers @@ -34,6 +67,7 @@ //{ '0', MetaMask|ControlMask, 10, keysym_t::RANGE, "0" "\033"}, //{ 'a', MetaMask|ControlMask, 26, keysym_t::RANGE, "a" "\033"}, }; +#endif static void output_string (rxvt_term *rt, const char *str) @@ -209,11 +243,14 @@ void keyboard_manager::register_done () { - unsigned int i, n = sizeof (stock_keymap) / sizeof (keysym_t); +#if STOCK_KEYMAP + int n = sizeof (stock_keymap) / sizeof (keysym_t); - if (keymap.back () != &stock_keymap[n - 1]) - for (i = 0; i < n; ++i) + //TODO: shield against repeated calls and empty keymap + //if (keymap.back () != &stock_keymap[n - 1]) + for (int i = 0; i < n; ++i) register_keymap (&stock_keymap[i]); +#endif purge_duplicate_keymap ();