MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / InsertKey

Method InsertKey

KeyboardLayoutManager/KeyboardLayoutManager.cpp:490–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488}
489
490void KeyboardLayoutManager::InsertKey(keyboard_led ins_key)
491{
492 /*---------------------------------------------------------------------*\
493 | Get the insertion point |
494 \*---------------------------------------------------------------------*/
495 unsigned int ins_row = ins_key.row;
496 unsigned int ins_col = ins_key.col;
497 const char* ins_name = ins_key.name;
498
499 unsigned int key_idx = 0;
500
501 for(/*key_idx*/; key_idx < keymap.size(); key_idx++)
502 {
503 /*---------------------------------------------------------------------*\
504 | Search through all existing keys and determine where in the list to |
505 | insert the new key. Order is row first, then column. |
506 \*---------------------------------------------------------------------*/
507 if((ins_row < keymap[key_idx].row) || ((ins_row == keymap[key_idx].row) && (ins_col <= keymap[key_idx].col)))
508 {
509 break;
510 }
511 }
512
513 /*---------------------------------------------------------------------*\
514 | Determine whether to update row shift or not |
515 \*---------------------------------------------------------------------*/
516 bool update_row = true;
517
518 /*---------------------------------------------------------------------*\
519 | If the search reached the end, put the new key at the end of the list |
520 \*---------------------------------------------------------------------*/
521 if(key_idx == keymap.size())
522 {
523 LOG_DEBUG(LOG_MSG_INSERT_BEFORE, KLM_CLASS_NAME, ins_name, "the end", ins_row, ins_col, KEY_EN_UNUSED);
524 keymap.push_back(ins_key);
525 update_row = false;
526 }
527
528 /*---------------------------------------------------------------------*\
529 | If inserting an empty key in the middle of the list, the key entry is |
530 | not actually added. Instead, increment the col field of all keys on |
531 | the same row after the inserted key. |
532 \*---------------------------------------------------------------------*/
533 else if(strlen(ins_name) == 0)
534 {
535 LOG_DEBUG(LOG_MSG_INSERT_BEFORE, KLM_CLASS_NAME, LOG_MSG_UNUSED_KEY, keymap[key_idx].name, keymap[key_idx].row, keymap[key_idx].col, LOG_MSG_SHIFTING_RIGHT);
536 }
537 else
538 {
539 LOG_DEBUG(LOG_MSG_INSERT_BEFORE, KLM_CLASS_NAME, ins_name, keymap[key_idx].name, ins_row, ins_col, KEY_EN_UNUSED);
540 keymap.insert(keymap.begin() + key_idx, ins_key);
541 key_idx++;
542 }
543
544 /*---------------------------------------------------------------------*\
545 | If update_row is true, key at key_idx is not the end of the vector. |
546 | For the remaining keys, if the row is equal to the inserted key row, |
547 | shift 1 column right |

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected