… | |
… | |
61 | * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK |
61 | * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK |
62 | * n(the number of groups) = the number of non-zero member of hash_bucket_size[]; |
62 | * n(the number of groups) = the number of non-zero member of hash_bucket_size[]; |
63 | * Ni(the size of group i) = hash_bucket_size[Ii]. |
63 | * Ni(the size of group i) = hash_bucket_size[Ii]. |
64 | */ |
64 | */ |
65 | |
65 | |
66 | static void |
|
|
67 | output_string (rxvt_term *term, const char *str) |
|
|
68 | { |
|
|
69 | if (strncmp (str, "command:", 8) == 0) |
|
|
70 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
|
|
71 | else if (strncmp (str, "perl:", 5) == 0) |
|
|
72 | HOOK_INVOKE((term, HOOK_USER_COMMAND, DT_STR, str + 5, DT_END)); |
|
|
73 | else |
|
|
74 | term->tt_write (str, strlen (str)); |
|
|
75 | } |
|
|
76 | |
|
|
77 | // return: priority_of_a - priority_of_b |
66 | // return: priority_of_a - priority_of_b |
78 | static int |
67 | static int |
79 | compare_priority (keysym_t *a, keysym_t *b) |
68 | compare_priority (keysym_t *a, keysym_t *b) |
80 | { |
69 | { |
81 | // (the more '1's in state; the less range): the greater priority |
70 | // (the more '1's in state; the less range): the greater priority |
… | |
… | |
100 | delete keymap [i]; |
89 | delete keymap [i]; |
101 | } |
90 | } |
102 | } |
91 | } |
103 | |
92 | |
104 | void |
93 | void |
105 | keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) |
94 | keyboard_manager::register_action (KeySym keysym, unsigned int state, const wchar_t *ws) |
106 | { |
95 | { |
107 | char *translation = rxvt_wcstoutf8 (ws); |
96 | char *translation = rxvt_wcstoutf8 (ws); |
108 | |
97 | |
109 | keysym_t *key = new keysym_t; |
98 | keysym_t *key = new keysym_t; |
110 | |
99 | |
… | |
… | |
113 | key->str = translation; |
102 | key->str = translation; |
114 | key->type = keysym_t::STRING; |
103 | key->type = keysym_t::STRING; |
115 | |
104 | |
116 | if (strncmp (translation, "builtin:", 8) == 0) |
105 | if (strncmp (translation, "builtin:", 8) == 0) |
117 | key->type = keysym_t::BUILTIN; |
106 | key->type = keysym_t::BUILTIN; |
|
|
107 | else if (strncmp (translation, "builtin-string:", 15) == 0) |
|
|
108 | key->type = keysym_t::BUILTIN_STRING; |
118 | |
109 | |
119 | if (keymap.size () == keymap.capacity ()) |
110 | if (keymap.size () == keymap.capacity ()) |
120 | keymap.reserve (keymap.size () * 2); |
111 | keymap.reserve (keymap.size () * 2); |
121 | |
112 | |
122 | keymap.push_back (key); |
113 | keymap.push_back (key); |
… | |
… | |
141 | |
132 | |
142 | if (index >= 0) |
133 | if (index >= 0) |
143 | { |
134 | { |
144 | keysym_t *key = keymap [index]; |
135 | keysym_t *key = keymap [index]; |
145 | |
136 | |
|
|
137 | if (key->type == keysym_t::BUILTIN_STRING) |
|
|
138 | { |
|
|
139 | term->tt_write_user_input (kbuf, len); |
|
|
140 | return true; |
|
|
141 | } |
146 | if (key->type != keysym_t::BUILTIN) |
142 | else if (key->type != keysym_t::BUILTIN) |
147 | { |
143 | { |
148 | wchar_t *ws = rxvt_utf8towcs (key->str); |
144 | wchar_t *ws = rxvt_utf8towcs (key->str); |
149 | char *str = rxvt_wcstombs (ws); |
145 | char *str = rxvt_wcstombs (ws); |
150 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
146 | // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) |
151 | free (ws); |
147 | free (ws); |
152 | |
148 | |
153 | output_string (term, str); |
149 | if (char *colon = strchr (str, ':')) |
|
|
150 | { |
|
|
151 | if (strncmp (str, "command:", 8) == 0) |
|
|
152 | term->cmdbuf_append (str + 8, strlen (str) - 8); |
|
|
153 | else if (strncmp (str, "string:", 7) == 0) |
|
|
154 | term->tt_write_user_input (colon + 1, strlen (colon + 1)); |
|
|
155 | else if (strncmp (str, "perl:", 5) == 0) |
|
|
156 | HOOK_INVOKE ((term, HOOK_USER_COMMAND, DT_STR, colon + 1, DT_END)); |
|
|
157 | else |
|
|
158 | HOOK_INVOKE ((term, HOOK_ACTION, DT_STR_LEN, str, colon - str, DT_STR, colon + 1, DT_INT, 0, DT_STR_LEN, kbuf, len, DT_END)); |
|
|
159 | } |
|
|
160 | else |
|
|
161 | term->tt_write_user_input (str, strlen (str)); |
154 | |
162 | |
155 | free (str); |
163 | free (str); |
156 | |
164 | |
157 | return true; |
165 | return true; |
158 | } |
166 | } |