* Parse a key-combination/command-name pair, and * insert it into the bindings list. */
| 312 | * insert it into the bindings list. |
| 313 | */ |
| 314 | void Keys::parseKey(char *key, char *commandName) |
| 315 | { |
| 316 | char *p, *modstr, *keystr; |
| 317 | KeysCommand_t symcode; |
| 318 | int st, keymod = 0, keycode = 0; |
| 319 | |
| 320 | _MSG("Keys::parseKey key='%s' commandName='%s'\n", key, commandName); |
| 321 | |
| 322 | // Get command code |
| 323 | if ((symcode = getCmdCode(commandName)) == KEYS_INVALID) { |
| 324 | MSG("Keys::parseKey: Invalid command name: '%s'\n", commandName); |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | // Skip space |
| 329 | for ( ; isspace(*key); ++key) ; |
| 330 | // Get modifiers |
| 331 | while(*key == '<' && (p = strchr(key, '>'))) { |
| 332 | ++key; |
| 333 | modstr = dStrndup(key, p - key); |
| 334 | if ((st = getModifier(modstr)) == -1) { |
| 335 | MSG("Keys::parseKey unknown modifier: %s\n", modstr); |
| 336 | } else { |
| 337 | keymod |= st; |
| 338 | } |
| 339 | dFree(modstr); |
| 340 | key = p + 1; |
| 341 | } |
| 342 | // Allow trailing space after keyname |
| 343 | keystr = (*key && (p = strchr(key + 1, ' '))) ? dStrndup(key, p - key - 1) : |
| 344 | dStrdup(key); |
| 345 | // Get key code |
| 346 | if (!key[1]) { |
| 347 | keycode = *key; |
| 348 | } else if (a_Utf8_char_count(keystr, strlen(keystr)) == 1) { |
| 349 | const char *beyond = keystr + strlen(keystr); |
| 350 | keycode = a_Utf8_decode(keystr, beyond, NULL); |
| 351 | } else if (key[0] == '0' && key[1] == 'x') { |
| 352 | /* keysym */ |
| 353 | keycode = strtol(key, NULL, 0x10); |
| 354 | } else if ((st = getKeyCode(keystr)) == -1) { |
| 355 | MSG("Keys::parseKey unknown keyname: %s\n", keystr); |
| 356 | } else { |
| 357 | keycode = st; |
| 358 | } |
| 359 | dFree(keystr); |
| 360 | |
| 361 | // Set binding |
| 362 | if (keycode) { |
| 363 | delKeyCmd(keycode, keymod); |
| 364 | if (symcode != KEYS_NOP) { |
| 365 | KeyBinding_t *node = dNew(KeyBinding_t, 1); |
| 366 | node->name = dStrdup(commandName); |
| 367 | node->cmd = symcode; |
| 368 | node->modifier = keymod; |
| 369 | node->key = keycode; |
| 370 | dList_insert_sorted(bindings, node, nodeByKeyCmp); |
| 371 | _MSG("parseKey: Adding key=%d, mod=%d\n", node->key, node->modifier); |
nothing calls this directly
no test coverage detected